| 352 * |
352 * |
| 353 * @param str (any supported string type) the string to cast |
353 * @param str (any supported string type) the string to cast |
| 354 * @return (@c cxstring) or (@c cxmutstr) the string wrapped as UCX string |
354 * @return (@c cxstring) or (@c cxmutstr) the string wrapped as UCX string |
| 355 */ |
355 */ |
| 356 #define cx_strcast_m(str) _Generic((str), \ |
356 #define cx_strcast_m(str) _Generic((str), \ |
| |
357 cxstring: cx_strcast_cxs, \ |
| 357 cxmutstr: cx_strcast_cxms, \ |
358 cxmutstr: cx_strcast_cxms, \ |
| 358 cxstring: cx_strcast_cxs, \ |
|
| 359 const unsigned char*: cx_strcast_ucc, \ |
359 const unsigned char*: cx_strcast_ucc, \ |
| 360 unsigned char *: cx_strcast_uc, \ |
360 unsigned char *: cx_strcast_uc, \ |
| 361 const char*: cx_strcast_cc, \ |
361 const char*: cx_strcast_cc, \ |
| 362 char *: cx_strcast_c) (str) |
362 char *: cx_strcast_c) (str) |
| 363 |
363 |
| 694 */ |
694 */ |
| 695 CX_EXTERN CX_NODISCARD |
695 CX_EXTERN CX_NODISCARD |
| 696 cxstring cx_strrchr_(cxstring string, int chr); |
696 cxstring cx_strrchr_(cxstring string, int chr); |
| 697 |
697 |
| 698 #ifdef __cplusplus |
698 #ifdef __cplusplus |
| 699 CX_CPPDECL cxstring cx_strchr_cpp(cxstring string, int chr) { |
699 CX_CPPDECL cxstring cx_strchr_cpp_(cxstring string, int chr) { |
| 700 return cx_strchr_(string, chr); |
700 return cx_strchr_(string, chr); |
| 701 } |
701 } |
| 702 CX_CPPDECL cxmutstr cx_strchr_cpp(cxmutstr string, int chr) { |
702 CX_CPPDECL cxmutstr cx_strchr_cpp_(cxmutstr string, int chr) { |
| 703 return cx_mutstrcast(cx_strchr_(cx_strcast(string), chr)); |
703 return cx_mutstrcast(cx_strchr_(cx_strcast(string), chr)); |
| 704 } |
704 } |
| 705 #define cx_strchr(s, chr) cx_strchr_cpp(cx_strcast_m(s), chr) |
705 #define cx_strchr(s, chr) cx_strchr_cpp_(cx_strcast_m(s), chr) |
| 706 CX_CPPDECL cxstring cx_strrchr_cpp(cxstring string, int chr) { |
706 CX_CPPDECL cxstring cx_strrchr_cpp_(cxstring string, int chr) { |
| 707 return cx_strrchr_(string, chr); |
707 return cx_strrchr_(string, chr); |
| 708 } |
708 } |
| 709 CX_CPPDECL cxmutstr cx_strrchr_cpp(cxmutstr string, int chr) { |
709 CX_CPPDECL cxmutstr cx_strrchr_cpp_(cxmutstr string, int chr) { |
| 710 return cx_mutstrcast(cx_strrchr_(cx_strcast(string), chr)); |
710 return cx_mutstrcast(cx_strrchr_(cx_strcast(string), chr)); |
| 711 } |
711 } |
| 712 #define cx_strrchr(s, chr) cx_strrchr_cpp(cx_strcast_m(s), chr) |
712 #define cx_strrchr(s, chr) cx_strrchr_cpp_(cx_strcast_m(s), chr) |
| 713 #else |
713 #else |
| 714 /** |
714 /** |
| 715 * Internal conversion function - do not use. |
715 * Internal conversion function - do not use. |
| 716 * @param string |
716 * @param string |
| 717 * @param chr |
717 * @param chr |
| 774 */ |
774 */ |
| 775 CX_EXTERN CX_NODISCARD |
775 CX_EXTERN CX_NODISCARD |
| 776 cxstring cx_strstr_(cxstring haystack, cxstring needle); |
776 cxstring cx_strstr_(cxstring haystack, cxstring needle); |
| 777 |
777 |
| 778 #ifdef __cplusplus |
778 #ifdef __cplusplus |
| 779 CX_CPPDECL cxstring cx_strstr_cpp(cxstring haystack, cxstring needle) { |
779 CX_CPPDECL cxstring cx_strstr_cpp_(cxstring haystack, cxstring needle) { |
| 780 return cx_strstr_(haystack, needle); |
780 return cx_strstr_(haystack, needle); |
| 781 } |
781 } |
| 782 CX_CPPDECL cxmutstr cx_strstr_cpp(cxmutstr haystack, cxstring needle) { |
782 CX_CPPDECL cxmutstr cx_strstr_cpp_(cxmutstr haystack, cxstring needle) { |
| 783 return cx_mutstrcast(cx_strstr_(cx_strcast(haystack), needle)); |
783 return cx_mutstrcast(cx_strstr_(cx_strcast(haystack), needle)); |
| 784 } |
784 } |
| 785 #define cx_strstr(h,n) cx_strstr_cpp(cx_strcast_m(h), cx_strcast(n)) |
785 #define cx_strstr(h,n) cx_strstr_cpp_(cx_strcast_m(h), cx_strcast(n)) |
| 786 #else |
786 #else |
| 787 /** |
787 /** |
| 788 * Internal conversion - do not use. |
788 * Internal conversion - do not use. |
| 789 * @param haystack |
789 * @param haystack |
| 790 * @param needle |
790 * @param needle |
| 1072 * @see cx_strfree() |
1072 * @see cx_strfree() |
| 1073 */ |
1073 */ |
| 1074 #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) |
1074 #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) |
| 1075 |
1075 |
| 1076 /** |
1076 /** |
| |
1077 * Trims a string. |
| |
1078 * Internal function - do not use. |
| |
1079 * @param string |
| |
1080 * @return |
| |
1081 */ |
| |
1082 CX_EXTERN CX_NODISCARD |
| |
1083 cxstring cx_strtrim_(cxstring string); |
| |
1084 |
| |
1085 #ifdef __cplusplus |
| |
1086 CX_CPPDECL cxstring cx_strtrim_cpp_(cxstring string) { |
| |
1087 return cx_strtrim_(string); |
| |
1088 } |
| |
1089 CX_CPPDECL cxmutstr cx_strtrim_cpp_(cxmutstr string) { |
| |
1090 return cx_mutstrcast(cx_strtrim_(cx_strcast(string))); |
| |
1091 } |
| |
1092 #define cx_strtrim(string) cx_strtrim_cpp_(cx_strcast_m(string)) |
| |
1093 #else |
| |
1094 /** |
| |
1095 * Internal conversion function. |
| |
1096 * @param string |
| |
1097 * @return |
| |
1098 */ |
| |
1099 CX_INLINE cxmutstr cx_strtrim_m_(cxmutstr string) { |
| |
1100 return cx_mutstrcast(cx_strtrim_(cx_strcast(string))); |
| |
1101 } |
| |
1102 |
| |
1103 /** |
| 1077 * Omits leading and trailing spaces. |
1104 * Omits leading and trailing spaces. |
| 1078 * |
1105 * |
| 1079 * @note the returned string references the same memory, thus you |
1106 * @note the returned string references the same memory, thus you |
| 1080 * must @em not free the returned memory. |
1107 * must @em not free the returned memory. |
| 1081 * |
1108 * |
| 1082 * @param string the string that shall be trimmed |
1109 * @param string the string that shall be trimmed |
| 1083 * @return the trimmed string |
1110 * @return (@c cxstring or @c cxmutstr) the trimmed string |
| 1084 */ |
1111 */ |
| 1085 CX_EXTERN CX_NODISCARD |
1112 #define cx_strtrim(string) _Generic(cx_strcast_m(string), \ |
| 1086 cxstring cx_strtrim(cxstring string); |
1113 cxstring: cx_strtrim_, \ |
| 1087 |
1114 cxmutstr: cx_strtrim_m_)(cx_strcast_m(string)) |
| 1088 /** |
1115 #endif |
| 1089 * Omits leading and trailing spaces. |
|
| 1090 * |
|
| 1091 * @note the returned string references the same memory, thus you |
|
| 1092 * must @em not free the returned memory. |
|
| 1093 * |
|
| 1094 * @param string the string that shall be trimmed |
|
| 1095 * @return the trimmed string |
|
| 1096 */ |
|
| 1097 CX_EXTERN CX_NODISCARD |
|
| 1098 cxmutstr cx_strtrim_m(cxmutstr string); |
|
| 1099 |
1116 |
| 1100 /** |
1117 /** |
| 1101 * Checks if a string has a specific prefix. |
1118 * Checks if a string has a specific prefix. |
| 1102 * |
1119 * |
| 1103 * @param string the string to check |
1120 * @param string the string to check |