src/ucx/cx/string.h

changeset 579
e10457d74fe1
parent 490
d218607f5a7e
equal deleted inserted replaced
578:eb48f716b31c 579:e10457d74fe1
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 /** 28 /**
29 * \file string.h 29 * @file string.h
30 * \brief Strings that know their length. 30 * @brief Strings that know their length.
31 * \author Mike Becker 31 * @author Mike Becker
32 * \author Olaf Wintermann 32 * @author Olaf Wintermann
33 * \version 3.0 33 * @copyright 2-Clause BSD License
34 * \copyright 2-Clause BSD License
35 */ 34 */
36 35
37 #ifndef UCX_STRING_H 36 #ifndef UCX_STRING_H
38 #define UCX_STRING_H 37 #define UCX_STRING_H
39 38
40 #include "common.h" 39 #include "common.h"
41 #include "allocator.h" 40 #include "allocator.h"
41
42 /**
43 * The maximum length of the "needle" in cx_strstr() that can use SBO.
44 */
45 cx_attr_export
46 extern const unsigned cx_strstr_sbo_size;
42 47
43 /** 48 /**
44 * The UCX string structure. 49 * The UCX string structure.
45 */ 50 */
46 struct cx_mutstr_s { 51 struct cx_mutstr_s {
47 /** 52 /**
48 * A pointer to the string. 53 * A pointer to the string.
49 * \note The string is not necessarily \c NULL terminated. 54 * @note The string is not necessarily @c NULL terminated.
50 * Always use the length.
51 */ 55 */
52 char *ptr; 56 char *ptr;
53 /** The length of the string */ 57 /** The length of the string */
54 size_t length; 58 size_t length;
55 }; 59 };
63 * The UCX string structure for immutable (constant) strings. 67 * The UCX string structure for immutable (constant) strings.
64 */ 68 */
65 struct cx_string_s { 69 struct cx_string_s {
66 /** 70 /**
67 * A pointer to the immutable string. 71 * A pointer to the immutable string.
68 * \note The string is not necessarily \c NULL terminated. 72 * @note The string is not necessarily @c NULL terminated.
69 * Always use the length.
70 */ 73 */
71 char const *ptr; 74 const char *ptr;
72 /** The length of the string */ 75 /** The length of the string */
73 size_t length; 76 size_t length;
74 }; 77 };
75 78
76 /** 79 /**
91 */ 94 */
92 cxstring delim; 95 cxstring delim;
93 /** 96 /**
94 * Optional array of more delimiters. 97 * Optional array of more delimiters.
95 */ 98 */
96 cxstring const *delim_more; 99 const cxstring *delim_more;
97 /** 100 /**
98 * Length of the array containing more delimiters. 101 * Length of the array containing more delimiters.
99 */ 102 */
100 size_t delim_more_count; 103 size_t delim_more_count;
101 /** 104 /**
142 #else // __cplusplus 145 #else // __cplusplus
143 146
144 /** 147 /**
145 * A literal initializer for an UCX string structure. 148 * A literal initializer for an UCX string structure.
146 * 149 *
147 * The argument MUST be a string (const char*) \em literal. 150 * The argument MUST be a string (const char*) @em literal.
148 * 151 *
149 * @param literal the string literal 152 * @param literal the string literal
150 */ 153 */
151 #define CX_STR(literal) (cxstring){literal, sizeof(literal) - 1} 154 #define CX_STR(literal) ((cxstring){literal, sizeof(literal) - 1})
152 155
153 #endif 156 #endif
154 157
155 158
156 /** 159 /**
157 * Wraps a mutable string that must be zero-terminated. 160 * Wraps a mutable string that must be zero-terminated.
158 * 161 *
159 * The length is implicitly inferred by using a call to \c strlen(). 162 * The length is implicitly inferred by using a call to @c strlen().
160 * 163 *
161 * \note the wrapped string will share the specified pointer to the string. 164 * @note the wrapped string will share the specified pointer to the string.
162 * If you do want a copy, use cx_strdup() on the return value of this function. 165 * If you do want a copy, use cx_strdup() on the return value of this function.
163 * 166 *
164 * If you need to wrap a constant string, use cx_str(). 167 * If you need to wrap a constant string, use cx_str().
165 * 168 *
166 * @param cstring the string to wrap, must be zero-terminated 169 * @param cstring the string to wrap, must be zero-terminated
167 * @return the wrapped string 170 * @return the wrapped string
168 * 171 *
169 * @see cx_mutstrn() 172 * @see cx_mutstrn()
170 */ 173 */
171 __attribute__((__warn_unused_result__, __nonnull__)) 174 cx_attr_nonnull
175 cx_attr_nodiscard
176 cx_attr_cstr_arg(1)
177 cx_attr_export
172 cxmutstr cx_mutstr(char *cstring); 178 cxmutstr cx_mutstr(char *cstring);
173 179
174 /** 180 /**
175 * Wraps a string that does not need to be zero-terminated. 181 * Wraps a string that does not need to be zero-terminated.
176 * 182 *
177 * The argument may be \c NULL if the length is zero. 183 * The argument may be @c NULL if the length is zero.
178 * 184 *
179 * \note the wrapped string will share the specified pointer to the string. 185 * @note the wrapped string will share the specified pointer to the string.
180 * If you do want a copy, use cx_strdup() on the return value of this function. 186 * If you do want a copy, use cx_strdup() on the return value of this function.
181 * 187 *
182 * If you need to wrap a constant string, use cx_strn(). 188 * If you need to wrap a constant string, use cx_strn().
183 * 189 *
184 * @param cstring the string to wrap (or \c NULL, only if the length is zero) 190 * @param cstring the string to wrap (or @c NULL, only if the length is zero)
185 * @param length the length of the string 191 * @param length the length of the string
186 * @return the wrapped string 192 * @return the wrapped string
187 * 193 *
188 * @see cx_mutstr() 194 * @see cx_mutstr()
189 */ 195 */
190 __attribute__((__warn_unused_result__)) 196 cx_attr_nodiscard
197 cx_attr_access_rw(1, 2)
198 cx_attr_export
191 cxmutstr cx_mutstrn( 199 cxmutstr cx_mutstrn(
192 char *cstring, 200 char *cstring,
193 size_t length 201 size_t length
194 ); 202 );
195 203
196 /** 204 /**
197 * Wraps a string that must be zero-terminated. 205 * Wraps a string that must be zero-terminated.
198 * 206 *
199 * The length is implicitly inferred by using a call to \c strlen(). 207 * The length is implicitly inferred by using a call to @c strlen().
200 * 208 *
201 * \note the wrapped string will share the specified pointer to the string. 209 * @note the wrapped string will share the specified pointer to the string.
202 * If you do want a copy, use cx_strdup() on the return value of this function. 210 * If you do want a copy, use cx_strdup() on the return value of this function.
203 * 211 *
204 * If you need to wrap a non-constant string, use cx_mutstr(). 212 * If you need to wrap a non-constant string, use cx_mutstr().
205 * 213 *
206 * @param cstring the string to wrap, must be zero-terminated 214 * @param cstring the string to wrap, must be zero-terminated
207 * @return the wrapped string 215 * @return the wrapped string
208 * 216 *
209 * @see cx_strn() 217 * @see cx_strn()
210 */ 218 */
211 __attribute__((__warn_unused_result__, __nonnull__)) 219 cx_attr_nonnull
212 cxstring cx_str(char const *cstring); 220 cx_attr_nodiscard
221 cx_attr_cstr_arg(1)
222 cx_attr_export
223 cxstring cx_str(const char *cstring);
213 224
214 225
215 /** 226 /**
216 * Wraps a string that does not need to be zero-terminated. 227 * Wraps a string that does not need to be zero-terminated.
217 * 228 *
218 * The argument may be \c NULL if the length is zero. 229 * The argument may be @c NULL if the length is zero.
219 * 230 *
220 * \note the wrapped string will share the specified pointer to the string. 231 * @note the wrapped string will share the specified pointer to the string.
221 * If you do want a copy, use cx_strdup() on the return value of this function. 232 * If you do want a copy, use cx_strdup() on the return value of this function.
222 * 233 *
223 * If you need to wrap a non-constant string, use cx_mutstrn(). 234 * If you need to wrap a non-constant string, use cx_mutstrn().
224 * 235 *
225 * @param cstring the string to wrap (or \c NULL, only if the length is zero) 236 * @param cstring the string to wrap (or @c NULL, only if the length is zero)
226 * @param length the length of the string 237 * @param length the length of the string
227 * @return the wrapped string 238 * @return the wrapped string
228 * 239 *
229 * @see cx_str() 240 * @see cx_str()
230 */ 241 */
231 __attribute__((__warn_unused_result__)) 242 cx_attr_nodiscard
243 cx_attr_access_r(1, 2)
244 cx_attr_export
232 cxstring cx_strn( 245 cxstring cx_strn(
233 char const *cstring, 246 const char *cstring,
234 size_t length 247 size_t length
235 ); 248 );
249
250 #ifdef __cplusplus
251 } // extern "C"
252 cx_attr_nodiscard
253 static inline cxstring cx_strcast(cxmutstr str) {
254 return cx_strn(str.ptr, str.length);
255 }
256 cx_attr_nodiscard
257 static inline cxstring cx_strcast(cxstring str) {
258 return str;
259 }
260 extern "C" {
261 #else
262 /**
263 * Internal function, do not use.
264 * @param str
265 * @return
266 * @see cx_strcast()
267 */
268 cx_attr_nodiscard
269 static inline cxstring cx_strcast_m(cxmutstr str) {
270 return (cxstring) {str.ptr, str.length};
271 }
272 /**
273 * Internal function, do not use.
274 * @param str
275 * @return
276 * @see cx_strcast()
277 */
278 cx_attr_nodiscard
279 static inline cxstring cx_strcast_c(cxstring str) {
280 return str;
281 }
236 282
237 /** 283 /**
238 * Casts a mutable string to an immutable string. 284 * Casts a mutable string to an immutable string.
239 * 285 *
240 * \note This is not seriously a cast. Instead you get a copy 286 * Does nothing for already immutable strings.
287 *
288 * @note This is not seriously a cast. Instead, you get a copy
241 * of the struct with the desired pointer type. Both structs still 289 * of the struct with the desired pointer type. Both structs still
242 * point to the same location, though! 290 * point to the same location, though!
243 * 291 *
244 * @param str the mutable string to cast 292 * @param str (@c cxstring or @c cxmutstr) the string to cast
245 * @return an immutable copy of the string pointer 293 * @return (@c cxstring) an immutable copy of the string pointer
246 */ 294 */
247 __attribute__((__warn_unused_result__)) 295 #define cx_strcast(str) _Generic((str), \
248 cxstring cx_strcast(cxmutstr str); 296 cxmutstr: cx_strcast_m, \
249 297 cxstring: cx_strcast_c) \
250 /** 298 (str)
251 * Passes the pointer in this string to \c free(). 299 #endif
252 * 300
253 * The pointer in the struct is set to \c NULL and the length is set to zero. 301 /**
254 * 302 * Passes the pointer in this string to @c free().
255 * \note There is no implementation for cxstring, because it is unlikely that 303 *
256 * you ever have a \c char \c const* you are really supposed to free. If you 304 * The pointer in the struct is set to @c NULL and the length is set to zero
257 * encounter such situation, you should double-check your code. 305 * which means that this function protects you against double-free.
306 *
307 * @note There is no implementation for cxstring, because it is unlikely that
308 * you ever have a <code>const char*</code> you are really supposed to free.
309 * If you encounter such situation, you should double-check your code.
258 * 310 *
259 * @param str the string to free 311 * @param str the string to free
260 */ 312 */
261 __attribute__((__nonnull__)) 313 cx_attr_export
262 void cx_strfree(cxmutstr *str); 314 void cx_strfree(cxmutstr *str);
263 315
264 /** 316 /**
265 * Passes the pointer in this string to the allocators free function. 317 * Passes the pointer in this string to the allocators free function.
266 * 318 *
267 * The pointer in the struct is set to \c NULL and the length is set to zero. 319 * The pointer in the struct is set to @c NULL and the length is set to zero
268 * 320 * which means that this function protects you against double-free.
269 * \note There is no implementation for cxstring, because it is unlikely that 321 *
270 * you ever have a \c char \c const* you are really supposed to free. If you 322 * @note There is no implementation for cxstring, because it is unlikely that
271 * encounter such situation, you should double-check your code. 323 * you ever have a <code>const char*</code> you are really supposed to free.
324 * If you encounter such situation, you should double-check your code.
272 * 325 *
273 * @param alloc the allocator 326 * @param alloc the allocator
274 * @param str the string to free 327 * @param str the string to free
275 */ 328 */
276 __attribute__((__nonnull__)) 329 cx_attr_nonnull_arg(1)
330 cx_attr_export
277 void cx_strfree_a( 331 void cx_strfree_a(
278 CxAllocator const *alloc, 332 const CxAllocator *alloc,
279 cxmutstr *str 333 cxmutstr *str
280 ); 334 );
281 335
282 /** 336 /**
283 * Returns the accumulated length of all specified strings. 337 * Returns the accumulated length of all specified strings.
284 * 338 *
285 * \attention if the count argument is larger than the number of the 339 * If this sum overflows, errno is set to EOVERFLOW.
340 *
341 * @attention if the count argument is larger than the number of the
286 * specified strings, the behavior is undefined. 342 * specified strings, the behavior is undefined.
287 * 343 *
288 * @param count the total number of specified strings 344 * @param count the total number of specified strings
289 * @param ... all strings 345 * @param ... all strings
290 * @return the accumulated length of all strings 346 * @return the accumulated length of all strings
291 */ 347 */
292 __attribute__((__warn_unused_result__)) 348 cx_attr_nodiscard
349 cx_attr_export
293 size_t cx_strlen( 350 size_t cx_strlen(
294 size_t count, 351 size_t count,
295 ... 352 ...
296 ); 353 );
297 354
298 /** 355 /**
299 * Concatenates strings. 356 * Concatenates strings.
300 * 357 *
301 * The resulting string will be allocated by the specified allocator. 358 * The resulting string will be allocated by the specified allocator.
302 * So developers \em must pass the return value to cx_strfree_a() eventually. 359 * So developers @em must pass the return value to cx_strfree_a() eventually.
303 * 360 *
304 * If \p str already contains a string, the memory will be reallocated and 361 * If @p str already contains a string, the memory will be reallocated and
305 * the other strings are appended. Otherwise, new memory is allocated. 362 * the other strings are appended. Otherwise, new memory is allocated.
306 * 363 *
307 * \note It is guaranteed that there is only one allocation. 364 * If memory allocation fails, the pointer in the returned string will
365 * be @c NULL. Depending on the allocator, @c errno might be set.
366 *
367 * @note It is guaranteed that there is only one allocation for the
368 * resulting string.
308 * It is also guaranteed that the returned string is zero-terminated. 369 * It is also guaranteed that the returned string is zero-terminated.
309 * 370 *
310 * @param alloc the allocator to use 371 * @param alloc the allocator to use
311 * @param str the string the other strings shall be concatenated to 372 * @param str the string the other strings shall be concatenated to
312 * @param count the number of the other following strings to concatenate 373 * @param count the number of the other following strings to concatenate
313 * @param ... all other strings 374 * @param ... all other UCX strings
314 * @return the concatenated string 375 * @return the concatenated string
315 */ 376 */
316 __attribute__((__warn_unused_result__, __nonnull__)) 377 cx_attr_nodiscard
378 cx_attr_nonnull
379 cx_attr_export
317 cxmutstr cx_strcat_ma( 380 cxmutstr cx_strcat_ma(
318 CxAllocator const *alloc, 381 const CxAllocator *alloc,
319 cxmutstr str, 382 cxmutstr str,
320 size_t count, 383 size_t count,
321 ... 384 ...
322 ); 385 );
323 386
324 /** 387 /**
325 * Concatenates strings and returns a new string. 388 * Concatenates strings and returns a new string.
326 * 389 *
327 * The resulting string will be allocated by the specified allocator. 390 * The resulting string will be allocated by the specified allocator.
328 * So developers \em must pass the return value to cx_strfree_a() eventually. 391 * So developers @em must pass the return value to cx_strfree_a() eventually.
329 * 392 *
330 * \note It is guaranteed that there is only one allocation. 393 * If memory allocation fails, the pointer in the returned string will
394 * be @c NULL. Depending on the allocator, @c errno might be set.
395 *
396 * @note It is guaranteed that there is only one allocation for the
397 * resulting string.
331 * It is also guaranteed that the returned string is zero-terminated. 398 * It is also guaranteed that the returned string is zero-terminated.
332 * 399 *
333 * @param alloc the allocator to use 400 * @param alloc (@c CxAllocator*) the allocator to use
334 * @param count the number of the other following strings to concatenate 401 * @param count (@c size_t) the number of the other following strings to concatenate
335 * @param ... all other strings 402 * @param ... all other UCX strings
336 * @return the concatenated string 403 * @return (@c cxmutstr) the concatenated string
337 */ 404 */
338 #define cx_strcat_a(alloc, count, ...) \ 405 #define cx_strcat_a(alloc, count, ...) \
339 cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__) 406 cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__)
340 407
341 /** 408 /**
342 * Concatenates strings and returns a new string. 409 * Concatenates strings and returns a new string.
343 * 410 *
344 * The resulting string will be allocated by standard \c malloc(). 411 * The resulting string will be allocated by standard @c malloc().
345 * So developers \em must pass the return value to cx_strfree() eventually. 412 * So developers @em must pass the return value to cx_strfree() eventually.
346 * 413 *
347 * \note It is guaranteed that there is only one allocation. 414 * If memory allocation fails, the pointer in the returned string will
415 * be @c NULL and @c errno might be set.
416 *
417 * @note It is guaranteed that there is only one allocation for the
418 * resulting string.
348 * It is also guaranteed that the returned string is zero-terminated. 419 * It is also guaranteed that the returned string is zero-terminated.
349 * 420 *
350 * @param count the number of the other following strings to concatenate 421 * @param count (@c size_t) the number of the other following strings to concatenate
351 * @param ... all other strings 422 * @param ... all other UCX strings
352 * @return the concatenated string 423 * @return (@c cxmutstr) the concatenated string
353 */ 424 */
354 #define cx_strcat(count, ...) \ 425 #define cx_strcat(count, ...) \
355 cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__) 426 cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__)
356 427
357 /** 428 /**
358 * Concatenates strings. 429 * Concatenates strings.
359 * 430 *
360 * The resulting string will be allocated by standard \c malloc(). 431 * The resulting string will be allocated by standard @c malloc().
361 * So developers \em must pass the return value to cx_strfree() eventually. 432 * So developers @em must pass the return value to cx_strfree() eventually.
362 * 433 *
363 * If \p str already contains a string, the memory will be reallocated and 434 * If @p str already contains a string, the memory will be reallocated and
364 * the other strings are appended. Otherwise, new memory is allocated. 435 * the other strings are appended. Otherwise, new memory is allocated.
365 * 436 *
366 * \note It is guaranteed that there is only one allocation. 437 * If memory allocation fails, the pointer in the returned string will
438 * be @c NULL and @c errno might be set.
439 *
440 * @note It is guaranteed that there is only one allocation for the
441 * resulting string.
367 * It is also guaranteed that the returned string is zero-terminated. 442 * It is also guaranteed that the returned string is zero-terminated.
368 * 443 *
369 * @param str the string the other strings shall be concatenated to 444 * @param str (@c cxmutstr) the string the other strings shall be concatenated to
370 * @param count the number of the other following strings to concatenate 445 * @param count (@c size_t) the number of the other following strings to concatenate
371 * @param ... all other strings 446 * @param ... all other strings
372 * @return the concatenated string 447 * @return (@c cxmutstr) the concatenated string
373 */ 448 */
374 #define cx_strcat_m(str, count, ...) \ 449 #define cx_strcat_m(str, count, ...) \
375 cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__) 450 cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__)
376 451
377 /** 452 /**
378 * Returns a substring starting at the specified location. 453 * Returns a substring starting at the specified location.
379 * 454 *
380 * \attention the new string references the same memory area as the 455 * @attention the new string references the same memory area as the
381 * input string and is usually \em not zero-terminated. 456 * input string and is usually @em not zero-terminated.
382 * Use cx_strdup() to get a copy. 457 * Use cx_strdup() to get a copy.
383 * 458 *
384 * @param string input string 459 * @param string input string
385 * @param start start location of the substring 460 * @param start start location of the substring
386 * @return a substring of \p string starting at \p start 461 * @return a substring of @p string starting at @p start
387 * 462 *
388 * @see cx_strsubsl() 463 * @see cx_strsubsl()
389 * @see cx_strsubs_m() 464 * @see cx_strsubs_m()
390 * @see cx_strsubsl_m() 465 * @see cx_strsubsl_m()
391 */ 466 */
392 __attribute__((__warn_unused_result__)) 467 cx_attr_nodiscard
468 cx_attr_export
393 cxstring cx_strsubs( 469 cxstring cx_strsubs(
394 cxstring string, 470 cxstring string,
395 size_t start 471 size_t start
396 ); 472 );
397 473
398 /** 474 /**
399 * Returns a substring starting at the specified location. 475 * Returns a substring starting at the specified location.
400 * 476 *
401 * The returned string will be limited to \p length bytes or the number 477 * The returned string will be limited to @p length bytes or the number
402 * of bytes available in \p string, whichever is smaller. 478 * of bytes available in @p string, whichever is smaller.
403 * 479 *
404 * \attention the new string references the same memory area as the 480 * @attention the new string references the same memory area as the
405 * input string and is usually \em not zero-terminated. 481 * input string and is usually @em not zero-terminated.
406 * Use cx_strdup() to get a copy. 482 * Use cx_strdup() to get a copy.
407 * 483 *
408 * @param string input string 484 * @param string input string
409 * @param start start location of the substring 485 * @param start start location of the substring
410 * @param length the maximum length of the returned string 486 * @param length the maximum length of the returned string
411 * @return a substring of \p string starting at \p start 487 * @return a substring of @p string starting at @p start
412 * 488 *
413 * @see cx_strsubs() 489 * @see cx_strsubs()
414 * @see cx_strsubs_m() 490 * @see cx_strsubs_m()
415 * @see cx_strsubsl_m() 491 * @see cx_strsubsl_m()
416 */ 492 */
417 __attribute__((__warn_unused_result__)) 493 cx_attr_nodiscard
494 cx_attr_export
418 cxstring cx_strsubsl( 495 cxstring cx_strsubsl(
419 cxstring string, 496 cxstring string,
420 size_t start, 497 size_t start,
421 size_t length 498 size_t length
422 ); 499 );
423 500
424 /** 501 /**
425 * Returns a substring starting at the specified location. 502 * Returns a substring starting at the specified location.
426 * 503 *
427 * \attention the new string references the same memory area as the 504 * @attention the new string references the same memory area as the
428 * input string and is usually \em not zero-terminated. 505 * input string and is usually @em not zero-terminated.
429 * Use cx_strdup() to get a copy. 506 * Use cx_strdup() to get a copy.
430 * 507 *
431 * @param string input string 508 * @param string input string
432 * @param start start location of the substring 509 * @param start start location of the substring
433 * @return a substring of \p string starting at \p start 510 * @return a substring of @p string starting at @p start
434 * 511 *
435 * @see cx_strsubsl_m() 512 * @see cx_strsubsl_m()
436 * @see cx_strsubs() 513 * @see cx_strsubs()
437 * @see cx_strsubsl() 514 * @see cx_strsubsl()
438 */ 515 */
439 __attribute__((__warn_unused_result__)) 516 cx_attr_nodiscard
517 cx_attr_export
440 cxmutstr cx_strsubs_m( 518 cxmutstr cx_strsubs_m(
441 cxmutstr string, 519 cxmutstr string,
442 size_t start 520 size_t start
443 ); 521 );
444 522
445 /** 523 /**
446 * Returns a substring starting at the specified location. 524 * Returns a substring starting at the specified location.
447 * 525 *
448 * The returned string will be limited to \p length bytes or the number 526 * The returned string will be limited to @p length bytes or the number
449 * of bytes available in \p string, whichever is smaller. 527 * of bytes available in @p string, whichever is smaller.
450 * 528 *
451 * \attention the new string references the same memory area as the 529 * @attention the new string references the same memory area as the
452 * input string and is usually \em not zero-terminated. 530 * input string and is usually @em not zero-terminated.
453 * Use cx_strdup() to get a copy. 531 * Use cx_strdup() to get a copy.
454 * 532 *
455 * @param string input string 533 * @param string input string
456 * @param start start location of the substring 534 * @param start start location of the substring
457 * @param length the maximum length of the returned string 535 * @param length the maximum length of the returned string
458 * @return a substring of \p string starting at \p start 536 * @return a substring of @p string starting at @p start
459 * 537 *
460 * @see cx_strsubs_m() 538 * @see cx_strsubs_m()
461 * @see cx_strsubs() 539 * @see cx_strsubs()
462 * @see cx_strsubsl() 540 * @see cx_strsubsl()
463 */ 541 */
464 __attribute__((__warn_unused_result__)) 542 cx_attr_nodiscard
543 cx_attr_export
465 cxmutstr cx_strsubsl_m( 544 cxmutstr cx_strsubsl_m(
466 cxmutstr string, 545 cxmutstr string,
467 size_t start, 546 size_t start,
468 size_t length 547 size_t length
469 ); 548 );
474 * 553 *
475 * If the string does not contain the character, an empty string is returned. 554 * If the string does not contain the character, an empty string is returned.
476 * 555 *
477 * @param string the string where to locate the character 556 * @param string the string where to locate the character
478 * @param chr the character to locate 557 * @param chr the character to locate
479 * @return a substring starting at the first location of \p chr 558 * @return a substring starting at the first location of @p chr
480 * 559 *
481 * @see cx_strchr_m() 560 * @see cx_strchr_m()
482 */ 561 */
483 __attribute__((__warn_unused_result__)) 562 cx_attr_nodiscard
563 cx_attr_export
484 cxstring cx_strchr( 564 cxstring cx_strchr(
485 cxstring string, 565 cxstring string,
486 int chr 566 int chr
487 ); 567 );
488 568
492 * 572 *
493 * If the string does not contain the character, an empty string is returned. 573 * If the string does not contain the character, an empty string is returned.
494 * 574 *
495 * @param string the string where to locate the character 575 * @param string the string where to locate the character
496 * @param chr the character to locate 576 * @param chr the character to locate
497 * @return a substring starting at the first location of \p chr 577 * @return a substring starting at the first location of @p chr
498 * 578 *
499 * @see cx_strchr() 579 * @see cx_strchr()
500 */ 580 */
501 __attribute__((__warn_unused_result__)) 581 cx_attr_nodiscard
582 cx_attr_export
502 cxmutstr cx_strchr_m( 583 cxmutstr cx_strchr_m(
503 cxmutstr string, 584 cxmutstr string,
504 int chr 585 int chr
505 ); 586 );
506 587
510 * 591 *
511 * If the string does not contain the character, an empty string is returned. 592 * If the string does not contain the character, an empty string is returned.
512 * 593 *
513 * @param string the string where to locate the character 594 * @param string the string where to locate the character
514 * @param chr the character to locate 595 * @param chr the character to locate
515 * @return a substring starting at the last location of \p chr 596 * @return a substring starting at the last location of @p chr
516 * 597 *
517 * @see cx_strrchr_m() 598 * @see cx_strrchr_m()
518 */ 599 */
519 __attribute__((__warn_unused_result__)) 600 cx_attr_nodiscard
601 cx_attr_export
520 cxstring cx_strrchr( 602 cxstring cx_strrchr(
521 cxstring string, 603 cxstring string,
522 int chr 604 int chr
523 ); 605 );
524 606
528 * 610 *
529 * If the string does not contain the character, an empty string is returned. 611 * If the string does not contain the character, an empty string is returned.
530 * 612 *
531 * @param string the string where to locate the character 613 * @param string the string where to locate the character
532 * @param chr the character to locate 614 * @param chr the character to locate
533 * @return a substring starting at the last location of \p chr 615 * @return a substring starting at the last location of @p chr
534 * 616 *
535 * @see cx_strrchr() 617 * @see cx_strrchr()
536 */ 618 */
537 __attribute__((__warn_unused_result__)) 619 cx_attr_nodiscard
620 cx_attr_export
538 cxmutstr cx_strrchr_m( 621 cxmutstr cx_strrchr_m(
539 cxmutstr string, 622 cxmutstr string,
540 int chr 623 int chr
541 ); 624 );
542 625
543 /** 626 /**
544 * Returns a substring starting at the location of the first occurrence of the 627 * Returns a substring starting at the location of the first occurrence of the
545 * specified string. 628 * specified string.
546 * 629 *
547 * If \p haystack does not contain \p needle, an empty string is returned. 630 * If @p haystack does not contain @p needle, an empty string is returned.
548 * 631 *
549 * If \p needle is an empty string, the complete \p haystack is 632 * If @p needle is an empty string, the complete @p haystack is
550 * returned. 633 * returned.
551 * 634 *
552 * @param haystack the string to be scanned 635 * @param haystack the string to be scanned
553 * @param needle string containing the sequence of characters to match 636 * @param needle string containing the sequence of characters to match
554 * @return a substring starting at the first occurrence of 637 * @return a substring starting at the first occurrence of
555 * \p needle, or an empty string, if the sequence is not 638 * @p needle, or an empty string, if the sequence is not
556 * contained 639 * contained
557 * @see cx_strstr_m() 640 * @see cx_strstr_m()
558 */ 641 */
559 __attribute__((__warn_unused_result__)) 642 cx_attr_nodiscard
643 cx_attr_export
560 cxstring cx_strstr( 644 cxstring cx_strstr(
561 cxstring haystack, 645 cxstring haystack,
562 cxstring needle 646 cxstring needle
563 ); 647 );
564 648
565 /** 649 /**
566 * Returns a substring starting at the location of the first occurrence of the 650 * Returns a substring starting at the location of the first occurrence of the
567 * specified string. 651 * specified string.
568 * 652 *
569 * If \p haystack does not contain \p needle, an empty string is returned. 653 * If @p haystack does not contain @p needle, an empty string is returned.
570 * 654 *
571 * If \p needle is an empty string, the complete \p haystack is 655 * If @p needle is an empty string, the complete @p haystack is
572 * returned. 656 * returned.
573 * 657 *
574 * @param haystack the string to be scanned 658 * @param haystack the string to be scanned
575 * @param needle string containing the sequence of characters to match 659 * @param needle string containing the sequence of characters to match
576 * @return a substring starting at the first occurrence of 660 * @return a substring starting at the first occurrence of
577 * \p needle, or an empty string, if the sequence is not 661 * @p needle, or an empty string, if the sequence is not
578 * contained 662 * contained
579 * @see cx_strstr() 663 * @see cx_strstr()
580 */ 664 */
581 __attribute__((__warn_unused_result__)) 665 cx_attr_nodiscard
666 cx_attr_export
582 cxmutstr cx_strstr_m( 667 cxmutstr cx_strstr_m(
583 cxmutstr haystack, 668 cxmutstr haystack,
584 cxstring needle 669 cxstring needle
585 ); 670 );
586 671
587 /** 672 /**
588 * Splits a given string using a delimiter string. 673 * Splits a given string using a delimiter string.
589 * 674 *
590 * \note The resulting array contains strings that point to the source 675 * @note The resulting array contains strings that point to the source
591 * \p string. Use cx_strdup() to get copies. 676 * @p string. Use cx_strdup() to get copies.
592 * 677 *
593 * @param string the string to split 678 * @param string the string to split
594 * @param delim the delimiter 679 * @param delim the delimiter
595 * @param limit the maximum number of split items 680 * @param limit the maximum number of split items
596 * @param output a pre-allocated array of at least \p limit length 681 * @param output a preallocated array of at least @p limit length
597 * @return the actual number of split items 682 * @return the actual number of split items
598 */ 683 */
599 __attribute__((__warn_unused_result__, __nonnull__)) 684 cx_attr_nodiscard
685 cx_attr_nonnull
686 cx_attr_access_w(4, 3)
687 cx_attr_export
600 size_t cx_strsplit( 688 size_t cx_strsplit(
601 cxstring string, 689 cxstring string,
602 cxstring delim, 690 cxstring delim,
603 size_t limit, 691 size_t limit,
604 cxstring *output 692 cxstring *output
605 ); 693 );
606 694
607 /** 695 /**
608 * Splits a given string using a delimiter string. 696 * Splits a given string using a delimiter string.
609 * 697 *
610 * The array pointed to by \p output will be allocated by \p allocator. 698 * The array pointed to by @p output will be allocated by @p allocator.
611 * 699 *
612 * \note The resulting array contains strings that point to the source 700 * @note The resulting array contains strings that point to the source
613 * \p string. Use cx_strdup() to get copies. 701 * @p string. Use cx_strdup() to get copies.
614 * 702 *
615 * \attention If allocation fails, the \c NULL pointer will be written to 703 * @attention If allocation fails, the @c NULL pointer will be written to
616 * \p output and the number returned will be zero. 704 * @p output and the number returned will be zero.
617 * 705 *
618 * @param allocator the allocator to use for allocating the resulting array 706 * @param allocator the allocator to use for allocating the resulting array
619 * @param string the string to split 707 * @param string the string to split
620 * @param delim the delimiter 708 * @param delim the delimiter
621 * @param limit the maximum number of split items 709 * @param limit the maximum number of split items
622 * @param output a pointer where the address of the allocated array shall be 710 * @param output a pointer where the address of the allocated array shall be
623 * written to 711 * written to
624 * @return the actual number of split items 712 * @return the actual number of split items
625 */ 713 */
626 __attribute__((__warn_unused_result__, __nonnull__)) 714 cx_attr_nodiscard
715 cx_attr_nonnull
716 cx_attr_access_w(5)
717 cx_attr_export
627 size_t cx_strsplit_a( 718 size_t cx_strsplit_a(
628 CxAllocator const *allocator, 719 const CxAllocator *allocator,
629 cxstring string, 720 cxstring string,
630 cxstring delim, 721 cxstring delim,
631 size_t limit, 722 size_t limit,
632 cxstring **output 723 cxstring **output
633 ); 724 );
634 725
635 726
636 /** 727 /**
637 * Splits a given string using a delimiter string. 728 * Splits a given string using a delimiter string.
638 * 729 *
639 * \note The resulting array contains strings that point to the source 730 * @note The resulting array contains strings that point to the source
640 * \p string. Use cx_strdup() to get copies. 731 * @p string. Use cx_strdup() to get copies.
641 * 732 *
642 * @param string the string to split 733 * @param string the string to split
643 * @param delim the delimiter 734 * @param delim the delimiter
644 * @param limit the maximum number of split items 735 * @param limit the maximum number of split items
645 * @param output a pre-allocated array of at least \p limit length 736 * @param output a preallocated array of at least @p limit length
646 * @return the actual number of split items 737 * @return the actual number of split items
647 */ 738 */
648 __attribute__((__warn_unused_result__, __nonnull__)) 739 cx_attr_nodiscard
740 cx_attr_nonnull
741 cx_attr_access_w(4, 3)
742 cx_attr_export
649 size_t cx_strsplit_m( 743 size_t cx_strsplit_m(
650 cxmutstr string, 744 cxmutstr string,
651 cxstring delim, 745 cxstring delim,
652 size_t limit, 746 size_t limit,
653 cxmutstr *output 747 cxmutstr *output
654 ); 748 );
655 749
656 /** 750 /**
657 * Splits a given string using a delimiter string. 751 * Splits a given string using a delimiter string.
658 * 752 *
659 * The array pointed to by \p output will be allocated by \p allocator. 753 * The array pointed to by @p output will be allocated by @p allocator.
660 * 754 *
661 * \note The resulting array contains strings that point to the source 755 * @note The resulting array contains strings that point to the source
662 * \p string. Use cx_strdup() to get copies. 756 * @p string. Use cx_strdup() to get copies.
663 * 757 *
664 * \attention If allocation fails, the \c NULL pointer will be written to 758 * @attention If allocation fails, the @c NULL pointer will be written to
665 * \p output and the number returned will be zero. 759 * @p output and the number returned will be zero.
666 * 760 *
667 * @param allocator the allocator to use for allocating the resulting array 761 * @param allocator the allocator to use for allocating the resulting array
668 * @param string the string to split 762 * @param string the string to split
669 * @param delim the delimiter 763 * @param delim the delimiter
670 * @param limit the maximum number of split items 764 * @param limit the maximum number of split items
671 * @param output a pointer where the address of the allocated array shall be 765 * @param output a pointer where the address of the allocated array shall be
672 * written to 766 * written to
673 * @return the actual number of split items 767 * @return the actual number of split items
674 */ 768 */
675 __attribute__((__warn_unused_result__, __nonnull__)) 769 cx_attr_nodiscard
770 cx_attr_nonnull
771 cx_attr_access_w(5)
772 cx_attr_export
676 size_t cx_strsplit_ma( 773 size_t cx_strsplit_ma(
677 CxAllocator const *allocator, 774 const CxAllocator *allocator,
678 cxmutstr string, 775 cxmutstr string,
679 cxstring delim, 776 cxstring delim,
680 size_t limit, 777 size_t limit,
681 cxmutstr **output 778 cxmutstr **output
682 ); 779 );
684 /** 781 /**
685 * Compares two strings. 782 * Compares two strings.
686 * 783 *
687 * @param s1 the first string 784 * @param s1 the first string
688 * @param s2 the second string 785 * @param s2 the second string
689 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 786 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
690 * than \p s2, zero if both strings equal 787 * than @p s2, zero if both strings equal
691 */ 788 */
692 __attribute__((__warn_unused_result__)) 789 cx_attr_nodiscard
790 cx_attr_export
693 int cx_strcmp( 791 int cx_strcmp(
694 cxstring s1, 792 cxstring s1,
695 cxstring s2 793 cxstring s2
696 ); 794 );
697 795
698 /** 796 /**
699 * Compares two strings ignoring case. 797 * Compares two strings ignoring case.
700 * 798 *
701 * @param s1 the first string 799 * @param s1 the first string
702 * @param s2 the second string 800 * @param s2 the second string
703 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 801 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
704 * than \p s2, zero if both strings equal ignoring case 802 * than @p s2, zero if both strings equal ignoring case
705 */ 803 */
706 __attribute__((__warn_unused_result__)) 804 cx_attr_nodiscard
805 cx_attr_export
707 int cx_strcasecmp( 806 int cx_strcasecmp(
708 cxstring s1, 807 cxstring s1,
709 cxstring s2 808 cxstring s2
710 ); 809 );
711 810
714 * 813 *
715 * This function has a compatible signature for the use as a cx_compare_func. 814 * This function has a compatible signature for the use as a cx_compare_func.
716 * 815 *
717 * @param s1 the first string 816 * @param s1 the first string
718 * @param s2 the second string 817 * @param s2 the second string
719 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 818 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
720 * than \p s2, zero if both strings equal 819 * than @p s2, zero if both strings equal
721 */ 820 */
722 __attribute__((__warn_unused_result__, __nonnull__)) 821 cx_attr_nodiscard
822 cx_attr_nonnull
823 cx_attr_export
723 int cx_strcmp_p( 824 int cx_strcmp_p(
724 void const *s1, 825 const void *s1,
725 void const *s2 826 const void *s2
726 ); 827 );
727 828
728 /** 829 /**
729 * Compares two strings ignoring case. 830 * Compares two strings ignoring case.
730 * 831 *
731 * This function has a compatible signature for the use as a cx_compare_func. 832 * This function has a compatible signature for the use as a cx_compare_func.
732 * 833 *
733 * @param s1 the first string 834 * @param s1 the first string
734 * @param s2 the second string 835 * @param s2 the second string
735 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 836 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
736 * than \p s2, zero if both strings equal ignoring case 837 * than @p s2, zero if both strings equal ignoring case
737 */ 838 */
738 __attribute__((__warn_unused_result__, __nonnull__)) 839 cx_attr_nodiscard
840 cx_attr_nonnull
841 cx_attr_export
739 int cx_strcasecmp_p( 842 int cx_strcasecmp_p(
740 void const *s1, 843 const void *s1,
741 void const *s2 844 const void *s2
742 ); 845 );
743 846
744 847
745 /** 848 /**
746 * Creates a duplicate of the specified string. 849 * Creates a duplicate of the specified string.
747 * 850 *
748 * The new string will contain a copy allocated by \p allocator. 851 * The new string will contain a copy allocated by @p allocator.
749 * 852 *
750 * \note The returned string is guaranteed to be zero-terminated. 853 * @note The returned string is guaranteed to be zero-terminated.
751 * 854 *
752 * @param allocator the allocator to use 855 * @param allocator the allocator to use
753 * @param string the string to duplicate 856 * @param string the string to duplicate
754 * @return a duplicate of the string 857 * @return a duplicate of the string
755 * @see cx_strdup() 858 * @see cx_strdup()
756 */ 859 */
757 __attribute__((__warn_unused_result__, __nonnull__)) 860 cx_attr_nodiscard
758 cxmutstr cx_strdup_a( 861 cx_attr_nonnull
759 CxAllocator const *allocator, 862 cx_attr_export
863 cxmutstr cx_strdup_a_(
864 const CxAllocator *allocator,
760 cxstring string 865 cxstring string
761 ); 866 );
762 867
763 /** 868 /**
764 * Creates a duplicate of the specified string. 869 * Creates a duplicate of the specified string.
765 * 870 *
871 * The new string will contain a copy allocated by @p allocator.
872 *
873 * @note The returned string is guaranteed to be zero-terminated.
874 *
875 * @param allocator (@c CxAllocator*) the allocator to use
876 * @param string the string to duplicate
877 * @return (@c cxmutstr) a duplicate of the string
878 * @see cx_strdup()
879 * @see cx_strfree_a()
880 */
881 #define cx_strdup_a(allocator, string) \
882 cx_strdup_a_((allocator), cx_strcast(string))
883
884 /**
885 * Creates a duplicate of the specified string.
886 *
766 * The new string will contain a copy allocated by standard 887 * The new string will contain a copy allocated by standard
767 * \c malloc(). So developers \em must pass the return value to cx_strfree(). 888 * @c malloc(). So developers @em must pass the return value to cx_strfree().
768 * 889 *
769 * \note The returned string is guaranteed to be zero-terminated. 890 * @note The returned string is guaranteed to be zero-terminated.
770 * 891 *
771 * @param string the string to duplicate 892 * @param string the string to duplicate
772 * @return a duplicate of the string 893 * @return (@c cxmutstr) a duplicate of the string
773 * @see cx_strdup_a() 894 * @see cx_strdup_a()
895 * @see cx_strfree()
774 */ 896 */
775 #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) 897 #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string)
776 898
777
778 /**
779 * Creates a duplicate of the specified string.
780 *
781 * The new string will contain a copy allocated by \p allocator.
782 *
783 * \note The returned string is guaranteed to be zero-terminated.
784 *
785 * @param allocator the allocator to use
786 * @param string the string to duplicate
787 * @return a duplicate of the string
788 * @see cx_strdup_m()
789 */
790 #define cx_strdup_ma(allocator, string) cx_strdup_a(allocator, cx_strcast(string))
791
792 /**
793 * Creates a duplicate of the specified string.
794 *
795 * The new string will contain a copy allocated by standard
796 * \c malloc(). So developers \em must pass the return value to cx_strfree().
797 *
798 * \note The returned string is guaranteed to be zero-terminated.
799 *
800 * @param string the string to duplicate
801 * @return a duplicate of the string
802 * @see cx_strdup_ma()
803 */
804 #define cx_strdup_m(string) cx_strdup_a(cxDefaultAllocator, cx_strcast(string))
805
806 /** 899 /**
807 * Omits leading and trailing spaces. 900 * Omits leading and trailing spaces.
808 * 901 *
809 * \note the returned string references the same memory, thus you 902 * @note the returned string references the same memory, thus you
810 * must \em not free the returned memory. 903 * must @em not free the returned memory.
811 * 904 *
812 * @param string the string that shall be trimmed 905 * @param string the string that shall be trimmed
813 * @return the trimmed string 906 * @return the trimmed string
814 */ 907 */
815 __attribute__((__warn_unused_result__)) 908 cx_attr_nodiscard
909 cx_attr_export
816 cxstring cx_strtrim(cxstring string); 910 cxstring cx_strtrim(cxstring string);
817 911
818 /** 912 /**
819 * Omits leading and trailing spaces. 913 * Omits leading and trailing spaces.
820 * 914 *
821 * \note the returned string references the same memory, thus you 915 * @note the returned string references the same memory, thus you
822 * must \em not free the returned memory. 916 * must @em not free the returned memory.
823 * 917 *
824 * @param string the string that shall be trimmed 918 * @param string the string that shall be trimmed
825 * @return the trimmed string 919 * @return the trimmed string
826 */ 920 */
827 __attribute__((__warn_unused_result__)) 921 cx_attr_nodiscard
922 cx_attr_export
828 cxmutstr cx_strtrim_m(cxmutstr string); 923 cxmutstr cx_strtrim_m(cxmutstr string);
829 924
830 /** 925 /**
831 * Checks, if a string has a specific prefix. 926 * Checks, if a string has a specific prefix.
832 * 927 *
833 * @param string the string to check 928 * @param string the string to check
834 * @param prefix the prefix the string should have 929 * @param prefix the prefix the string should have
835 * @return \c true, if and only if the string has the specified prefix, 930 * @return @c true, if and only if the string has the specified prefix,
836 * \c false otherwise 931 * @c false otherwise
837 */ 932 */
838 __attribute__((__warn_unused_result__)) 933 cx_attr_nodiscard
934 cx_attr_export
839 bool cx_strprefix( 935 bool cx_strprefix(
840 cxstring string, 936 cxstring string,
841 cxstring prefix 937 cxstring prefix
842 ); 938 );
843 939
844 /** 940 /**
845 * Checks, if a string has a specific suffix. 941 * Checks, if a string has a specific suffix.
846 * 942 *
847 * @param string the string to check 943 * @param string the string to check
848 * @param suffix the suffix the string should have 944 * @param suffix the suffix the string should have
849 * @return \c true, if and only if the string has the specified suffix, 945 * @return @c true, if and only if the string has the specified suffix,
850 * \c false otherwise 946 * @c false otherwise
851 */ 947 */
852 __attribute__((__warn_unused_result__)) 948 cx_attr_nodiscard
949 cx_attr_export
853 bool cx_strsuffix( 950 bool cx_strsuffix(
854 cxstring string, 951 cxstring string,
855 cxstring suffix 952 cxstring suffix
856 ); 953 );
857 954
858 /** 955 /**
859 * Checks, if a string has a specific prefix, ignoring the case. 956 * Checks, if a string has a specific prefix, ignoring the case.
860 * 957 *
861 * @param string the string to check 958 * @param string the string to check
862 * @param prefix the prefix the string should have 959 * @param prefix the prefix the string should have
863 * @return \c true, if and only if the string has the specified prefix, 960 * @return @c true, if and only if the string has the specified prefix,
864 * \c false otherwise 961 * @c false otherwise
865 */ 962 */
866 __attribute__((__warn_unused_result__)) 963 cx_attr_nodiscard
964 cx_attr_export
867 bool cx_strcaseprefix( 965 bool cx_strcaseprefix(
868 cxstring string, 966 cxstring string,
869 cxstring prefix 967 cxstring prefix
870 ); 968 );
871 969
872 /** 970 /**
873 * Checks, if a string has a specific suffix, ignoring the case. 971 * Checks, if a string has a specific suffix, ignoring the case.
874 * 972 *
875 * @param string the string to check 973 * @param string the string to check
876 * @param suffix the suffix the string should have 974 * @param suffix the suffix the string should have
877 * @return \c true, if and only if the string has the specified suffix, 975 * @return @c true, if and only if the string has the specified suffix,
878 * \c false otherwise 976 * @c false otherwise
879 */ 977 */
880 __attribute__((__warn_unused_result__)) 978 cx_attr_nodiscard
979 cx_attr_export
881 bool cx_strcasesuffix( 980 bool cx_strcasesuffix(
882 cxstring string, 981 cxstring string,
883 cxstring suffix 982 cxstring suffix
884 ); 983 );
885 984
886 /** 985 /**
887 * Converts the string to lower case. 986 * Replaces a string with another string.
888 * 987 *
889 * The change is made in-place. If you want a copy, use cx_strdup(), first. 988 * Replaces at most @p replmax occurrences.
890 * 989 *
891 * @param string the string to modify 990 * The returned string will be allocated by @p allocator and is guaranteed
892 * @see cx_strdup()
893 */
894 void cx_strlower(cxmutstr string);
895
896 /**
897 * Converts the string to upper case.
898 *
899 * The change is made in-place. If you want a copy, use cx_strdup(), first.
900 *
901 * @param string the string to modify
902 * @see cx_strdup()
903 */
904 void cx_strupper(cxmutstr string);
905
906 /**
907 * Replaces a pattern in a string with another string.
908 *
909 * The pattern is taken literally and is no regular expression.
910 * Replaces at most \p replmax occurrences.
911 *
912 * The returned string will be allocated by \p allocator and is guaranteed
913 * to be zero-terminated. 991 * to be zero-terminated.
914 * 992 *
915 * If allocation fails, or the input string is empty, 993 * If allocation fails, or the input string is empty,
916 * the returned string will be empty. 994 * the returned string will be empty.
917 * 995 *
918 * @param allocator the allocator to use 996 * @param allocator the allocator to use
919 * @param str the string where replacements should be applied 997 * @param str the string where replacements should be applied
920 * @param pattern the pattern to search for 998 * @param search the string to search for
921 * @param replacement the replacement string 999 * @param replacement the replacement string
922 * @param replmax maximum number of replacements 1000 * @param replmax maximum number of replacements
923 * @return the resulting string after applying the replacements 1001 * @return the resulting string after applying the replacements
924 */ 1002 */
925 __attribute__((__warn_unused_result__, __nonnull__)) 1003 cx_attr_nodiscard
1004 cx_attr_nonnull
1005 cx_attr_export
926 cxmutstr cx_strreplacen_a( 1006 cxmutstr cx_strreplacen_a(
927 CxAllocator const *allocator, 1007 const CxAllocator *allocator,
928 cxstring str, 1008 cxstring str,
929 cxstring pattern, 1009 cxstring search,
930 cxstring replacement, 1010 cxstring replacement,
931 size_t replmax 1011 size_t replmax
932 ); 1012 );
933 1013
934 /** 1014 /**
935 * Replaces a pattern in a string with another string. 1015 * Replaces a string with another string.
936 * 1016 *
937 * The pattern is taken literally and is no regular expression. 1017 * Replaces at most @p replmax occurrences.
938 * Replaces at most \p replmax occurrences. 1018 *
939 * 1019 * The returned string will be allocated by @c malloc() and is guaranteed
940 * The returned string will be allocated by \c malloc() and is guaranteed
941 * to be zero-terminated. 1020 * to be zero-terminated.
942 * 1021 *
943 * If allocation fails, or the input string is empty, 1022 * If allocation fails, or the input string is empty,
944 * the returned string will be empty. 1023 * the returned string will be empty.
945 * 1024 *
946 * @param str the string where replacements should be applied 1025 * @param str (@c cxstring) the string where replacements should be applied
947 * @param pattern the pattern to search for 1026 * @param search (@c cxstring) the string to search for
948 * @param replacement the replacement string 1027 * @param replacement (@c cxstring) the replacement string
949 * @param replmax maximum number of replacements 1028 * @param replmax (@c size_t) maximum number of replacements
950 * @return the resulting string after applying the replacements 1029 * @return (@c cxmutstr) the resulting string after applying the replacements
951 */ 1030 */
952 #define cx_strreplacen(str, pattern, replacement, replmax) \ 1031 #define cx_strreplacen(str, search, replacement, replmax) \
953 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, replmax) 1032 cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, replmax)
954 1033
955 /** 1034 /**
956 * Replaces a pattern in a string with another string. 1035 * Replaces a string with another string.
957 * 1036 *
958 * The pattern is taken literally and is no regular expression. 1037 * The returned string will be allocated by @p allocator and is guaranteed
959 *
960 * The returned string will be allocated by \p allocator and is guaranteed
961 * to be zero-terminated. 1038 * to be zero-terminated.
962 * 1039 *
963 * If allocation fails, or the input string is empty, 1040 * If allocation fails, or the input string is empty,
964 * the returned string will be empty. 1041 * the returned string will be empty.
965 * 1042 *
966 * @param allocator the allocator to use 1043 * @param allocator (@c CxAllocator*) the allocator to use
967 * @param str the string where replacements should be applied 1044 * @param str (@c cxstring) the string where replacements should be applied
968 * @param pattern the pattern to search for 1045 * @param search (@c cxstring) the string to search for
969 * @param replacement the replacement string 1046 * @param replacement (@c cxstring) the replacement string
970 * @return the resulting string after applying the replacements 1047 * @return (@c cxmutstr) the resulting string after applying the replacements
971 */ 1048 */
972 #define cx_strreplace_a(allocator, str, pattern, replacement) \ 1049 #define cx_strreplace_a(allocator, str, search, replacement) \
973 cx_strreplacen_a(allocator, str, pattern, replacement, SIZE_MAX) 1050 cx_strreplacen_a(allocator, str, search, replacement, SIZE_MAX)
974 1051
975 /** 1052 /**
976 * Replaces a pattern in a string with another string. 1053 * Replaces a string with another string.
977 * 1054 *
978 * The pattern is taken literally and is no regular expression. 1055 * The returned string will be allocated by @c malloc() and is guaranteed
979 * Replaces at most \p replmax occurrences.
980 *
981 * The returned string will be allocated by \c malloc() and is guaranteed
982 * to be zero-terminated. 1056 * to be zero-terminated.
983 * 1057 *
984 * If allocation fails, or the input string is empty, 1058 * If allocation fails, or the input string is empty,
985 * the returned string will be empty. 1059 * the returned string will be empty.
986 * 1060 *
987 * @param str the string where replacements should be applied 1061 * @param str (@c cxstring) the string where replacements should be applied
988 * @param pattern the pattern to search for 1062 * @param search (@c cxstring) the string to search for
989 * @param replacement the replacement string 1063 * @param replacement (@c cxstring) the replacement string
990 * @return the resulting string after applying the replacements 1064 * @return (@c cxmutstr) the resulting string after applying the replacements
991 */ 1065 */
992 #define cx_strreplace(str, pattern, replacement) \ 1066 #define cx_strreplace(str, search, replacement) \
993 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, SIZE_MAX) 1067 cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, SIZE_MAX)
994 1068
995 /** 1069 /**
996 * Creates a string tokenization context. 1070 * Creates a string tokenization context.
997 * 1071 *
998 * @param str the string to tokenize 1072 * @param str the string to tokenize
999 * @param delim the delimiter (must not be empty) 1073 * @param delim the delimiter (must not be empty)
1000 * @param limit the maximum number of tokens that shall be returned 1074 * @param limit the maximum number of tokens that shall be returned
1001 * @return a new string tokenization context 1075 * @return a new string tokenization context
1002 */ 1076 */
1003 __attribute__((__warn_unused_result__)) 1077 cx_attr_nodiscard
1004 CxStrtokCtx cx_strtok( 1078 cx_attr_export
1079 CxStrtokCtx cx_strtok_(
1005 cxstring str, 1080 cxstring str,
1006 cxstring delim, 1081 cxstring delim,
1007 size_t limit 1082 size_t limit
1008 ); 1083 );
1009 1084
1010 /** 1085 /**
1011 * Creates a string tokenization context for a mutable string. 1086 * Creates a string tokenization context.
1012 * 1087 *
1013 * @param str the string to tokenize 1088 * @param str the string to tokenize
1014 * @param delim the delimiter (must not be empty) 1089 * @param delim the delimiter string (must not be empty)
1015 * @param limit the maximum number of tokens that shall be returned 1090 * @param limit (@c size_t) the maximum number of tokens that shall be returned
1016 * @return a new string tokenization context 1091 * @return (@c CxStrtokCtx) a new string tokenization context
1017 */ 1092 */
1018 __attribute__((__warn_unused_result__)) 1093 #define cx_strtok(str, delim, limit) \
1019 CxStrtokCtx cx_strtok_m( 1094 cx_strtok_(cx_strcast(str), cx_strcast(delim), (limit))
1020 cxmutstr str,
1021 cxstring delim,
1022 size_t limit
1023 );
1024 1095
1025 /** 1096 /**
1026 * Returns the next token. 1097 * Returns the next token.
1027 * 1098 *
1028 * The token will point to the source string. 1099 * The token will point to the source string.
1030 * @param ctx the tokenization context 1101 * @param ctx the tokenization context
1031 * @param token a pointer to memory where the next token shall be stored 1102 * @param token a pointer to memory where the next token shall be stored
1032 * @return true if successful, false if the limit or the end of the string 1103 * @return true if successful, false if the limit or the end of the string
1033 * has been reached 1104 * has been reached
1034 */ 1105 */
1035 __attribute__((__warn_unused_result__, __nonnull__)) 1106 cx_attr_nonnull
1107 cx_attr_nodiscard
1108 cx_attr_access_w(2)
1109 cx_attr_export
1036 bool cx_strtok_next( 1110 bool cx_strtok_next(
1037 CxStrtokCtx *ctx, 1111 CxStrtokCtx *ctx,
1038 cxstring *token 1112 cxstring *token
1039 ); 1113 );
1040 1114
1041 /** 1115 /**
1042 * Returns the next token of a mutable string. 1116 * Returns the next token of a mutable string.
1043 * 1117 *
1044 * The token will point to the source string. 1118 * The token will point to the source string.
1119 *
1120 * @attention
1045 * If the context was not initialized over a mutable string, modifying 1121 * If the context was not initialized over a mutable string, modifying
1046 * the data of the returned token is undefined behavior. 1122 * the data of the returned token is undefined behavior.
1047 * 1123 *
1048 * @param ctx the tokenization context 1124 * @param ctx the tokenization context
1049 * @param token a pointer to memory where the next token shall be stored 1125 * @param token a pointer to memory where the next token shall be stored
1050 * @return true if successful, false if the limit or the end of the string 1126 * @return true if successful, false if the limit or the end of the string
1051 * has been reached 1127 * has been reached
1052 */ 1128 */
1053 __attribute__((__warn_unused_result__, __nonnull__)) 1129 cx_attr_nonnull
1130 cx_attr_nodiscard
1131 cx_attr_access_w(2)
1132 cx_attr_export
1054 bool cx_strtok_next_m( 1133 bool cx_strtok_next_m(
1055 CxStrtokCtx *ctx, 1134 CxStrtokCtx *ctx,
1056 cxmutstr *token 1135 cxmutstr *token
1057 ); 1136 );
1058 1137
1061 * 1140 *
1062 * @param ctx the tokenization context 1141 * @param ctx the tokenization context
1063 * @param delim array of more delimiters 1142 * @param delim array of more delimiters
1064 * @param count number of elements in the array 1143 * @param count number of elements in the array
1065 */ 1144 */
1066 __attribute__((__nonnull__)) 1145 cx_attr_nonnull
1146 cx_attr_access_r(2, 3)
1147 cx_attr_export
1067 void cx_strtok_delim( 1148 void cx_strtok_delim(
1068 CxStrtokCtx *ctx, 1149 CxStrtokCtx *ctx,
1069 cxstring const *delim, 1150 const cxstring *delim,
1070 size_t count 1151 size_t count
1071 ); 1152 );
1072 1153
1154 /* ------------------------------------------------------------------------- *
1155 * string to number conversion functions *
1156 * ------------------------------------------------------------------------- */
1157
1158 /**
1159 * Converts a string to a number.
1160 *
1161 * The function returns non-zero when conversion is not possible.
1162 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1163 * It sets errno to ERANGE when the target datatype is too small.
1164 *
1165 * @param str the string to convert
1166 * @param output a pointer to the integer variable where the result shall be stored
1167 * @param base 2, 8, 10, or 16
1168 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1169 * @retval zero success
1170 * @retval non-zero conversion was not possible
1171 */
1172 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1173 int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep);
1174
1175 /**
1176 * Converts a string to a number.
1177 *
1178 * The function returns non-zero when conversion is not possible.
1179 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1180 * It sets errno to ERANGE when the target datatype is too small.
1181 *
1182 * @param str the string to convert
1183 * @param output a pointer to the integer variable where the result shall be stored
1184 * @param base 2, 8, 10, or 16
1185 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1186 * @retval zero success
1187 * @retval non-zero conversion was not possible
1188 */
1189 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1190 int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep);
1191
1192 /**
1193 * Converts a string to a number.
1194 *
1195 * The function returns non-zero when conversion is not possible.
1196 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1197 * It sets errno to ERANGE when the target datatype is too small.
1198 *
1199 * @param str the string to convert
1200 * @param output a pointer to the integer variable where the result shall be stored
1201 * @param base 2, 8, 10, or 16
1202 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1203 * @retval zero success
1204 * @retval non-zero conversion was not possible
1205 */
1206 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1207 int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep);
1208
1209 /**
1210 * Converts a string to a number.
1211 *
1212 * The function returns non-zero when conversion is not possible.
1213 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1214 * It sets errno to ERANGE when the target datatype is too small.
1215 *
1216 * @param str the string to convert
1217 * @param output a pointer to the integer variable where the result shall be stored
1218 * @param base 2, 8, 10, or 16
1219 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1220 * @retval zero success
1221 * @retval non-zero conversion was not possible
1222 */
1223 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1224 int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep);
1225
1226 /**
1227 * Converts a string to a number.
1228 *
1229 * The function returns non-zero when conversion is not possible.
1230 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1231 * It sets errno to ERANGE when the target datatype is too small.
1232 *
1233 * @param str the string to convert
1234 * @param output a pointer to the integer variable where the result shall be stored
1235 * @param base 2, 8, 10, or 16
1236 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1237 * @retval zero success
1238 * @retval non-zero conversion was not possible
1239 */
1240 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1241 int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep);
1242
1243 /**
1244 * Converts a string to a number.
1245 *
1246 * The function returns non-zero when conversion is not possible.
1247 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1248 * It sets errno to ERANGE when the target datatype is too small.
1249 *
1250 * @param str the string to convert
1251 * @param output a pointer to the integer variable where the result shall be stored
1252 * @param base 2, 8, 10, or 16
1253 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1254 * @retval zero success
1255 * @retval non-zero conversion was not possible
1256 */
1257 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1258 int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep);
1259
1260 /**
1261 * Converts a string to a number.
1262 *
1263 * The function returns non-zero when conversion is not possible.
1264 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1265 * It sets errno to ERANGE when the target datatype is too small.
1266 *
1267 * @param str the string to convert
1268 * @param output a pointer to the integer variable where the result shall be stored
1269 * @param base 2, 8, 10, or 16
1270 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1271 * @retval zero success
1272 * @retval non-zero conversion was not possible
1273 */
1274 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1275 int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep);
1276
1277 /**
1278 * Converts a string to a number.
1279 *
1280 * The function returns non-zero when conversion is not possible.
1281 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1282 * It sets errno to ERANGE when the target datatype is too small.
1283 *
1284 * @param str the string to convert
1285 * @param output a pointer to the integer variable where the result shall be stored
1286 * @param base 2, 8, 10, or 16
1287 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1288 * @retval zero success
1289 * @retval non-zero conversion was not possible
1290 */
1291 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1292 int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep);
1293
1294 /**
1295 * Converts a string to a number.
1296 *
1297 * The function returns non-zero when conversion is not possible.
1298 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1299 * It sets errno to ERANGE when the target datatype is too small.
1300 *
1301 * @param str the string to convert
1302 * @param output a pointer to the integer variable where the result shall be stored
1303 * @param base 2, 8, 10, or 16
1304 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1305 * @retval zero success
1306 * @retval non-zero conversion was not possible
1307 */
1308 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1309 int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep);
1310
1311 /**
1312 * Converts a string to a number.
1313 *
1314 * The function returns non-zero when conversion is not possible.
1315 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1316 * It sets errno to ERANGE when the target datatype is too small.
1317 *
1318 * @param str the string to convert
1319 * @param output a pointer to the integer variable where the result shall be stored
1320 * @param base 2, 8, 10, or 16
1321 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1322 * @retval zero success
1323 * @retval non-zero conversion was not possible
1324 */
1325 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1326 int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep);
1327
1328 /**
1329 * Converts a string to a number.
1330 *
1331 * The function returns non-zero when conversion is not possible.
1332 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1333 * It sets errno to ERANGE when the target datatype is too small.
1334 *
1335 * @param str the string to convert
1336 * @param output a pointer to the integer variable where the result shall be stored
1337 * @param base 2, 8, 10, or 16
1338 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1339 * @retval zero success
1340 * @retval non-zero conversion was not possible
1341 */
1342 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1343 int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep);
1344
1345 /**
1346 * Converts a string to a number.
1347 *
1348 * The function returns non-zero when conversion is not possible.
1349 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1350 * It sets errno to ERANGE when the target datatype is too small.
1351 *
1352 * @param str the string to convert
1353 * @param output a pointer to the integer variable where the result shall be stored
1354 * @param base 2, 8, 10, or 16
1355 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1356 * @retval zero success
1357 * @retval non-zero conversion was not possible
1358 */
1359 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1360 int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep);
1361
1362 /**
1363 * Converts a string to a number.
1364 *
1365 * The function returns non-zero when conversion is not possible.
1366 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1367 * It sets errno to ERANGE when the target datatype is too small.
1368 *
1369 * @param str the string to convert
1370 * @param output a pointer to the integer variable where the result shall be stored
1371 * @param base 2, 8, 10, or 16
1372 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1373 * @retval zero success
1374 * @retval non-zero conversion was not possible
1375 */
1376 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1377 int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep);
1378
1379 /**
1380 * Converts a string to a number.
1381 *
1382 * The function returns non-zero when conversion is not possible.
1383 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1384 * It sets errno to ERANGE when the target datatype is too small.
1385 *
1386 * @param str the string to convert
1387 * @param output a pointer to the integer variable where the result shall be stored
1388 * @param base 2, 8, 10, or 16
1389 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1390 * @retval zero success
1391 * @retval non-zero conversion was not possible
1392 */
1393 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1394 int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep);
1395
1396 /**
1397 * Converts a string to a number.
1398 *
1399 * The function returns non-zero when conversion is not possible.
1400 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1401 * It sets errno to ERANGE when the target datatype is too small.
1402 *
1403 * @param str the string to convert
1404 * @param output a pointer to the integer variable where the result shall be stored
1405 * @param base 2, 8, 10, or 16
1406 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1407 * @retval zero success
1408 * @retval non-zero conversion was not possible
1409 */
1410 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1411 int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep);
1412
1413 /**
1414 * Converts a string to a number.
1415 *
1416 * The function returns non-zero when conversion is not possible.
1417 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1418 * It sets errno to ERANGE when the target datatype is too small.
1419 *
1420 * @param str the string to convert
1421 * @param output a pointer to the integer variable where the result shall be stored
1422 * @param base 2, 8, 10, or 16
1423 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1424 * @retval zero success
1425 * @retval non-zero conversion was not possible
1426 */
1427 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1428 int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep);
1429
1430 /**
1431 * Converts a string to a number.
1432 *
1433 * The function returns non-zero when conversion is not possible.
1434 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1435 * It sets errno to ERANGE when the target datatype is too small.
1436 *
1437 * @param str the string to convert
1438 * @param output a pointer to the integer variable where the result shall be stored
1439 * @param base 2, 8, 10, or 16
1440 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1441 * @retval zero success
1442 * @retval non-zero conversion was not possible
1443 */
1444 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1445 int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep);
1446
1447 /**
1448 * Converts a string to a single precision floating point number.
1449 *
1450 * The function returns non-zero when conversion is not possible.
1451 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1452 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
1453 *
1454 * @param str the string to convert
1455 * @param output a pointer to the float variable where the result shall be stored
1456 * @param decsep the decimal separator
1457 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1458 * @retval zero success
1459 * @retval non-zero conversion was not possible
1460 */
1461 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1462 int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep);
1463
1464 /**
1465 * Converts a string to a double precision floating point number.
1466 *
1467 * The function returns non-zero when conversion is not possible.
1468 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1469 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
1470 *
1471 * @param str the string to convert
1472 * @param output a pointer to the float variable where the result shall be stored
1473 * @param decsep the decimal separator
1474 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1475 * @retval zero success
1476 * @retval non-zero conversion was not possible
1477 */
1478 cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
1479 int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep);
1480
1481 /**
1482 * Converts a string to a number.
1483 *
1484 * The function returns non-zero when conversion is not possible.
1485 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1486 * It sets errno to ERANGE when the target datatype is too small.
1487 *
1488 * @param str the string to convert
1489 * @param output a pointer to the integer variable where the result shall be stored
1490 * @param base 2, 8, 10, or 16
1491 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1492 * @retval zero success
1493 * @retval non-zero conversion was not possible
1494 */
1495 #define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc_(cx_strcast(str), output, base, groupsep)
1496
1497 /**
1498 * Converts a string to a number.
1499 *
1500 * The function returns non-zero when conversion is not possible.
1501 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1502 * It sets errno to ERANGE when the target datatype is too small.
1503 *
1504 * @param str the string to convert
1505 * @param output a pointer to the integer variable where the result shall be stored
1506 * @param base 2, 8, 10, or 16
1507 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1508 * @retval zero success
1509 * @retval non-zero conversion was not possible
1510 */
1511 #define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc_(cx_strcast(str), output, base, groupsep)
1512
1513 /**
1514 * Converts a string to a number.
1515 *
1516 * The function returns non-zero when conversion is not possible.
1517 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1518 * It sets errno to ERANGE when the target datatype is too small.
1519 *
1520 * @param str the string to convert
1521 * @param output a pointer to the integer variable where the result shall be stored
1522 * @param base 2, 8, 10, or 16
1523 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1524 * @retval zero success
1525 * @retval non-zero conversion was not possible
1526 */
1527 #define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc_(cx_strcast(str), output, base, groupsep)
1528
1529 /**
1530 * Converts a string to a number.
1531 *
1532 * The function returns non-zero when conversion is not possible.
1533 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1534 * It sets errno to ERANGE when the target datatype is too small.
1535 *
1536 * @param str the string to convert
1537 * @param output a pointer to the integer variable where the result shall be stored
1538 * @param base 2, 8, 10, or 16
1539 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1540 * @retval zero success
1541 * @retval non-zero conversion was not possible
1542 */
1543 #define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc_(cx_strcast(str), output, base, groupsep)
1544
1545 /**
1546 * Converts a string to a number.
1547 *
1548 * The function returns non-zero when conversion is not possible.
1549 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1550 * It sets errno to ERANGE when the target datatype is too small.
1551 *
1552 * @param str the string to convert
1553 * @param output a pointer to the integer variable where the result shall be stored
1554 * @param base 2, 8, 10, or 16
1555 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1556 * @retval zero success
1557 * @retval non-zero conversion was not possible
1558 */
1559 #define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc_(cx_strcast(str), output, base, groupsep)
1560
1561 /**
1562 * Converts a string to a number.
1563 *
1564 * The function returns non-zero when conversion is not possible.
1565 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1566 * It sets errno to ERANGE when the target datatype is too small.
1567 *
1568 * @param str the string to convert
1569 * @param output a pointer to the integer variable where the result shall be stored
1570 * @param base 2, 8, 10, or 16
1571 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1572 * @retval zero success
1573 * @retval non-zero conversion was not possible
1574 */
1575 #define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc_(cx_strcast(str), output, base, groupsep)
1576
1577 /**
1578 * Converts a string to a number.
1579 *
1580 * The function returns non-zero when conversion is not possible.
1581 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1582 * It sets errno to ERANGE when the target datatype is too small.
1583 *
1584 * @param str the string to convert
1585 * @param output a pointer to the integer variable where the result shall be stored
1586 * @param base 2, 8, 10, or 16
1587 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1588 * @retval zero success
1589 * @retval non-zero conversion was not possible
1590 */
1591 #define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc_(cx_strcast(str), output, base, groupsep)
1592
1593 /**
1594 * Converts a string to a number.
1595 *
1596 * The function returns non-zero when conversion is not possible.
1597 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1598 * It sets errno to ERANGE when the target datatype is too small.
1599 *
1600 * @param str the string to convert
1601 * @param output a pointer to the integer variable where the result shall be stored
1602 * @param base 2, 8, 10, or 16
1603 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1604 * @retval zero success
1605 * @retval non-zero conversion was not possible
1606 */
1607 #define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc_(cx_strcast(str), output, base, groupsep)
1608
1609 /**
1610 * Converts a string to a number.
1611 *
1612 * The function returns non-zero when conversion is not possible.
1613 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1614 * It sets errno to ERANGE when the target datatype is too small.
1615 *
1616 * @param str the string to convert
1617 * @param output a pointer to the integer variable where the result shall be stored
1618 * @param base 2, 8, 10, or 16
1619 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1620 * @retval zero success
1621 * @retval non-zero conversion was not possible
1622 */
1623 #define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc_(cx_strcast(str), output, base, groupsep)
1624
1625 /**
1626 * Converts a string to a number.
1627 *
1628 * The function returns non-zero when conversion is not possible.
1629 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1630 * It sets errno to ERANGE when the target datatype is too small.
1631 *
1632 * @param str the string to convert
1633 * @param output a pointer to the integer variable where the result shall be stored
1634 * @param base 2, 8, 10, or 16
1635 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1636 * @retval zero success
1637 * @retval non-zero conversion was not possible
1638 */
1639 #define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc_(cx_strcast(str), output, base, groupsep)
1640
1641 /**
1642 * Converts a string to a number.
1643 *
1644 * The function returns non-zero when conversion is not possible.
1645 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1646 * It sets errno to ERANGE when the target datatype is too small.
1647 *
1648 * @param str the string to convert
1649 * @param output a pointer to the integer variable where the result shall be stored
1650 * @param base 2, 8, 10, or 16
1651 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1652 * @retval zero success
1653 * @retval non-zero conversion was not possible
1654 */
1655 #define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc_(cx_strcast(str), output, base, groupsep)
1656
1657 /**
1658 * Converts a string to a number.
1659 *
1660 * The function returns non-zero when conversion is not possible.
1661 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1662 * It sets errno to ERANGE when the target datatype is too small.
1663 *
1664 * @param str the string to convert
1665 * @param output a pointer to the integer variable where the result shall be stored
1666 * @param base 2, 8, 10, or 16
1667 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1668 * @retval zero success
1669 * @retval non-zero conversion was not possible
1670 */
1671 #define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc_(cx_strcast(str), output, base, groupsep)
1672
1673 /**
1674 * Converts a string to a number.
1675 *
1676 * The function returns non-zero when conversion is not possible.
1677 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1678 * It sets errno to ERANGE when the target datatype is too small.
1679 *
1680 * @param str the string to convert
1681 * @param output a pointer to the integer variable where the result shall be stored
1682 * @param base 2, 8, 10, or 16
1683 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1684 * @retval zero success
1685 * @retval non-zero conversion was not possible
1686 */
1687 #define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc_(cx_strcast(str), output, base, groupsep)
1688
1689 /**
1690 * Converts a string to a number.
1691 *
1692 * The function returns non-zero when conversion is not possible.
1693 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1694 * It sets errno to ERANGE when the target datatype is too small.
1695 *
1696 * @param str the string to convert
1697 * @param output a pointer to the integer variable where the result shall be stored
1698 * @param base 2, 8, 10, or 16
1699 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1700 * @retval zero success
1701 * @retval non-zero conversion was not possible
1702 */
1703 #define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc_(cx_strcast(str), output, base, groupsep)
1704
1705 /**
1706 * Converts a string to a number.
1707 *
1708 * The function returns non-zero when conversion is not possible.
1709 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1710 * It sets errno to ERANGE when the target datatype is too small.
1711 *
1712 * @param str the string to convert
1713 * @param output a pointer to the integer variable where the result shall be stored
1714 * @param base 2, 8, 10, or 16
1715 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1716 * @retval zero success
1717 * @retval non-zero conversion was not possible
1718 */
1719 #define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc_(cx_strcast(str), output, base, groupsep)
1720
1721 /**
1722 * Converts a string to a number.
1723 *
1724 * The function returns non-zero when conversion is not possible.
1725 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1726 * It sets errno to ERANGE when the target datatype is too small.
1727 *
1728 * @param str the string to convert
1729 * @param output a pointer to the integer variable where the result shall be stored
1730 * @param base 2, 8, 10, or 16
1731 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1732 * @retval zero success
1733 * @retval non-zero conversion was not possible
1734 */
1735 #define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc_(cx_strcast(str), output, base, groupsep)
1736
1737 /**
1738 * Converts a string to a number.
1739 *
1740 * The function returns non-zero when conversion is not possible.
1741 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1742 * It sets errno to ERANGE when the target datatype is too small.
1743 *
1744 * @param str the string to convert
1745 * @param output a pointer to the integer variable where the result shall be stored
1746 * @param base 2, 8, 10, or 16
1747 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1748 * @retval zero success
1749 * @retval non-zero conversion was not possible
1750 */
1751 #define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc_(cx_strcast(str), output, base, groupsep)
1752
1753 /**
1754 * Converts a string to a number.
1755 *
1756 * The function returns non-zero when conversion is not possible.
1757 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1758 * It sets errno to ERANGE when the target datatype is too small.
1759 *
1760 * The comma character is treated as group separator and ignored during parsing.
1761 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1762 *
1763 * @param str the string to convert
1764 * @param output a pointer to the integer variable where the result shall be stored
1765 * @param base 2, 8, 10, or 16
1766 * @retval zero success
1767 * @retval non-zero conversion was not possible
1768 */
1769 #define cx_strtos(str, output, base) cx_strtos_lc_(cx_strcast(str), output, base, ",")
1770
1771 /**
1772 * Converts a string to a number.
1773 *
1774 * The function returns non-zero when conversion is not possible.
1775 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1776 * It sets errno to ERANGE when the target datatype is too small.
1777 *
1778 * The comma character is treated as group separator and ignored during parsing.
1779 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1780 *
1781 * @param str the string to convert
1782 * @param output a pointer to the integer variable where the result shall be stored
1783 * @param base 2, 8, 10, or 16
1784 * @retval zero success
1785 * @retval non-zero conversion was not possible
1786 */
1787 #define cx_strtoi(str, output, base) cx_strtoi_lc_(cx_strcast(str), output, base, ",")
1788
1789 /**
1790 * Converts a string to a number.
1791 *
1792 * The function returns non-zero when conversion is not possible.
1793 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1794 * It sets errno to ERANGE when the target datatype is too small.
1795 *
1796 * The comma character is treated as group separator and ignored during parsing.
1797 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1798 *
1799 * @param str the string to convert
1800 * @param output a pointer to the integer variable where the result shall be stored
1801 * @param base 2, 8, 10, or 16
1802 * @retval zero success
1803 * @retval non-zero conversion was not possible
1804 */
1805 #define cx_strtol(str, output, base) cx_strtol_lc_(cx_strcast(str), output, base, ",")
1806
1807 /**
1808 * Converts a string to a number.
1809 *
1810 * The function returns non-zero when conversion is not possible.
1811 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1812 * It sets errno to ERANGE when the target datatype is too small.
1813 *
1814 * The comma character is treated as group separator and ignored during parsing.
1815 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1816 *
1817 * @param str the string to convert
1818 * @param output a pointer to the integer variable where the result shall be stored
1819 * @param base 2, 8, 10, or 16
1820 * @retval zero success
1821 * @retval non-zero conversion was not possible
1822 */
1823 #define cx_strtoll(str, output, base) cx_strtoll_lc_(cx_strcast(str), output, base, ",")
1824
1825 /**
1826 * Converts a string to a number.
1827 *
1828 * The function returns non-zero when conversion is not possible.
1829 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1830 * It sets errno to ERANGE when the target datatype is too small.
1831 *
1832 * The comma character is treated as group separator and ignored during parsing.
1833 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1834 *
1835 * @param str the string to convert
1836 * @param output a pointer to the integer variable where the result shall be stored
1837 * @param base 2, 8, 10, or 16
1838 * @retval zero success
1839 * @retval non-zero conversion was not possible
1840 */
1841 #define cx_strtoi8(str, output, base) cx_strtoi8_lc_(cx_strcast(str), output, base, ",")
1842
1843 /**
1844 * Converts a string to a number.
1845 *
1846 * The function returns non-zero when conversion is not possible.
1847 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1848 * It sets errno to ERANGE when the target datatype is too small.
1849 *
1850 * The comma character is treated as group separator and ignored during parsing.
1851 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1852 *
1853 * @param str the string to convert
1854 * @param output a pointer to the integer variable where the result shall be stored
1855 * @param base 2, 8, 10, or 16
1856 * @retval zero success
1857 * @retval non-zero conversion was not possible
1858 */
1859 #define cx_strtoi16(str, output, base) cx_strtoi16_lc_(cx_strcast(str), output, base, ",")
1860
1861 /**
1862 * Converts a string to a number.
1863 *
1864 * The function returns non-zero when conversion is not possible.
1865 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1866 * It sets errno to ERANGE when the target datatype is too small.
1867 *
1868 * The comma character is treated as group separator and ignored during parsing.
1869 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1870 *
1871 * @param str the string to convert
1872 * @param output a pointer to the integer variable where the result shall be stored
1873 * @param base 2, 8, 10, or 16
1874 * @retval zero success
1875 * @retval non-zero conversion was not possible
1876 */
1877 #define cx_strtoi32(str, output, base) cx_strtoi32_lc_(cx_strcast(str), output, base, ",")
1878
1879 /**
1880 * Converts a string to a number.
1881 *
1882 * The function returns non-zero when conversion is not possible.
1883 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1884 * It sets errno to ERANGE when the target datatype is too small.
1885 *
1886 * The comma character is treated as group separator and ignored during parsing.
1887 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1888 *
1889 * @param str the string to convert
1890 * @param output a pointer to the integer variable where the result shall be stored
1891 * @param base 2, 8, 10, or 16
1892 * @retval zero success
1893 * @retval non-zero conversion was not possible
1894 */
1895 #define cx_strtoi64(str, output, base) cx_strtoi64_lc_(cx_strcast(str), output, base, ",")
1896
1897 /**
1898 * Converts a string to a number.
1899 *
1900 * The function returns non-zero when conversion is not possible.
1901 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1902 * It sets errno to ERANGE when the target datatype is too small.
1903 *
1904 * The comma character is treated as group separator and ignored during parsing.
1905 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1906 *
1907 * @param str the string to convert
1908 * @param output a pointer to the integer variable where the result shall be stored
1909 * @param base 2, 8, 10, or 16
1910 * @retval zero success
1911 * @retval non-zero conversion was not possible
1912 */
1913 #define cx_strtoz(str, output, base) cx_strtoz_lc_(cx_strcast(str), output, base, ",")
1914
1915 /**
1916 * Converts a string to a number.
1917 *
1918 * The function returns non-zero when conversion is not possible.
1919 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1920 * It sets errno to ERANGE when the target datatype is too small.
1921 *
1922 * The comma character is treated as group separator and ignored during parsing.
1923 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1924 *
1925 * @param str the string to convert
1926 * @param output a pointer to the integer variable where the result shall be stored
1927 * @param base 2, 8, 10, or 16
1928 * @retval zero success
1929 * @retval non-zero conversion was not possible
1930 */
1931 #define cx_strtous(str, output, base) cx_strtous_lc_(cx_strcast(str), output, base, ",")
1932
1933 /**
1934 * Converts a string to a number.
1935 *
1936 * The function returns non-zero when conversion is not possible.
1937 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1938 * It sets errno to ERANGE when the target datatype is too small.
1939 *
1940 * The comma character is treated as group separator and ignored during parsing.
1941 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1942 *
1943 * @param str the string to convert
1944 * @param output a pointer to the integer variable where the result shall be stored
1945 * @param base 2, 8, 10, or 16
1946 * @retval zero success
1947 * @retval non-zero conversion was not possible
1948 */
1949 #define cx_strtou(str, output, base) cx_strtou_lc_(cx_strcast(str), output, base, ",")
1950
1951 /**
1952 * Converts a string to a number.
1953 *
1954 * The function returns non-zero when conversion is not possible.
1955 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1956 * It sets errno to ERANGE when the target datatype is too small.
1957 *
1958 * The comma character is treated as group separator and ignored during parsing.
1959 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1960 *
1961 * @param str the string to convert
1962 * @param output a pointer to the integer variable where the result shall be stored
1963 * @param base 2, 8, 10, or 16
1964 * @retval zero success
1965 * @retval non-zero conversion was not possible
1966 */
1967 #define cx_strtoul(str, output, base) cx_strtoul_lc_(cx_strcast(str), output, base, ",")
1968
1969 /**
1970 * Converts a string to a number.
1971 *
1972 * The function returns non-zero when conversion is not possible.
1973 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1974 * It sets errno to ERANGE when the target datatype is too small.
1975 *
1976 * The comma character is treated as group separator and ignored during parsing.
1977 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1978 *
1979 * @param str the string to convert
1980 * @param output a pointer to the integer variable where the result shall be stored
1981 * @param base 2, 8, 10, or 16
1982 * @retval zero success
1983 * @retval non-zero conversion was not possible
1984 */
1985 #define cx_strtoull(str, output, base) cx_strtoull_lc_(cx_strcast(str), output, base, ",")
1986
1987 /**
1988 * Converts a string to a number.
1989 *
1990 * The function returns non-zero when conversion is not possible.
1991 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1992 * It sets errno to ERANGE when the target datatype is too small.
1993 *
1994 * The comma character is treated as group separator and ignored during parsing.
1995 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
1996 *
1997 * @param str the string to convert
1998 * @param output a pointer to the integer variable where the result shall be stored
1999 * @param base 2, 8, 10, or 16
2000 * @retval zero success
2001 * @retval non-zero conversion was not possible
2002 */
2003 #define cx_strtou8(str, output, base) cx_strtou8_lc_(cx_strcast(str), output, base, ",")
2004
2005 /**
2006 * Converts a string to a number.
2007 *
2008 * The function returns non-zero when conversion is not possible.
2009 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
2010 * It sets errno to ERANGE when the target datatype is too small.
2011 *
2012 * The comma character is treated as group separator and ignored during parsing.
2013 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
2014 *
2015 * @param str the string to convert
2016 * @param output a pointer to the integer variable where the result shall be stored
2017 * @param base 2, 8, 10, or 16
2018 * @retval zero success
2019 * @retval non-zero conversion was not possible
2020 */
2021 #define cx_strtou16(str, output, base) cx_strtou16_lc_(cx_strcast(str), output, base, ",")
2022
2023 /**
2024 * Converts a string to a number.
2025 *
2026 * The function returns non-zero when conversion is not possible.
2027 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
2028 * It sets errno to ERANGE when the target datatype is too small.
2029 *
2030 * The comma character is treated as group separator and ignored during parsing.
2031 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
2032 *
2033 * @param str the string to convert
2034 * @param output a pointer to the integer variable where the result shall be stored
2035 * @param base 2, 8, 10, or 16
2036 * @retval zero success
2037 * @retval non-zero conversion was not possible
2038 */
2039 #define cx_strtou32(str, output, base) cx_strtou32_lc_(cx_strcast(str), output, base, ",")
2040
2041 /**
2042 * Converts a string to a number.
2043 *
2044 * The function returns non-zero when conversion is not possible.
2045 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
2046 * It sets errno to ERANGE when the target datatype is too small.
2047 *
2048 * The comma character is treated as group separator and ignored during parsing.
2049 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
2050 *
2051 * @param str the string to convert
2052 * @param output a pointer to the integer variable where the result shall be stored
2053 * @param base 2, 8, 10, or 16
2054 * @retval zero success
2055 * @retval non-zero conversion was not possible
2056 */
2057 #define cx_strtou64(str, output, base) cx_strtou64_lc_(cx_strcast(str), output, base, ",")
2058
2059 /**
2060 * Converts a string to a single precision floating point number.
2061 *
2062 * The function returns non-zero when conversion is not possible.
2063 * In that case the function sets errno to EINVAL when the reason is an invalid character.
2064 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
2065 *
2066 * @param str the string to convert
2067 * @param output a pointer to the float variable where the result shall be stored
2068 * @param decsep the decimal separator
2069 * @param groupsep each character in this string is treated as group separator and ignored during conversion
2070 * @retval zero success
2071 * @retval non-zero conversion was not possible
2072 */
2073 #define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc_(cx_strcast(str), output, decsep, groupsep)
2074
2075 /**
2076 * Converts a string to a double precision floating point number.
2077 *
2078 * The function returns non-zero when conversion is not possible.
2079 * In that case the function sets errno to EINVAL when the reason is an invalid character.
2080 *
2081 * @param str the string to convert
2082 * @param output a pointer to the double variable where the result shall be stored
2083 * @param decsep the decimal separator
2084 * @param groupsep each character in this string is treated as group separator and ignored during conversion
2085 * @retval zero success
2086 * @retval non-zero conversion was not possible
2087 */
2088 #define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc_(cx_strcast(str), output, decsep, groupsep)
2089
2090 /**
2091 * Converts a string to a single precision floating point number.
2092 *
2093 * The function returns non-zero when conversion is not possible.
2094 * In that case the function sets errno to EINVAL when the reason is an invalid character.
2095 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
2096 *
2097 * The decimal separator is assumed to be a dot character.
2098 * The comma character is treated as group separator and ignored during parsing.
2099 * If you want to choose a different format, use cx_strtof_lc().
2100 *
2101 * @param str the string to convert
2102 * @param output a pointer to the float variable where the result shall be stored
2103 * @retval zero success
2104 * @retval non-zero conversion was not possible
2105 */
2106 #define cx_strtof(str, output) cx_strtof_lc_(cx_strcast(str), output, '.', ",")
2107
2108 /**
2109 * Converts a string to a double precision floating point number.
2110 *
2111 * The function returns non-zero when conversion is not possible.
2112 * In that case the function sets errno to EINVAL when the reason is an invalid character.
2113 *
2114 * The decimal separator is assumed to be a dot character.
2115 * The comma character is treated as group separator and ignored during parsing.
2116 * If you want to choose a different format, use cx_strtof_lc().
2117 *
2118 * @param str the string to convert
2119 * @param output a pointer to the double variable where the result shall be stored
2120 * @retval zero success
2121 * @retval non-zero conversion was not possible
2122 */
2123 #define cx_strtod(str, output) cx_strtod_lc_(cx_strcast(str), output, '.', ",")
1073 2124
1074 #ifdef __cplusplus 2125 #ifdef __cplusplus
1075 } // extern "C" 2126 } // extern "C"
1076 #endif 2127 #endif
1077 2128

mercurial