src/cx/string.h

changeset 697
ebdce4bf262b
parent 693
494d9b20b99e
child 700
72dccb560084
equal deleted inserted replaced
696:1ba4ec2e7a89 697:ebdce4bf262b
294 size_t count, 294 size_t count,
295 ... 295 ...
296 ); 296 );
297 297
298 /** 298 /**
299 * Concatenates two or more strings. 299 * Concatenates strings.
300 * 300 *
301 * The resulting string will be allocated by the specified allocator. 301 * The resulting string will be allocated by the specified allocator.
302 * So developers \em must pass the return value to cx_strfree() eventually. 302 * So developers \em must pass the return value to cx_strfree_a() eventually.
303 * 303 *
304 * \note It is guaranteed that there is only one allocation. 304 * If \p str already contains a string, the memory will be reallocated and
305 * It is also guaranteed that the returned string is zero-terminated. 305 * the other strings are appended. Otherwise, new memory is allocated.
306 *
307 * \note It is guaranteed that there is only one allocation.
308 * It is also guaranteed that the returned string is zero-terminated.
306 * 309 *
307 * @param alloc the allocator to use 310 * @param alloc the allocator to use
308 * @param count the total number of strings to concatenate 311 * @param str the string the other strings shall be concatenated to
309 * @param ... all strings 312 * @param count the number of the other following strings to concatenate
313 * @param ... all other strings
310 * @return the concatenated string 314 * @return the concatenated string
311 */ 315 */
312 __attribute__((__warn_unused_result__, __nonnull__)) 316 __attribute__((__warn_unused_result__, __nonnull__))
313 cxmutstr cx_strcat_a( 317 cxmutstr cx_strcat_ma(
314 CxAllocator const *alloc, 318 CxAllocator const *alloc,
319 cxmutstr str,
315 size_t count, 320 size_t count,
316 ... 321 ...
317 ); 322 );
318 323
319 /** 324 /**
320 * Concatenates two or more strings. 325 * Concatenates strings and returns a new string.
326 *
327 * The resulting string will be allocated by the specified allocator.
328 * So developers \em must pass the return value to cx_strfree_a() eventually.
329 *
330 * \note It is guaranteed that there is only one allocation.
331 * It is also guaranteed that the returned string is zero-terminated.
332 *
333 * @param alloc the allocator to use
334 * @param count the number of the other following strings to concatenate
335 * @param ... all other strings
336 * @return the concatenated string
337 */
338 #define cx_strcat_a(alloc, count, ...) \
339 cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__)
340
341 /**
342 * Concatenates strings and returns a new string.
321 * 343 *
322 * The resulting string will be allocated by standard \c malloc(). 344 * The resulting string will be allocated by standard \c malloc().
323 * So developers \em must pass the return value to cx_strfree() eventually. 345 * So developers \em must pass the return value to cx_strfree() eventually.
324 * 346 *
325 * \note It is guaranteed that there is only one allocation. 347 * \note It is guaranteed that there is only one allocation.
326 * It is also guaranteed that the returned string is zero-terminated. 348 * It is also guaranteed that the returned string is zero-terminated.
327 * 349 *
328 * @param count the total number of strings to concatenate 350 * @param count the number of the other following strings to concatenate
329 * @param ... all strings 351 * @param ... all other strings
330 * @return the concatenated string 352 * @return the concatenated string
331 */ 353 */
332 #define cx_strcat(count, ...) \ 354 #define cx_strcat(count, ...) \
333 cx_strcat_a(cxDefaultAllocator, count, __VA_ARGS__) 355 cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__)
356
357 /**
358 * Concatenates strings.
359 *
360 * The resulting string will be allocated by standard \c malloc().
361 * So developers \em must pass the return value to cx_strfree() eventually.
362 *
363 * If \p str already contains a string, the memory will be reallocated and
364 * the other strings are appended. Otherwise, new memory is allocated.
365 *
366 * \note It is guaranteed that there is only one allocation.
367 * It is also guaranteed that the returned string is zero-terminated.
368 *
369 * @param str the string the other strings shall be concatenated to
370 * @param count the number of the other following strings to concatenate
371 * @param ... all other strings
372 * @return the concatenated string
373 */
374 #define cx_strcat_m(str, count, ...) \
375 cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__)
334 376
335 /** 377 /**
336 * Returns a substring starting at the specified location. 378 * Returns a substring starting at the specified location.
337 * 379 *
338 * \attention the new string references the same memory area as the 380 * \attention the new string references the same memory area as the

mercurial