| 223 ## Basic Splitting |
223 ## Basic Splitting |
| 224 |
224 |
| 225 ```C |
225 ```C |
| 226 #include <cx/string.h> |
226 #include <cx/string.h> |
| 227 |
227 |
| 228 size_t cx_strsplit(cxstring string, AnyStr delim, |
228 size_t cx_strsplit(UcxStr string, AnyStr delim, |
| 229 size_t limit, cxstring *output); |
229 size_t limit, UcxStr *output); |
| 230 |
230 |
| 231 size_t cx_strsplit_a(const CxAllocator *allocator, |
231 size_t cx_strsplit_a(const CxAllocator *allocator, |
| 232 cxstring string, AnyStr delim, |
232 UcxStr string, AnyStr delim, |
| 233 size_t limit, cxstring **output); |
233 size_t limit, UcxStr **output); |
| 234 |
|
| 235 size_t cx_strsplit_m(cxmutstr string, AnyStr delim, |
|
| 236 size_t limit, cxmutstr *output); |
|
| 237 |
|
| 238 size_t cx_strsplit_ma(const CxAllocator *allocator, |
|
| 239 cxmutstr string, AnyStr delim, |
|
| 240 size_t limit, cxmutstr **output); |
|
| 241 ``` |
234 ``` |
| 242 |
235 |
| 243 The `cx_strsplit()` function splits the input `string` using the specified delimiter `delim` |
236 The `cx_strsplit()` function splits the input `string` using the specified delimiter `delim` |
| 244 and writes the substrings into the pre-allocated `output` array. |
237 and writes the substrings into the pre-allocated `output` array. |
| 245 The maximum number of resulting strings can be specified with `limit`. |
238 The maximum number of resulting strings can be specified with `limit`. |
| 247 The function returns the actual number of items written to `output`. |
240 The function returns the actual number of items written to `output`. |
| 248 |
241 |
| 249 On the other hand, `cx_strsplit_a()` uses the specified `allocator` to allocate the output array, |
242 On the other hand, `cx_strsplit_a()` uses the specified `allocator` to allocate the output array, |
| 250 and writes the pointer to the allocated memory to `output`. |
243 and writes the pointer to the allocated memory to `output`. |
| 251 |
244 |
| 252 The functions `cx_strsplit_m()` and `cx_strsplit_ma()` are equivalent to `cx_strsplit()` and `cx_strsplit_a()`, |
245 > The type of the `UcxStr` must the same for `string` and `output` (i.e., either both `cxstring` or both `cxmutstr`). |
| 253 except that they work on `cxmustr` instead of `cxstring`. |
246 > {style="note"} |
| 254 |
247 |
| 255 > The `allocator` in `cx_strsplit_a()` and `cx_strsplit_ma()` is _only_ used to allocate the output array. |
248 > The `allocator` in `cx_strsplit_a()` is _only_ used to allocate the output array. |
| 256 > The strings will always point into the original `string` |
249 > The strings will always point into the original `string` |
| 257 > and you need to use `cx_strdup()` or `cx_strdup_a()` if you want copies or zero-terminated strings after performing the split. |
250 > and you need to use `cx_strdup()` or `cx_strdup_a()` if you want copies or zero-terminated strings after performing the split. |
| 258 {style="note"} |
251 {style="note"} |
| 259 |
252 |
| 260 ## Complex Tokenization |
253 ## Complex Tokenization |