117 * @param ... all other strings |
117 * @param ... all other strings |
118 * @return the cumulated length of all strings |
118 * @return the cumulated length of all strings |
119 */ |
119 */ |
120 size_t sstrnlen(size_t count, sstr_t string, ...); |
120 size_t sstrnlen(size_t count, sstr_t string, ...); |
121 |
121 |
122 |
122 /** |
123 /** |
123 * Concatenates two or more strings. |
124 * Concatenates strings. |
124 * |
125 * |
125 * The resulting string will be allocated by standard <code>malloc()</code>. |
126 * At least one string must be specified and there must be enough memory |
126 * So developers <b>MUST</b> pass the sstr_t.ptr to <code>free()</code>. |
127 * available referenced by the destination sstr_t.ptr for this function to |
127 * |
128 * successfully concatenate all specified strings. |
128 * The sstr_t.ptr of the return value will <i>always</i> be <code>NULL</code>- |
129 * |
129 * terminated. |
130 * The sstr_t.length of the destination string specifies the capacity and |
130 * |
131 * should match the total memory available referenced by the destination |
|
132 * sstr_t.ptr. This function <i>never</i> copies data beyond the capacity and |
|
133 * does not modify any of the source strings. |
|
134 * |
|
135 * <b>Attention:</b> |
|
136 * <ul> |
|
137 * <li>Any content in the destination string will be overwritten</li> |
|
138 * <li>The destination sstr_t.ptr is <b>NOT</b> |
|
139 * <code>NULL</code>-terminated</li> |
|
140 * <li>The destination sstr_t.length is set to the total length of the |
|
141 * concatenated strings</li> |
|
142 * <li><i>Hint:</i> get a <code>NULL</code>-terminated string by performing |
|
143 * <code>mystring.ptr[mystring.length]='\0'</code> after calling this |
|
144 * function</li> |
|
145 * </ul> |
|
146 * |
|
147 * @param dest new sstr_t with capacity information and allocated memory |
|
148 * @param count the total number of strings to concatenate |
131 * @param count the total number of strings to concatenate |
149 * @param src the first string |
132 * @param s1 first string |
150 * @param ... all other strings |
133 * @param s2 second string |
151 * @return the argument for <code>dest</code> is returned |
134 * @param ... all remaining strings |
152 */ |
135 * @return the concatenated string |
153 sstr_t sstrncat(sstr_t dest, size_t count, sstr_t src, ...); |
136 */ |
|
137 sstr_t sstrcat(size_t count, sstr_t s1, sstr_t s2, ...); |
|
138 |
|
139 /** |
|
140 * Concatenates two or more strings using an UcxAllocator. |
|
141 * |
|
142 * See sstrcat() for details. |
|
143 * |
|
144 * @param a the allocator to use |
|
145 * @param count the total number of strings to concatenate |
|
146 * @param s1 first string |
|
147 * @param s2 second string |
|
148 * @param ... all remaining strings |
|
149 * @return the concatenated string |
|
150 */ |
|
151 sstr_t sstrcat_a(UcxAllocator *a, size_t count, sstr_t s1, sstr_t s2, ...); |
154 |
152 |
155 |
153 |
156 /** |
154 /** |
157 * Returns a substring starting at the specified location. |
155 * Returns a substring starting at the specified location. |
158 * |
156 * |
225 * <li>the string equals the delimeter</li> |
223 * <li>the string equals the delimeter</li> |
226 * <li>memory allocation fails</li> |
224 * <li>memory allocation fails</li> |
227 * </ul> |
225 * </ul> |
228 * |
226 * |
229 * The integer referenced by <code>count</code> is used as input and determines |
227 * The integer referenced by <code>count</code> is used as input and determines |
230 * the maximum size of the resulting list, i.e. the maximum count of splits to |
228 * the maximum size of the resulting array, i.e. the maximum count of splits to |
231 * perform + 1. |
229 * perform + 1. |
232 * |
230 * |
233 * The integer referenced by <code>count</code> is also used as output and is |
231 * The integer referenced by <code>count</code> is also used as output and is |
234 * set to |
232 * set to |
235 * <ul> |
233 * <ul> |
236 * <li>-2, on memory allocation errors</li> |
234 * <li>-2, on memory allocation errors</li> |
237 * <li>-1, if either the string or the delimiter is an empty string</li> |
235 * <li>-1, if either the string or the delimiter is an empty string</li> |
238 * <li>0, if the string equals the delimiter</li> |
236 * <li>0, if the string equals the delimiter</li> |
239 * <li>1, if the string does not contain the delimiter</li> |
237 * <li>1, if the string does not contain the delimiter</li> |
240 * <li>the count of list items, otherwise</li> |
238 * <li>the count of array items, otherwise</li> |
241 * </ul> |
239 * </ul> |
242 * |
240 * |
243 * If the string starts with the delimiter, the first item of the resulting |
241 * If the string starts with the delimiter, the first item of the resulting |
244 * list will be an empty string. |
242 * array will be an empty string. |
245 * |
243 * |
246 * If the string ends with the delimiter and the maximum list size is not |
244 * If the string ends with the delimiter and the maximum list size is not |
247 * exceeded, the last list item will be an empty string. |
245 * exceeded, the last array item will be an empty string. |
248 * |
246 * |
249 * <b>Attention:</b> All list items <b>AND</b> all sstr_t.ptr of the list |
247 * <b>Attention:</b> The array pointer <b>AND</b> all sstr_t.ptr of the array |
250 * items must be manually passed to <code>free()</code>. Use sstrsplit_a() with |
248 * items must be manually passed to <code>free()</code>. Use sstrsplit_a() with |
251 * an allocator to managed memory, to avoid this. |
249 * an allocator to managed memory, to avoid this. |
252 * |
250 * |
253 * @param string the string to split |
251 * @param string the string to split |
254 * @param delim the delimiter string |
252 * @param delim the delimiter string |
255 * @param count IN: the maximum size of the resulting list (0 for an |
253 * @param count IN: the maximum size of the resulting array (0 = no limit), |
256 * unbounded list), OUT: the actual size of the list |
254 * OUT: the actual size of the array |
257 * @return a list of the split strings as sstr_t array or |
255 * @return a sstr_t array containing the split strings or |
258 * <code>NULL</code> on error |
256 * <code>NULL</code> on error |
259 * |
257 * |
260 * @see sstrsplit_a() |
258 * @see sstrsplit_a() |
261 */ |
259 */ |
262 sstr_t* sstrsplit(sstr_t string, sstr_t delim, size_t *count); |
260 sstr_t* sstrsplit(sstr_t string, sstr_t delim, ssize_t *count); |
263 |
261 |
264 /** |
262 /** |
265 * Performing sstrsplit() using an UcxAllocator. |
263 * Performing sstrsplit() using an UcxAllocator. |
266 * |
264 * |
267 * <i>Read the description of sstrsplit() for details.</i> |
265 * <i>Read the description of sstrsplit() for details.</i> |
268 * |
266 * |
269 * The memory for the sstr_t.ptr pointers of the list items and the memory for |
267 * The memory for the sstr_t.ptr pointers of the array items and the memory for |
270 * the sstr_t array itself are allocated by using the UcxAllocator.malloc() |
268 * the sstr_t array itself are allocated by using the UcxAllocator.malloc() |
271 * function. |
269 * function. |
272 * |
270 * |
273 * <b>Note:</b> the allocator is not used for memory that is freed within the |
271 * <b>Note:</b> the allocator is not used for memory that is freed within the |
274 * same call of this function (locally scoped variables). |
272 * same call of this function (locally scoped variables). |
275 * |
273 * |
276 * @param allocator the UcxAllocator used for allocating memory |
274 * @param allocator the UcxAllocator used for allocating memory |
277 * @param string the string to split |
275 * @param string the string to split |
278 * @param delim the delimiter string |
276 * @param delim the delimiter string |
279 * @param count IN: the maximum size of the resulting list (0 for an |
277 * @param count IN: the maximum size of the resulting array (0 = no limit), |
280 * unbounded list), OUT: the actual size of the list |
278 * OUT: the actual size of the array |
281 * @return a list of the split strings as sstr_t array or |
279 * @return a sstr_t array containing the split strings or |
282 * <code>NULL</code> on error |
280 * <code>NULL</code> on error |
283 * |
281 * |
284 * @see sstrsplit() |
282 * @see sstrsplit() |
285 */ |
283 */ |
286 sstr_t* sstrsplit_a(UcxAllocator *allocator, sstr_t string, sstr_t delim, |
284 sstr_t* sstrsplit_a(UcxAllocator *allocator, sstr_t string, sstr_t delim, |
287 size_t *count); |
285 ssize_t *count); |
288 |
286 |
289 /** |
287 /** |
290 * Compares two UCX strings with standard <code>memcmp()</code>. |
288 * Compares two UCX strings with standard <code>memcmp()</code>. |
291 * |
289 * |
292 * At first it compares the sstr_t.length attribute of the two strings. The |
290 * At first it compares the sstr_t.length attribute of the two strings. The |
383 * @param suffix the suffix the string should have |
381 * @param suffix the suffix the string should have |
384 * @return 1, if and only if the string has the specified suffix, 0 otherwise |
382 * @return 1, if and only if the string has the specified suffix, 0 otherwise |
385 */ |
383 */ |
386 int sstrsuffix(sstr_t string, sstr_t suffix); |
384 int sstrsuffix(sstr_t string, sstr_t suffix); |
387 |
385 |
|
386 /** |
|
387 * Returns a lower case version of a string. |
|
388 * |
|
389 * This function creates a duplicate of the input string, first. See the |
|
390 * documentation of sstrdup() for the implications. |
|
391 * |
|
392 * @param string the input string |
|
393 * @return the resulting lower case string |
|
394 * @see sstrdup() |
|
395 */ |
|
396 sstr_t sstrlower(sstr_t string); |
|
397 |
|
398 /** |
|
399 * Returns a lower case version of a string. |
|
400 * |
|
401 * This function creates a duplicate of the input string, first. See the |
|
402 * documentation of sstrdup_a() for the implications. |
|
403 * |
|
404 * @param allocator the allocator used for duplicating the string |
|
405 * @param string the input string |
|
406 * @return the resulting lower case string |
|
407 * @see sstrdup_a() |
|
408 */ |
|
409 sstr_t sstrlower_a(UcxAllocator *allocator, sstr_t string); |
|
410 |
|
411 /** |
|
412 * Returns a upper case version of a string. |
|
413 * |
|
414 * This function creates a duplicate of the input string, first. See the |
|
415 * documentation of sstrdup() for the implications. |
|
416 * |
|
417 * @param string the input string |
|
418 * @return the resulting upper case string |
|
419 * @see sstrdup() |
|
420 */ |
|
421 sstr_t sstrupper(sstr_t string); |
|
422 |
|
423 /** |
|
424 * Returns a upper case version of a string. |
|
425 * |
|
426 * This function creates a duplicate of the input string, first. See the |
|
427 * documentation of sstrdup_a() for the implications. |
|
428 * |
|
429 * @param allocator the allocator used for duplicating the string |
|
430 * @param string the input string |
|
431 * @return the resulting upper case string |
|
432 * @see sstrdup_a() |
|
433 */ |
|
434 sstr_t sstrupper_a(UcxAllocator *allocator, sstr_t string); |
|
435 |
388 #ifdef __cplusplus |
436 #ifdef __cplusplus |
389 } |
437 } |
390 #endif |
438 #endif |
391 |
439 |
392 #endif /* UCX_STRING_H */ |
440 #endif /* UCX_STRING_H */ |