docs/Writerside/topics/string.h.md

changeset 1667
608cc0b25352
parent 1652
db8299984bfe
child 1668
3ffdfe1776b4
equal deleted inserted replaced
1665:b79405fbf91d 1667:608cc0b25352
117 ## Concatenation 117 ## Concatenation
118 118
119 ```C 119 ```C
120 #include <cx/string.h> 120 #include <cx/string.h>
121 121
122 cxmutstr cx_strcat(size_t count, ... ); 122 int cx_strcat(cxmutstr *str, size_t count, ... );
123 123
124 cxmutstr cx_strcat_a(const CxAllocator *alloc, size_t count, ... ); 124 int cx_strcat_a(const CxAllocator *allocator,
125 125 cxmutstr *str, size_t count, ... );
126 cxmutstr cx_strcat_m(cxmutstr str, size_t count, ... );
127
128 cxmutstr cx_strcat_ma(const CxAllocator *alloc,
129 cxmutstr str, size_t count, ... );
130 126
131 size_t cx_strlen(size_t count, ...); 127 size_t cx_strlen(size_t count, ...);
132 ``` 128 ```
133 129
134 The `cx_strcat_a()` function takes `count` UCX strings (`cxstring` or `cxmutstr`), 130 The `cx_strcat_a()` function takes `count` UCX strings (`cxstring` or `cxmutstr` - not pointers!),
135 allocates memory for a concatenation of those strings _with a single allocation_, 131 allocates memory in `str` for a concatenation of those strings _with a single allocation_,
136 and copies the contents of the strings to the new memory. 132 and appends the contents of the strings to `str`.
137 `cx_strcat()` is equivalent, except that it uses the [default allocator](allocator.h.md#default-allocator). 133 `cx_strcat()` is equivalent, except that it uses the [default allocator](allocator.h.md#default-allocator).
138 134
139 The `cx_strcat_ma()` and `cx_strcat_m()` append the `count` strings to the specified string `str` and, 135 Example usage:
140 instead of allocating new memory, reallocate the existing memory in `str`. 136 ```C
141 If the pointer in `str` is `NULL`, there is no difference to `cx_strcat_a()`. 137 cxmutstr str = {0};
142 Note, that `count` always denotes the number of variadic arguments in _both_ variants. 138 cx_strcat(&str, 2, cx_str("Hello, "), cx_str("World!"));
139 ```
143 140
144 The function `cx_strlen()` sums the length of the specified strings. 141 The function `cx_strlen()` sums the length of the specified strings.
145 142
146 > There is no reason to use `cx_strlen()` for a single UCX string. 143 > There is no reason to use `cx_strlen()` for a single UCX string.
147 > You can access the `length` field of the structure directly. 144 > You can access the `length` field of the structure directly.

mercurial