| 33 |
33 |
| 34 cxmutstr cx_mutstrn(char *cstring, size_t length); |
34 cxmutstr cx_mutstrn(char *cstring, size_t length); |
| 35 |
35 |
| 36 cxstring cx_strcast(AnyStr str); |
36 cxstring cx_strcast(AnyStr str); |
| 37 |
37 |
| 38 cxmutstr cx_strdupa(AnyStr string); |
38 cxmutstr cx_strdup(AnyStr string); |
| 39 |
39 |
| 40 cxmutstr cx_strdup_a(const CxAllocator *allocator, AnyStr string); |
40 cxmutstr cx_strdup_a(const CxAllocator *allocator, AnyStr string); |
| 41 |
41 |
| 42 void cx_strfree(cxmutstr *str); |
42 void cx_strfree(cxmutstr *str); |
| 43 |
43 |
| 44 void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str); |
44 void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str); |
| 45 ``` |
45 ``` |
| 46 |
46 |
| 47 > Documentation work in progress. |
47 The functions `cx_str()` and `cx_mutstr()` create a UCX string from a `const char*` or a `char*` |
| 48 >{style="warning"} |
48 and compute the length with a call to stdlib `strlen()`. |
| |
49 In case you already know the length, or the string is not zero-terminated, you can use `cx_strn()` or `cx_mutstrn()`. |
| |
50 |
| |
51 The function `cx_strdup_a()` allocates new memory with the given `allocator` and copies the given `string` |
| |
52 and guarantees that the result string is zero-terminated. |
| |
53 The function `cx_strdup()` is equivalent to `cx_strdup_a()`, except that it uses the default stdlib allocator. |
| |
54 |
| |
55 Allocated strings are always of type `cxmutstr` and can be deallocated by a call to `cx_strfree()` or `cx_strfree_a()`. |
| |
56 The caller must make sure to use the correct allocator for deallocating a string. |
| |
57 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. |
| |
58 It is also safe to call the functions with a `NULL`-pointer, just like any other `free()`-like function. |
| 49 |
59 |
| 50 > When you want to convert a string _literal_ into a UCX string, you can also use the `CX_STR(lit)` macro. |
60 > When you want to convert a string _literal_ into a UCX string, you can also use the `CX_STR(lit)` macro. |
| 51 > This macro uses the fact that `sizeof(lit)` for a string literal `lit` is always the string length plus one, |
61 > This macro uses the fact that `sizeof(lit)` for a string literal `lit` is always the string length plus one, |
| 52 > effectively saving an invocation of `strlen()`. |
62 > effectively saving an invocation of `strlen()`. |
| 53 > However, this only works for literals - in all other cases you must use `cx_str()` or `cx_strn`. |
63 > However, this only works for literals - in all other cases you must use `cx_str()` or `cx_strn`. |