| 93 } |
93 } |
| 94 #endif |
94 #endif |
| 95 |
95 |
| 96 |
96 |
| 97 #ifdef __cplusplus |
97 #ifdef __cplusplus |
| |
98 /** |
| |
99 * One of two type adjustment functions that return a scstr_t. |
| |
100 * |
| |
101 * Used <b>internally</b> to convert a UCX string to an immutable UCX string. |
| |
102 * |
| |
103 * <b>Do not use this function manually.</b> |
| |
104 * |
| |
105 * @param str some sstr_t |
| |
106 * @return an immutable (scstr_t) version of the provided string. |
| |
107 */ |
| 98 inline scstr_t s2scstr(sstr_t s) { |
108 inline scstr_t s2scstr(sstr_t s) { |
| 99 scstr_t c; |
109 scstr_t c; |
| 100 c.ptr = s.ptr; |
110 c.ptr = s.ptr; |
| 101 c.length = s.ptr; |
111 c.length = s.ptr; |
| 102 return c; |
112 return c; |
| 103 } |
113 } |
| 104 inline scstr_t s2scstr(scstr_t c) { |
|
| 105 return c; |
|
| 106 } |
|
| 107 #define SCSTR s2scstr |
|
| 108 #else |
|
| 109 |
114 |
| 110 /** |
115 /** |
| 111 * One of two type adjustment functions that return a scstr_t. |
116 * One of two type adjustment functions that return a scstr_t. |
| 112 * |
117 * |
| 113 * Used internally to convert a UCX string to an immutable UCX string. |
118 * Used <b>internally</b> to convert a UCX string to an immutable UCX string. |
| 114 * This variant is used, when the string is already immutable and no operation |
119 * This variant is used, when the string is already immutable and no operation |
| 115 * needs to be performed. |
120 * needs to be performed. |
| 116 * |
121 * |
| |
122 * <b>Do not use this function manually.</b> |
| |
123 * |
| 117 * @param str some scstr_t |
124 * @param str some scstr_t |
| 118 * @return the argument itself |
125 * @return the argument itself |
| 119 */ |
126 */ |
| |
127 inline scstr_t s2scstr(scstr_t str) { |
| |
128 return str; |
| |
129 } |
| |
130 |
| |
131 /** |
| |
132 * Converts a UCX string to an immutable UCX string (scstr_t). |
| |
133 * @param str some UCX string |
| |
134 * @return the an immutable version of the provided string |
| |
135 */ |
| |
136 #define SCSTR(s) s2scstr(s) |
| |
137 #else |
| |
138 |
| |
139 /** |
| |
140 * One of two type adjustment functions that return a scstr_t. |
| |
141 * |
| |
142 * Used <b>internally</b> to convert a UCX string to an immutable UCX string. |
| |
143 * This variant is used, when the string is already immutable and no operation |
| |
144 * needs to be performed. |
| |
145 * |
| |
146 * <b>Do not use this function manually.</b> |
| |
147 * |
| |
148 * @param str some scstr_t |
| |
149 * @return the argument itself |
| |
150 */ |
| 120 scstr_t ucx_sc2sc(scstr_t str); |
151 scstr_t ucx_sc2sc(scstr_t str); |
| 121 |
152 |
| 122 /** |
153 /** |
| 123 * One of two type adjustment functions that return a scstr_t. |
154 * One of two type adjustment functions that return a scstr_t. |
| 124 * |
155 * |
| 125 * Used internally to convert a UCX string to an immutable UCX string. |
156 * Used <b>internally</b> to convert a UCX string to an immutable UCX string. |
| |
157 * |
| |
158 * <b>Do not use this function manually.</b> |
| 126 * |
159 * |
| 127 * @param str some sstr_t |
160 * @param str some sstr_t |
| 128 * @return an immutable (scstr_t) version of the provided string. |
161 * @return an immutable (scstr_t) version of the provided string. |
| 129 */ |
162 */ |
| 130 scstr_t ucx_ss2sc(sstr_t str); |
163 scstr_t ucx_ss2sc(sstr_t str); |
| 131 |
164 |
| 132 #if __STDC_VERSION__ >= 201112L |
165 #if __STDC_VERSION__ >= 201112L |
| 133 /** |
166 /** |
| 134 * Casts a UCX string to an immutable UCX string (scstr_t). |
167 * Converts a UCX string to an immutable UCX string (scstr_t). |
| 135 * @param str some UCX string |
168 * @param str some UCX string |
| 136 * @return the an immutable version of the provided string |
169 * @return the an immutable version of the provided string |
| 137 */ |
170 */ |
| 138 #define SCSTR(str) _Generic(str, sstr_t: ucx_ss2sc, scstr_t: ucx_sc2sc)(str) |
171 #define SCSTR(str) _Generic(str, sstr_t: ucx_ss2sc, scstr_t: ucx_sc2sc)(str) |
| 139 |
172 |
| 140 #elif defined(__GNUC__) || defined(__clang__) |
173 #elif defined(__GNUC__) || defined(__clang__) |
| 141 |
174 |
| 142 /** |
175 /** |
| 143 * Casts a UCX string to an immutable UCX string (scstr_t). |
176 * Converts a UCX string to an immutable UCX string (scstr_t). |
| 144 * @param str some UCX string |
177 * @param str some UCX string |
| 145 * @return the an immutable version of the provided string |
178 * @return the an immutable version of the provided string |
| 146 */ |
179 */ |
| 147 #define SCSTR(str) __builtin_choose_expr( \ |
180 #define SCSTR(str) __builtin_choose_expr( \ |
| 148 __builtin_types_compatible_p(typeof(str), sstr_t), \ |
181 __builtin_types_compatible_p(typeof(str), sstr_t), \ |
| 162 ucx_tmp_var_c.length = ucx_tmp_var_str.length;\ |
195 ucx_tmp_var_c.length = ucx_tmp_var_str.length;\ |
| 163 ucx_tmp_var_c; }) |
196 ucx_tmp_var_c; }) |
| 164 #else /* no generics and no builtins */ |
197 #else /* no generics and no builtins */ |
| 165 |
198 |
| 166 /** |
199 /** |
| 167 * Casts a UCX string to an immutable UCX string (scstr_t). |
200 * Converts a UCX string to an immutable UCX string (scstr_t). |
| 168 * |
201 * |
| 169 * This internal function (ab)uses the C standard an expects one single |
202 * This internal function (ab)uses the C standard an expects one single |
| 170 * argument which is then implicitly converted to scstr_t without a warning. |
203 * argument which is then implicitly converted to scstr_t without a warning. |
| 171 * |
204 * |
| 172 * @return the an immutable version of the provided string |
205 * @return the an immutable version of the provided string |
| 173 */ |
206 */ |
| 174 scstr_t ucx_ss2c_s(); |
207 scstr_t ucx_ss2c_s(); |
| 175 |
208 |
| 176 /** |
209 /** |
| 177 * Casts a UCX string to an immutable UCX string (scstr_t). |
210 * Converts a UCX string to an immutable UCX string (scstr_t). |
| 178 * @param str some UCX string |
211 * @param str some UCX string |
| 179 * @return the an immutable version of the provided string |
212 * @return the an immutable version of the provided string |
| 180 */ |
213 */ |
| 181 #define SCSTR(str) ucx_ss2c_s(str) |
214 #define SCSTR(str) ucx_ss2c_s(str) |
| 182 #endif /* C11 feature test */ |
215 #endif /* C11 feature test */ |
| 610 * <code>NULL</code> on error |
643 * <code>NULL</code> on error |
| 611 * |
644 * |
| 612 * @see sstrsplit() |
645 * @see sstrsplit() |
| 613 */ |
646 */ |
| 614 #define sstrsplit_a(allocator, string, delim, count) \ |
647 #define sstrsplit_a(allocator, string, delim, count) \ |
| 615 scstrsplit_a(allocator, SCSTR(string), SCSTR(delim, count)) |
648 scstrsplit_a(allocator, SCSTR(string), SCSTR(delim), count) |
| 616 |
649 |
| 617 /** |
650 /** |
| 618 * Compares two UCX strings with standard <code>memcmp()</code>. |
651 * Compares two UCX strings with standard <code>memcmp()</code>. |
| 619 * |
652 * |
| 620 * At first it compares the scstr_t.length attribute of the two strings. The |
653 * At first it compares the scstr_t.length attribute of the two strings. The |