--- a/docs/Writerside/topics/string.h.md Wed Dec 31 15:25:30 2025 +0100 +++ b/docs/Writerside/topics/string.h.md Wed Dec 31 16:01:08 2025 +0100 @@ -14,7 +14,7 @@ > To simplify documentation, we introduce the pseudo-type `AnyStr` with the meaning that > any UCX string and any C string are supported. > The implementation is actually hidden behind a macro which uses `cx_strcast()` to guarantee compatibility. -> Similarly we introduce `UcxStr` with the meaning that it is either a `cxstring` or a `cxmutstr`, +> Similarly, we introduce `UcxStr` with the meaning that it is either a `cxstring` or a `cxmutstr`, > created by `cx_strcast_m()`. {style="note"} @@ -66,11 +66,11 @@ and guarantees that the result string is zero-terminated. The function `cx_strdup()` is equivalent to `cx_strdup_a()`, except that it uses the [default allocator](allocator.h.md#default-allocator). -The functions `cx_strcpy_a()` and `cx_strcpy()` copy the contents of the `source` string to the `dest` string, +The functions `cx_strcpy_a()` and `cx_strcpy()` copy the contents of the `source` string to the `dest` string and also guarantee zero-termination of the resulting string. The memory in `dest` is either freshly allocated or re-allocated to fit the size of the string plus the terminator. -Allocated strings are always of type `cxmutstr` and can be deallocated by a call to `cx_strfree()` or `cx_strfree_a()`. +Allocated strings always have the type `cxmutstr` and can be deallocated by a call to `cx_strfree()` or `cx_strfree_a()`. The caller must make sure to use the correct allocator for deallocating a string. It is safe to call these functions multiple times on a given string, as the pointer will be nulled and the length set to zero. It is also safe to call the functions with a `NULL`-pointer, just like any other `free()`-like function. @@ -111,7 +111,7 @@ The `cx_strcmp()` function compares two strings lexicographically and returns an integer greater than, equal to, or less than 0, if `s1` is greater than, equal to, or less than `s2`, respectively. -The `cx_strcmp_p()` function takes pointers to UCX strings (i.e., only to `cxstring` and `cxmutstr`) and the signature is compatible with `cx_compare_func`. +The `cx_strcmp_p()` function takes pointers to UCX strings (i.e., only to `cxstring` and `cxmutstr`), and the signature is compatible with `cx_compare_func`. Use this as a compare function for lists or other data structures. The functions `cx_strprefix()` and `cx_strsuffic()` check if `string` starts with `prefix` or ends with `suffix`, respectively. @@ -140,7 +140,7 @@ and appends the contents of the strings to `str`. `cx_strcat()` is equivalent, except that it uses the [default allocator](allocator.h.md#default-allocator). -When there is no `str` where the other strings shall be appended to, you can pass `CX_NULLSTR` as first argument. +When there is no `str` where the other strings shall be appended to, you can pass `CX_NULLSTR` as the first argument. In that case, a completely new string is allocated. Example usage: @@ -239,14 +239,14 @@ That means, at most `limit-1` splits are performed. The function returns the actual number of items written to `output`. -On the other hand, `cx_strsplit_a()` uses the specified `allocator` to allocate the output array, +On the other hand, `cx_strsplit_a()` uses the specified `allocator` to allocate the output array and writes the pointer to the allocated memory to `output`. > The type of the `UcxStr` must the same for `string` and `output` (i.e., either both `cxstring` or both `cxmutstr`). > {style="note"} > The `allocator` in `cx_strsplit_a()` is _only_ used to allocate the output array. -> The strings will always point into the original `string` +> The strings will always point into the original `string`, > and you need to use `cx_strdup()` or `cx_strdup_a()` if you want copies or zero-terminated strings after performing the split. {style="note"} @@ -263,14 +263,14 @@ bool cx_strtok_next(CxStrtokCtx *ctx, UcxStr* token); ``` -You can tokenize a string by creating a _tokenization_ context with `cx_strtok()`, +You can tokenize a string by creating a _tokenization_ context with `cx_strtok()` and calling `cx_strtok_next()` as long as it returns `true`. The tokenization context is initialized with the string `str` to tokenize, one delimiter `delim`, and a `limit` for the maximum number of tokens. When `limit` is reached, the remaining part of `str` is returned as one single token. -You can add additional delimiters to the context by calling `cx_strtok_delim()`, and +You can add additional delimiters to the context by calling `cx_strtok_delim()` and specifying an array of delimiters to use. > Regardless of how the context was initialized, you can use `cx_strtok_next()`