ucx/cx/string.h

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

mercurial