StrInitFromCstrAlloc
Description
Initialize a Str from a C string buffer using an explicit allocator.
Parameters
| Name | Direction | Description |
|---|---|---|
cstr |
in | Source character buffer. |
len |
in | Number of bytes to copy from cstr. |
alloc |
in | Allocator to bind to the returned string. |
Success
Returns a fully initialized Str whose first len bytes are a copy of cstr, with capacity for at least len + 1 bytes and alloc bound as the string’s allocator.
Failure
Returns an empty Str (length 0, capacity 0, data NULL, allocator still bound) when allocation fails. Use StrTryInitFromCstrAlloc if you need explicit failure propagation.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Str.c:39:
}
Str StrInitFromCstrAlloc(const char *cstr, size len, Allocator alloc) {
Str result = StrInit(alloc);- In
Init.h:114:
#define STR_INIT_FROM_CSTR_HAS_ARGS(...) STR_INIT_FROM_CSTR_HAS_ARGS_IMPL(__VA_ARGS__, 3, 2, 1, 0)
#define StrInitFromCstr(...) CONCAT(StrInitFromCstr_, STR_INIT_FROM_CSTR_HAS_ARGS(__VA_ARGS__))(__VA_ARGS__)
#define StrInitFromCstr_2(cstr, len) StrInitFromCstrAlloc((cstr), (len), DefaultAllocator())
#define StrInitFromCstr_3(cstr, len, alloc) StrInitFromCstrAlloc((cstr), (len), (alloc))- In
Init.h:115:
#define StrInitFromCstr(...) CONCAT(StrInitFromCstr_, STR_INIT_FROM_CSTR_HAS_ARGS(__VA_ARGS__))(__VA_ARGS__)
#define StrInitFromCstr_2(cstr, len) StrInitFromCstrAlloc((cstr), (len), DefaultAllocator())
#define StrInitFromCstr_3(cstr, len, alloc) StrInitFromCstrAlloc((cstr), (len), (alloc))
///
Last updated on