StrSplit
Description
Split s into a vector of new Str objects delimited by key. Each returned Str owns its own storage and is independently modifiable. Use when callers will further mutate the pieces.
Two call shapes via _Generic on key: StrSplit(s, key) – key is Str * or Zstr.
Parameters
| Name | Direction | Description |
|---|---|---|
s |
in | Str to split. |
key |
in | Delimiter (Str * / Zstr). |
Success
Returns a non-empty Strs vector. Caller owns the vector and must VecDeinit it; that releases each contained Str as well. s is not modified.
Failure
Returns a zero-length Strs vector. s is not modified.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Str.Ops.c:203:
// Test string split functions
bool test_str_split(void) {
WriteFmt("Testing StrSplit and StrSplitToIters\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Str.Ops.c:209:
// Test StrSplit
Str s = StrInitFromZstr("Hello,World,Test", &alloc);
Strs split = StrSplit(&s, ",");
bool result = (VecLen(&split) == 3);
Last updated on