src/cx/string.h

changeset 1107
9d77c7a99441
parent 1050
3df63e95921a
equal deleted inserted replaced
1106:0480f8600fb7 1107:9d77c7a99441
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 * \copyright 2-Clause BSD License 33 * @copyright 2-Clause BSD License
34 */ 34 */
35 35
36 #ifndef UCX_STRING_H 36 #ifndef UCX_STRING_H
37 #define UCX_STRING_H 37 #define UCX_STRING_H
38 38
48 * The UCX string structure. 48 * The UCX string structure.
49 */ 49 */
50 struct cx_mutstr_s { 50 struct cx_mutstr_s {
51 /** 51 /**
52 * A pointer to the string. 52 * A pointer to the string.
53 * \note The string is not necessarily \c NULL terminated. 53 * @note The string is not necessarily @c NULL terminated.
54 * Always use the length. 54 * Always use the length.
55 */ 55 */
56 char *ptr; 56 char *ptr;
57 /** The length of the string */ 57 /** The length of the string */
58 size_t length; 58 size_t length;
67 * The UCX string structure for immutable (constant) strings. 67 * The UCX string structure for immutable (constant) strings.
68 */ 68 */
69 struct cx_string_s { 69 struct cx_string_s {
70 /** 70 /**
71 * A pointer to the immutable string. 71 * A pointer to the immutable string.
72 * \note The string is not necessarily \c NULL terminated. 72 * @note The string is not necessarily @c NULL terminated.
73 * Always use the length. 73 * Always use the length.
74 */ 74 */
75 const char *ptr; 75 const char *ptr;
76 /** The length of the string */ 76 /** The length of the string */
77 size_t length; 77 size_t length;
146 #else // __cplusplus 146 #else // __cplusplus
147 147
148 /** 148 /**
149 * A literal initializer for an UCX string structure. 149 * A literal initializer for an UCX string structure.
150 * 150 *
151 * The argument MUST be a string (const char*) \em literal. 151 * The argument MUST be a string (const char*) @em literal.
152 * 152 *
153 * @param literal the string literal 153 * @param literal the string literal
154 */ 154 */
155 #define CX_STR(literal) (cxstring){literal, sizeof(literal) - 1} 155 #define CX_STR(literal) (cxstring){literal, sizeof(literal) - 1}
156 156
158 158
159 159
160 /** 160 /**
161 * Wraps a mutable string that must be zero-terminated. 161 * Wraps a mutable string that must be zero-terminated.
162 * 162 *
163 * The length is implicitly inferred by using a call to \c strlen(). 163 * The length is implicitly inferred by using a call to @c strlen().
164 * 164 *
165 * \note the wrapped string will share the specified pointer to the string. 165 * @note the wrapped string will share the specified pointer to the string.
166 * If you do want a copy, use cx_strdup() on the return value of this function. 166 * If you do want a copy, use cx_strdup() on the return value of this function.
167 * 167 *
168 * If you need to wrap a constant string, use cx_str(). 168 * If you need to wrap a constant string, use cx_str().
169 * 169 *
170 * @param cstring the string to wrap, must be zero-terminated 170 * @param cstring the string to wrap, must be zero-terminated
178 cxmutstr cx_mutstr(char *cstring); 178 cxmutstr cx_mutstr(char *cstring);
179 179
180 /** 180 /**
181 * Wraps a string that does not need to be zero-terminated. 181 * Wraps a string that does not need to be zero-terminated.
182 * 182 *
183 * The argument may be \c NULL if the length is zero. 183 * The argument may be @c NULL if the length is zero.
184 * 184 *
185 * \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.
186 * 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.
187 * 187 *
188 * If you need to wrap a constant string, use cx_strn(). 188 * If you need to wrap a constant string, use cx_strn().
189 * 189 *
190 * @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)
191 * @param length the length of the string 191 * @param length the length of the string
192 * @return the wrapped string 192 * @return the wrapped string
193 * 193 *
194 * @see cx_mutstr() 194 * @see cx_mutstr()
195 */ 195 */
201 ); 201 );
202 202
203 /** 203 /**
204 * Wraps a string that must be zero-terminated. 204 * Wraps a string that must be zero-terminated.
205 * 205 *
206 * The length is implicitly inferred by using a call to \c strlen(). 206 * The length is implicitly inferred by using a call to @c strlen().
207 * 207 *
208 * \note the wrapped string will share the specified pointer to the string. 208 * @note the wrapped string will share the specified pointer to the string.
209 * If you do want a copy, use cx_strdup() on the return value of this function. 209 * If you do want a copy, use cx_strdup() on the return value of this function.
210 * 210 *
211 * If you need to wrap a non-constant string, use cx_mutstr(). 211 * If you need to wrap a non-constant string, use cx_mutstr().
212 * 212 *
213 * @param cstring the string to wrap, must be zero-terminated 213 * @param cstring the string to wrap, must be zero-terminated
222 222
223 223
224 /** 224 /**
225 * Wraps a string that does not need to be zero-terminated. 225 * Wraps a string that does not need to be zero-terminated.
226 * 226 *
227 * The argument may be \c NULL if the length is zero. 227 * The argument may be @c NULL if the length is zero.
228 * 228 *
229 * \note the wrapped string will share the specified pointer to the string. 229 * @note the wrapped string will share the specified pointer to the string.
230 * If you do want a copy, use cx_strdup() on the return value of this function. 230 * If you do want a copy, use cx_strdup() on the return value of this function.
231 * 231 *
232 * If you need to wrap a non-constant string, use cx_mutstrn(). 232 * If you need to wrap a non-constant string, use cx_mutstrn().
233 * 233 *
234 * @param cstring the string to wrap (or \c NULL, only if the length is zero) 234 * @param cstring the string to wrap (or @c NULL, only if the length is zero)
235 * @param length the length of the string 235 * @param length the length of the string
236 * @return the wrapped string 236 * @return the wrapped string
237 * 237 *
238 * @see cx_str() 238 * @see cx_str()
239 */ 239 */
280 /** 280 /**
281 * Casts a mutable string to an immutable string. 281 * Casts a mutable string to an immutable string.
282 * 282 *
283 * Does nothing for already immutable strings. 283 * Does nothing for already immutable strings.
284 * 284 *
285 * \note This is not seriously a cast. Instead, you get a copy 285 * @note This is not seriously a cast. Instead, you get a copy
286 * of the struct with the desired pointer type. Both structs still 286 * of the struct with the desired pointer type. Both structs still
287 * point to the same location, though! 287 * point to the same location, though!
288 * 288 *
289 * @param str the mutable string to cast 289 * @param str (@c cxstring or @c cxmutstr) the string to cast
290 * @return an immutable copy of the string pointer 290 * @return (@c cxstring) an immutable copy of the string pointer
291 */ 291 */
292 #define cx_strcast(str) _Generic((str), \ 292 #define cx_strcast(str) _Generic((str), \
293 cxmutstr: cx_strcast_m, \ 293 cxmutstr: cx_strcast_m, \
294 cxstring: cx_strcast_c) \ 294 cxstring: cx_strcast_c) \
295 (str) 295 (str)
296 #endif 296 #endif
297 297
298 /** 298 /**
299 * Passes the pointer in this string to \c free(). 299 * Passes the pointer in this string to @c free().
300 * 300 *
301 * The pointer in the struct is set to \c NULL and the length is set to zero. 301 * The pointer in the struct is set to @c NULL and the length is set to zero.
302 * 302 *
303 * \note There is no implementation for cxstring, because it is unlikely that 303 * @note There is no implementation for cxstring, because it is unlikely that
304 * you ever have a <code>const char*</code> you are really supposed to free. 304 * you ever have a <code>const char*</code> you are really supposed to free.
305 * If you encounter such situation, you should double-check your code. 305 * If you encounter such situation, you should double-check your code.
306 * 306 *
307 * @param str the string to free 307 * @param str the string to free
308 */ 308 */
309 void cx_strfree(cxmutstr *str); 309 void cx_strfree(cxmutstr *str);
310 310
311 /** 311 /**
312 * Passes the pointer in this string to the allocators free function. 312 * Passes the pointer in this string to the allocators free function.
313 * 313 *
314 * The pointer in the struct is set to \c NULL and the length is set to zero. 314 * The pointer in the struct is set to @c NULL and the length is set to zero.
315 * 315 *
316 * \note There is no implementation for cxstring, because it is unlikely that 316 * @note There is no implementation for cxstring, because it is unlikely that
317 * you ever have a <code>const char*</code> you are really supposed to free. 317 * you ever have a <code>const char*</code> you are really supposed to free.
318 * If you encounter such situation, you should double-check your code. 318 * If you encounter such situation, you should double-check your code.
319 * 319 *
320 * @param alloc the allocator 320 * @param alloc the allocator
321 * @param str the string to free 321 * @param str the string to free
329 /** 329 /**
330 * Returns the accumulated length of all specified strings. 330 * Returns the accumulated length of all specified strings.
331 * 331 *
332 * If this sum overflows, errno is set to EOVERFLOW. 332 * If this sum overflows, errno is set to EOVERFLOW.
333 * 333 *
334 * \attention if the count argument is larger than the number of the 334 * @attention if the count argument is larger than the number of the
335 * specified strings, the behavior is undefined. 335 * specified strings, the behavior is undefined.
336 * 336 *
337 * @param count the total number of specified strings 337 * @param count the total number of specified strings
338 * @param ... all strings 338 * @param ... all strings
339 * @return the accumulated length of all strings 339 * @return the accumulated length of all strings
346 346
347 /** 347 /**
348 * Concatenates strings. 348 * Concatenates strings.
349 * 349 *
350 * The resulting string will be allocated by the specified allocator. 350 * The resulting string will be allocated by the specified allocator.
351 * So developers \em must pass the return value to cx_strfree_a() eventually. 351 * So developers @em must pass the return value to cx_strfree_a() eventually.
352 * 352 *
353 * If \p str already contains a string, the memory will be reallocated and 353 * If @p str already contains a string, the memory will be reallocated and
354 * the other strings are appended. Otherwise, new memory is allocated. 354 * the other strings are appended. Otherwise, new memory is allocated.
355 * 355 *
356 * If memory allocation fails, the pointer in the returned string will 356 * If memory allocation fails, the pointer in the returned string will
357 * be \c NULL. Depending on the allocator, \c errno might be set. 357 * be @c NULL. Depending on the allocator, @c errno might be set.
358 * 358 *
359 * \note It is guaranteed that there is only one allocation for the 359 * @note It is guaranteed that there is only one allocation for the
360 * resulting string. 360 * resulting string.
361 * It is also guaranteed that the returned string is zero-terminated. 361 * It is also guaranteed that the returned string is zero-terminated.
362 * 362 *
363 * @param alloc the allocator to use 363 * @param alloc the allocator to use
364 * @param str the string the other strings shall be concatenated to 364 * @param str the string the other strings shall be concatenated to
365 * @param count the number of the other following strings to concatenate 365 * @param count the number of the other following strings to concatenate
366 * @param ... all other strings 366 * @param ... all other UCX strings
367 * @return the concatenated string 367 * @return the concatenated string
368 */ 368 */
369 cx_attr_nodiscard 369 cx_attr_nodiscard
370 cx_attr_nonnull 370 cx_attr_nonnull
371 cxmutstr cx_strcat_ma( 371 cxmutstr cx_strcat_ma(
377 377
378 /** 378 /**
379 * Concatenates strings and returns a new string. 379 * Concatenates strings and returns a new string.
380 * 380 *
381 * The resulting string will be allocated by the specified allocator. 381 * The resulting string will be allocated by the specified allocator.
382 * So developers \em must pass the return value to cx_strfree_a() eventually. 382 * So developers @em must pass the return value to cx_strfree_a() eventually.
383 * 383 *
384 * If memory allocation fails, the pointer in the returned string will 384 * If memory allocation fails, the pointer in the returned string will
385 * be \c NULL. Depending on the allocator, \c errno might be set. 385 * be @c NULL. Depending on the allocator, @c errno might be set.
386 * 386 *
387 * \note It is guaranteed that there is only one allocation for the 387 * @note It is guaranteed that there is only one allocation for the
388 * resulting string. 388 * resulting string.
389 * It is also guaranteed that the returned string is zero-terminated. 389 * It is also guaranteed that the returned string is zero-terminated.
390 * 390 *
391 * @param alloc the allocator to use 391 * @param alloc (@c CxAllocator*) the allocator to use
392 * @param count the number of the other following strings to concatenate 392 * @param count (@c size_t) the number of the other following strings to concatenate
393 * @param ... all other strings 393 * @param ... all other UCX strings
394 * @return the concatenated string 394 * @return (@c cxmutstr) the concatenated string
395 */ 395 */
396 #define cx_strcat_a(alloc, count, ...) \ 396 #define cx_strcat_a(alloc, count, ...) \
397 cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__) 397 cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__)
398 398
399 /** 399 /**
400 * Concatenates strings and returns a new string. 400 * Concatenates strings and returns a new string.
401 * 401 *
402 * The resulting string will be allocated by standard \c malloc(). 402 * The resulting string will be allocated by standard @c malloc().
403 * So developers \em must pass the return value to cx_strfree() eventually. 403 * So developers @em must pass the return value to cx_strfree() eventually.
404 * 404 *
405 * If memory allocation fails, the pointer in the returned string will 405 * If memory allocation fails, the pointer in the returned string will
406 * be \c NULL and \c errno might be set. 406 * be @c NULL and @c errno might be set.
407 * 407 *
408 * \note It is guaranteed that there is only one allocation for the 408 * @note It is guaranteed that there is only one allocation for the
409 * resulting string. 409 * resulting string.
410 * It is also guaranteed that the returned string is zero-terminated. 410 * It is also guaranteed that the returned string is zero-terminated.
411 * 411 *
412 * @param count the number of the other following strings to concatenate 412 * @param count (@c size_t) the number of the other following strings to concatenate
413 * @param ... all other strings 413 * @param ... all other UCX strings
414 * @return the concatenated string 414 * @return (@c cxmutstr) the concatenated string
415 */ 415 */
416 #define cx_strcat(count, ...) \ 416 #define cx_strcat(count, ...) \
417 cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__) 417 cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__)
418 418
419 /** 419 /**
420 * Concatenates strings. 420 * Concatenates strings.
421 * 421 *
422 * The resulting string will be allocated by standard \c malloc(). 422 * The resulting string will be allocated by standard @c malloc().
423 * So developers \em must pass the return value to cx_strfree() eventually. 423 * So developers @em must pass the return value to cx_strfree() eventually.
424 * 424 *
425 * If \p str already contains a string, the memory will be reallocated and 425 * If @p str already contains a string, the memory will be reallocated and
426 * the other strings are appended. Otherwise, new memory is allocated. 426 * the other strings are appended. Otherwise, new memory is allocated.
427 * 427 *
428 * If memory allocation fails, the pointer in the returned string will 428 * If memory allocation fails, the pointer in the returned string will
429 * be \c NULL and \c errno might be set. 429 * be @c NULL and @c errno might be set.
430 * 430 *
431 * \note It is guaranteed that there is only one allocation for the 431 * @note It is guaranteed that there is only one allocation for the
432 * resulting string. 432 * resulting string.
433 * It is also guaranteed that the returned string is zero-terminated. 433 * It is also guaranteed that the returned string is zero-terminated.
434 * 434 *
435 * @param str the string the other strings shall be concatenated to 435 * @param str (@c cxmutstr) the string the other strings shall be concatenated to
436 * @param count the number of the other following strings to concatenate 436 * @param count (@c size_t) the number of the other following strings to concatenate
437 * @param ... all other strings 437 * @param ... all other strings
438 * @return the concatenated string 438 * @return (@c cxmutstr) the concatenated string
439 */ 439 */
440 #define cx_strcat_m(str, count, ...) \ 440 #define cx_strcat_m(str, count, ...) \
441 cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__) 441 cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__)
442 442
443 /** 443 /**
444 * Returns a substring starting at the specified location. 444 * Returns a substring starting at the specified location.
445 * 445 *
446 * \attention the new string references the same memory area as the 446 * @attention the new string references the same memory area as the
447 * input string and is usually \em not zero-terminated. 447 * input string and is usually @em not zero-terminated.
448 * Use cx_strdup() to get a copy. 448 * Use cx_strdup() to get a copy.
449 * 449 *
450 * @param string input string 450 * @param string input string
451 * @param start start location of the substring 451 * @param start start location of the substring
452 * @return a substring of \p string starting at \p start 452 * @return a substring of @p string starting at @p start
453 * 453 *
454 * @see cx_strsubsl() 454 * @see cx_strsubsl()
455 * @see cx_strsubs_m() 455 * @see cx_strsubs_m()
456 * @see cx_strsubsl_m() 456 * @see cx_strsubsl_m()
457 */ 457 */
462 ); 462 );
463 463
464 /** 464 /**
465 * Returns a substring starting at the specified location. 465 * Returns a substring starting at the specified location.
466 * 466 *
467 * The returned string will be limited to \p length bytes or the number 467 * The returned string will be limited to @p length bytes or the number
468 * of bytes available in \p string, whichever is smaller. 468 * of bytes available in @p string, whichever is smaller.
469 * 469 *
470 * \attention the new string references the same memory area as the 470 * @attention the new string references the same memory area as the
471 * input string and is usually \em not zero-terminated. 471 * input string and is usually @em not zero-terminated.
472 * Use cx_strdup() to get a copy. 472 * Use cx_strdup() to get a copy.
473 * 473 *
474 * @param string input string 474 * @param string input string
475 * @param start start location of the substring 475 * @param start start location of the substring
476 * @param length the maximum length of the returned string 476 * @param length the maximum length of the returned string
477 * @return a substring of \p string starting at \p start 477 * @return a substring of @p string starting at @p start
478 * 478 *
479 * @see cx_strsubs() 479 * @see cx_strsubs()
480 * @see cx_strsubs_m() 480 * @see cx_strsubs_m()
481 * @see cx_strsubsl_m() 481 * @see cx_strsubsl_m()
482 */ 482 */
488 ); 488 );
489 489
490 /** 490 /**
491 * Returns a substring starting at the specified location. 491 * Returns a substring starting at the specified location.
492 * 492 *
493 * \attention the new string references the same memory area as the 493 * @attention the new string references the same memory area as the
494 * input string and is usually \em not zero-terminated. 494 * input string and is usually @em not zero-terminated.
495 * Use cx_strdup() to get a copy. 495 * Use cx_strdup() to get a copy.
496 * 496 *
497 * @param string input string 497 * @param string input string
498 * @param start start location of the substring 498 * @param start start location of the substring
499 * @return a substring of \p string starting at \p start 499 * @return a substring of @p string starting at @p start
500 * 500 *
501 * @see cx_strsubsl_m() 501 * @see cx_strsubsl_m()
502 * @see cx_strsubs() 502 * @see cx_strsubs()
503 * @see cx_strsubsl() 503 * @see cx_strsubsl()
504 */ 504 */
509 ); 509 );
510 510
511 /** 511 /**
512 * Returns a substring starting at the specified location. 512 * Returns a substring starting at the specified location.
513 * 513 *
514 * The returned string will be limited to \p length bytes or the number 514 * The returned string will be limited to @p length bytes or the number
515 * of bytes available in \p string, whichever is smaller. 515 * of bytes available in @p string, whichever is smaller.
516 * 516 *
517 * \attention the new string references the same memory area as the 517 * @attention the new string references the same memory area as the
518 * input string and is usually \em not zero-terminated. 518 * input string and is usually @em not zero-terminated.
519 * Use cx_strdup() to get a copy. 519 * Use cx_strdup() to get a copy.
520 * 520 *
521 * @param string input string 521 * @param string input string
522 * @param start start location of the substring 522 * @param start start location of the substring
523 * @param length the maximum length of the returned string 523 * @param length the maximum length of the returned string
524 * @return a substring of \p string starting at \p start 524 * @return a substring of @p string starting at @p start
525 * 525 *
526 * @see cx_strsubs_m() 526 * @see cx_strsubs_m()
527 * @see cx_strsubs() 527 * @see cx_strsubs()
528 * @see cx_strsubsl() 528 * @see cx_strsubsl()
529 */ 529 */
540 * 540 *
541 * If the string does not contain the character, an empty string is returned. 541 * If the string does not contain the character, an empty string is returned.
542 * 542 *
543 * @param string the string where to locate the character 543 * @param string the string where to locate the character
544 * @param chr the character to locate 544 * @param chr the character to locate
545 * @return a substring starting at the first location of \p chr 545 * @return a substring starting at the first location of @p chr
546 * 546 *
547 * @see cx_strchr_m() 547 * @see cx_strchr_m()
548 */ 548 */
549 cx_attr_nodiscard 549 cx_attr_nodiscard
550 cxstring cx_strchr( 550 cxstring cx_strchr(
558 * 558 *
559 * If the string does not contain the character, an empty string is returned. 559 * If the string does not contain the character, an empty string is returned.
560 * 560 *
561 * @param string the string where to locate the character 561 * @param string the string where to locate the character
562 * @param chr the character to locate 562 * @param chr the character to locate
563 * @return a substring starting at the first location of \p chr 563 * @return a substring starting at the first location of @p chr
564 * 564 *
565 * @see cx_strchr() 565 * @see cx_strchr()
566 */ 566 */
567 cx_attr_nodiscard 567 cx_attr_nodiscard
568 cxmutstr cx_strchr_m( 568 cxmutstr cx_strchr_m(
576 * 576 *
577 * If the string does not contain the character, an empty string is returned. 577 * If the string does not contain the character, an empty string is returned.
578 * 578 *
579 * @param string the string where to locate the character 579 * @param string the string where to locate the character
580 * @param chr the character to locate 580 * @param chr the character to locate
581 * @return a substring starting at the last location of \p chr 581 * @return a substring starting at the last location of @p chr
582 * 582 *
583 * @see cx_strrchr_m() 583 * @see cx_strrchr_m()
584 */ 584 */
585 cx_attr_nodiscard 585 cx_attr_nodiscard
586 cxstring cx_strrchr( 586 cxstring cx_strrchr(
594 * 594 *
595 * If the string does not contain the character, an empty string is returned. 595 * If the string does not contain the character, an empty string is returned.
596 * 596 *
597 * @param string the string where to locate the character 597 * @param string the string where to locate the character
598 * @param chr the character to locate 598 * @param chr the character to locate
599 * @return a substring starting at the last location of \p chr 599 * @return a substring starting at the last location of @p chr
600 * 600 *
601 * @see cx_strrchr() 601 * @see cx_strrchr()
602 */ 602 */
603 cx_attr_nodiscard 603 cx_attr_nodiscard
604 cxmutstr cx_strrchr_m( 604 cxmutstr cx_strrchr_m(
608 608
609 /** 609 /**
610 * Returns a substring starting at the location of the first occurrence of the 610 * Returns a substring starting at the location of the first occurrence of the
611 * specified string. 611 * specified string.
612 * 612 *
613 * If \p haystack does not contain \p needle, an empty string is returned. 613 * If @p haystack does not contain @p needle, an empty string is returned.
614 * 614 *
615 * If \p needle is an empty string, the complete \p haystack is 615 * If @p needle is an empty string, the complete @p haystack is
616 * returned. 616 * returned.
617 * 617 *
618 * @param haystack the string to be scanned 618 * @param haystack the string to be scanned
619 * @param needle string containing the sequence of characters to match 619 * @param needle string containing the sequence of characters to match
620 * @return a substring starting at the first occurrence of 620 * @return a substring starting at the first occurrence of
621 * \p needle, or an empty string, if the sequence is not 621 * @p needle, or an empty string, if the sequence is not
622 * contained 622 * contained
623 * @see cx_strstr_m() 623 * @see cx_strstr_m()
624 */ 624 */
625 cx_attr_nodiscard 625 cx_attr_nodiscard
626 cxstring cx_strstr( 626 cxstring cx_strstr(
630 630
631 /** 631 /**
632 * Returns a substring starting at the location of the first occurrence of the 632 * Returns a substring starting at the location of the first occurrence of the
633 * specified string. 633 * specified string.
634 * 634 *
635 * If \p haystack does not contain \p needle, an empty string is returned. 635 * If @p haystack does not contain @p needle, an empty string is returned.
636 * 636 *
637 * If \p needle is an empty string, the complete \p haystack is 637 * If @p needle is an empty string, the complete @p haystack is
638 * returned. 638 * returned.
639 * 639 *
640 * @param haystack the string to be scanned 640 * @param haystack the string to be scanned
641 * @param needle string containing the sequence of characters to match 641 * @param needle string containing the sequence of characters to match
642 * @return a substring starting at the first occurrence of 642 * @return a substring starting at the first occurrence of
643 * \p needle, or an empty string, if the sequence is not 643 * @p needle, or an empty string, if the sequence is not
644 * contained 644 * contained
645 * @see cx_strstr() 645 * @see cx_strstr()
646 */ 646 */
647 cx_attr_nodiscard 647 cx_attr_nodiscard
648 cxmutstr cx_strstr_m( 648 cxmutstr cx_strstr_m(
651 ); 651 );
652 652
653 /** 653 /**
654 * Splits a given string using a delimiter string. 654 * Splits a given string using a delimiter string.
655 * 655 *
656 * \note The resulting array contains strings that point to the source 656 * @note The resulting array contains strings that point to the source
657 * \p string. Use cx_strdup() to get copies. 657 * @p string. Use cx_strdup() to get copies.
658 * 658 *
659 * @param string the string to split 659 * @param string the string to split
660 * @param delim the delimiter 660 * @param delim the delimiter
661 * @param limit the maximum number of split items 661 * @param limit the maximum number of split items
662 * @param output a pre-allocated array of at least \p limit length 662 * @param output a pre-allocated array of at least @p limit length
663 * @return the actual number of split items 663 * @return the actual number of split items
664 */ 664 */
665 cx_attr_nodiscard 665 cx_attr_nodiscard
666 cx_attr_nonnull 666 cx_attr_nonnull
667 cx_attr_access_w(4, 3) 667 cx_attr_access_w(4, 3)
673 ); 673 );
674 674
675 /** 675 /**
676 * Splits a given string using a delimiter string. 676 * Splits a given string using a delimiter string.
677 * 677 *
678 * The array pointed to by \p output will be allocated by \p allocator. 678 * The array pointed to by @p output will be allocated by @p allocator.
679 * 679 *
680 * \note The resulting array contains strings that point to the source 680 * @note The resulting array contains strings that point to the source
681 * \p string. Use cx_strdup() to get copies. 681 * @p string. Use cx_strdup() to get copies.
682 * 682 *
683 * \attention If allocation fails, the \c NULL pointer will be written to 683 * @attention If allocation fails, the @c NULL pointer will be written to
684 * \p output and the number returned will be zero. 684 * @p output and the number returned will be zero.
685 * 685 *
686 * @param allocator the allocator to use for allocating the resulting array 686 * @param allocator the allocator to use for allocating the resulting array
687 * @param string the string to split 687 * @param string the string to split
688 * @param delim the delimiter 688 * @param delim the delimiter
689 * @param limit the maximum number of split items 689 * @param limit the maximum number of split items
704 704
705 705
706 /** 706 /**
707 * Splits a given string using a delimiter string. 707 * Splits a given string using a delimiter string.
708 * 708 *
709 * \note The resulting array contains strings that point to the source 709 * @note The resulting array contains strings that point to the source
710 * \p string. Use cx_strdup() to get copies. 710 * @p string. Use cx_strdup() to get copies.
711 * 711 *
712 * @param string the string to split 712 * @param string the string to split
713 * @param delim the delimiter 713 * @param delim the delimiter
714 * @param limit the maximum number of split items 714 * @param limit the maximum number of split items
715 * @param output a pre-allocated array of at least \p limit length 715 * @param output a pre-allocated array of at least @p limit length
716 * @return the actual number of split items 716 * @return the actual number of split items
717 */ 717 */
718 cx_attr_nodiscard 718 cx_attr_nodiscard
719 cx_attr_nonnull 719 cx_attr_nonnull
720 cx_attr_access_w(4, 3) 720 cx_attr_access_w(4, 3)
726 ); 726 );
727 727
728 /** 728 /**
729 * Splits a given string using a delimiter string. 729 * Splits a given string using a delimiter string.
730 * 730 *
731 * The array pointed to by \p output will be allocated by \p allocator. 731 * The array pointed to by @p output will be allocated by @p allocator.
732 * 732 *
733 * \note The resulting array contains strings that point to the source 733 * @note The resulting array contains strings that point to the source
734 * \p string. Use cx_strdup() to get copies. 734 * @p string. Use cx_strdup() to get copies.
735 * 735 *
736 * \attention If allocation fails, the \c NULL pointer will be written to 736 * @attention If allocation fails, the @c NULL pointer will be written to
737 * \p output and the number returned will be zero. 737 * @p output and the number returned will be zero.
738 * 738 *
739 * @param allocator the allocator to use for allocating the resulting array 739 * @param allocator the allocator to use for allocating the resulting array
740 * @param string the string to split 740 * @param string the string to split
741 * @param delim the delimiter 741 * @param delim the delimiter
742 * @param limit the maximum number of split items 742 * @param limit the maximum number of split items
758 /** 758 /**
759 * Compares two strings. 759 * Compares two strings.
760 * 760 *
761 * @param s1 the first string 761 * @param s1 the first string
762 * @param s2 the second string 762 * @param s2 the second string
763 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 763 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
764 * than \p s2, zero if both strings equal 764 * than @p s2, zero if both strings equal
765 */ 765 */
766 cx_attr_nodiscard 766 cx_attr_nodiscard
767 int cx_strcmp( 767 int cx_strcmp(
768 cxstring s1, 768 cxstring s1,
769 cxstring s2 769 cxstring s2
772 /** 772 /**
773 * Compares two strings ignoring case. 773 * Compares two strings ignoring case.
774 * 774 *
775 * @param s1 the first string 775 * @param s1 the first string
776 * @param s2 the second string 776 * @param s2 the second string
777 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 777 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
778 * than \p s2, zero if both strings equal ignoring case 778 * than @p s2, zero if both strings equal ignoring case
779 */ 779 */
780 cx_attr_nodiscard 780 cx_attr_nodiscard
781 int cx_strcasecmp( 781 int cx_strcasecmp(
782 cxstring s1, 782 cxstring s1,
783 cxstring s2 783 cxstring s2
788 * 788 *
789 * This function has a compatible signature for the use as a cx_compare_func. 789 * This function has a compatible signature for the use as a cx_compare_func.
790 * 790 *
791 * @param s1 the first string 791 * @param s1 the first string
792 * @param s2 the second string 792 * @param s2 the second string
793 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 793 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
794 * than \p s2, zero if both strings equal 794 * than @p s2, zero if both strings equal
795 */ 795 */
796 cx_attr_nodiscard 796 cx_attr_nodiscard
797 cx_attr_nonnull 797 cx_attr_nonnull
798 int cx_strcmp_p( 798 int cx_strcmp_p(
799 const void *s1, 799 const void *s1,
805 * 805 *
806 * This function has a compatible signature for the use as a cx_compare_func. 806 * This function has a compatible signature for the use as a cx_compare_func.
807 * 807 *
808 * @param s1 the first string 808 * @param s1 the first string
809 * @param s2 the second string 809 * @param s2 the second string
810 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 810 * @return negative if @p s1 is smaller than @p s2, positive if @p s1 is larger
811 * than \p s2, zero if both strings equal ignoring case 811 * than @p s2, zero if both strings equal ignoring case
812 */ 812 */
813 cx_attr_nodiscard 813 cx_attr_nodiscard
814 cx_attr_nonnull 814 cx_attr_nonnull
815 int cx_strcasecmp_p( 815 int cx_strcasecmp_p(
816 const void *s1, 816 const void *s1,
819 819
820 820
821 /** 821 /**
822 * Creates a duplicate of the specified string. 822 * Creates a duplicate of the specified string.
823 * 823 *
824 * The new string will contain a copy allocated by \p allocator. 824 * The new string will contain a copy allocated by @p allocator.
825 * 825 *
826 * \note The returned string is guaranteed to be zero-terminated. 826 * @note The returned string is guaranteed to be zero-terminated.
827 * 827 *
828 * @param allocator the allocator to use 828 * @param allocator the allocator to use
829 * @param string the string to duplicate 829 * @param string the string to duplicate
830 * @return a duplicate of the string 830 * @return a duplicate of the string
831 * @see cx_strdup() 831 * @see cx_strdup()
839 839
840 /** 840 /**
841 * Creates a duplicate of the specified string. 841 * Creates a duplicate of the specified string.
842 * 842 *
843 * The new string will contain a copy allocated by standard 843 * The new string will contain a copy allocated by standard
844 * \c malloc(). So developers \em must pass the return value to cx_strfree(). 844 * @c malloc(). So developers @em must pass the return value to cx_strfree().
845 * 845 *
846 * \note The returned string is guaranteed to be zero-terminated. 846 * @note The returned string is guaranteed to be zero-terminated.
847 * 847 *
848 * @param string the string to duplicate 848 * @param string (@c cxstring) the string to duplicate
849 * @return a duplicate of the string 849 * @return (@c cxmutstr) a duplicate of the string
850 * @see cx_strdup_a() 850 * @see cx_strdup_a()
851 */ 851 */
852 #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) 852 #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string)
853 853
854 854
855 /** 855 /**
856 * Creates a duplicate of the specified string. 856 * Creates a duplicate of the specified string.
857 * 857 *
858 * The new string will contain a copy allocated by \p allocator. 858 * The new string will contain a copy allocated by @p allocator.
859 * 859 *
860 * \note The returned string is guaranteed to be zero-terminated. 860 * @note The returned string is guaranteed to be zero-terminated.
861 * 861 *
862 * @param allocator the allocator to use 862 * @param allocator (@c CxAllocator*) the allocator to use
863 * @param string the string to duplicate 863 * @param string (@c cxmutstr) the string to duplicate
864 * @return a duplicate of the string 864 * @return (@c cxmutstr) a duplicate of the string
865 * @see cx_strdup_m() 865 * @see cx_strdup_m()
866 */ 866 */
867 #define cx_strdup_ma(allocator, string) cx_strdup_a(allocator, cx_strcast(string)) 867 #define cx_strdup_ma(allocator, string) cx_strdup_a(allocator, cx_strcast(string))
868 868
869 /** 869 /**
870 * Creates a duplicate of the specified string. 870 * Creates a duplicate of the specified string.
871 * 871 *
872 * The new string will contain a copy allocated by standard 872 * The new string will contain a copy allocated by standard
873 * \c malloc(). So developers \em must pass the return value to cx_strfree(). 873 * @c malloc(). So developers @em must pass the return value to cx_strfree().
874 * 874 *
875 * \note The returned string is guaranteed to be zero-terminated. 875 * @note The returned string is guaranteed to be zero-terminated.
876 * 876 *
877 * @param string the string to duplicate 877 * @param string (@c cxmutstr) the string to duplicate
878 * @return a duplicate of the string 878 * @return (@c cxmutstr) a duplicate of the string
879 * @see cx_strdup_ma() 879 * @see cx_strdup_ma()
880 */ 880 */
881 #define cx_strdup_m(string) cx_strdup_a(cxDefaultAllocator, cx_strcast(string)) 881 #define cx_strdup_m(string) cx_strdup_a(cxDefaultAllocator, cx_strcast(string))
882 882
883 /** 883 /**
884 * Omits leading and trailing spaces. 884 * Omits leading and trailing spaces.
885 * 885 *
886 * \note the returned string references the same memory, thus you 886 * @note the returned string references the same memory, thus you
887 * must \em not free the returned memory. 887 * must @em not free the returned memory.
888 * 888 *
889 * @param string the string that shall be trimmed 889 * @param string the string that shall be trimmed
890 * @return the trimmed string 890 * @return the trimmed string
891 */ 891 */
892 cx_attr_nodiscard 892 cx_attr_nodiscard
893 cxstring cx_strtrim(cxstring string); 893 cxstring cx_strtrim(cxstring string);
894 894
895 /** 895 /**
896 * Omits leading and trailing spaces. 896 * Omits leading and trailing spaces.
897 * 897 *
898 * \note the returned string references the same memory, thus you 898 * @note the returned string references the same memory, thus you
899 * must \em not free the returned memory. 899 * must @em not free the returned memory.
900 * 900 *
901 * @param string the string that shall be trimmed 901 * @param string the string that shall be trimmed
902 * @return the trimmed string 902 * @return the trimmed string
903 */ 903 */
904 cx_attr_nodiscard 904 cx_attr_nodiscard
907 /** 907 /**
908 * Checks, if a string has a specific prefix. 908 * Checks, if a string has a specific prefix.
909 * 909 *
910 * @param string the string to check 910 * @param string the string to check
911 * @param prefix the prefix the string should have 911 * @param prefix the prefix the string should have
912 * @return \c true, if and only if the string has the specified prefix, 912 * @return @c true, if and only if the string has the specified prefix,
913 * \c false otherwise 913 * @c false otherwise
914 */ 914 */
915 cx_attr_nodiscard 915 cx_attr_nodiscard
916 bool cx_strprefix( 916 bool cx_strprefix(
917 cxstring string, 917 cxstring string,
918 cxstring prefix 918 cxstring prefix
921 /** 921 /**
922 * Checks, if a string has a specific suffix. 922 * Checks, if a string has a specific suffix.
923 * 923 *
924 * @param string the string to check 924 * @param string the string to check
925 * @param suffix the suffix the string should have 925 * @param suffix the suffix the string should have
926 * @return \c true, if and only if the string has the specified suffix, 926 * @return @c true, if and only if the string has the specified suffix,
927 * \c false otherwise 927 * @c false otherwise
928 */ 928 */
929 cx_attr_nodiscard 929 cx_attr_nodiscard
930 bool cx_strsuffix( 930 bool cx_strsuffix(
931 cxstring string, 931 cxstring string,
932 cxstring suffix 932 cxstring suffix
935 /** 935 /**
936 * Checks, if a string has a specific prefix, ignoring the case. 936 * Checks, if a string has a specific prefix, ignoring the case.
937 * 937 *
938 * @param string the string to check 938 * @param string the string to check
939 * @param prefix the prefix the string should have 939 * @param prefix the prefix the string should have
940 * @return \c true, if and only if the string has the specified prefix, 940 * @return @c true, if and only if the string has the specified prefix,
941 * \c false otherwise 941 * @c false otherwise
942 */ 942 */
943 cx_attr_nodiscard 943 cx_attr_nodiscard
944 bool cx_strcaseprefix( 944 bool cx_strcaseprefix(
945 cxstring string, 945 cxstring string,
946 cxstring prefix 946 cxstring prefix
949 /** 949 /**
950 * Checks, if a string has a specific suffix, ignoring the case. 950 * Checks, if a string has a specific suffix, ignoring the case.
951 * 951 *
952 * @param string the string to check 952 * @param string the string to check
953 * @param suffix the suffix the string should have 953 * @param suffix the suffix the string should have
954 * @return \c true, if and only if the string has the specified suffix, 954 * @return @c true, if and only if the string has the specified suffix,
955 * \c false otherwise 955 * @c false otherwise
956 */ 956 */
957 cx_attr_nodiscard 957 cx_attr_nodiscard
958 bool cx_strcasesuffix( 958 bool cx_strcasesuffix(
959 cxstring string, 959 cxstring string,
960 cxstring suffix 960 cxstring suffix
982 982
983 /** 983 /**
984 * Replaces a pattern in a string with another string. 984 * Replaces a pattern in a string with another string.
985 * 985 *
986 * The pattern is taken literally and is no regular expression. 986 * The pattern is taken literally and is no regular expression.
987 * Replaces at most \p replmax occurrences. 987 * Replaces at most @p replmax occurrences.
988 * 988 *
989 * The returned string will be allocated by \p allocator and is guaranteed 989 * The returned string will be allocated by @p allocator and is guaranteed
990 * to be zero-terminated. 990 * to be zero-terminated.
991 * 991 *
992 * If allocation fails, or the input string is empty, 992 * If allocation fails, or the input string is empty,
993 * the returned string will be empty. 993 * the returned string will be empty.
994 * 994 *
1011 1011
1012 /** 1012 /**
1013 * Replaces a pattern in a string with another string. 1013 * Replaces a pattern in a string with another string.
1014 * 1014 *
1015 * The pattern is taken literally and is no regular expression. 1015 * The pattern is taken literally and is no regular expression.
1016 * Replaces at most \p replmax occurrences. 1016 * Replaces at most @p replmax occurrences.
1017 * 1017 *
1018 * The returned string will be allocated by \c malloc() and is guaranteed 1018 * The returned string will be allocated by @c malloc() and is guaranteed
1019 * to be zero-terminated. 1019 * to be zero-terminated.
1020 * 1020 *
1021 * If allocation fails, or the input string is empty, 1021 * If allocation fails, or the input string is empty,
1022 * the returned string will be empty. 1022 * the returned string will be empty.
1023 * 1023 *
1024 * @param str the string where replacements should be applied 1024 * @param str (@c cxstring) the string where replacements should be applied
1025 * @param pattern the pattern to search for 1025 * @param pattern (@c cxstring) the pattern to search for
1026 * @param replacement the replacement string 1026 * @param replacement (@c cxstring) the replacement string
1027 * @param replmax maximum number of replacements 1027 * @param replmax (@c size_t) maximum number of replacements
1028 * @return the resulting string after applying the replacements 1028 * @return (@c cxmutstr) the resulting string after applying the replacements
1029 */ 1029 */
1030 #define cx_strreplacen(str, pattern, replacement, replmax) \ 1030 #define cx_strreplacen(str, pattern, replacement, replmax) \
1031 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, replmax) 1031 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, replmax)
1032 1032
1033 /** 1033 /**
1034 * Replaces a pattern in a string with another string. 1034 * Replaces a pattern in a string with another string.
1035 * 1035 *
1036 * The pattern is taken literally and is no regular expression. 1036 * The pattern is taken literally and is no regular expression.
1037 * 1037 *
1038 * The returned string will be allocated by \p allocator and is guaranteed 1038 * The returned string will be allocated by @p allocator and is guaranteed
1039 * to be zero-terminated. 1039 * to be zero-terminated.
1040 * 1040 *
1041 * If allocation fails, or the input string is empty, 1041 * If allocation fails, or the input string is empty,
1042 * the returned string will be empty. 1042 * the returned string will be empty.
1043 * 1043 *
1044 * @param allocator the allocator to use 1044 * @param allocator (@c CxAllocator*) the allocator to use
1045 * @param str the string where replacements should be applied 1045 * @param str (@c cxstring) the string where replacements should be applied
1046 * @param pattern the pattern to search for 1046 * @param pattern (@c cxstring) the pattern to search for
1047 * @param replacement the replacement string 1047 * @param replacement (@c cxstring) the replacement string
1048 * @return the resulting string after applying the replacements 1048 * @return (@c cxmutstr) the resulting string after applying the replacements
1049 */ 1049 */
1050 #define cx_strreplace_a(allocator, str, pattern, replacement) \ 1050 #define cx_strreplace_a(allocator, str, pattern, replacement) \
1051 cx_strreplacen_a(allocator, str, pattern, replacement, SIZE_MAX) 1051 cx_strreplacen_a(allocator, str, pattern, replacement, SIZE_MAX)
1052 1052
1053 /** 1053 /**
1054 * Replaces a pattern in a string with another string. 1054 * Replaces a pattern in a string with another string.
1055 * 1055 *
1056 * The pattern is taken literally and is no regular expression. 1056 * The pattern is taken literally and is no regular expression.
1057 * Replaces at most \p replmax occurrences. 1057 * Replaces at most @p replmax occurrences.
1058 * 1058 *
1059 * The returned string will be allocated by \c malloc() and is guaranteed 1059 * The returned string will be allocated by @c malloc() and is guaranteed
1060 * to be zero-terminated. 1060 * to be zero-terminated.
1061 * 1061 *
1062 * If allocation fails, or the input string is empty, 1062 * If allocation fails, or the input string is empty,
1063 * the returned string will be empty. 1063 * the returned string will be empty.
1064 * 1064 *
1065 * @param str the string where replacements should be applied 1065 * @param str (@c cxstring) the string where replacements should be applied
1066 * @param pattern the pattern to search for 1066 * @param pattern (@c cxstring) the pattern to search for
1067 * @param replacement the replacement string 1067 * @param replacement (@c cxstring) the replacement string
1068 * @return the resulting string after applying the replacements 1068 * @return (@c cxmutstr) the resulting string after applying the replacements
1069 */ 1069 */
1070 #define cx_strreplace(str, pattern, replacement) \ 1070 #define cx_strreplace(str, pattern, replacement) \
1071 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, SIZE_MAX) 1071 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, SIZE_MAX)
1072 1072
1073 /** 1073 /**
1156 /* ------------------------------------------------------------------------- * 1156 /* ------------------------------------------------------------------------- *
1157 * string to number conversion functions * 1157 * string to number conversion functions *
1158 * ------------------------------------------------------------------------- */ 1158 * ------------------------------------------------------------------------- */
1159 1159
1160 /** 1160 /**
1161 * \copydoc cx_strtouz_lc() 1161 * @copydoc cx_strtouz_lc()
1162 */ 1162 */
1163 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1163 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1164 int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep); 1164 int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep);
1165 /** 1165 /**
1166 * \copydoc cx_strtouz_lc() 1166 * @copydoc cx_strtouz_lc()
1167 */ 1167 */
1168 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1168 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1169 int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep); 1169 int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep);
1170 /** 1170 /**
1171 * \copydoc cx_strtouz_lc() 1171 * @copydoc cx_strtouz_lc()
1172 */ 1172 */
1173 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1173 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1174 int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep); 1174 int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep);
1175 /** 1175 /**
1176 * \copydoc cx_strtouz_lc() 1176 * @copydoc cx_strtouz_lc()
1177 */ 1177 */
1178 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1178 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1179 int cx_strtoll_lc(cxstring str, long long *output, int base, const char *groupsep); 1179 int cx_strtoll_lc(cxstring str, long long *output, int base, const char *groupsep);
1180 /** 1180 /**
1181 * \copydoc cx_strtouz_lc() 1181 * @copydoc cx_strtouz_lc()
1182 */ 1182 */
1183 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1183 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1184 int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep); 1184 int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep);
1185 /** 1185 /**
1186 * \copydoc cx_strtouz_lc() 1186 * @copydoc cx_strtouz_lc()
1187 */ 1187 */
1188 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1188 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1189 int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep); 1189 int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep);
1190 /** 1190 /**
1191 * \copydoc cx_strtouz_lc() 1191 * @copydoc cx_strtouz_lc()
1192 */ 1192 */
1193 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1193 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1194 int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep); 1194 int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep);
1195 /** 1195 /**
1196 * \copydoc cx_strtouz_lc() 1196 * @copydoc cx_strtouz_lc()
1197 */ 1197 */
1198 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1198 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1199 int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep); 1199 int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep);
1200 /** 1200 /**
1201 * \copydoc cx_strtouz_lc() 1201 * @copydoc cx_strtouz_lc()
1202 */ 1202 */
1203 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1203 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1204 int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep); 1204 int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep);
1205 /** 1205 /**
1206 * \copydoc cx_strtouz_lc() 1206 * @copydoc cx_strtouz_lc()
1207 */ 1207 */
1208 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1208 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1209 int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep); 1209 int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep);
1210 /** 1210 /**
1211 * \copydoc cx_strtouz_lc() 1211 * @copydoc cx_strtouz_lc()
1212 */ 1212 */
1213 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1213 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1214 int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep); 1214 int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep);
1215 /** 1215 /**
1216 * \copydoc cx_strtouz_lc() 1216 * @copydoc cx_strtouz_lc()
1217 */ 1217 */
1218 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1218 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1219 int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep); 1219 int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep);
1220 /** 1220 /**
1221 * \copydoc cx_strtouz_lc() 1221 * @copydoc cx_strtouz_lc()
1222 */ 1222 */
1223 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1223 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1224 int cx_strtoull_lc(cxstring str, unsigned long long *output, int base, const char *groupsep); 1224 int cx_strtoull_lc(cxstring str, unsigned long long *output, int base, const char *groupsep);
1225 /** 1225 /**
1226 * \copydoc cx_strtouz_lc() 1226 * @copydoc cx_strtouz_lc()
1227 */ 1227 */
1228 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1228 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1229 int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep); 1229 int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep);
1230 /** 1230 /**
1231 * \copydoc cx_strtouz_lc() 1231 * @copydoc cx_strtouz_lc()
1232 */ 1232 */
1233 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1233 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1234 int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep); 1234 int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep);
1235 /** 1235 /**
1236 * \copydoc cx_strtouz_lc() 1236 * @copydoc cx_strtouz_lc()
1237 */ 1237 */
1238 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1238 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1239 int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep); 1239 int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep);
1240 /** 1240 /**
1241 * \copydoc cx_strtouz_lc() 1241 * @copydoc cx_strtouz_lc()
1242 */ 1242 */
1243 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1243 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1244 int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep); 1244 int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep);
1245 1245
1246 /** 1246 /**
1252 * 1252 *
1253 * @param str the string to convert 1253 * @param str the string to convert
1254 * @param output a pointer to the integer variable where the result shall be stored 1254 * @param output a pointer to the integer variable where the result shall be stored
1255 * @param base 2, 8, 10, or 16 1255 * @param base 2, 8, 10, or 16
1256 * @param groupsep each character in this string is treated as group separator and ignored during conversion 1256 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1257 * @return zero on success, non-zero if conversion was not possible 1257 * @retval zero success
1258 * @retval non-zero conversion was not possible
1258 */ 1259 */
1259 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1260 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1260 int cx_strtouz_lc(cxstring str, size_t *output, int base, const char *groupsep); 1261 int cx_strtouz_lc(cxstring str, size_t *output, int base, const char *groupsep);
1261 1262
1262 /** 1263 /**
1272 * 1273 *
1273 * @param str the string to convert 1274 * @param str the string to convert
1274 * @param output a pointer to the float variable where the result shall be stored 1275 * @param output a pointer to the float variable where the result shall be stored
1275 * @param decsep the decimal separator 1276 * @param decsep the decimal separator
1276 * @param groupsep each character in this string is treated as group separator and ignored during conversion 1277 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1277 * @return zero on success, non-zero if conversion was not possible 1278 * @retval zero success
1279 * @retval non-zero conversion was not possible
1278 */ 1280 */
1279 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1281 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1280 int cx_strtof_lc(cxstring str, float *output, char decsep, const char *groupsep); 1282 int cx_strtof_lc(cxstring str, float *output, char decsep, const char *groupsep);
1281 1283
1282 /** 1284 /**
1292 * 1294 *
1293 * @param str the string to convert 1295 * @param str the string to convert
1294 * @param output a pointer to the float variable where the result shall be stored 1296 * @param output a pointer to the float variable where the result shall be stored
1295 * @param decsep the decimal separator 1297 * @param decsep the decimal separator
1296 * @param groupsep each character in this string is treated as group separator and ignored during conversion 1298 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1297 * @return zero on success, non-zero if conversion was not possible 1299 * @retval zero success
1300 * @retval non-zero conversion was not possible
1298 */ 1301 */
1299 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1302 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1300 int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep); 1303 int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep);
1301 1304
1302 #ifndef CX_STR_IMPLEMENTATION 1305 #ifndef CX_STR_IMPLEMENTATION
1303 /** 1306 /**
1304 * \copydoc cx_strtouz_lc() 1307 * @copydoc cx_strtouz_lc()
1305 */ 1308 */
1306 #define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc(cx_strcast(str), output, base, groupsep) 1309 #define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc(cx_strcast(str), output, base, groupsep)
1307 /** 1310 /**
1308 * \copydoc cx_strtouz_lc() 1311 * @copydoc cx_strtouz_lc()
1309 */ 1312 */
1310 #define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc(cx_strcast(str), output, base, groupsep) 1313 #define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc(cx_strcast(str), output, base, groupsep)
1311 /** 1314 /**
1312 * \copydoc cx_strtouz_lc() 1315 * @copydoc cx_strtouz_lc()
1313 */ 1316 */
1314 #define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc(cx_strcast(str), output, base, groupsep) 1317 #define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc(cx_strcast(str), output, base, groupsep)
1315 /** 1318 /**
1316 * \copydoc cx_strtouz_lc() 1319 * @copydoc cx_strtouz_lc()
1317 */ 1320 */
1318 #define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc(cx_strcast(str), output, base, groupsep) 1321 #define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc(cx_strcast(str), output, base, groupsep)
1319 /** 1322 /**
1320 * \copydoc cx_strtouz_lc() 1323 * @copydoc cx_strtouz_lc()
1321 */ 1324 */
1322 #define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc(cx_strcast(str), output, base, groupsep) 1325 #define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc(cx_strcast(str), output, base, groupsep)
1323 /** 1326 /**
1324 * \copydoc cx_strtouz_lc() 1327 * @copydoc cx_strtouz_lc()
1325 */ 1328 */
1326 #define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc(cx_strcast(str), output, base, groupsep) 1329 #define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc(cx_strcast(str), output, base, groupsep)
1327 /** 1330 /**
1328 * \copydoc cx_strtouz_lc() 1331 * @copydoc cx_strtouz_lc()
1329 */ 1332 */
1330 #define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc(cx_strcast(str), output, base, groupsep) 1333 #define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc(cx_strcast(str), output, base, groupsep)
1331 /** 1334 /**
1332 * \copydoc cx_strtouz_lc() 1335 * @copydoc cx_strtouz_lc()
1333 */ 1336 */
1334 #define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc(cx_strcast(str), output, base, groupsep) 1337 #define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc(cx_strcast(str), output, base, groupsep)
1335 /** 1338 /**
1336 * \copydoc cx_strtouz_lc() 1339 * @copydoc cx_strtouz_lc()
1337 */ 1340 */
1338 #define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc(cx_strcast(str), output, base, groupsep) 1341 #define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc(cx_strcast(str), output, base, groupsep)
1339 /** 1342 /**
1340 * \copydoc cx_strtouz_lc() 1343 * @copydoc cx_strtouz_lc()
1341 */ 1344 */
1342 #define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc(cx_strcast(str), output, base, groupsep) 1345 #define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc(cx_strcast(str), output, base, groupsep)
1343 /** 1346 /**
1344 * \copydoc cx_strtouz_lc() 1347 * @copydoc cx_strtouz_lc()
1345 */ 1348 */
1346 #define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc(cx_strcast(str), output, base, groupsep) 1349 #define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc(cx_strcast(str), output, base, groupsep)
1347 /** 1350 /**
1348 * \copydoc cx_strtouz_lc() 1351 * @copydoc cx_strtouz_lc()
1349 */ 1352 */
1350 #define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc(cx_strcast(str), output, base, groupsep) 1353 #define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc(cx_strcast(str), output, base, groupsep)
1351 /** 1354 /**
1352 * \copydoc cx_strtouz_lc() 1355 * @copydoc cx_strtouz_lc()
1353 */ 1356 */
1354 #define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc(cx_strcast(str), output, base, groupsep) 1357 #define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc(cx_strcast(str), output, base, groupsep)
1355 /** 1358 /**
1356 * \copydoc cx_strtouz_lc() 1359 * @copydoc cx_strtouz_lc()
1357 */ 1360 */
1358 #define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc(cx_strcast(str), output, base, groupsep) 1361 #define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc(cx_strcast(str), output, base, groupsep)
1359 /** 1362 /**
1360 * \copydoc cx_strtouz_lc() 1363 * @copydoc cx_strtouz_lc()
1361 */ 1364 */
1362 #define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc(cx_strcast(str), output, base, groupsep) 1365 #define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc(cx_strcast(str), output, base, groupsep)
1363 /** 1366 /**
1364 * \copydoc cx_strtouz_lc() 1367 * @copydoc cx_strtouz_lc()
1365 */ 1368 */
1366 #define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc(cx_strcast(str), output, base, groupsep) 1369 #define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc(cx_strcast(str), output, base, groupsep)
1367 /** 1370 /**
1368 * \copydoc cx_strtouz_lc() 1371 * @copydoc cx_strtouz_lc()
1369 */ 1372 */
1370 #define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc(cx_strcast(str), output, base, groupsep) 1373 #define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc(cx_strcast(str), output, base, groupsep)
1371 /** 1374 /**
1372 * Converts a string to a number. 1375 * Converts a string to a number.
1373 * 1376 *
1377 * 1380 *
1378 * @param str the string to convert 1381 * @param str the string to convert
1379 * @param output a pointer to the integer variable where the result shall be stored 1382 * @param output a pointer to the integer variable where the result shall be stored
1380 * @param base 2, 8, 10, or 16 1383 * @param base 2, 8, 10, or 16
1381 * @param groupsep each character in this string is treated as group separator and ignored during conversion 1384 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1382 * @return zero on success, non-zero if conversion was not possible 1385 * @retval zero success
1386 * @retval non-zero conversion was not possible
1383 */ 1387 */
1384 #define cx_strtouz_lc(str, output, base, groupsep) cx_strtouz_lc(cx_strcast(str), output, base, groupsep) 1388 #define cx_strtouz_lc(str, output, base, groupsep) cx_strtouz_lc(cx_strcast(str), output, base, groupsep)
1385 1389
1386 /** 1390 /**
1387 * \copydoc cx_strtouz() 1391 * @copydoc cx_strtouz()
1388 */ 1392 */
1389 #define cx_strtos(str, output, base) cx_strtos_lc(str, output, base, ",") 1393 #define cx_strtos(str, output, base) cx_strtos_lc(str, output, base, ",")
1390 /** 1394 /**
1391 * \copydoc cx_strtouz() 1395 * @copydoc cx_strtouz()
1392 */ 1396 */
1393 #define cx_strtoi(str, output, base) cx_strtoi_lc(str, output, base, ",") 1397 #define cx_strtoi(str, output, base) cx_strtoi_lc(str, output, base, ",")
1394 /** 1398 /**
1395 * \copydoc cx_strtouz() 1399 * @copydoc cx_strtouz()
1396 */ 1400 */
1397 #define cx_strtol(str, output, base) cx_strtol_lc(str, output, base, ",") 1401 #define cx_strtol(str, output, base) cx_strtol_lc(str, output, base, ",")
1398 /** 1402 /**
1399 * \copydoc cx_strtouz() 1403 * @copydoc cx_strtouz()
1400 */ 1404 */
1401 #define cx_strtoll(str, output, base) cx_strtoll_lc(str, output, base, ",") 1405 #define cx_strtoll(str, output, base) cx_strtoll_lc(str, output, base, ",")
1402 /** 1406 /**
1403 * \copydoc cx_strtouz() 1407 * @copydoc cx_strtouz()
1404 */ 1408 */
1405 #define cx_strtoi8(str, output, base) cx_strtoi8_lc(str, output, base, ",") 1409 #define cx_strtoi8(str, output, base) cx_strtoi8_lc(str, output, base, ",")
1406 /** 1410 /**
1407 * \copydoc cx_strtouz() 1411 * @copydoc cx_strtouz()
1408 */ 1412 */
1409 #define cx_strtoi16(str, output, base) cx_strtoi16_lc(str, output, base, ",") 1413 #define cx_strtoi16(str, output, base) cx_strtoi16_lc(str, output, base, ",")
1410 /** 1414 /**
1411 * \copydoc cx_strtouz() 1415 * @copydoc cx_strtouz()
1412 */ 1416 */
1413 #define cx_strtoi32(str, output, base) cx_strtoi32_lc(str, output, base, ",") 1417 #define cx_strtoi32(str, output, base) cx_strtoi32_lc(str, output, base, ",")
1414 /** 1418 /**
1415 * \copydoc cx_strtouz() 1419 * @copydoc cx_strtouz()
1416 */ 1420 */
1417 #define cx_strtoi64(str, output, base) cx_strtoi64_lc(str, output, base, ",") 1421 #define cx_strtoi64(str, output, base) cx_strtoi64_lc(str, output, base, ",")
1418 /** 1422 /**
1419 * \copydoc cx_strtouz() 1423 * @copydoc cx_strtouz()
1420 */ 1424 */
1421 #define cx_strtoz(str, output, base) cx_strtoz_lc(str, output, base, ",") 1425 #define cx_strtoz(str, output, base) cx_strtoz_lc(str, output, base, ",")
1422 /** 1426 /**
1423 * \copydoc cx_strtouz() 1427 * @copydoc cx_strtouz()
1424 */ 1428 */
1425 #define cx_strtous(str, output, base) cx_strtous_lc(str, output, base, ",") 1429 #define cx_strtous(str, output, base) cx_strtous_lc(str, output, base, ",")
1426 /** 1430 /**
1427 * \copydoc cx_strtouz() 1431 * @copydoc cx_strtouz()
1428 */ 1432 */
1429 #define cx_strtou(str, output, base) cx_strtou_lc(str, output, base, ",") 1433 #define cx_strtou(str, output, base) cx_strtou_lc(str, output, base, ",")
1430 /** 1434 /**
1431 * \copydoc cx_strtouz() 1435 * @copydoc cx_strtouz()
1432 */ 1436 */
1433 #define cx_strtoul(str, output, base) cx_strtoul_lc(str, output, base, ",") 1437 #define cx_strtoul(str, output, base) cx_strtoul_lc(str, output, base, ",")
1434 /** 1438 /**
1435 * \copydoc cx_strtouz() 1439 * @copydoc cx_strtouz()
1436 */ 1440 */
1437 #define cx_strtoull(str, output, base) cx_strtoull_lc(str, output, base, ",") 1441 #define cx_strtoull(str, output, base) cx_strtoull_lc(str, output, base, ",")
1438 /** 1442 /**
1439 * \copydoc cx_strtouz() 1443 * @copydoc cx_strtouz()
1440 */ 1444 */
1441 #define cx_strtou8(str, output, base) cx_strtou8_lc(str, output, base, ",") 1445 #define cx_strtou8(str, output, base) cx_strtou8_lc(str, output, base, ",")
1442 /** 1446 /**
1443 * \copydoc cx_strtouz() 1447 * @copydoc cx_strtouz()
1444 */ 1448 */
1445 #define cx_strtou16(str, output, base) cx_strtou16_lc(str, output, base, ",") 1449 #define cx_strtou16(str, output, base) cx_strtou16_lc(str, output, base, ",")
1446 /** 1450 /**
1447 * \copydoc cx_strtouz() 1451 * @copydoc cx_strtouz()
1448 */ 1452 */
1449 #define cx_strtou32(str, output, base) cx_strtou32_lc(str, output, base, ",") 1453 #define cx_strtou32(str, output, base) cx_strtou32_lc(str, output, base, ",")
1450 /** 1454 /**
1451 * \copydoc cx_strtouz() 1455 * @copydoc cx_strtouz()
1452 */ 1456 */
1453 #define cx_strtou64(str, output, base) cx_strtou64_lc(str, output, base, ",") 1457 #define cx_strtou64(str, output, base) cx_strtou64_lc(str, output, base, ",")
1454 /** 1458 /**
1455 * Converts a string to a number. 1459 * Converts a string to a number.
1456 * 1460 *
1457 * The function returns non-zero when conversion is not possible. 1461 * The function returns non-zero when conversion is not possible.
1458 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. 1462 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1459 * It sets errno to ERANGE when the target datatype is too small. 1463 * It sets errno to ERANGE when the target datatype is too small.
1460 * 1464 *
1461 * The comma character is treated as group separator and ignored during parsing. 1465 * The comma character is treated as group separator and ignored during parsing.
1462 * If you want to choose the set of group separators, use the \c _lc variant of this function (e.g. cx_strtouz_lc()). 1466 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1463 * 1467 *
1464 * @param str the string to convert 1468 * @param str the string to convert
1465 * @param output a pointer to the integer variable where the result shall be stored 1469 * @param output a pointer to the integer variable where the result shall be stored
1466 * @param base 2, 8, 10, or 16 1470 * @param base 2, 8, 10, or 16
1467 * @return zero on success, non-zero if conversion was not possible 1471 * @retval zero success
1472 * @retval non-zero conversion was not possible
1468 */ 1473 */
1469 #define cx_strtouz(str, output, base) cx_strtouz_lc(str, output, base, ",") 1474 #define cx_strtouz(str, output, base) cx_strtouz_lc(str, output, base, ",")
1470 1475
1471 /** 1476 /**
1472 * Converts a string to a single precision floating point number. 1477 * Converts a string to a single precision floating point number.
1481 * 1486 *
1482 * @param str the string to convert 1487 * @param str the string to convert
1483 * @param output a pointer to the float variable where the result shall be stored 1488 * @param output a pointer to the float variable where the result shall be stored
1484 * @param decsep the decimal separator 1489 * @param decsep the decimal separator
1485 * @param groupsep each character in this string is treated as group separator and ignored during conversion 1490 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1486 * @return zero on success, non-zero if conversion was not possible 1491 * @retval zero success
1492 * @retval non-zero conversion was not possible
1487 */ 1493 */
1488 #define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc(cx_strcast(str), output, decsep, groupsep) 1494 #define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc(cx_strcast(str), output, decsep, groupsep)
1489 /** 1495 /**
1490 * Converts a string to a double precision floating point number. 1496 * Converts a string to a double precision floating point number.
1497 *
1498 * The function returns non-zero when conversion is not possible.
1499 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1500 *
1501 * The decimal separator is assumed to be a dot character.
1502 * The comma character is treated as group separator and ignored during parsing.
1503 * If you want to choose a different format, use cx_strtof_lc().
1504 *
1505 * @param str the string to convert
1506 * @param output a pointer to the double variable where the result shall be stored
1507 * @param decsep the decimal separator
1508 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1509 * @retval zero success
1510 * @retval non-zero conversion was not possible
1511 */
1512 #define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc(cx_strcast(str), output, decsep, groupsep)
1513
1514 /**
1515 * Converts a string to a single precision floating point number.
1491 * 1516 *
1492 * The function returns non-zero when conversion is not possible. 1517 * The function returns non-zero when conversion is not possible.
1493 * In that case the function sets errno to EINVAL when the reason is an invalid character. 1518 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1494 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. 1519 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
1495 * 1520 *
1497 * The comma character is treated as group separator and ignored during parsing. 1522 * The comma character is treated as group separator and ignored during parsing.
1498 * If you want to choose a different format, use cx_strtof_lc(). 1523 * If you want to choose a different format, use cx_strtof_lc().
1499 * 1524 *
1500 * @param str the string to convert 1525 * @param str the string to convert
1501 * @param output a pointer to the float variable where the result shall be stored 1526 * @param output a pointer to the float variable where the result shall be stored
1502 * @param decsep the decimal separator 1527 * @retval zero success
1503 * @param groupsep each character in this string is treated as group separator and ignored during conversion 1528 * @retval non-zero conversion was not possible
1504 * @return zero on success, non-zero if conversion was not possible 1529 */
1505 */ 1530 #define cx_strtof(str, output) cx_strtof_lc(str, output, '.', ",")
1506 #define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc(cx_strcast(str), output, decsep, groupsep) 1531 /**
1507 1532 * Converts a string to a double precision floating point number.
1508 /**
1509 * Converts a string to a single precision floating point number.
1510 * 1533 *
1511 * The function returns non-zero when conversion is not possible. 1534 * The function returns non-zero when conversion is not possible.
1512 * In that case the function sets errno to EINVAL when the reason is an invalid character. 1535 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1513 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
1514 * 1536 *
1515 * The decimal separator is assumed to be a dot character. 1537 * The decimal separator is assumed to be a dot character.
1516 * The comma character is treated as group separator and ignored during parsing. 1538 * The comma character is treated as group separator and ignored during parsing.
1517 * If you want to choose a different format, use cx_strtof_lc(). 1539 * If you want to choose a different format, use cx_strtof_lc().
1518 * 1540 *
1519 * @param str the string to convert 1541 * @param str the string to convert
1520 * @param output a pointer to the float variable where the result shall be stored 1542 * @param output a pointer to the double variable where the result shall be stored
1521 * @return zero on success, non-zero if conversion was not possible 1543 * @retval zero success
1522 */ 1544 * @retval non-zero conversion was not possible
1523 #define cx_strtof(str, output) cx_strtof_lc(str, output, '.', ",")
1524 /**
1525 * Converts a string to a double precision floating point number.
1526 *
1527 * The function returns non-zero when conversion is not possible.
1528 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1529 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
1530 *
1531 * The decimal separator is assumed to be a dot character.
1532 * The comma character is treated as group separator and ignored during parsing.
1533 * If you want to choose a different format, use cx_strtof_lc().
1534 *
1535 * @param str the string to convert
1536 * @param output a pointer to the float variable where the result shall be stored
1537 * @return zero on success, non-zero if conversion was not possible
1538 */ 1545 */
1539 #define cx_strtod(str, output) cx_strtod_lc(str, output, '.', ",") 1546 #define cx_strtod(str, output) cx_strtod_lc(str, output, '.', ",")
1540 1547
1541 #endif 1548 #endif
1542 1549

mercurial