| 157 * @param cstring the string to wrap (must be zero-terminated) |
157 * @param cstring the string to wrap (must be zero-terminated) |
| 158 * @return the wrapped string |
158 * @return the wrapped string |
| 159 * |
159 * |
| 160 * @see cx_mutstrn() |
160 * @see cx_mutstrn() |
| 161 */ |
161 */ |
| 162 cx_attr_nodiscard cx_attr_cstr_arg(1) |
162 CX_NODISCARD CX_CSTR_ARG(1) |
| 163 CX_INLINE cxmutstr cx_mutstr(char *cstring) { |
163 CX_INLINE cxmutstr cx_mutstr(char *cstring) { |
| 164 cxmutstr str; |
164 cxmutstr str; |
| 165 str.ptr = cstring; |
165 str.ptr = cstring; |
| 166 str.length = cstring == NULL ? 0 : strlen(cstring); |
166 str.length = cstring == NULL ? 0 : strlen(cstring); |
| 167 return str; |
167 return str; |
| 206 * @param cstring the string to wrap (must be zero-terminated) |
206 * @param cstring the string to wrap (must be zero-terminated) |
| 207 * @return the wrapped string |
207 * @return the wrapped string |
| 208 * |
208 * |
| 209 * @see cx_strn() |
209 * @see cx_strn() |
| 210 */ |
210 */ |
| 211 cx_attr_nodiscard cx_attr_cstr_arg(1) |
211 CX_NODISCARD CX_CSTR_ARG(1) |
| 212 CX_INLINE cxstring cx_str(const char *cstring) { |
212 CX_INLINE cxstring cx_str(const char *cstring) { |
| 213 cxstring str; |
213 cxstring str; |
| 214 str.ptr = cstring; |
214 str.ptr = cstring; |
| 215 str.length = cstring == NULL ? 0 : strlen(cstring); |
215 str.length = cstring == NULL ? 0 : strlen(cstring); |
| 216 return str; |
216 return str; |
| 231 * @param length the length of the string |
231 * @param length the length of the string |
| 232 * @return the wrapped string |
232 * @return the wrapped string |
| 233 * |
233 * |
| 234 * @see cx_str() |
234 * @see cx_str() |
| 235 */ |
235 */ |
| 236 cx_attr_nodiscard cx_attr_access_r(1, 2) |
236 CX_NODISCARD CX_ACCESS_R(1, 2) |
| 237 CX_INLINE cxstring cx_strn(const char *cstring, size_t length) { |
237 CX_INLINE cxstring cx_strn(const char *cstring, size_t length) { |
| 238 cxstring str; |
238 cxstring str; |
| 239 str.ptr = cstring; |
239 str.ptr = cstring; |
| 240 str.length = length; |
240 str.length = length; |
| 241 return str; |
241 return str; |
| 242 } |
242 } |
| 243 |
243 |
| 244 #ifdef __cplusplus |
244 #ifdef __cplusplus |
| 245 cx_attr_nodiscard |
245 CX_NODISCARD |
| 246 CX_CPPDECL cxmutstr cx_strcast_m(cxmutstr str) { |
246 CX_CPPDECL cxmutstr cx_strcast_m(cxmutstr str) { |
| 247 return str; |
247 return str; |
| 248 } |
248 } |
| 249 cx_attr_nodiscard |
249 CX_NODISCARD |
| 250 CX_CPPDECL cxstring cx_strcast_m(cxstring str) { |
250 CX_CPPDECL cxstring cx_strcast_m(cxstring str) { |
| 251 return str; |
251 return str; |
| 252 } |
252 } |
| 253 cx_attr_nodiscard |
253 CX_NODISCARD |
| 254 CX_CPPDECL cxmutstr cx_strcast_m(char *str) { |
254 CX_CPPDECL cxmutstr cx_strcast_m(char *str) { |
| 255 return cx_mutstr(str); |
255 return cx_mutstr(str); |
| 256 } |
256 } |
| 257 cx_attr_nodiscard |
257 CX_NODISCARD |
| 258 CX_CPPDECL cxmutstr cx_strcast_m(unsigned char *str) { |
258 CX_CPPDECL cxmutstr cx_strcast_m(unsigned char *str) { |
| 259 return cx_mutstr(reinterpret_cast<char*>(str)); |
259 return cx_mutstr(reinterpret_cast<char*>(str)); |
| 260 } |
260 } |
| 261 cx_attr_nodiscard |
261 CX_NODISCARD |
| 262 CX_CPPDECL cxstring cx_strcast_m(const char *str) { |
262 CX_CPPDECL cxstring cx_strcast_m(const char *str) { |
| 263 return cx_str(str); |
263 return cx_str(str); |
| 264 } |
264 } |
| 265 cx_attr_nodiscard |
265 CX_NODISCARD |
| 266 CX_CPPDECL cxstring cx_strcast_m(const unsigned char *str) { |
266 CX_CPPDECL cxstring cx_strcast_m(const unsigned char *str) { |
| 267 return cx_str(reinterpret_cast<const char*>(str)); |
267 return cx_str(reinterpret_cast<const char*>(str)); |
| 268 } |
268 } |
| 269 cx_attr_nodiscard |
269 CX_NODISCARD |
| 270 CX_CPPDECL cxstring cx_strcast_(cxmutstr str) { |
270 CX_CPPDECL cxstring cx_strcast_(cxmutstr str) { |
| 271 return cx_strn(str.ptr, str.length); |
271 return cx_strn(str.ptr, str.length); |
| 272 } |
272 } |
| 273 cx_attr_nodiscard |
273 CX_NODISCARD |
| 274 CX_CPPDECL cxstring cx_strcast_(cxstring str) { |
274 CX_CPPDECL cxstring cx_strcast_(cxstring str) { |
| 275 return str; |
275 return str; |
| 276 } |
276 } |
| 277 #define cx_strcast(s) cx_strcast_(cx_strcast_m(s)) |
277 #define cx_strcast(s) cx_strcast_(cx_strcast_m(s)) |
| 278 extern "C" { |
|
| 279 #else |
278 #else |
| 280 /** |
279 /** |
| 281 * Internal function, do not use. |
280 * Internal function, do not use. |
| 282 * @param str |
281 * @param str |
| 283 * @return |
282 * @return |
| 284 * @see cx_strcast_m() |
283 * @see cx_strcast_m() |
| 285 * @see cx_strcast() |
284 * @see cx_strcast() |
| 286 */ |
285 */ |
| 287 cx_attr_nodiscard |
286 CX_NODISCARD |
| 288 CX_INLINE cxmutstr cx_strcast_cxms(cxmutstr str) { |
287 CX_INLINE cxmutstr cx_strcast_cxms(cxmutstr str) { |
| 289 return str; |
288 return str; |
| 290 } |
289 } |
| 291 /** |
290 /** |
| 292 * Internal function, do not use. |
291 * Internal function, do not use. |
| 293 * @param str |
292 * @param str |
| 294 * @return |
293 * @return |
| 295 * @see cx_strcast_m() |
294 * @see cx_strcast_m() |
| 296 * @see cx_strcast() |
295 * @see cx_strcast() |
| 297 */ |
296 */ |
| 298 cx_attr_nodiscard |
297 CX_NODISCARD |
| 299 CX_INLINE cxstring cx_strcast_cxs(cxstring str) { |
298 CX_INLINE cxstring cx_strcast_cxs(cxstring str) { |
| 300 return str; |
299 return str; |
| 301 } |
300 } |
| 302 |
301 |
| 303 /** |
302 /** |
| 417 * you ever have a <code>const char*</code> you are really supposed to free. |
416 * you ever have a <code>const char*</code> you are really supposed to free. |
| 418 * If you encounter such a situation, you should double-check your code. |
417 * If you encounter such a situation, you should double-check your code. |
| 419 * |
418 * |
| 420 * @param str the string to free |
419 * @param str the string to free |
| 421 */ |
420 */ |
| 422 CX_EXPORT void cx_strfree(cxmutstr *str); |
421 CX_EXTERN |
| |
422 void cx_strfree(cxmutstr *str); |
| 423 |
423 |
| 424 /** |
424 /** |
| 425 * Passes the pointer in this string to the allocator's free function. |
425 * Passes the pointer in this string to the allocator's free function. |
| 426 * |
426 * |
| 427 * The pointer in the struct is set to @c NULL, and the length is set to zero, |
427 * The pointer in the struct is set to @c NULL, and the length is set to zero, |
| 432 * If you encounter such a situation, you should double-check your code. |
432 * If you encounter such a situation, you should double-check your code. |
| 433 * |
433 * |
| 434 * @param alloc the allocator |
434 * @param alloc the allocator |
| 435 * @param str the string to free |
435 * @param str the string to free |
| 436 */ |
436 */ |
| 437 cx_attr_nonnull_arg(1) |
437 CX_EXTERN CX_NONNULL_ARG(1) |
| 438 CX_EXPORT void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str); |
438 void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str); |
| 439 |
439 |
| 440 /** |
440 /** |
| 441 * Copies a string. |
441 * Copies a string. |
| 442 * |
442 * |
| 443 * Internal function - do not use. |
443 * Internal function - do not use. |
| 448 * |
448 * |
| 449 * @retval zero success |
449 * @retval zero success |
| 450 * @retval non-zero if re-allocation failed |
450 * @retval non-zero if re-allocation failed |
| 451 * @see cx_strcpy_a() |
451 * @see cx_strcpy_a() |
| 452 */ |
452 */ |
| 453 cx_attr_nonnull_arg(1) |
453 CX_EXTERN CX_NONNULL_ARG(1) |
| 454 CX_EXPORT int cx_strcpy_a_(const CxAllocator *alloc, cxmutstr *dest, cxstring src); |
454 int cx_strcpy_a_(const CxAllocator *alloc, cxmutstr *dest, cxstring src); |
| 455 |
455 |
| 456 /** |
456 /** |
| 457 * Copies a string. |
457 * Copies a string. |
| 458 * |
458 * |
| 459 * The memory in the @p dest structure is either allocated or re-allocated to fit the entire |
459 * The memory in the @p dest structure is either allocated or re-allocated to fit the entire |
| 494 * |
494 * |
| 495 * @param count the total number of specified strings |
495 * @param count the total number of specified strings |
| 496 * @param ... all strings |
496 * @param ... all strings |
| 497 * @return the accumulated length of all strings |
497 * @return the accumulated length of all strings |
| 498 */ |
498 */ |
| 499 cx_attr_nodiscard |
499 CX_EXTERN CX_NODISCARD |
| 500 CX_EXPORT size_t cx_strlen(size_t count, ...); |
500 size_t cx_strlen(size_t count, ...); |
| 501 |
501 |
| 502 /** |
502 /** |
| 503 * Concatenates strings. |
503 * Concatenates strings. |
| 504 * |
504 * |
| 505 * The resulting string will be allocated by the specified allocator. |
505 * The resulting string will be allocated by the specified allocator. |
| 517 * @param str the string the other strings shall be concatenated to |
517 * @param str the string the other strings shall be concatenated to |
| 518 * @param count the number of the other following strings to concatenate |
518 * @param count the number of the other following strings to concatenate |
| 519 * @param ... all other UCX strings |
519 * @param ... all other UCX strings |
| 520 * @return the concatenated string |
520 * @return the concatenated string |
| 521 */ |
521 */ |
| 522 cx_attr_nonnull |
522 CX_EXTERN CX_NONNULL |
| 523 CX_EXPORT cxmutstr cx_strcat_a(const CxAllocator *alloc, |
523 cxmutstr cx_strcat_a(const CxAllocator *alloc, |
| 524 cxmutstr str, size_t count, ...); |
524 cxmutstr str, size_t count, ...); |
| 525 |
525 |
| 526 /** |
526 /** |
| 527 * Concatenates strings and returns a new string. |
527 * Concatenates strings and returns a new string. |
| 528 * |
528 * |
| 551 * @param start start location of the substring |
551 * @param start start location of the substring |
| 552 * @param length the maximum length of the returned string |
552 * @param length the maximum length of the returned string |
| 553 * @return a substring of @p string starting at @p start |
553 * @return a substring of @p string starting at @p start |
| 554 * @see cx_strsubsl() |
554 * @see cx_strsubsl() |
| 555 */ |
555 */ |
| 556 cx_attr_nodiscard |
556 CX_EXTERN CX_NODISCARD |
| 557 CX_EXPORT cxstring cx_strsubsl_(cxstring string, size_t start, size_t length); |
557 cxstring cx_strsubsl_(cxstring string, size_t start, size_t length); |
| 558 |
558 |
| 559 /** |
559 /** |
| 560 * Returns a substring. |
560 * Returns a substring. |
| 561 * |
561 * |
| 562 * Internal function - do not use. |
562 * Internal function - do not use. |
| 564 * @param string input string |
564 * @param string input string |
| 565 * @param start start location of the substring |
565 * @param start start location of the substring |
| 566 * @return a substring of @p string starting at @p start |
566 * @return a substring of @p string starting at @p start |
| 567 * @see cx_strsubs() |
567 * @see cx_strsubs() |
| 568 */ |
568 */ |
| 569 cx_attr_nodiscard |
569 CX_EXTERN CX_NODISCARD |
| 570 CX_EXPORT cxstring cx_strsubs_(cxstring string, size_t start); |
570 cxstring cx_strsubs_(cxstring string, size_t start); |
| 571 |
571 |
| 572 CX_INLINE cxmutstr cx_strsubs_m_(cxmutstr string, size_t start) { |
572 CX_INLINE |
| |
573 cxmutstr cx_strsubs_m_(cxmutstr string, size_t start) { |
| 573 return cx_mutstrcast(cx_strsubs_(cx_strcast(string), start)); |
574 return cx_mutstrcast(cx_strsubs_(cx_strcast(string), start)); |
| 574 } |
575 } |
| 575 |
576 |
| 576 CX_INLINE cxmutstr cx_strsubsl_m_(cxmutstr string, size_t start, size_t length) { |
577 CX_INLINE |
| |
578 cxmutstr cx_strsubsl_m_(cxmutstr string, size_t start, size_t length) { |
| 577 return cx_mutstrcast(cx_strsubsl_(cx_strcast(string), start, length)); |
579 return cx_mutstrcast(cx_strsubsl_(cx_strcast(string), start, length)); |
| 578 } |
580 } |
| 579 |
581 |
| 580 #ifdef __cplusplus |
582 #ifdef __cplusplus |
| 581 } // extern "C" |
|
| 582 CX_CPPDECL cxstring cx_strsubs_cpp_(cxstring string, size_t start) { |
583 CX_CPPDECL cxstring cx_strsubs_cpp_(cxstring string, size_t start) { |
| 583 return cx_strsubs_(string, start); |
584 return cx_strsubs_(string, start); |
| 584 } |
585 } |
| 585 CX_CPPDECL cxstring cx_strsubsl_cpp_(cxstring string, size_t start, size_t length) { |
586 CX_CPPDECL cxstring cx_strsubsl_cpp_(cxstring string, size_t start, size_t length) { |
| 586 return cx_strsubsl_(string, start, length); |
587 return cx_strsubsl_(string, start, length); |
| 591 CX_CPPDECL cxmutstr cx_strsubsl_cpp_(cxmutstr string, size_t start, size_t length) { |
592 CX_CPPDECL cxmutstr cx_strsubsl_cpp_(cxmutstr string, size_t start, size_t length) { |
| 592 return cx_strsubsl_m_(string, start, length); |
593 return cx_strsubsl_m_(string, start, length); |
| 593 } |
594 } |
| 594 #define cx_strsubs(string, start) cx_strsubs_cpp_(cx_strcast_m(string), start) |
595 #define cx_strsubs(string, start) cx_strsubs_cpp_(cx_strcast_m(string), start) |
| 595 #define cx_strsubsl(string, start, length) cx_strsubsl_cpp_(cx_strcast_m(string), start, length) |
596 #define cx_strsubsl(string, start, length) cx_strsubsl_cpp_(cx_strcast_m(string), start, length) |
| 596 extern "C" { |
|
| 597 #else |
597 #else |
| 598 /** |
598 /** |
| 599 * Returns a substring starting at the specified location. |
599 * Returns a substring starting at the specified location. |
| 600 * |
600 * |
| 601 * @attention the new string references the same memory area as the |
601 * @attention the new string references the same memory area as the |
| 642 * @param str the string |
642 * @param str the string |
| 643 * @param index the index offset |
643 * @param index the index offset |
| 644 * @return the character at the index |
644 * @return the character at the index |
| 645 * @see cx_strat() |
645 * @see cx_strat() |
| 646 */ |
646 */ |
| 647 CX_INLINE char cx_strat_(cxstring str, off_t index) { |
647 CX_INLINE |
| |
648 char cx_strat_(cxstring str, off_t index) { |
| 648 size_t i; |
649 size_t i; |
| 649 if (index >= 0) { |
650 if (index >= 0) { |
| 650 i = index; |
651 i = index; |
| 651 } else { |
652 } else { |
| 652 i = (size_t) (str.length + index); |
653 i = (size_t) (str.length + index); |
| 682 * @param chr the character to locate |
683 * @param chr the character to locate |
| 683 * @return a substring starting at the first location of @p chr |
684 * @return a substring starting at the first location of @p chr |
| 684 * |
685 * |
| 685 * @see cx_strchr_m() |
686 * @see cx_strchr_m() |
| 686 */ |
687 */ |
| 687 cx_attr_nodiscard |
688 CX_EXTERN CX_NODISCARD |
| 688 CX_EXPORT cxstring cx_strchr(cxstring string, int chr); |
689 cxstring cx_strchr(cxstring string, int chr); |
| 689 |
690 |
| 690 /** |
691 /** |
| 691 * Returns a substring starting at the location of the first occurrence of the |
692 * Returns a substring starting at the location of the first occurrence of the |
| 692 * specified character. |
693 * specified character. |
| 693 * |
694 * |
| 697 * @param chr the character to locate |
698 * @param chr the character to locate |
| 698 * @return a substring starting at the first location of @p chr |
699 * @return a substring starting at the first location of @p chr |
| 699 * |
700 * |
| 700 * @see cx_strchr() |
701 * @see cx_strchr() |
| 701 */ |
702 */ |
| 702 cx_attr_nodiscard |
703 CX_EXTERN CX_NODISCARD |
| 703 CX_EXPORT cxmutstr cx_strchr_m(cxmutstr string, int chr); |
704 cxmutstr cx_strchr_m(cxmutstr string, int chr); |
| 704 |
705 |
| 705 /** |
706 /** |
| 706 * Returns a substring starting at the location of the last occurrence of the |
707 * Returns a substring starting at the location of the last occurrence of the |
| 707 * specified character. |
708 * specified character. |
| 708 * |
709 * |
| 712 * @param chr the character to locate |
713 * @param chr the character to locate |
| 713 * @return a substring starting at the last location of @p chr |
714 * @return a substring starting at the last location of @p chr |
| 714 * |
715 * |
| 715 * @see cx_strrchr_m() |
716 * @see cx_strrchr_m() |
| 716 */ |
717 */ |
| 717 cx_attr_nodiscard |
718 CX_EXTERN CX_NODISCARD |
| 718 CX_EXPORT cxstring cx_strrchr(cxstring string, int chr); |
719 cxstring cx_strrchr(cxstring string, int chr); |
| 719 |
720 |
| 720 /** |
721 /** |
| 721 * Returns a substring starting at the location of the last occurrence of the |
722 * Returns a substring starting at the location of the last occurrence of the |
| 722 * specified character. |
723 * specified character. |
| 723 * |
724 * |
| 727 * @param chr the character to locate |
728 * @param chr the character to locate |
| 728 * @return a substring starting at the last location of @p chr |
729 * @return a substring starting at the last location of @p chr |
| 729 * |
730 * |
| 730 * @see cx_strrchr() |
731 * @see cx_strrchr() |
| 731 */ |
732 */ |
| 732 cx_attr_nodiscard |
733 CX_EXTERN CX_NODISCARD |
| 733 CX_EXPORT cxmutstr cx_strrchr_m(cxmutstr string, int chr); |
734 cxmutstr cx_strrchr_m(cxmutstr string, int chr); |
| 734 |
735 |
| 735 /** |
736 /** |
| 736 * Searches for a specific substring. |
737 * Searches for a specific substring. |
| 737 * |
738 * |
| 738 * Internal function - do not use. |
739 * Internal function - do not use. |
| 741 * @param needle string containing the sequence of characters to match |
742 * @param needle string containing the sequence of characters to match |
| 742 * @return a substring starting at the first occurrence of @p needle, |
743 * @return a substring starting at the first occurrence of @p needle, |
| 743 * or an empty string, if the sequence is not contained |
744 * or an empty string, if the sequence is not contained |
| 744 * @see cx_strstr() |
745 * @see cx_strstr() |
| 745 */ |
746 */ |
| 746 cx_attr_nodiscard |
747 CX_EXTERN CX_NODISCARD |
| 747 CX_EXPORT cxstring cx_strstr_(cxstring haystack, cxstring needle); |
748 cxstring cx_strstr_(cxstring haystack, cxstring needle); |
| 748 |
749 |
| 749 /** |
750 /** |
| 750 * Returns a substring starting at the location of the first occurrence of the |
751 * Returns a substring starting at the location of the first occurrence of the |
| 751 * specified string. |
752 * specified string. |
| 752 * |
753 * |
| 772 * @param needle string containing the sequence of characters to match |
773 * @param needle string containing the sequence of characters to match |
| 773 * @return a substring starting at the first occurrence of @p needle, |
774 * @return a substring starting at the first occurrence of @p needle, |
| 774 * or an empty string, if the sequence is not contained |
775 * or an empty string, if the sequence is not contained |
| 775 * @see cx_strstr_m() |
776 * @see cx_strstr_m() |
| 776 */ |
777 */ |
| 777 cx_attr_nodiscard |
778 CX_EXTERN CX_NODISCARD |
| 778 CX_EXPORT cxmutstr cx_strstr_m_(cxmutstr haystack, cxstring needle); |
779 cxmutstr cx_strstr_m_(cxmutstr haystack, cxstring needle); |
| 779 |
780 |
| 780 /** |
781 /** |
| 781 * Returns a substring starting at the location of the first occurrence of the |
782 * Returns a substring starting at the location of the first occurrence of the |
| 782 * specified string. |
783 * specified string. |
| 783 * |
784 * |
| 804 * @param limit the maximum number of split items |
805 * @param limit the maximum number of split items |
| 805 * @param output the output array |
806 * @param output the output array |
| 806 * @return the actual number of split items |
807 * @return the actual number of split items |
| 807 * @see cx_strsplit() |
808 * @see cx_strsplit() |
| 808 */ |
809 */ |
| 809 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3) |
810 CX_EXTERN CX_NODISCARD CX_NONNULL CX_ACCESS_W(4, 3) |
| 810 CX_EXPORT size_t cx_strsplit_(cxstring string, cxstring delim, |
811 size_t cx_strsplit_(cxstring string, cxstring delim, |
| 811 size_t limit, cxstring *output); |
812 size_t limit, cxstring *output); |
| 812 |
813 |
| 813 /** |
814 /** |
| 814 * Splits a given string using a delimiter string. |
815 * Splits a given string using a delimiter string. |
| 815 * |
816 * |
| 821 * @param limit the maximum number of split items |
822 * @param limit the maximum number of split items |
| 822 * @param output the output array |
823 * @param output the output array |
| 823 * @return the actual number of split items |
824 * @return the actual number of split items |
| 824 * @see cx_strsplit_a() |
825 * @see cx_strsplit_a() |
| 825 */ |
826 */ |
| 826 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5) |
827 CX_EXTERN CX_NODISCARD CX_NONNULL CX_ACCESS_W(5) |
| 827 CX_EXPORT size_t cx_strsplit_a_(const CxAllocator *allocator, |
828 size_t cx_strsplit_a_(const CxAllocator *allocator, |
| 828 cxstring string, cxstring delim, |
829 cxstring string, cxstring delim, |
| 829 size_t limit, cxstring **output); |
830 size_t limit, cxstring **output); |
| 830 |
831 |
| 831 |
832 |
| 832 /** |
833 /** |
| 839 * @param limit the maximum number of split items |
840 * @param limit the maximum number of split items |
| 840 * @param output the output array |
841 * @param output the output array |
| 841 * @return the actual number of split items |
842 * @return the actual number of split items |
| 842 * @see cx_strsplit_m() |
843 * @see cx_strsplit_m() |
| 843 */ |
844 */ |
| 844 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3) |
845 CX_EXTERN CX_NODISCARD CX_NONNULL CX_ACCESS_W(4, 3) |
| 845 CX_EXPORT size_t cx_strsplit_m_(cxmutstr string, cxstring delim, |
846 size_t cx_strsplit_m_(cxmutstr string, cxstring delim, |
| 846 size_t limit, cxmutstr *output); |
847 size_t limit, cxmutstr *output); |
| 847 |
848 |
| 848 /** |
849 /** |
| 849 * Splits a given string using a delimiter string. |
850 * Splits a given string using a delimiter string. |
| 850 * |
851 * |
| 856 * @param limit the maximum number of split items |
857 * @param limit the maximum number of split items |
| 857 * @param output the output array |
858 * @param output the output array |
| 858 * @return the actual number of split items |
859 * @return the actual number of split items |
| 859 * @see cx_strsplit_ma() |
860 * @see cx_strsplit_ma() |
| 860 */ |
861 */ |
| 861 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5) |
862 CX_EXTERN CX_NODISCARD CX_NONNULL CX_ACCESS_W(5) |
| 862 CX_EXPORT size_t cx_strsplit_ma_(const CxAllocator *allocator, |
863 size_t cx_strsplit_ma_(const CxAllocator *allocator, |
| 863 cxmutstr string, cxstring delim, size_t limit, |
864 cxmutstr string, cxstring delim, size_t limit, |
| 864 cxmutstr **output); |
865 cxmutstr **output); |
| 865 |
866 |
| 866 /** |
867 /** |
| 867 * Splits a given string using a delimiter string. |
868 * Splits a given string using a delimiter string. |
| 944 * @param s1 the first string |
945 * @param s1 the first string |
| 945 * @param s2 the second string |
946 * @param s2 the second string |
| 946 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
947 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
| 947 * than @p s2, zero if both strings equal |
948 * than @p s2, zero if both strings equal |
| 948 */ |
949 */ |
| 949 cx_attr_nodiscard |
950 CX_EXTERN CX_NODISCARD |
| 950 CX_EXPORT int cx_strcmp_(cxstring s1, cxstring s2); |
951 int cx_strcmp_(cxstring s1, cxstring s2); |
| 951 |
952 |
| 952 /** |
953 /** |
| 953 * Compares two strings. |
954 * Compares two strings. |
| 954 * |
955 * |
| 955 * @param s1 the first string |
956 * @param s1 the first string |
| 965 * @param s1 the first string |
966 * @param s1 the first string |
| 966 * @param s2 the second string |
967 * @param s2 the second string |
| 967 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
968 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
| 968 * than @p s2, zero if both strings equal ignoring case |
969 * than @p s2, zero if both strings equal ignoring case |
| 969 */ |
970 */ |
| 970 cx_attr_nodiscard |
971 CX_EXTERN CX_NODISCARD |
| 971 CX_EXPORT int cx_strcasecmp_(cxstring s1, cxstring s2); |
972 int cx_strcasecmp_(cxstring s1, cxstring s2); |
| 972 |
973 |
| 973 /** |
974 /** |
| 974 * Compares two strings ignoring case. |
975 * Compares two strings ignoring case. |
| 975 * |
976 * |
| 976 * @param s1 the first string |
977 * @param s1 the first string |
| 991 * @param s1 the first string |
992 * @param s1 the first string |
| 992 * @param s2 the second string |
993 * @param s2 the second string |
| 993 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
994 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
| 994 * than @p s2, zero if both strings equal |
995 * than @p s2, zero if both strings equal |
| 995 */ |
996 */ |
| 996 cx_attr_nodiscard cx_attr_nonnull |
997 CX_EXTERN CX_NODISCARD CX_NONNULL |
| 997 CX_EXPORT int cx_strcmp_p(const void *s1, const void *s2); |
998 int cx_strcmp_p(const void *s1, const void *s2); |
| 998 |
999 |
| 999 /** |
1000 /** |
| 1000 * Compares two strings ignoring case. |
1001 * Compares two strings ignoring case. |
| 1001 * |
1002 * |
| 1002 * This function has a compatible signature for the use as a cx_compare_func. |
1003 * This function has a compatible signature for the use as a cx_compare_func. |
| 1004 * @param s1 the first string |
1005 * @param s1 the first string |
| 1005 * @param s2 the second string |
1006 * @param s2 the second string |
| 1006 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
1007 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger |
| 1007 * than @p s2, zero if both strings equal ignoring case |
1008 * than @p s2, zero if both strings equal ignoring case |
| 1008 */ |
1009 */ |
| 1009 cx_attr_nodiscard cx_attr_nonnull |
1010 CX_EXTERN CX_NODISCARD CX_NONNULL |
| 1010 CX_EXPORT int cx_strcasecmp_p(const void *s1, const void *s2); |
1011 int cx_strcasecmp_p(const void *s1, const void *s2); |
| 1011 |
|
| 1012 |
1012 |
| 1013 /** |
1013 /** |
| 1014 * Creates a duplicate of the specified string. |
1014 * Creates a duplicate of the specified string. |
| 1015 * |
1015 * |
| 1016 * The new string will contain a copy allocated by @p allocator. |
1016 * The new string will contain a copy allocated by @p allocator. |
| 1020 * @param allocator the allocator to use |
1020 * @param allocator the allocator to use |
| 1021 * @param string the string to duplicate |
1021 * @param string the string to duplicate |
| 1022 * @return a duplicate of the string |
1022 * @return a duplicate of the string |
| 1023 * @see cx_strdup() |
1023 * @see cx_strdup() |
| 1024 */ |
1024 */ |
| 1025 cx_attr_nodiscard cx_attr_nonnull |
1025 CX_EXTERN CX_NODISCARD CX_NONNULL |
| 1026 CX_EXPORT cxmutstr cx_strdup_a_(const CxAllocator *allocator, cxstring string); |
1026 cxmutstr cx_strdup_a_(const CxAllocator *allocator, cxstring string); |
| 1027 |
1027 |
| 1028 /** |
1028 /** |
| 1029 * Creates a duplicate of the specified string. |
1029 * Creates a duplicate of the specified string. |
| 1030 * |
1030 * |
| 1031 * The new string will contain a copy allocated by @p allocator. |
1031 * The new string will contain a copy allocated by @p allocator. |
| 1062 * must @em not free the returned memory. |
1062 * must @em not free the returned memory. |
| 1063 * |
1063 * |
| 1064 * @param string the string that shall be trimmed |
1064 * @param string the string that shall be trimmed |
| 1065 * @return the trimmed string |
1065 * @return the trimmed string |
| 1066 */ |
1066 */ |
| 1067 cx_attr_nodiscard |
1067 CX_EXTERN CX_NODISCARD |
| 1068 CX_EXPORT cxstring cx_strtrim(cxstring string); |
1068 cxstring cx_strtrim(cxstring string); |
| 1069 |
1069 |
| 1070 /** |
1070 /** |
| 1071 * Omits leading and trailing spaces. |
1071 * Omits leading and trailing spaces. |
| 1072 * |
1072 * |
| 1073 * @note the returned string references the same memory, thus you |
1073 * @note the returned string references the same memory, thus you |
| 1074 * must @em not free the returned memory. |
1074 * must @em not free the returned memory. |
| 1075 * |
1075 * |
| 1076 * @param string the string that shall be trimmed |
1076 * @param string the string that shall be trimmed |
| 1077 * @return the trimmed string |
1077 * @return the trimmed string |
| 1078 */ |
1078 */ |
| 1079 cx_attr_nodiscard |
1079 CX_EXTERN CX_NODISCARD |
| 1080 CX_EXPORT cxmutstr cx_strtrim_m(cxmutstr string); |
1080 cxmutstr cx_strtrim_m(cxmutstr string); |
| 1081 |
1081 |
| 1082 /** |
1082 /** |
| 1083 * Checks if a string has a specific prefix. |
1083 * Checks if a string has a specific prefix. |
| 1084 * |
1084 * |
| 1085 * @param string the string to check |
1085 * @param string the string to check |
| 1086 * @param prefix the prefix the string should have |
1086 * @param prefix the prefix the string should have |
| 1087 * @return @c true, if and only if the string has the specified prefix, |
1087 * @return @c true, if and only if the string has the specified prefix, |
| 1088 * @c false otherwise |
1088 * @c false otherwise |
| 1089 */ |
1089 */ |
| 1090 cx_attr_nodiscard |
1090 CX_EXTERN CX_NODISCARD |
| 1091 CX_EXPORT bool cx_strprefix_(cxstring string, cxstring prefix); |
1091 bool cx_strprefix_(cxstring string, cxstring prefix); |
| 1092 |
1092 |
| 1093 /** |
1093 /** |
| 1094 * Checks if a string has a specific prefix. |
1094 * Checks if a string has a specific prefix. |
| 1095 * |
1095 * |
| 1096 * @param string the string to check |
1096 * @param string the string to check |
| 1106 * @param string the string to check |
1106 * @param string the string to check |
| 1107 * @param suffix the suffix the string should have |
1107 * @param suffix the suffix the string should have |
| 1108 * @return @c true, if and only if the string has the specified suffix, |
1108 * @return @c true, if and only if the string has the specified suffix, |
| 1109 * @c false otherwise |
1109 * @c false otherwise |
| 1110 */ |
1110 */ |
| 1111 cx_attr_nodiscard |
1111 CX_EXTERN CX_NODISCARD |
| 1112 CX_EXPORT bool cx_strsuffix_(cxstring string, cxstring suffix); |
1112 bool cx_strsuffix_(cxstring string, cxstring suffix); |
| 1113 |
1113 |
| 1114 /** |
1114 /** |
| 1115 * Checks if a string has a specific suffix. |
1115 * Checks if a string has a specific suffix. |
| 1116 * |
1116 * |
| 1117 * @param string the string to check |
1117 * @param string the string to check |
| 1127 * @param string the string to check |
1127 * @param string the string to check |
| 1128 * @param prefix the prefix the string should have |
1128 * @param prefix the prefix the string should have |
| 1129 * @return @c true, if and only if the string has the specified prefix, |
1129 * @return @c true, if and only if the string has the specified prefix, |
| 1130 * @c false otherwise |
1130 * @c false otherwise |
| 1131 */ |
1131 */ |
| 1132 cx_attr_nodiscard |
1132 CX_EXTERN CX_NODISCARD |
| 1133 CX_EXPORT bool cx_strcaseprefix_(cxstring string, cxstring prefix); |
1133 bool cx_strcaseprefix_(cxstring string, cxstring prefix); |
| 1134 |
1134 |
| 1135 /** |
1135 /** |
| 1136 * Checks if a string has a specific prefix, ignoring the case. |
1136 * Checks if a string has a specific prefix, ignoring the case. |
| 1137 * |
1137 * |
| 1138 * @param string the string to check |
1138 * @param string the string to check |
| 1148 * @param string the string to check |
1148 * @param string the string to check |
| 1149 * @param suffix the suffix the string should have |
1149 * @param suffix the suffix the string should have |
| 1150 * @return @c true, if and only if the string has the specified suffix, |
1150 * @return @c true, if and only if the string has the specified suffix, |
| 1151 * @c false otherwise |
1151 * @c false otherwise |
| 1152 */ |
1152 */ |
| 1153 cx_attr_nodiscard |
1153 CX_EXTERN CX_NODISCARD |
| 1154 CX_EXPORT bool cx_strcasesuffix_(cxstring string, cxstring suffix); |
1154 bool cx_strcasesuffix_(cxstring string, cxstring suffix); |
| 1155 |
1155 |
| 1156 /** |
1156 /** |
| 1157 * Checks, if a string has a specific suffix, ignoring the case. |
1157 * Checks, if a string has a specific suffix, ignoring the case. |
| 1158 * |
1158 * |
| 1159 * @param string the string to check |
1159 * @param string the string to check |
| 1160 * @param suffix the suffix the string should have |
1160 * @param suffix the suffix the string should have |
| 1161 * @return @c true, if and only if the string has the specified suffix, |
1161 * @return @c true, if and only if the string has the specified suffix, |
| 1162 * @c false otherwise |
1162 * @c false otherwise |
| 1163 */ |
1163 */ |
| 1164 #define cx_strcasesuffix(string, suffix) cx_strcasesuffix_(cx_strcast(string), cx_strcast(suffix)) |
1164 #define cx_strcasesuffix(string, suffix) cx_strcasesuffix_(cx_strcast(string), cx_strcast(suffix)) |
| 1165 |
|
| 1166 |
1165 |
| 1167 /** |
1166 /** |
| 1168 * Replaces a string with another string. |
1167 * Replaces a string with another string. |
| 1169 * |
1168 * |
| 1170 * Internal function - do not use. |
1169 * Internal function - do not use. |
| 1178 * @see cx_strreplace_a() |
1177 * @see cx_strreplace_a() |
| 1179 * @see cx_strreplace() |
1178 * @see cx_strreplace() |
| 1180 * @see cx_strreplacen_a() |
1179 * @see cx_strreplacen_a() |
| 1181 * @see cx_strreplacen() |
1180 * @see cx_strreplacen() |
| 1182 */ |
1181 */ |
| 1183 cx_attr_nodiscard cx_attr_nonnull |
1182 CX_EXTERN CX_NODISCARD CX_NONNULL |
| 1184 CX_EXPORT cxmutstr cx_strreplace_(const CxAllocator *allocator, |
1183 cxmutstr cx_strreplace_(const CxAllocator *allocator, |
| 1185 cxstring str, cxstring search, cxstring replacement, size_t replmax); |
1184 cxstring str, cxstring search, cxstring replacement, size_t replmax); |
| 1186 |
1185 |
| 1187 /** |
1186 /** |
| 1188 * Replaces a string with another string. |
1187 * Replaces a string with another string. |
| 1189 * |
1188 * |
| 1266 * @param str the string to tokenize |
1265 * @param str the string to tokenize |
| 1267 * @param delim the delimiter (must not be empty) |
1266 * @param delim the delimiter (must not be empty) |
| 1268 * @param limit the maximum number of tokens that shall be returned |
1267 * @param limit the maximum number of tokens that shall be returned |
| 1269 * @return a new string tokenization context |
1268 * @return a new string tokenization context |
| 1270 */ |
1269 */ |
| 1271 cx_attr_nodiscard |
1270 CX_EXTERN CX_NODISCARD |
| 1272 CX_EXPORT CxStrtokCtx cx_strtok_(cxstring str, cxstring delim, size_t limit); |
1271 CxStrtokCtx cx_strtok_(cxstring str, cxstring delim, size_t limit); |
| 1273 |
1272 |
| 1274 /** |
1273 /** |
| 1275 * Creates a string tokenization context. |
1274 * Creates a string tokenization context. |
| 1276 * |
1275 * |
| 1277 * @param str the string to tokenize |
1276 * @param str the string to tokenize |
| 1290 * @param ctx the tokenization context |
1289 * @param ctx the tokenization context |
| 1291 * @param token a pointer to memory where the next token shall be stored |
1290 * @param token a pointer to memory where the next token shall be stored |
| 1292 * @return true if successful, false if the limit or the end of the string |
1291 * @return true if successful, false if the limit or the end of the string |
| 1293 * has been reached |
1292 * has been reached |
| 1294 */ |
1293 */ |
| 1295 cx_attr_nonnull cx_attr_nodiscard cx_attr_access_w(2) |
1294 CX_EXTERN CX_NONNULL CX_NODISCARD CX_ACCESS_W(2) |
| 1296 CX_EXPORT bool cx_strtok_next_(CxStrtokCtx *ctx, cxstring *token); |
1295 bool cx_strtok_next_(CxStrtokCtx *ctx, cxstring *token); |
| 1297 |
1296 |
| 1298 #ifdef __cplusplus |
1297 #ifdef __cplusplus |
| 1299 } // extern "C" |
|
| 1300 CX_CPPDECL cx_strtok_next(CxStrtokCtx *ctx, cxstring *token) { |
1298 CX_CPPDECL cx_strtok_next(CxStrtokCtx *ctx, cxstring *token) { |
| 1301 return cx_strtok_next_(ctx, token); |
1299 return cx_strtok_next_(ctx, token); |
| 1302 } |
1300 } |
| 1303 CX_CPPDECL cx_strtok_next(CxStrtokCtx *ctx, cxmutstr *token) { |
1301 CX_CPPDECL cx_strtok_next(CxStrtokCtx *ctx, cxmutstr *token) { |
| 1304 // Note: this is actually UB - fixed with start_lifetime_as() in C++23 |
1302 // Note: this is actually UB - fixed with start_lifetime_as() in C++23 |
| 1305 // but it works on all supported platforms |
1303 // but it works on all supported platforms |
| 1306 return cx_strtok_next_(ctx, reinterpret_cast<cxstring*>(token)); |
1304 return cx_strtok_next_(ctx, reinterpret_cast<cxstring*>(token)); |
| 1307 } |
1305 } |
| 1308 extern "C" { |
|
| 1309 #else // ! __cplusplus |
1306 #else // ! __cplusplus |
| 1310 /** |
1307 /** |
| 1311 * Returns the next token. |
1308 * Returns the next token. |
| 1312 * |
1309 * |
| 1313 * The token will point to the source string. |
1310 * The token will point to the source string. |
| 1328 * |
1325 * |
| 1329 * @param ctx the tokenization context |
1326 * @param ctx the tokenization context |
| 1330 * @param delim array of more delimiters |
1327 * @param delim array of more delimiters |
| 1331 * @param count number of elements in the array |
1328 * @param count number of elements in the array |
| 1332 */ |
1329 */ |
| 1333 cx_attr_nonnull cx_attr_access_r(2, 3) |
1330 CX_EXTERN CX_NONNULL CX_ACCESS_R(2, 3) |
| 1334 CX_EXPORT void cx_strtok_delim(CxStrtokCtx *ctx, const cxstring *delim, size_t count); |
1331 void cx_strtok_delim(CxStrtokCtx *ctx, const cxstring *delim, size_t count); |
| 1335 |
1332 |
| 1336 /* ------------------------------------------------------------------------- * |
1333 /* ------------------------------------------------------------------------- * |
| 1337 * string to number conversion functions * |
1334 * string to number conversion functions * |
| 1338 * ------------------------------------------------------------------------- */ |
1335 * ------------------------------------------------------------------------- */ |
| 1339 |
1336 |
| 1349 * @param base 2, 8, 10, or 16 |
1346 * @param base 2, 8, 10, or 16 |
| 1350 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1347 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1351 * @retval zero success |
1348 * @retval zero success |
| 1352 * @retval non-zero conversion was not possible |
1349 * @retval non-zero conversion was not possible |
| 1353 */ |
1350 */ |
| 1354 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1351 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1355 CX_EXPORT int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep); |
1352 int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep); |
| 1356 |
1353 |
| 1357 /** |
1354 /** |
| 1358 * Converts a string to a number. |
1355 * Converts a string to a number. |
| 1359 * |
1356 * |
| 1360 * The function returns non-zero when conversion is not possible. |
1357 * The function returns non-zero when conversion is not possible. |
| 1366 * @param base 2, 8, 10, or 16 |
1363 * @param base 2, 8, 10, or 16 |
| 1367 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1364 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1368 * @retval zero success |
1365 * @retval zero success |
| 1369 * @retval non-zero conversion was not possible |
1366 * @retval non-zero conversion was not possible |
| 1370 */ |
1367 */ |
| 1371 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1368 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1372 CX_EXPORT int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep); |
1369 int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep); |
| 1373 |
1370 |
| 1374 /** |
1371 /** |
| 1375 * Converts a string to a number. |
1372 * Converts a string to a number. |
| 1376 * |
1373 * |
| 1377 * The function returns non-zero when conversion is not possible. |
1374 * The function returns non-zero when conversion is not possible. |
| 1383 * @param base 2, 8, 10, or 16 |
1380 * @param base 2, 8, 10, or 16 |
| 1384 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1381 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1385 * @retval zero success |
1382 * @retval zero success |
| 1386 * @retval non-zero conversion was not possible |
1383 * @retval non-zero conversion was not possible |
| 1387 */ |
1384 */ |
| 1388 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1385 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1389 CX_EXPORT int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep); |
1386 int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep); |
| 1390 |
1387 |
| 1391 /** |
1388 /** |
| 1392 * Converts a string to a number. |
1389 * Converts a string to a number. |
| 1393 * |
1390 * |
| 1394 * The function returns non-zero when conversion is not possible. |
1391 * The function returns non-zero when conversion is not possible. |
| 1400 * @param base 2, 8, 10, or 16 |
1397 * @param base 2, 8, 10, or 16 |
| 1401 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1398 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1402 * @retval zero success |
1399 * @retval zero success |
| 1403 * @retval non-zero conversion was not possible |
1400 * @retval non-zero conversion was not possible |
| 1404 */ |
1401 */ |
| 1405 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1402 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1406 CX_EXPORT int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep); |
1403 int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep); |
| 1407 |
1404 |
| 1408 /** |
1405 /** |
| 1409 * Converts a string to a number. |
1406 * Converts a string to a number. |
| 1410 * |
1407 * |
| 1411 * The function returns non-zero when conversion is not possible. |
1408 * The function returns non-zero when conversion is not possible. |
| 1417 * @param base 2, 8, 10, or 16 |
1414 * @param base 2, 8, 10, or 16 |
| 1418 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1415 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1419 * @retval zero success |
1416 * @retval zero success |
| 1420 * @retval non-zero conversion was not possible |
1417 * @retval non-zero conversion was not possible |
| 1421 */ |
1418 */ |
| 1422 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1419 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1423 CX_EXPORT int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep); |
1420 int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep); |
| 1424 |
1421 |
| 1425 /** |
1422 /** |
| 1426 * Converts a string to a number. |
1423 * Converts a string to a number. |
| 1427 * |
1424 * |
| 1428 * The function returns non-zero when conversion is not possible. |
1425 * The function returns non-zero when conversion is not possible. |
| 1434 * @param base 2, 8, 10, or 16 |
1431 * @param base 2, 8, 10, or 16 |
| 1435 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1432 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1436 * @retval zero success |
1433 * @retval zero success |
| 1437 * @retval non-zero conversion was not possible |
1434 * @retval non-zero conversion was not possible |
| 1438 */ |
1435 */ |
| 1439 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1436 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1440 CX_EXPORT int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep); |
1437 int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep); |
| 1441 |
1438 |
| 1442 /** |
1439 /** |
| 1443 * Converts a string to a number. |
1440 * Converts a string to a number. |
| 1444 * |
1441 * |
| 1445 * The function returns non-zero when conversion is not possible. |
1442 * The function returns non-zero when conversion is not possible. |
| 1451 * @param base 2, 8, 10, or 16 |
1448 * @param base 2, 8, 10, or 16 |
| 1452 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1449 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1453 * @retval zero success |
1450 * @retval zero success |
| 1454 * @retval non-zero conversion was not possible |
1451 * @retval non-zero conversion was not possible |
| 1455 */ |
1452 */ |
| 1456 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1453 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1457 CX_EXPORT int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep); |
1454 int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep); |
| 1458 |
1455 |
| 1459 /** |
1456 /** |
| 1460 * Converts a string to a number. |
1457 * Converts a string to a number. |
| 1461 * |
1458 * |
| 1462 * The function returns non-zero when conversion is not possible. |
1459 * The function returns non-zero when conversion is not possible. |
| 1468 * @param base 2, 8, 10, or 16 |
1465 * @param base 2, 8, 10, or 16 |
| 1469 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1466 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1470 * @retval zero success |
1467 * @retval zero success |
| 1471 * @retval non-zero conversion was not possible |
1468 * @retval non-zero conversion was not possible |
| 1472 */ |
1469 */ |
| 1473 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1470 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1474 CX_EXPORT int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep); |
1471 int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep); |
| 1475 |
1472 |
| 1476 /** |
1473 /** |
| 1477 * Converts a string to a number. |
1474 * Converts a string to a number. |
| 1478 * |
1475 * |
| 1479 * The function returns non-zero when conversion is not possible. |
1476 * The function returns non-zero when conversion is not possible. |
| 1485 * @param base 2, 8, 10, or 16 |
1482 * @param base 2, 8, 10, or 16 |
| 1486 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1483 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1487 * @retval zero success |
1484 * @retval zero success |
| 1488 * @retval non-zero conversion was not possible |
1485 * @retval non-zero conversion was not possible |
| 1489 */ |
1486 */ |
| 1490 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1487 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1491 CX_EXPORT int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep); |
1488 int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep); |
| 1492 |
1489 |
| 1493 /** |
1490 /** |
| 1494 * Converts a string to a number. |
1491 * Converts a string to a number. |
| 1495 * |
1492 * |
| 1496 * The function returns non-zero when conversion is not possible. |
1493 * The function returns non-zero when conversion is not possible. |
| 1502 * @param base 2, 8, 10, or 16 |
1499 * @param base 2, 8, 10, or 16 |
| 1503 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1500 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1504 * @retval zero success |
1501 * @retval zero success |
| 1505 * @retval non-zero conversion was not possible |
1502 * @retval non-zero conversion was not possible |
| 1506 */ |
1503 */ |
| 1507 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1504 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1508 CX_EXPORT int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep); |
1505 int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep); |
| 1509 |
1506 |
| 1510 /** |
1507 /** |
| 1511 * Converts a string to a number. |
1508 * Converts a string to a number. |
| 1512 * |
1509 * |
| 1513 * The function returns non-zero when conversion is not possible. |
1510 * The function returns non-zero when conversion is not possible. |
| 1519 * @param base 2, 8, 10, or 16 |
1516 * @param base 2, 8, 10, or 16 |
| 1520 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1517 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1521 * @retval zero success |
1518 * @retval zero success |
| 1522 * @retval non-zero conversion was not possible |
1519 * @retval non-zero conversion was not possible |
| 1523 */ |
1520 */ |
| 1524 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1521 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1525 CX_EXPORT int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep); |
1522 int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep); |
| 1526 |
1523 |
| 1527 /** |
1524 /** |
| 1528 * Converts a string to a number. |
1525 * Converts a string to a number. |
| 1529 * |
1526 * |
| 1530 * The function returns non-zero when conversion is not possible. |
1527 * The function returns non-zero when conversion is not possible. |
| 1536 * @param base 2, 8, 10, or 16 |
1533 * @param base 2, 8, 10, or 16 |
| 1537 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1534 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1538 * @retval zero success |
1535 * @retval zero success |
| 1539 * @retval non-zero conversion was not possible |
1536 * @retval non-zero conversion was not possible |
| 1540 */ |
1537 */ |
| 1541 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1538 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1542 CX_EXPORT int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep); |
1539 int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep); |
| 1543 |
1540 |
| 1544 /** |
1541 /** |
| 1545 * Converts a string to a number. |
1542 * Converts a string to a number. |
| 1546 * |
1543 * |
| 1547 * The function returns non-zero when conversion is not possible. |
1544 * The function returns non-zero when conversion is not possible. |
| 1553 * @param base 2, 8, 10, or 16 |
1550 * @param base 2, 8, 10, or 16 |
| 1554 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1551 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1555 * @retval zero success |
1552 * @retval zero success |
| 1556 * @retval non-zero conversion was not possible |
1553 * @retval non-zero conversion was not possible |
| 1557 */ |
1554 */ |
| 1558 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1555 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1559 CX_EXPORT int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep); |
1556 int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep); |
| 1560 |
1557 |
| 1561 /** |
1558 /** |
| 1562 * Converts a string to a number. |
1559 * Converts a string to a number. |
| 1563 * |
1560 * |
| 1564 * The function returns non-zero when conversion is not possible. |
1561 * The function returns non-zero when conversion is not possible. |
| 1570 * @param base 2, 8, 10, or 16 |
1567 * @param base 2, 8, 10, or 16 |
| 1571 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1568 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1572 * @retval zero success |
1569 * @retval zero success |
| 1573 * @retval non-zero conversion was not possible |
1570 * @retval non-zero conversion was not possible |
| 1574 */ |
1571 */ |
| 1575 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1572 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1576 CX_EXPORT int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep); |
1573 int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep); |
| 1577 |
1574 |
| 1578 /** |
1575 /** |
| 1579 * Converts a string to a number. |
1576 * Converts a string to a number. |
| 1580 * |
1577 * |
| 1581 * The function returns non-zero when conversion is not possible. |
1578 * The function returns non-zero when conversion is not possible. |
| 1587 * @param base 2, 8, 10, or 16 |
1584 * @param base 2, 8, 10, or 16 |
| 1588 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1585 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1589 * @retval zero success |
1586 * @retval zero success |
| 1590 * @retval non-zero conversion was not possible |
1587 * @retval non-zero conversion was not possible |
| 1591 */ |
1588 */ |
| 1592 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1589 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1593 CX_EXPORT int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep); |
1590 int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep); |
| 1594 |
1591 |
| 1595 /** |
1592 /** |
| 1596 * Converts a string to a number. |
1593 * Converts a string to a number. |
| 1597 * |
1594 * |
| 1598 * The function returns non-zero when conversion is not possible. |
1595 * The function returns non-zero when conversion is not possible. |
| 1604 * @param base 2, 8, 10, or 16 |
1601 * @param base 2, 8, 10, or 16 |
| 1605 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1602 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1606 * @retval zero success |
1603 * @retval zero success |
| 1607 * @retval non-zero conversion was not possible |
1604 * @retval non-zero conversion was not possible |
| 1608 */ |
1605 */ |
| 1609 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1606 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1610 CX_EXPORT int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep); |
1607 int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep); |
| 1611 |
1608 |
| 1612 /** |
1609 /** |
| 1613 * Converts a string to a number. |
1610 * Converts a string to a number. |
| 1614 * |
1611 * |
| 1615 * The function returns non-zero when conversion is not possible. |
1612 * The function returns non-zero when conversion is not possible. |
| 1621 * @param base 2, 8, 10, or 16 |
1618 * @param base 2, 8, 10, or 16 |
| 1622 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1619 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1623 * @retval zero success |
1620 * @retval zero success |
| 1624 * @retval non-zero conversion was not possible |
1621 * @retval non-zero conversion was not possible |
| 1625 */ |
1622 */ |
| 1626 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1623 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1627 CX_EXPORT int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep); |
1624 int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep); |
| 1628 |
1625 |
| 1629 /** |
1626 /** |
| 1630 * Converts a string to a single precision floating-point number. |
1627 * Converts a string to a single precision floating-point number. |
| 1631 * |
1628 * |
| 1632 * The function returns non-zero when conversion is not possible. |
1629 * The function returns non-zero when conversion is not possible. |
| 1638 * @param decsep the decimal separator |
1635 * @param decsep the decimal separator |
| 1639 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1636 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1640 * @retval zero success |
1637 * @retval zero success |
| 1641 * @retval non-zero conversion was not possible |
1638 * @retval non-zero conversion was not possible |
| 1642 */ |
1639 */ |
| 1643 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1640 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1644 CX_EXPORT int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep); |
1641 int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep); |
| 1645 |
1642 |
| 1646 /** |
1643 /** |
| 1647 * Converts a string to a double precision floating-point number. |
1644 * Converts a string to a double precision floating-point number. |
| 1648 * |
1645 * |
| 1649 * The function returns non-zero when conversion is not possible. |
1646 * The function returns non-zero when conversion is not possible. |
| 1655 * @param decsep the decimal separator |
1652 * @param decsep the decimal separator |
| 1656 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
1653 * @param groupsep each character in this string is treated as a group separator and ignored during conversion |
| 1657 * @retval zero success |
1654 * @retval zero success |
| 1658 * @retval non-zero conversion was not possible |
1655 * @retval non-zero conversion was not possible |
| 1659 */ |
1656 */ |
| 1660 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1657 CX_EXTERN CX_ACCESS_W(2) CX_NONNULL_ARG(2) |
| 1661 CX_EXPORT int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep); |
1658 int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep); |
| 1662 |
1659 |
| 1663 /** |
1660 /** |
| 1664 * Converts a string to a number. |
1661 * Converts a string to a number. |
| 1665 * |
1662 * |
| 1666 * The function returns non-zero when conversion is not possible. |
1663 * The function returns non-zero when conversion is not possible. |
| 2302 * @retval zero success |
2299 * @retval zero success |
| 2303 * @retval non-zero conversion was not possible |
2300 * @retval non-zero conversion was not possible |
| 2304 */ |
2301 */ |
| 2305 #define cx_strtod(str, output) cx_strtod_lc_(cx_strcast(str), output, '.', ",") |
2302 #define cx_strtod(str, output) cx_strtod_lc_(cx_strcast(str), output, '.', ",") |
| 2306 |
2303 |
| 2307 #ifdef __cplusplus |
|
| 2308 } // extern "C" |
|
| 2309 #endif |
|
| 2310 |
|
| 2311 #endif //UCX_STRING_H |
2304 #endif //UCX_STRING_H |