src/cx/string.h

changeset 1426
3a89b31f0724
parent 1424
563033aa998c
equal deleted inserted replaced
1425:83284b289430 1426:3a89b31f0724
46 #define CX_PRIstr ".*s" 46 #define CX_PRIstr ".*s"
47 47
48 /** 48 /**
49 * The maximum length of the "needle" in cx_strstr() that can use SBO. 49 * The maximum length of the "needle" in cx_strstr() that can use SBO.
50 */ 50 */
51 cx_attr_export 51 CX_EXPORT extern const unsigned cx_strstr_sbo_size;
52 extern const unsigned cx_strstr_sbo_size;
53 52
54 /** 53 /**
55 * The UCX string structure. 54 * The UCX string structure.
56 */ 55 */
57 struct cx_mutstr_s { 56 struct cx_mutstr_s {
177 * @param cstring the string to wrap (must be zero-terminated) 176 * @param cstring the string to wrap (must be zero-terminated)
178 * @return the wrapped string 177 * @return the wrapped string
179 * 178 *
180 * @see cx_mutstrn() 179 * @see cx_mutstrn()
181 */ 180 */
182 cx_attr_nodiscard 181 cx_attr_nodiscard cx_attr_cstr_arg(1)
183 cx_attr_cstr_arg(1) 182 CX_EXPORT cxmutstr cx_mutstr(char *cstring);
184 cx_attr_export
185 cxmutstr cx_mutstr(char *cstring);
186 183
187 /** 184 /**
188 * Wraps a string that does not need to be zero-terminated. 185 * Wraps a string that does not need to be zero-terminated.
189 * 186 *
190 * The argument may be @c NULL if the length is zero. 187 * The argument may be @c NULL if the length is zero.
198 * @param length the length of the string 195 * @param length the length of the string
199 * @return the wrapped string 196 * @return the wrapped string
200 * 197 *
201 * @see cx_mutstr() 198 * @see cx_mutstr()
202 */ 199 */
203 cx_attr_nodiscard 200 cx_attr_nodiscard cx_attr_access_rw(1, 2)
204 cx_attr_access_rw(1, 2) 201 CX_EXPORT cxmutstr cx_mutstrn(char *cstring, size_t length);
205 cx_attr_export
206 cxmutstr cx_mutstrn(
207 char *cstring,
208 size_t length
209 );
210 202
211 /** 203 /**
212 * Wraps a string that must be zero-terminated. 204 * Wraps a string that must be zero-terminated.
213 * 205 *
214 * The length is implicitly inferred by using a call to @c strlen(). 206 * The length is implicitly inferred by using a call to @c strlen().
223 * @param cstring the string to wrap (must be zero-terminated) 215 * @param cstring the string to wrap (must be zero-terminated)
224 * @return the wrapped string 216 * @return the wrapped string
225 * 217 *
226 * @see cx_strn() 218 * @see cx_strn()
227 */ 219 */
228 cx_attr_nodiscard 220 cx_attr_nodiscard cx_attr_cstr_arg(1)
229 cx_attr_cstr_arg(1) 221 CX_EXPORT cxstring cx_str(const char *cstring);
230 cx_attr_export
231 cxstring cx_str(const char *cstring);
232 222
233 223
234 /** 224 /**
235 * Wraps a string that does not need to be zero-terminated. 225 * Wraps a string that does not need to be zero-terminated.
236 * 226 *
245 * @param length the length of the string 235 * @param length the length of the string
246 * @return the wrapped string 236 * @return the wrapped string
247 * 237 *
248 * @see cx_str() 238 * @see cx_str()
249 */ 239 */
250 cx_attr_nodiscard 240 cx_attr_nodiscard cx_attr_access_r(1, 2)
251 cx_attr_access_r(1, 2) 241 CX_EXPORT cxstring cx_strn(const char *cstring, size_t length);
252 cx_attr_export
253 cxstring cx_strn(
254 const char *cstring,
255 size_t length
256 );
257 242
258 #ifdef __cplusplus 243 #ifdef __cplusplus
259 } // extern "C" 244 } // extern "C"
260 cx_attr_nodiscard 245 cx_attr_nodiscard
261 static inline cxstring cx_strcast(cxmutstr str) { 246 CX_CPPDECL cxstring cx_strcast(cxmutstr str) {
262 return cx_strn(str.ptr, str.length); 247 return cx_strn(str.ptr, str.length);
263 } 248 }
264 cx_attr_nodiscard 249 cx_attr_nodiscard
265 static inline cxstring cx_strcast(cxstring str) { 250 CX_CPPDECL cxstring cx_strcast(cxstring str) {
266 return str; 251 return str;
267 } 252 }
268 cx_attr_nodiscard 253 cx_attr_nodiscard
269 static inline cxstring cx_strcast(const char *str) { 254 CX_CPPDECL cxstring cx_strcast(const char *str) {
270 return cx_str(str); 255 return cx_str(str);
256 }
257 cx_attr_nodiscard
258 CX_CPPDECL cxstring cx_strcast(const unsigned char *str) {
259 return cx_str(static_cast<const char*>(str));
271 } 260 }
272 extern "C" { 261 extern "C" {
273 #else 262 #else
274 /** 263 /**
275 * Internal function, do not use. 264 * Internal function, do not use.
276 * @param str 265 * @param str
277 * @return 266 * @return
278 * @see cx_strcast() 267 * @see cx_strcast()
279 */ 268 */
280 cx_attr_nodiscard 269 cx_attr_nodiscard
281 static inline cxstring cx_strcast_m(cxmutstr str) { 270 CX_INLINE cxstring cx_strcast_m(cxmutstr str) {
282 return (cxstring) {str.ptr, str.length}; 271 return (cxstring) {str.ptr, str.length};
283 } 272 }
284 /** 273 /**
285 * Internal function, do not use. 274 * Internal function, do not use.
286 * @param str 275 * @param str
287 * @return 276 * @return
288 * @see cx_strcast() 277 * @see cx_strcast()
289 */ 278 */
290 cx_attr_nodiscard 279 cx_attr_nodiscard
291 static inline cxstring cx_strcast_c(cxstring str) { 280 CX_INLINE cxstring cx_strcast_c(cxstring str) {
292 return str; 281 return str;
293 } 282 }
294 283
295 /** 284 /**
296 * Internal function, do not use. 285 * Internal function, do not use.
297 * @param str 286 * @param str
298 * @return 287 * @return
299 * @see cx_strcast() 288 * @see cx_strcast()
300 */ 289 */
301 cx_attr_nodiscard 290 cx_attr_nodiscard
302 static inline cxstring cx_strcast_z(const char *str) { 291 CX_INLINE cxstring cx_strcast_u(const unsigned char *str) {
292 return cx_str((const char*)str);
293 }
294
295 /**
296 * Internal function, do not use.
297 * @param str
298 * @return
299 * @see cx_strcast()
300 */
301 cx_attr_nodiscard
302 CX_INLINE cxstring cx_strcast_z(const char *str) {
303 return cx_str(str); 303 return cx_str(str);
304 } 304 }
305 305
306 /** 306 /**
307 * Wraps any string into an UCX string. 307 * Wraps any string into an UCX string.
310 * @return (@c cxstring) the string wrapped as UCX string 310 * @return (@c cxstring) the string wrapped as UCX string
311 */ 311 */
312 #define cx_strcast(str) _Generic((str), \ 312 #define cx_strcast(str) _Generic((str), \
313 cxmutstr: cx_strcast_m, \ 313 cxmutstr: cx_strcast_m, \
314 cxstring: cx_strcast_c, \ 314 cxstring: cx_strcast_c, \
315 const unsigned char*: cx_strcast_z, \ 315 const unsigned char*: cx_strcast_u, \
316 unsigned char *: cx_strcast_z, \ 316 unsigned char *: cx_strcast_u, \
317 const char*: cx_strcast_z, \ 317 const char*: cx_strcast_z, \
318 char *: cx_strcast_z) (str) 318 char *: cx_strcast_z) (str)
319 #endif 319 #endif
320 320
321 /** 321 /**
328 * you ever have a <code>const char*</code> you are really supposed to free. 328 * you ever have a <code>const char*</code> you are really supposed to free.
329 * If you encounter such a situation, you should double-check your code. 329 * If you encounter such a situation, you should double-check your code.
330 * 330 *
331 * @param str the string to free 331 * @param str the string to free
332 */ 332 */
333 cx_attr_export 333 CX_EXPORT void cx_strfree(cxmutstr *str);
334 void cx_strfree(cxmutstr *str);
335 334
336 /** 335 /**
337 * Passes the pointer in this string to the allocator's free function. 336 * Passes the pointer in this string to the allocator's free function.
338 * 337 *
339 * The pointer in the struct is set to @c NULL, and the length is set to zero, 338 * The pointer in the struct is set to @c NULL, and the length is set to zero,
345 * 344 *
346 * @param alloc the allocator 345 * @param alloc the allocator
347 * @param str the string to free 346 * @param str the string to free
348 */ 347 */
349 cx_attr_nonnull_arg(1) 348 cx_attr_nonnull_arg(1)
350 cx_attr_export 349 CX_EXPORT void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str);
351 void cx_strfree_a(
352 const CxAllocator *alloc,
353 cxmutstr *str
354 );
355 350
356 /** 351 /**
357 * Copies a string. 352 * Copies a string.
358 * 353 *
359 * The memory in the @p dest structure is either allocated or re-allocated to fit the entire 354 * The memory in the @p dest structure is either allocated or re-allocated to fit the entire
367 * 362 *
368 * @retval zero success 363 * @retval zero success
369 * @retval non-zero if re-allocation failed 364 * @retval non-zero if re-allocation failed
370 */ 365 */
371 cx_attr_nonnull_arg(1) 366 cx_attr_nonnull_arg(1)
372 cx_attr_export 367 CX_EXPORT int cx_strcpy_a(const CxAllocator *alloc, cxmutstr *dest, cxstring src);
373 int cx_strcpy_a(
374 const CxAllocator *alloc,
375 cxmutstr *dest,
376 cxstring src
377 );
378 368
379 369
380 /** 370 /**
381 * Copies a string. 371 * Copies a string.
382 * 372 *
404 * @param count the total number of specified strings 394 * @param count the total number of specified strings
405 * @param ... all strings 395 * @param ... all strings
406 * @return the accumulated length of all strings 396 * @return the accumulated length of all strings
407 */ 397 */
408 cx_attr_nodiscard 398 cx_attr_nodiscard
409 cx_attr_export 399 CX_EXPORT size_t cx_strlen(size_t count, ...);
410 size_t cx_strlen(
411 size_t count,
412 ...
413 );
414 400
415 /** 401 /**
416 * Concatenates strings. 402 * Concatenates strings.
417 * 403 *
418 * The resulting string will be allocated by the specified allocator. 404 * The resulting string will be allocated by the specified allocator.
432 * @param str the string the other strings shall be concatenated to 418 * @param str the string the other strings shall be concatenated to
433 * @param count the number of the other following strings to concatenate 419 * @param count the number of the other following strings to concatenate
434 * @param ... all other UCX strings 420 * @param ... all other UCX strings
435 * @return the concatenated string 421 * @return the concatenated string
436 */ 422 */
437 cx_attr_nodiscard 423 cx_attr_nodiscard cx_attr_nonnull
438 cx_attr_nonnull 424 CX_EXPORT cxmutstr cx_strcat_ma(const CxAllocator *alloc,
439 cx_attr_export 425 cxmutstr str, size_t count, ...);
440 cxmutstr cx_strcat_ma(
441 const CxAllocator *alloc,
442 cxmutstr str,
443 size_t count,
444 ...
445 );
446 426
447 /** 427 /**
448 * Concatenates strings and returns a new string. 428 * Concatenates strings and returns a new string.
449 * 429 *
450 * The resulting string will be allocated by the specified allocator. 430 * The resulting string will be allocated by the specified allocator.
461 * @param count (@c size_t) the number of the other following strings to concatenate 441 * @param count (@c size_t) the number of the other following strings to concatenate
462 * @param ... all other UCX strings 442 * @param ... all other UCX strings
463 * @return (@c cxmutstr) the concatenated string 443 * @return (@c cxmutstr) the concatenated string
464 */ 444 */
465 #define cx_strcat_a(alloc, count, ...) \ 445 #define cx_strcat_a(alloc, count, ...) \
466 cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__) 446 cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__)
467 447
468 /** 448 /**
469 * Concatenates strings and returns a new string. 449 * Concatenates strings and returns a new string.
470 * 450 *
471 * The resulting string will be allocated by the cxDefaultAllocator. 451 * The resulting string will be allocated by the cxDefaultAllocator.
481 * @param count (@c size_t) the number of the other following strings to concatenate 461 * @param count (@c size_t) the number of the other following strings to concatenate
482 * @param ... all other UCX strings 462 * @param ... all other UCX strings
483 * @return (@c cxmutstr) the concatenated string 463 * @return (@c cxmutstr) the concatenated string
484 */ 464 */
485 #define cx_strcat(count, ...) \ 465 #define cx_strcat(count, ...) \
486 cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__) 466 cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__)
487 467
488 /** 468 /**
489 * Concatenates strings. 469 * Concatenates strings.
490 * 470 *
491 * The resulting string will be allocated by the cxDefaultAllocator. 471 * The resulting string will be allocated by the cxDefaultAllocator.
505 * @param count (@c size_t) the number of the other following strings to concatenate 485 * @param count (@c size_t) the number of the other following strings to concatenate
506 * @param ... all other strings 486 * @param ... all other strings
507 * @return (@c cxmutstr) the concatenated string 487 * @return (@c cxmutstr) the concatenated string
508 */ 488 */
509 #define cx_strcat_m(str, count, ...) \ 489 #define cx_strcat_m(str, count, ...) \
510 cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__) 490 cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__)
511 491
512 /** 492 /**
513 * Returns a substring starting at the specified location. 493 * Returns a substring starting at the specified location.
514 * 494 *
515 * @attention the new string references the same memory area as the 495 * @attention the new string references the same memory area as the
523 * @see cx_strsubsl() 503 * @see cx_strsubsl()
524 * @see cx_strsubs_m() 504 * @see cx_strsubs_m()
525 * @see cx_strsubsl_m() 505 * @see cx_strsubsl_m()
526 */ 506 */
527 cx_attr_nodiscard 507 cx_attr_nodiscard
528 cx_attr_export 508 CX_EXPORT cxstring cx_strsubs(cxstring string, size_t start);
529 cxstring cx_strsubs(
530 cxstring string,
531 size_t start
532 );
533 509
534 /** 510 /**
535 * Returns a substring starting at the specified location. 511 * Returns a substring starting at the specified location.
536 * 512 *
537 * The returned string will be limited to @p length bytes or the number 513 * The returned string will be limited to @p length bytes or the number
549 * @see cx_strsubs() 525 * @see cx_strsubs()
550 * @see cx_strsubs_m() 526 * @see cx_strsubs_m()
551 * @see cx_strsubsl_m() 527 * @see cx_strsubsl_m()
552 */ 528 */
553 cx_attr_nodiscard 529 cx_attr_nodiscard
554 cx_attr_export 530 CX_EXPORT cxstring cx_strsubsl(cxstring string, size_t start, size_t length);
555 cxstring cx_strsubsl(
556 cxstring string,
557 size_t start,
558 size_t length
559 );
560 531
561 /** 532 /**
562 * Returns a substring starting at the specified location. 533 * Returns a substring starting at the specified location.
563 * 534 *
564 * @attention the new string references the same memory area as the 535 * @attention the new string references the same memory area as the
572 * @see cx_strsubsl_m() 543 * @see cx_strsubsl_m()
573 * @see cx_strsubs() 544 * @see cx_strsubs()
574 * @see cx_strsubsl() 545 * @see cx_strsubsl()
575 */ 546 */
576 cx_attr_nodiscard 547 cx_attr_nodiscard
577 cx_attr_export 548 CX_EXPORT cxmutstr cx_strsubs_m(cxmutstr string, size_t start);
578 cxmutstr cx_strsubs_m(
579 cxmutstr string,
580 size_t start
581 );
582 549
583 /** 550 /**
584 * Returns a substring starting at the specified location. 551 * Returns a substring starting at the specified location.
585 * 552 *
586 * The returned string will be limited to @p length bytes or the number 553 * The returned string will be limited to @p length bytes or the number
598 * @see cx_strsubs_m() 565 * @see cx_strsubs_m()
599 * @see cx_strsubs() 566 * @see cx_strsubs()
600 * @see cx_strsubsl() 567 * @see cx_strsubsl()
601 */ 568 */
602 cx_attr_nodiscard 569 cx_attr_nodiscard
603 cx_attr_export 570 CX_EXPORT cxmutstr cx_strsubsl_m(cxmutstr string, size_t start, size_t length);
604 cxmutstr cx_strsubsl_m(
605 cxmutstr string,
606 size_t start,
607 size_t length
608 );
609 571
610 /** 572 /**
611 * Returns a substring starting at the location of the first occurrence of the 573 * Returns a substring starting at the location of the first occurrence of the
612 * specified character. 574 * specified character.
613 * 575 *
618 * @return a substring starting at the first location of @p chr 580 * @return a substring starting at the first location of @p chr
619 * 581 *
620 * @see cx_strchr_m() 582 * @see cx_strchr_m()
621 */ 583 */
622 cx_attr_nodiscard 584 cx_attr_nodiscard
623 cx_attr_export 585 CX_EXPORT cxstring cx_strchr(cxstring string, int chr);
624 cxstring cx_strchr(
625 cxstring string,
626 int chr
627 );
628 586
629 /** 587 /**
630 * Returns a substring starting at the location of the first occurrence of the 588 * Returns a substring starting at the location of the first occurrence of the
631 * specified character. 589 * specified character.
632 * 590 *
637 * @return a substring starting at the first location of @p chr 595 * @return a substring starting at the first location of @p chr
638 * 596 *
639 * @see cx_strchr() 597 * @see cx_strchr()
640 */ 598 */
641 cx_attr_nodiscard 599 cx_attr_nodiscard
642 cx_attr_export 600 CX_EXPORT cxmutstr cx_strchr_m(cxmutstr string, int chr);
643 cxmutstr cx_strchr_m(
644 cxmutstr string,
645 int chr
646 );
647 601
648 /** 602 /**
649 * Returns a substring starting at the location of the last occurrence of the 603 * Returns a substring starting at the location of the last occurrence of the
650 * specified character. 604 * specified character.
651 * 605 *
656 * @return a substring starting at the last location of @p chr 610 * @return a substring starting at the last location of @p chr
657 * 611 *
658 * @see cx_strrchr_m() 612 * @see cx_strrchr_m()
659 */ 613 */
660 cx_attr_nodiscard 614 cx_attr_nodiscard
661 cx_attr_export 615 CX_EXPORT cxstring cx_strrchr(cxstring string, int chr);
662 cxstring cx_strrchr(
663 cxstring string,
664 int chr
665 );
666 616
667 /** 617 /**
668 * Returns a substring starting at the location of the last occurrence of the 618 * Returns a substring starting at the location of the last occurrence of the
669 * specified character. 619 * specified character.
670 * 620 *
675 * @return a substring starting at the last location of @p chr 625 * @return a substring starting at the last location of @p chr
676 * 626 *
677 * @see cx_strrchr() 627 * @see cx_strrchr()
678 */ 628 */
679 cx_attr_nodiscard 629 cx_attr_nodiscard
680 cx_attr_export 630 CX_EXPORT cxmutstr cx_strrchr_m(cxmutstr string, int chr);
681 cxmutstr cx_strrchr_m(
682 cxmutstr string,
683 int chr
684 );
685 631
686 /** 632 /**
687 * Returns a substring starting at the location of the first occurrence of the 633 * Returns a substring starting at the location of the first occurrence of the
688 * specified string. 634 * specified string.
689 * 635 *
698 * @p needle, or an empty string, if the sequence is not 644 * @p needle, or an empty string, if the sequence is not
699 * contained 645 * contained
700 * @see cx_strstr_m() 646 * @see cx_strstr_m()
701 */ 647 */
702 cx_attr_nodiscard 648 cx_attr_nodiscard
703 cx_attr_export 649 CX_EXPORT cxstring cx_strstr(cxstring haystack, cxstring needle);
704 cxstring cx_strstr(
705 cxstring haystack,
706 cxstring needle
707 );
708 650
709 /** 651 /**
710 * Returns a substring starting at the location of the first occurrence of the 652 * Returns a substring starting at the location of the first occurrence of the
711 * specified string. 653 * specified string.
712 * 654 *
721 * @p needle, or an empty string, if the sequence is not 663 * @p needle, or an empty string, if the sequence is not
722 * contained 664 * contained
723 * @see cx_strstr() 665 * @see cx_strstr()
724 */ 666 */
725 cx_attr_nodiscard 667 cx_attr_nodiscard
726 cx_attr_export 668 CX_EXPORT cxmutstr cx_strstr_m(cxmutstr haystack, cxstring needle);
727 cxmutstr cx_strstr_m(
728 cxmutstr haystack,
729 cxstring needle
730 );
731 669
732 /** 670 /**
733 * Splits a given string using a delimiter string. 671 * Splits a given string using a delimiter string.
734 * 672 *
735 * @note The resulting array contains strings that point to the source 673 * @note The resulting array contains strings that point to the source
739 * @param delim the delimiter 677 * @param delim the delimiter
740 * @param limit the maximum number of split items 678 * @param limit the maximum number of split items
741 * @param output a preallocated array of at least @p limit length 679 * @param output a preallocated array of at least @p limit length
742 * @return the actual number of split items 680 * @return the actual number of split items
743 */ 681 */
744 cx_attr_nodiscard 682 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3)
745 cx_attr_nonnull 683 CX_EXPORT size_t cx_strsplit(cxstring string, cxstring delim,
746 cx_attr_access_w(4, 3) 684 size_t limit, cxstring *output);
747 cx_attr_export
748 size_t cx_strsplit(
749 cxstring string,
750 cxstring delim,
751 size_t limit,
752 cxstring *output
753 );
754 685
755 /** 686 /**
756 * Splits a given string using a delimiter string. 687 * Splits a given string using a delimiter string.
757 * 688 *
758 * The array pointed to by @p output will be allocated by @p allocator. 689 * The array pointed to by @p output will be allocated by @p allocator.
769 * @param limit the maximum number of split items 700 * @param limit the maximum number of split items
770 * @param output a pointer where the address of the allocated array shall be 701 * @param output a pointer where the address of the allocated array shall be
771 * written to 702 * written to
772 * @return the actual number of split items 703 * @return the actual number of split items
773 */ 704 */
774 cx_attr_nodiscard 705 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5)
775 cx_attr_nonnull 706 CX_EXPORT size_t cx_strsplit_a(const CxAllocator *allocator,
776 cx_attr_access_w(5) 707 cxstring string, cxstring delim,
777 cx_attr_export 708 size_t limit, cxstring **output);
778 size_t cx_strsplit_a(
779 const CxAllocator *allocator,
780 cxstring string,
781 cxstring delim,
782 size_t limit,
783 cxstring **output
784 );
785 709
786 710
787 /** 711 /**
788 * Splits a given string using a delimiter string. 712 * Splits a given string using a delimiter string.
789 * 713 *
794 * @param delim the delimiter 718 * @param delim the delimiter
795 * @param limit the maximum number of split items 719 * @param limit the maximum number of split items
796 * @param output a preallocated array of at least @p limit length 720 * @param output a preallocated array of at least @p limit length
797 * @return the actual number of split items 721 * @return the actual number of split items
798 */ 722 */
799 cx_attr_nodiscard 723 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3)
800 cx_attr_nonnull 724 CX_EXPORT size_t cx_strsplit_m(cxmutstr string, cxstring delim,
801 cx_attr_access_w(4, 3) 725 size_t limit, cxmutstr *output);
802 cx_attr_export
803 size_t cx_strsplit_m(
804 cxmutstr string,
805 cxstring delim,
806 size_t limit,
807 cxmutstr *output
808 );
809 726
810 /** 727 /**
811 * Splits a given string using a delimiter string. 728 * Splits a given string using a delimiter string.
812 * 729 *
813 * The array pointed to by @p output will be allocated by @p allocator. 730 * The array pointed to by @p output will be allocated by @p allocator.
824 * @param limit the maximum number of split items 741 * @param limit the maximum number of split items
825 * @param output a pointer where the address of the allocated array shall be 742 * @param output a pointer where the address of the allocated array shall be
826 * written to 743 * written to
827 * @return the actual number of split items 744 * @return the actual number of split items
828 */ 745 */
829 cx_attr_nodiscard 746 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5)
830 cx_attr_nonnull 747 CX_EXPORT size_t cx_strsplit_ma(const CxAllocator *allocator,
831 cx_attr_access_w(5) 748 cxmutstr string, cxstring delim, size_t limit,
832 cx_attr_export 749 cxmutstr **output);
833 size_t cx_strsplit_ma(
834 const CxAllocator *allocator,
835 cxmutstr string,
836 cxstring delim,
837 size_t limit,
838 cxmutstr **output
839 );
840 750
841 /** 751 /**
842 * Compares two strings. 752 * Compares two strings.
843 * 753 *
844 * @param s1 the first string 754 * @param s1 the first string
845 * @param s2 the second string 755 * @param s2 the second string
846 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger 756 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
847 * than @p s2, zero if both strings equal 757 * than @p s2, zero if both strings equal
848 */ 758 */
849 cx_attr_nodiscard 759 cx_attr_nodiscard
850 cx_attr_export 760 CX_EXPORT int cx_strcmp_(cxstring s1, cxstring s2);
851 int cx_strcmp( 761
852 cxstring s1, 762 /**
853 cxstring s2 763 * Compares two strings.
854 ); 764 *
765 * @param s1 the first string
766 * @param s2 the second string
767 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
768 * than @p s2, zero if both strings equal
769 */
770 #define cx_strcmp(s1, s2) cx_strcmp_(cx_strcast(s1), cx_strcast(s2))
855 771
856 /** 772 /**
857 * Compares two strings ignoring case. 773 * Compares two strings ignoring case.
858 * 774 *
859 * @param s1 the first string 775 * @param s1 the first string
860 * @param s2 the second string 776 * @param s2 the second string
861 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger 777 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
862 * than @p s2, zero if both strings equal ignoring case 778 * than @p s2, zero if both strings equal ignoring case
863 */ 779 */
864 cx_attr_nodiscard 780 cx_attr_nodiscard
865 cx_attr_export 781 CX_EXPORT int cx_strcasecmp_(cxstring s1, cxstring s2);
866 int cx_strcasecmp( 782
867 cxstring s1, 783 /**
868 cxstring s2 784 * Compares two strings ignoring case.
869 ); 785 *
786 * @param s1 the first string
787 * @param s2 the second string
788 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
789 * than @p s2, zero if both strings equal ignoring case
790 */
791 #define cx_strcasecmp(s1, s2) cx_strcasecmp_(cx_strcast(s1), cx_strcast(s2))
870 792
871 /** 793 /**
872 * Compares two strings. 794 * Compares two strings.
873 * 795 *
874 * This function has a compatible signature for the use as a cx_compare_func. 796 * This function has a compatible signature for the use as a cx_compare_func.
797 *
798 * @attention This function can @em only compare UCX strings. It is unsafe to
799 * pass normal C-strings to this function.
875 * 800 *
876 * @param s1 the first string 801 * @param s1 the first string
877 * @param s2 the second string 802 * @param s2 the second string
878 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger 803 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
879 * than @p s2, zero if both strings equal 804 * than @p s2, zero if both strings equal
880 */ 805 */
881 cx_attr_nodiscard 806 cx_attr_nodiscard cx_attr_nonnull
882 cx_attr_nonnull 807 CX_EXPORT int cx_strcmp_p(const void *s1, const void *s2);
883 cx_attr_export
884 int cx_strcmp_p(
885 const void *s1,
886 const void *s2
887 );
888 808
889 /** 809 /**
890 * Compares two strings ignoring case. 810 * Compares two strings ignoring case.
891 * 811 *
892 * This function has a compatible signature for the use as a cx_compare_func. 812 * This function has a compatible signature for the use as a cx_compare_func.
894 * @param s1 the first string 814 * @param s1 the first string
895 * @param s2 the second string 815 * @param s2 the second string
896 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger 816 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
897 * than @p s2, zero if both strings equal ignoring case 817 * than @p s2, zero if both strings equal ignoring case
898 */ 818 */
899 cx_attr_nodiscard 819 cx_attr_nodiscard cx_attr_nonnull
900 cx_attr_nonnull 820 CX_EXPORT int cx_strcasecmp_p(const void *s1, const void *s2);
901 cx_attr_export
902 int cx_strcasecmp_p(
903 const void *s1,
904 const void *s2
905 );
906 821
907 822
908 /** 823 /**
909 * Creates a duplicate of the specified string. 824 * Creates a duplicate of the specified string.
910 * 825 *
915 * @param allocator the allocator to use 830 * @param allocator the allocator to use
916 * @param string the string to duplicate 831 * @param string the string to duplicate
917 * @return a duplicate of the string 832 * @return a duplicate of the string
918 * @see cx_strdup() 833 * @see cx_strdup()
919 */ 834 */
920 cx_attr_nodiscard 835 cx_attr_nodiscard cx_attr_nonnull
921 cx_attr_nonnull 836 CX_EXPORT cxmutstr cx_strdup_a_(const CxAllocator *allocator, cxstring string);
922 cx_attr_export
923 cxmutstr cx_strdup_a_(
924 const CxAllocator *allocator,
925 cxstring string
926 );
927 837
928 /** 838 /**
929 * Creates a duplicate of the specified string. 839 * Creates a duplicate of the specified string.
930 * 840 *
931 * The new string will contain a copy allocated by @p allocator. 841 * The new string will contain a copy allocated by @p allocator.
936 * @param string the string to duplicate 846 * @param string the string to duplicate
937 * @return (@c cxmutstr) a duplicate of the string 847 * @return (@c cxmutstr) a duplicate of the string
938 * @see cx_strdup() 848 * @see cx_strdup()
939 * @see cx_strfree_a() 849 * @see cx_strfree_a()
940 */ 850 */
941 #define cx_strdup_a(allocator, string) \ 851 #define cx_strdup_a(allocator, string) cx_strdup_a_((allocator), cx_strcast(string))
942 cx_strdup_a_((allocator), cx_strcast(string))
943 852
944 /** 853 /**
945 * Creates a duplicate of the specified string. 854 * Creates a duplicate of the specified string.
946 * 855 *
947 * The new string will contain a copy allocated by the cxDefaultAllocator. 856 * The new string will contain a copy allocated by the cxDefaultAllocator.
964 * 873 *
965 * @param string the string that shall be trimmed 874 * @param string the string that shall be trimmed
966 * @return the trimmed string 875 * @return the trimmed string
967 */ 876 */
968 cx_attr_nodiscard 877 cx_attr_nodiscard
969 cx_attr_export 878 CX_EXPORT cxstring cx_strtrim(cxstring string);
970 cxstring cx_strtrim(cxstring string);
971 879
972 /** 880 /**
973 * Omits leading and trailing spaces. 881 * Omits leading and trailing spaces.
974 * 882 *
975 * @note the returned string references the same memory, thus you 883 * @note the returned string references the same memory, thus you
977 * 885 *
978 * @param string the string that shall be trimmed 886 * @param string the string that shall be trimmed
979 * @return the trimmed string 887 * @return the trimmed string
980 */ 888 */
981 cx_attr_nodiscard 889 cx_attr_nodiscard
982 cx_attr_export 890 CX_EXPORT cxmutstr cx_strtrim_m(cxmutstr string);
983 cxmutstr cx_strtrim_m(cxmutstr string);
984 891
985 /** 892 /**
986 * Checks if a string has a specific prefix. 893 * Checks if a string has a specific prefix.
987 * 894 *
988 * @param string the string to check 895 * @param string the string to check
989 * @param prefix the prefix the string should have 896 * @param prefix the prefix the string should have
990 * @return @c true, if and only if the string has the specified prefix, 897 * @return @c true, if and only if the string has the specified prefix,
991 * @c false otherwise 898 * @c false otherwise
992 */ 899 */
993 cx_attr_nodiscard 900 cx_attr_nodiscard
994 cx_attr_export 901 CX_EXPORT bool cx_strprefix_(cxstring string, cxstring prefix);
995 bool cx_strprefix( 902
996 cxstring string, 903 /**
997 cxstring prefix 904 * Checks if a string has a specific prefix.
998 ); 905 *
906 * @param string the string to check
907 * @param prefix the prefix the string should have
908 * @return @c true, if and only if the string has the specified prefix,
909 * @c false otherwise
910 */
911 #define cx_strprefix(string, prefix) cx_strprefix_(cx_strcast(string), cx_strcast(prefix))
999 912
1000 /** 913 /**
1001 * Checks if a string has a specific suffix. 914 * Checks if a string has a specific suffix.
1002 * 915 *
1003 * @param string the string to check 916 * @param string the string to check
1004 * @param suffix the suffix the string should have 917 * @param suffix the suffix the string should have
1005 * @return @c true, if and only if the string has the specified suffix, 918 * @return @c true, if and only if the string has the specified suffix,
1006 * @c false otherwise 919 * @c false otherwise
1007 */ 920 */
1008 cx_attr_nodiscard 921 cx_attr_nodiscard
1009 cx_attr_export 922 CX_EXPORT bool cx_strsuffix_(cxstring string, cxstring suffix);
1010 bool cx_strsuffix( 923
1011 cxstring string, 924 /**
1012 cxstring suffix 925 * Checks if a string has a specific suffix.
1013 ); 926 *
927 * @param string the string to check
928 * @param suffix the suffix the string should have
929 * @return @c true, if and only if the string has the specified suffix,
930 * @c false otherwise
931 */
932 #define cx_strsuffix(string, suffix) cx_strsuffix_(cx_strcast(string), cx_strcast(suffix))
1014 933
1015 /** 934 /**
1016 * Checks if a string has a specific prefix, ignoring the case. 935 * Checks if a string has a specific prefix, ignoring the case.
1017 * 936 *
1018 * @param string the string to check 937 * @param string the string to check
1019 * @param prefix the prefix the string should have 938 * @param prefix the prefix the string should have
1020 * @return @c true, if and only if the string has the specified prefix, 939 * @return @c true, if and only if the string has the specified prefix,
1021 * @c false otherwise 940 * @c false otherwise
1022 */ 941 */
1023 cx_attr_nodiscard 942 cx_attr_nodiscard
1024 cx_attr_export 943 CX_EXPORT bool cx_strcaseprefix_(cxstring string, cxstring prefix);
1025 bool cx_strcaseprefix( 944
1026 cxstring string, 945 /**
1027 cxstring prefix 946 * Checks if a string has a specific prefix, ignoring the case.
1028 ); 947 *
948 * @param string the string to check
949 * @param prefix the prefix the string should have
950 * @return @c true, if and only if the string has the specified prefix,
951 * @c false otherwise
952 */
953 #define cx_strcaseprefix(string, prefix) cx_strcaseprefix_(cx_strcast(string), cx_strcast(prefix))
1029 954
1030 /** 955 /**
1031 * Checks, if a string has a specific suffix, ignoring the case. 956 * Checks, if a string has a specific suffix, ignoring the case.
1032 * 957 *
1033 * @param string the string to check 958 * @param string the string to check
1034 * @param suffix the suffix the string should have 959 * @param suffix the suffix the string should have
1035 * @return @c true, if and only if the string has the specified suffix, 960 * @return @c true, if and only if the string has the specified suffix,
1036 * @c false otherwise 961 * @c false otherwise
1037 */ 962 */
1038 cx_attr_nodiscard 963 cx_attr_nodiscard
1039 cx_attr_export 964 CX_EXPORT bool cx_strcasesuffix_(cxstring string, cxstring suffix);
1040 bool cx_strcasesuffix( 965
1041 cxstring string, 966 /**
1042 cxstring suffix 967 * Checks, if a string has a specific suffix, ignoring the case.
1043 ); 968 *
969 * @param string the string to check
970 * @param suffix the suffix the string should have
971 * @return @c true, if and only if the string has the specified suffix,
972 * @c false otherwise
973 */
974 #define cx_strcasesuffix(string, suffix) cx_strcasesuffix_(cx_strcast(string), cx_strcast(suffix))
1044 975
1045 /** 976 /**
1046 * Replaces a string with another string. 977 * Replaces a string with another string.
1047 * 978 *
1048 * The function replaces at most @p replmax occurrences. 979 * The function replaces at most @p replmax occurrences.
1058 * @param search the string to search for 989 * @param search the string to search for
1059 * @param replacement the replacement string 990 * @param replacement the replacement string
1060 * @param replmax maximum number of replacements 991 * @param replmax maximum number of replacements
1061 * @return the resulting string after applying the replacements 992 * @return the resulting string after applying the replacements
1062 */ 993 */
1063 cx_attr_nodiscard 994 cx_attr_nodiscard cx_attr_nonnull
1064 cx_attr_nonnull 995 CX_EXPORT cxmutstr cx_strreplacen_a(const CxAllocator *allocator,
1065 cx_attr_export 996 cxstring str, cxstring search, cxstring replacement, size_t replmax);
1066 cxmutstr cx_strreplacen_a(
1067 const CxAllocator *allocator,
1068 cxstring str,
1069 cxstring search,
1070 cxstring replacement,
1071 size_t replmax
1072 );
1073 997
1074 /** 998 /**
1075 * Replaces a string with another string. 999 * Replaces a string with another string.
1076 * 1000 *
1077 * The function replaces at most @p replmax occurrences. 1001 * The function replaces at most @p replmax occurrences.
1087 * @param replacement (@c cxstring) the replacement string 1011 * @param replacement (@c cxstring) the replacement string
1088 * @param replmax (@c size_t) maximum number of replacements 1012 * @param replmax (@c size_t) maximum number of replacements
1089 * @return (@c cxmutstr) the resulting string after applying the replacements 1013 * @return (@c cxmutstr) the resulting string after applying the replacements
1090 */ 1014 */
1091 #define cx_strreplacen(str, search, replacement, replmax) \ 1015 #define cx_strreplacen(str, search, replacement, replmax) \
1092 cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, replmax) 1016 cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, replmax)
1093 1017
1094 /** 1018 /**
1095 * Replaces a string with another string. 1019 * Replaces a string with another string.
1096 * 1020 *
1097 * The returned string will be allocated by @p allocator and is guaranteed 1021 * The returned string will be allocated by @p allocator and is guaranteed
1105 * @param search (@c cxstring) the string to search for 1029 * @param search (@c cxstring) the string to search for
1106 * @param replacement (@c cxstring) the replacement string 1030 * @param replacement (@c cxstring) the replacement string
1107 * @return (@c cxmutstr) the resulting string after applying the replacements 1031 * @return (@c cxmutstr) the resulting string after applying the replacements
1108 */ 1032 */
1109 #define cx_strreplace_a(allocator, str, search, replacement) \ 1033 #define cx_strreplace_a(allocator, str, search, replacement) \
1110 cx_strreplacen_a(allocator, str, search, replacement, SIZE_MAX) 1034 cx_strreplacen_a(allocator, str, search, replacement, SIZE_MAX)
1111 1035
1112 /** 1036 /**
1113 * Replaces a string with another string. 1037 * Replaces a string with another string.
1114 * 1038 *
1115 * The returned string will be allocated by the cxDefaultAllocator and is guaranteed 1039 * The returned string will be allocated by the cxDefaultAllocator and is guaranteed
1122 * @param search (@c cxstring) the string to search for 1046 * @param search (@c cxstring) the string to search for
1123 * @param replacement (@c cxstring) the replacement string 1047 * @param replacement (@c cxstring) the replacement string
1124 * @return (@c cxmutstr) the resulting string after applying the replacements 1048 * @return (@c cxmutstr) the resulting string after applying the replacements
1125 */ 1049 */
1126 #define cx_strreplace(str, search, replacement) \ 1050 #define cx_strreplace(str, search, replacement) \
1127 cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, SIZE_MAX) 1051 cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, SIZE_MAX)
1128 1052
1129 /** 1053 /**
1130 * Creates a string tokenization context. 1054 * Creates a string tokenization context.
1131 * 1055 *
1132 * @param str the string to tokenize 1056 * @param str the string to tokenize
1133 * @param delim the delimiter (must not be empty) 1057 * @param delim the delimiter (must not be empty)
1134 * @param limit the maximum number of tokens that shall be returned 1058 * @param limit the maximum number of tokens that shall be returned
1135 * @return a new string tokenization context 1059 * @return a new string tokenization context
1136 */ 1060 */
1137 cx_attr_nodiscard 1061 cx_attr_nodiscard
1138 cx_attr_export 1062 CX_EXPORT CxStrtokCtx cx_strtok_(cxstring str, cxstring delim, size_t limit);
1139 CxStrtokCtx cx_strtok_(
1140 cxstring str,
1141 cxstring delim,
1142 size_t limit
1143 );
1144 1063
1145 /** 1064 /**
1146 * Creates a string tokenization context. 1065 * Creates a string tokenization context.
1147 * 1066 *
1148 * @param str the string to tokenize 1067 * @param str the string to tokenize
1149 * @param delim the delimiter string (must not be empty) 1068 * @param delim the delimiter string (must not be empty)
1150 * @param limit (@c size_t) the maximum number of tokens that shall be returned 1069 * @param limit (@c size_t) the maximum number of tokens that shall be returned
1151 * @return (@c CxStrtokCtx) a new string tokenization context 1070 * @return (@c CxStrtokCtx) a new string tokenization context
1152 */ 1071 */
1153 #define cx_strtok(str, delim, limit) \ 1072 #define cx_strtok(str, delim, limit) \
1154 cx_strtok_(cx_strcast(str), cx_strcast(delim), (limit)) 1073 cx_strtok_(cx_strcast(str), cx_strcast(delim), (limit))
1155 1074
1156 /** 1075 /**
1157 * Returns the next token. 1076 * Returns the next token.
1158 * 1077 *
1159 * The token will point to the source string. 1078 * The token will point to the source string.
1161 * @param ctx the tokenization context 1080 * @param ctx the tokenization context
1162 * @param token a pointer to memory where the next token shall be stored 1081 * @param token a pointer to memory where the next token shall be stored
1163 * @return true if successful, false if the limit or the end of the string 1082 * @return true if successful, false if the limit or the end of the string
1164 * has been reached 1083 * has been reached
1165 */ 1084 */
1166 cx_attr_nonnull 1085 cx_attr_nonnull cx_attr_nodiscard cx_attr_access_w(2)
1167 cx_attr_nodiscard 1086 CX_EXPORT bool cx_strtok_next(CxStrtokCtx *ctx, cxstring *token);
1168 cx_attr_access_w(2)
1169 cx_attr_export
1170 bool cx_strtok_next(
1171 CxStrtokCtx *ctx,
1172 cxstring *token
1173 );
1174 1087
1175 /** 1088 /**
1176 * Returns the next token of a mutable string. 1089 * Returns the next token of a mutable string.
1177 * 1090 *
1178 * The token will point to the source string. 1091 * The token will point to the source string.
1184 * @param ctx the tokenization context 1097 * @param ctx the tokenization context
1185 * @param token a pointer to memory where the next token shall be stored 1098 * @param token a pointer to memory where the next token shall be stored
1186 * @return true if successful, false if the limit or the end of the string 1099 * @return true if successful, false if the limit or the end of the string
1187 * has been reached 1100 * has been reached
1188 */ 1101 */
1189 cx_attr_nonnull 1102 cx_attr_nonnull cx_attr_nodiscard cx_attr_access_w(2)
1190 cx_attr_nodiscard 1103 CX_EXPORT bool cx_strtok_next_m(CxStrtokCtx *ctx, cxmutstr *token);
1191 cx_attr_access_w(2)
1192 cx_attr_export
1193 bool cx_strtok_next_m(
1194 CxStrtokCtx *ctx,
1195 cxmutstr *token
1196 );
1197 1104
1198 /** 1105 /**
1199 * Defines an array of more delimiters for the specified tokenization context. 1106 * Defines an array of more delimiters for the specified tokenization context.
1200 * 1107 *
1201 * @param ctx the tokenization context 1108 * @param ctx the tokenization context
1202 * @param delim array of more delimiters 1109 * @param delim array of more delimiters
1203 * @param count number of elements in the array 1110 * @param count number of elements in the array
1204 */ 1111 */
1205 cx_attr_nonnull 1112 cx_attr_nonnull cx_attr_access_r(2, 3)
1206 cx_attr_access_r(2, 3) 1113 CX_EXPORT void cx_strtok_delim(CxStrtokCtx *ctx, const cxstring *delim, size_t count);
1207 cx_attr_export
1208 void cx_strtok_delim(
1209 CxStrtokCtx *ctx,
1210 const cxstring *delim,
1211 size_t count
1212 );
1213 1114
1214 /* ------------------------------------------------------------------------- * 1115 /* ------------------------------------------------------------------------- *
1215 * string to number conversion functions * 1116 * string to number conversion functions *
1216 * ------------------------------------------------------------------------- */ 1117 * ------------------------------------------------------------------------- */
1217 1118
1227 * @param base 2, 8, 10, or 16 1128 * @param base 2, 8, 10, or 16
1228 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1129 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1229 * @retval zero success 1130 * @retval zero success
1230 * @retval non-zero conversion was not possible 1131 * @retval non-zero conversion was not possible
1231 */ 1132 */
1232 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1133 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1233 int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep); 1134 CX_EXPORT int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep);
1234 1135
1235 /** 1136 /**
1236 * Converts a string to a number. 1137 * Converts a string to a number.
1237 * 1138 *
1238 * The function returns non-zero when conversion is not possible. 1139 * The function returns non-zero when conversion is not possible.
1244 * @param base 2, 8, 10, or 16 1145 * @param base 2, 8, 10, or 16
1245 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1146 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1246 * @retval zero success 1147 * @retval zero success
1247 * @retval non-zero conversion was not possible 1148 * @retval non-zero conversion was not possible
1248 */ 1149 */
1249 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1150 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1250 int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep); 1151 CX_EXPORT int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep);
1251 1152
1252 /** 1153 /**
1253 * Converts a string to a number. 1154 * Converts a string to a number.
1254 * 1155 *
1255 * The function returns non-zero when conversion is not possible. 1156 * The function returns non-zero when conversion is not possible.
1261 * @param base 2, 8, 10, or 16 1162 * @param base 2, 8, 10, or 16
1262 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1163 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1263 * @retval zero success 1164 * @retval zero success
1264 * @retval non-zero conversion was not possible 1165 * @retval non-zero conversion was not possible
1265 */ 1166 */
1266 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1167 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1267 int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep); 1168 CX_EXPORT int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep);
1268 1169
1269 /** 1170 /**
1270 * Converts a string to a number. 1171 * Converts a string to a number.
1271 * 1172 *
1272 * The function returns non-zero when conversion is not possible. 1173 * The function returns non-zero when conversion is not possible.
1278 * @param base 2, 8, 10, or 16 1179 * @param base 2, 8, 10, or 16
1279 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1180 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1280 * @retval zero success 1181 * @retval zero success
1281 * @retval non-zero conversion was not possible 1182 * @retval non-zero conversion was not possible
1282 */ 1183 */
1283 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1184 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1284 int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep); 1185 CX_EXPORT int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep);
1285 1186
1286 /** 1187 /**
1287 * Converts a string to a number. 1188 * Converts a string to a number.
1288 * 1189 *
1289 * The function returns non-zero when conversion is not possible. 1190 * The function returns non-zero when conversion is not possible.
1295 * @param base 2, 8, 10, or 16 1196 * @param base 2, 8, 10, or 16
1296 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1197 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1297 * @retval zero success 1198 * @retval zero success
1298 * @retval non-zero conversion was not possible 1199 * @retval non-zero conversion was not possible
1299 */ 1200 */
1300 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1201 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1301 int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep); 1202 CX_EXPORT int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep);
1302 1203
1303 /** 1204 /**
1304 * Converts a string to a number. 1205 * Converts a string to a number.
1305 * 1206 *
1306 * The function returns non-zero when conversion is not possible. 1207 * The function returns non-zero when conversion is not possible.
1312 * @param base 2, 8, 10, or 16 1213 * @param base 2, 8, 10, or 16
1313 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1214 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1314 * @retval zero success 1215 * @retval zero success
1315 * @retval non-zero conversion was not possible 1216 * @retval non-zero conversion was not possible
1316 */ 1217 */
1317 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1218 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1318 int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep); 1219 CX_EXPORT int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep);
1319 1220
1320 /** 1221 /**
1321 * Converts a string to a number. 1222 * Converts a string to a number.
1322 * 1223 *
1323 * The function returns non-zero when conversion is not possible. 1224 * The function returns non-zero when conversion is not possible.
1329 * @param base 2, 8, 10, or 16 1230 * @param base 2, 8, 10, or 16
1330 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1231 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1331 * @retval zero success 1232 * @retval zero success
1332 * @retval non-zero conversion was not possible 1233 * @retval non-zero conversion was not possible
1333 */ 1234 */
1334 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1235 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1335 int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep); 1236 CX_EXPORT int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep);
1336 1237
1337 /** 1238 /**
1338 * Converts a string to a number. 1239 * Converts a string to a number.
1339 * 1240 *
1340 * The function returns non-zero when conversion is not possible. 1241 * The function returns non-zero when conversion is not possible.
1346 * @param base 2, 8, 10, or 16 1247 * @param base 2, 8, 10, or 16
1347 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1248 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1348 * @retval zero success 1249 * @retval zero success
1349 * @retval non-zero conversion was not possible 1250 * @retval non-zero conversion was not possible
1350 */ 1251 */
1351 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1252 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1352 int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep); 1253 CX_EXPORT int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep);
1353 1254
1354 /** 1255 /**
1355 * Converts a string to a number. 1256 * Converts a string to a number.
1356 * 1257 *
1357 * The function returns non-zero when conversion is not possible. 1258 * The function returns non-zero when conversion is not possible.
1363 * @param base 2, 8, 10, or 16 1264 * @param base 2, 8, 10, or 16
1364 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1265 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1365 * @retval zero success 1266 * @retval zero success
1366 * @retval non-zero conversion was not possible 1267 * @retval non-zero conversion was not possible
1367 */ 1268 */
1368 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1269 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1369 int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep); 1270 CX_EXPORT int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep);
1370 1271
1371 /** 1272 /**
1372 * Converts a string to a number. 1273 * Converts a string to a number.
1373 * 1274 *
1374 * The function returns non-zero when conversion is not possible. 1275 * The function returns non-zero when conversion is not possible.
1380 * @param base 2, 8, 10, or 16 1281 * @param base 2, 8, 10, or 16
1381 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1282 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1382 * @retval zero success 1283 * @retval zero success
1383 * @retval non-zero conversion was not possible 1284 * @retval non-zero conversion was not possible
1384 */ 1285 */
1385 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1286 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1386 int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep); 1287 CX_EXPORT int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep);
1387 1288
1388 /** 1289 /**
1389 * Converts a string to a number. 1290 * Converts a string to a number.
1390 * 1291 *
1391 * The function returns non-zero when conversion is not possible. 1292 * The function returns non-zero when conversion is not possible.
1397 * @param base 2, 8, 10, or 16 1298 * @param base 2, 8, 10, or 16
1398 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1299 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1399 * @retval zero success 1300 * @retval zero success
1400 * @retval non-zero conversion was not possible 1301 * @retval non-zero conversion was not possible
1401 */ 1302 */
1402 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1303 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1403 int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep); 1304 CX_EXPORT int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep);
1404 1305
1405 /** 1306 /**
1406 * Converts a string to a number. 1307 * Converts a string to a number.
1407 * 1308 *
1408 * The function returns non-zero when conversion is not possible. 1309 * The function returns non-zero when conversion is not possible.
1414 * @param base 2, 8, 10, or 16 1315 * @param base 2, 8, 10, or 16
1415 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1316 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1416 * @retval zero success 1317 * @retval zero success
1417 * @retval non-zero conversion was not possible 1318 * @retval non-zero conversion was not possible
1418 */ 1319 */
1419 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1320 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1420 int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep); 1321 CX_EXPORT int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep);
1421 1322
1422 /** 1323 /**
1423 * Converts a string to a number. 1324 * Converts a string to a number.
1424 * 1325 *
1425 * The function returns non-zero when conversion is not possible. 1326 * The function returns non-zero when conversion is not possible.
1431 * @param base 2, 8, 10, or 16 1332 * @param base 2, 8, 10, or 16
1432 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1333 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1433 * @retval zero success 1334 * @retval zero success
1434 * @retval non-zero conversion was not possible 1335 * @retval non-zero conversion was not possible
1435 */ 1336 */
1436 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1337 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1437 int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep); 1338 CX_EXPORT int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep);
1438 1339
1439 /** 1340 /**
1440 * Converts a string to a number. 1341 * Converts a string to a number.
1441 * 1342 *
1442 * The function returns non-zero when conversion is not possible. 1343 * The function returns non-zero when conversion is not possible.
1448 * @param base 2, 8, 10, or 16 1349 * @param base 2, 8, 10, or 16
1449 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1350 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1450 * @retval zero success 1351 * @retval zero success
1451 * @retval non-zero conversion was not possible 1352 * @retval non-zero conversion was not possible
1452 */ 1353 */
1453 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1354 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1454 int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep); 1355 CX_EXPORT int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep);
1455 1356
1456 /** 1357 /**
1457 * Converts a string to a number. 1358 * Converts a string to a number.
1458 * 1359 *
1459 * The function returns non-zero when conversion is not possible. 1360 * The function returns non-zero when conversion is not possible.
1465 * @param base 2, 8, 10, or 16 1366 * @param base 2, 8, 10, or 16
1466 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1367 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1467 * @retval zero success 1368 * @retval zero success
1468 * @retval non-zero conversion was not possible 1369 * @retval non-zero conversion was not possible
1469 */ 1370 */
1470 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1371 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1471 int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep); 1372 CX_EXPORT int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep);
1472 1373
1473 /** 1374 /**
1474 * Converts a string to a number. 1375 * Converts a string to a number.
1475 * 1376 *
1476 * The function returns non-zero when conversion is not possible. 1377 * The function returns non-zero when conversion is not possible.
1482 * @param base 2, 8, 10, or 16 1383 * @param base 2, 8, 10, or 16
1483 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1384 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1484 * @retval zero success 1385 * @retval zero success
1485 * @retval non-zero conversion was not possible 1386 * @retval non-zero conversion was not possible
1486 */ 1387 */
1487 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1388 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1488 int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep); 1389 CX_EXPORT int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep);
1489 1390
1490 /** 1391 /**
1491 * Converts a string to a number. 1392 * Converts a string to a number.
1492 * 1393 *
1493 * The function returns non-zero when conversion is not possible. 1394 * The function returns non-zero when conversion is not possible.
1499 * @param base 2, 8, 10, or 16 1400 * @param base 2, 8, 10, or 16
1500 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1401 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1501 * @retval zero success 1402 * @retval zero success
1502 * @retval non-zero conversion was not possible 1403 * @retval non-zero conversion was not possible
1503 */ 1404 */
1504 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1405 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1505 int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep); 1406 CX_EXPORT int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep);
1506 1407
1507 /** 1408 /**
1508 * Converts a string to a single precision floating-point number. 1409 * Converts a string to a single precision floating-point number.
1509 * 1410 *
1510 * The function returns non-zero when conversion is not possible. 1411 * The function returns non-zero when conversion is not possible.
1516 * @param decsep the decimal separator 1417 * @param decsep the decimal separator
1517 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1418 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1518 * @retval zero success 1419 * @retval zero success
1519 * @retval non-zero conversion was not possible 1420 * @retval non-zero conversion was not possible
1520 */ 1421 */
1521 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1422 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1522 int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep); 1423 CX_EXPORT int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep);
1523 1424
1524 /** 1425 /**
1525 * Converts a string to a double precision floating-point number. 1426 * Converts a string to a double precision floating-point number.
1526 * 1427 *
1527 * The function returns non-zero when conversion is not possible. 1428 * The function returns non-zero when conversion is not possible.
1533 * @param decsep the decimal separator 1434 * @param decsep the decimal separator
1534 * @param groupsep each character in this string is treated as a group separator and ignored during conversion 1435 * @param groupsep each character in this string is treated as a group separator and ignored during conversion
1535 * @retval zero success 1436 * @retval zero success
1536 * @retval non-zero conversion was not possible 1437 * @retval non-zero conversion was not possible
1537 */ 1438 */
1538 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export 1439 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1539 int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep); 1440 CX_EXPORT int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep);
1540 1441
1541 /** 1442 /**
1542 * Converts a string to a number. 1443 * Converts a string to a number.
1543 * 1444 *
1544 * The function returns non-zero when conversion is not possible. 1445 * The function returns non-zero when conversion is not possible.

mercurial