| 280 /** |
280 /** |
| 281 * Casts a mutable string to an immutable string. |
281 * Casts a mutable string to an immutable string. |
| 282 * |
282 * |
| 283 * Does nothing for already immutable strings. |
283 * Does nothing for already immutable strings. |
| 284 * |
284 * |
| 285 * \note This is not seriously a cast. Instead, you get a copy |
285 * @note This is not seriously a cast. Instead, you get a copy |
| 286 * of the struct with the desired pointer type. Both structs still |
286 * of the struct with the desired pointer type. Both structs still |
| 287 * point to the same location, though! |
287 * point to the same location, though! |
| 288 * |
288 * |
| 289 * @param str the mutable string to cast |
289 * @param str (@c cxstring or @c cxmutstr) the string to cast |
| 290 * @return an immutable copy of the string pointer |
290 * @return (@c cxstring) an immutable copy of the string pointer |
| 291 */ |
291 */ |
| 292 #define cx_strcast(str) _Generic((str), \ |
292 #define cx_strcast(str) _Generic((str), \ |
| 293 cxmutstr: cx_strcast_m, \ |
293 cxmutstr: cx_strcast_m, \ |
| 294 cxstring: cx_strcast_c) \ |
294 cxstring: cx_strcast_c) \ |
| 295 (str) |
295 (str) |
| 296 #endif |
296 #endif |
| 297 |
297 |
| 298 /** |
298 /** |
| 299 * Passes the pointer in this string to \c free(). |
299 * Passes the pointer in this string to @c free(). |
| 300 * |
300 * |
| 301 * The pointer in the struct is set to \c NULL and the length is set to zero. |
301 * The pointer in the struct is set to @c NULL and the length is set to zero. |
| 302 * |
302 * |
| 303 * \note There is no implementation for cxstring, because it is unlikely that |
303 * @note There is no implementation for cxstring, because it is unlikely that |
| 304 * you ever have a <code>const char*</code> you are really supposed to free. |
304 * you ever have a <code>const char*</code> you are really supposed to free. |
| 305 * If you encounter such situation, you should double-check your code. |
305 * If you encounter such situation, you should double-check your code. |
| 306 * |
306 * |
| 307 * @param str the string to free |
307 * @param str the string to free |
| 308 */ |
308 */ |
| 309 void cx_strfree(cxmutstr *str); |
309 void cx_strfree(cxmutstr *str); |
| 310 |
310 |
| 311 /** |
311 /** |
| 312 * Passes the pointer in this string to the allocators free function. |
312 * Passes the pointer in this string to the allocators free function. |
| 313 * |
313 * |
| 314 * The pointer in the struct is set to \c NULL and the length is set to zero. |
314 * The pointer in the struct is set to @c NULL and the length is set to zero. |
| 315 * |
315 * |
| 316 * \note There is no implementation for cxstring, because it is unlikely that |
316 * @note There is no implementation for cxstring, because it is unlikely that |
| 317 * you ever have a <code>const char*</code> you are really supposed to free. |
317 * you ever have a <code>const char*</code> you are really supposed to free. |
| 318 * If you encounter such situation, you should double-check your code. |
318 * If you encounter such situation, you should double-check your code. |
| 319 * |
319 * |
| 320 * @param alloc the allocator |
320 * @param alloc the allocator |
| 321 * @param str the string to free |
321 * @param str the string to free |
| 377 |
377 |
| 378 /** |
378 /** |
| 379 * Concatenates strings and returns a new string. |
379 * Concatenates strings and returns a new string. |
| 380 * |
380 * |
| 381 * The resulting string will be allocated by the specified allocator. |
381 * The resulting string will be allocated by the specified allocator. |
| 382 * So developers \em must pass the return value to cx_strfree_a() eventually. |
382 * So developers @em must pass the return value to cx_strfree_a() eventually. |
| 383 * |
383 * |
| 384 * If memory allocation fails, the pointer in the returned string will |
384 * If memory allocation fails, the pointer in the returned string will |
| 385 * be \c NULL. Depending on the allocator, \c errno might be set. |
385 * be @c NULL. Depending on the allocator, @c errno might be set. |
| 386 * |
386 * |
| 387 * \note It is guaranteed that there is only one allocation for the |
387 * @note It is guaranteed that there is only one allocation for the |
| 388 * resulting string. |
388 * resulting string. |
| 389 * It is also guaranteed that the returned string is zero-terminated. |
389 * It is also guaranteed that the returned string is zero-terminated. |
| 390 * |
390 * |
| 391 * @param alloc the allocator to use |
391 * @param alloc (@c CxAllocator*) the allocator to use |
| 392 * @param count the number of the other following strings to concatenate |
392 * @param count (@c size_t) the number of the other following strings to concatenate |
| 393 * @param ... all other strings |
393 * @param ... all other UCX strings |
| 394 * @return the concatenated string |
394 * @return (@c cxmutstr) the concatenated string |
| 395 */ |
395 */ |
| 396 #define cx_strcat_a(alloc, count, ...) \ |
396 #define cx_strcat_a(alloc, count, ...) \ |
| 397 cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__) |
397 cx_strcat_ma(alloc, cx_mutstrn(NULL, 0), count, __VA_ARGS__) |
| 398 |
398 |
| 399 /** |
399 /** |
| 400 * Concatenates strings and returns a new string. |
400 * Concatenates strings and returns a new string. |
| 401 * |
401 * |
| 402 * The resulting string will be allocated by standard \c malloc(). |
402 * The resulting string will be allocated by standard @c malloc(). |
| 403 * So developers \em must pass the return value to cx_strfree() eventually. |
403 * So developers @em must pass the return value to cx_strfree() eventually. |
| 404 * |
404 * |
| 405 * If memory allocation fails, the pointer in the returned string will |
405 * If memory allocation fails, the pointer in the returned string will |
| 406 * be \c NULL and \c errno might be set. |
406 * be @c NULL and @c errno might be set. |
| 407 * |
407 * |
| 408 * \note It is guaranteed that there is only one allocation for the |
408 * @note It is guaranteed that there is only one allocation for the |
| 409 * resulting string. |
409 * resulting string. |
| 410 * It is also guaranteed that the returned string is zero-terminated. |
410 * It is also guaranteed that the returned string is zero-terminated. |
| 411 * |
411 * |
| 412 * @param count the number of the other following strings to concatenate |
412 * @param count (@c size_t) the number of the other following strings to concatenate |
| 413 * @param ... all other strings |
413 * @param ... all other UCX strings |
| 414 * @return the concatenated string |
414 * @return (@c cxmutstr) the concatenated string |
| 415 */ |
415 */ |
| 416 #define cx_strcat(count, ...) \ |
416 #define cx_strcat(count, ...) \ |
| 417 cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__) |
417 cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(NULL, 0), count, __VA_ARGS__) |
| 418 |
418 |
| 419 /** |
419 /** |
| 420 * Concatenates strings. |
420 * Concatenates strings. |
| 421 * |
421 * |
| 422 * The resulting string will be allocated by standard \c malloc(). |
422 * The resulting string will be allocated by standard @c malloc(). |
| 423 * So developers \em must pass the return value to cx_strfree() eventually. |
423 * So developers @em must pass the return value to cx_strfree() eventually. |
| 424 * |
424 * |
| 425 * If \p str already contains a string, the memory will be reallocated and |
425 * If @p str already contains a string, the memory will be reallocated and |
| 426 * the other strings are appended. Otherwise, new memory is allocated. |
426 * the other strings are appended. Otherwise, new memory is allocated. |
| 427 * |
427 * |
| 428 * If memory allocation fails, the pointer in the returned string will |
428 * If memory allocation fails, the pointer in the returned string will |
| 429 * be \c NULL and \c errno might be set. |
429 * be @c NULL and @c errno might be set. |
| 430 * |
430 * |
| 431 * \note It is guaranteed that there is only one allocation for the |
431 * @note It is guaranteed that there is only one allocation for the |
| 432 * resulting string. |
432 * resulting string. |
| 433 * It is also guaranteed that the returned string is zero-terminated. |
433 * It is also guaranteed that the returned string is zero-terminated. |
| 434 * |
434 * |
| 435 * @param str the string the other strings shall be concatenated to |
435 * @param str (@c cxmutstr) the string the other strings shall be concatenated to |
| 436 * @param count the number of the other following strings to concatenate |
436 * @param count (@c size_t) the number of the other following strings to concatenate |
| 437 * @param ... all other strings |
437 * @param ... all other strings |
| 438 * @return the concatenated string |
438 * @return (@c cxmutstr) the concatenated string |
| 439 */ |
439 */ |
| 440 #define cx_strcat_m(str, count, ...) \ |
440 #define cx_strcat_m(str, count, ...) \ |
| 441 cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__) |
441 cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__) |
| 442 |
442 |
| 443 /** |
443 /** |
| 444 * Returns a substring starting at the specified location. |
444 * Returns a substring starting at the specified location. |
| 445 * |
445 * |
| 446 * \attention the new string references the same memory area as the |
446 * @attention the new string references the same memory area as the |
| 447 * input string and is usually \em not zero-terminated. |
447 * input string and is usually @em not zero-terminated. |
| 448 * Use cx_strdup() to get a copy. |
448 * Use cx_strdup() to get a copy. |
| 449 * |
449 * |
| 450 * @param string input string |
450 * @param string input string |
| 451 * @param start start location of the substring |
451 * @param start start location of the substring |
| 452 * @return a substring of \p string starting at \p start |
452 * @return a substring of @p string starting at @p start |
| 453 * |
453 * |
| 454 * @see cx_strsubsl() |
454 * @see cx_strsubsl() |
| 455 * @see cx_strsubs_m() |
455 * @see cx_strsubs_m() |
| 456 * @see cx_strsubsl_m() |
456 * @see cx_strsubsl_m() |
| 457 */ |
457 */ |
| 839 |
839 |
| 840 /** |
840 /** |
| 841 * Creates a duplicate of the specified string. |
841 * Creates a duplicate of the specified string. |
| 842 * |
842 * |
| 843 * The new string will contain a copy allocated by standard |
843 * The new string will contain a copy allocated by standard |
| 844 * \c malloc(). So developers \em must pass the return value to cx_strfree(). |
844 * @c malloc(). So developers @em must pass the return value to cx_strfree(). |
| 845 * |
845 * |
| 846 * \note The returned string is guaranteed to be zero-terminated. |
846 * @note The returned string is guaranteed to be zero-terminated. |
| 847 * |
847 * |
| 848 * @param string the string to duplicate |
848 * @param string (@c cxstring) the string to duplicate |
| 849 * @return a duplicate of the string |
849 * @return (@c cxmutstr) a duplicate of the string |
| 850 * @see cx_strdup_a() |
850 * @see cx_strdup_a() |
| 851 */ |
851 */ |
| 852 #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) |
852 #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) |
| 853 |
853 |
| 854 |
854 |
| 855 /** |
855 /** |
| 856 * Creates a duplicate of the specified string. |
856 * Creates a duplicate of the specified string. |
| 857 * |
857 * |
| 858 * The new string will contain a copy allocated by \p allocator. |
858 * The new string will contain a copy allocated by @p allocator. |
| 859 * |
859 * |
| 860 * \note The returned string is guaranteed to be zero-terminated. |
860 * @note The returned string is guaranteed to be zero-terminated. |
| 861 * |
861 * |
| 862 * @param allocator the allocator to use |
862 * @param allocator (@c CxAllocator*) the allocator to use |
| 863 * @param string the string to duplicate |
863 * @param string (@c cxmutstr) the string to duplicate |
| 864 * @return a duplicate of the string |
864 * @return (@c cxmutstr) a duplicate of the string |
| 865 * @see cx_strdup_m() |
865 * @see cx_strdup_m() |
| 866 */ |
866 */ |
| 867 #define cx_strdup_ma(allocator, string) cx_strdup_a(allocator, cx_strcast(string)) |
867 #define cx_strdup_ma(allocator, string) cx_strdup_a(allocator, cx_strcast(string)) |
| 868 |
868 |
| 869 /** |
869 /** |
| 870 * Creates a duplicate of the specified string. |
870 * Creates a duplicate of the specified string. |
| 871 * |
871 * |
| 872 * The new string will contain a copy allocated by standard |
872 * The new string will contain a copy allocated by standard |
| 873 * \c malloc(). So developers \em must pass the return value to cx_strfree(). |
873 * @c malloc(). So developers @em must pass the return value to cx_strfree(). |
| 874 * |
874 * |
| 875 * \note The returned string is guaranteed to be zero-terminated. |
875 * @note The returned string is guaranteed to be zero-terminated. |
| 876 * |
876 * |
| 877 * @param string the string to duplicate |
877 * @param string (@c cxmutstr) the string to duplicate |
| 878 * @return a duplicate of the string |
878 * @return (@c cxmutstr) a duplicate of the string |
| 879 * @see cx_strdup_ma() |
879 * @see cx_strdup_ma() |
| 880 */ |
880 */ |
| 881 #define cx_strdup_m(string) cx_strdup_a(cxDefaultAllocator, cx_strcast(string)) |
881 #define cx_strdup_m(string) cx_strdup_a(cxDefaultAllocator, cx_strcast(string)) |
| 882 |
882 |
| 883 /** |
883 /** |
| 884 * Omits leading and trailing spaces. |
884 * Omits leading and trailing spaces. |
| 885 * |
885 * |
| 886 * \note the returned string references the same memory, thus you |
886 * @note the returned string references the same memory, thus you |
| 887 * must \em not free the returned memory. |
887 * must @em not free the returned memory. |
| 888 * |
888 * |
| 889 * @param string the string that shall be trimmed |
889 * @param string the string that shall be trimmed |
| 890 * @return the trimmed string |
890 * @return the trimmed string |
| 891 */ |
891 */ |
| 892 cx_attr_nodiscard |
892 cx_attr_nodiscard |
| 893 cxstring cx_strtrim(cxstring string); |
893 cxstring cx_strtrim(cxstring string); |
| 894 |
894 |
| 895 /** |
895 /** |
| 896 * Omits leading and trailing spaces. |
896 * Omits leading and trailing spaces. |
| 897 * |
897 * |
| 898 * \note the returned string references the same memory, thus you |
898 * @note the returned string references the same memory, thus you |
| 899 * must \em not free the returned memory. |
899 * must @em not free the returned memory. |
| 900 * |
900 * |
| 901 * @param string the string that shall be trimmed |
901 * @param string the string that shall be trimmed |
| 902 * @return the trimmed string |
902 * @return the trimmed string |
| 903 */ |
903 */ |
| 904 cx_attr_nodiscard |
904 cx_attr_nodiscard |
| 1011 |
1011 |
| 1012 /** |
1012 /** |
| 1013 * Replaces a pattern in a string with another string. |
1013 * Replaces a pattern in a string with another string. |
| 1014 * |
1014 * |
| 1015 * The pattern is taken literally and is no regular expression. |
1015 * The pattern is taken literally and is no regular expression. |
| 1016 * Replaces at most \p replmax occurrences. |
1016 * Replaces at most @p replmax occurrences. |
| 1017 * |
1017 * |
| 1018 * The returned string will be allocated by \c malloc() and is guaranteed |
1018 * The returned string will be allocated by @c malloc() and is guaranteed |
| 1019 * to be zero-terminated. |
1019 * to be zero-terminated. |
| 1020 * |
1020 * |
| 1021 * If allocation fails, or the input string is empty, |
1021 * If allocation fails, or the input string is empty, |
| 1022 * the returned string will be empty. |
1022 * the returned string will be empty. |
| 1023 * |
1023 * |
| 1024 * @param str the string where replacements should be applied |
1024 * @param str (@c cxstring) the string where replacements should be applied |
| 1025 * @param pattern the pattern to search for |
1025 * @param pattern (@c cxstring) the pattern to search for |
| 1026 * @param replacement the replacement string |
1026 * @param replacement (@c cxstring) the replacement string |
| 1027 * @param replmax maximum number of replacements |
1027 * @param replmax (@c size_t) maximum number of replacements |
| 1028 * @return the resulting string after applying the replacements |
1028 * @return (@c cxmutstr) the resulting string after applying the replacements |
| 1029 */ |
1029 */ |
| 1030 #define cx_strreplacen(str, pattern, replacement, replmax) \ |
1030 #define cx_strreplacen(str, pattern, replacement, replmax) \ |
| 1031 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, replmax) |
1031 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, replmax) |
| 1032 |
1032 |
| 1033 /** |
1033 /** |
| 1034 * Replaces a pattern in a string with another string. |
1034 * Replaces a pattern in a string with another string. |
| 1035 * |
1035 * |
| 1036 * The pattern is taken literally and is no regular expression. |
1036 * The pattern is taken literally and is no regular expression. |
| 1037 * |
1037 * |
| 1038 * The returned string will be allocated by \p allocator and is guaranteed |
1038 * The returned string will be allocated by @p allocator and is guaranteed |
| 1039 * to be zero-terminated. |
1039 * to be zero-terminated. |
| 1040 * |
1040 * |
| 1041 * If allocation fails, or the input string is empty, |
1041 * If allocation fails, or the input string is empty, |
| 1042 * the returned string will be empty. |
1042 * the returned string will be empty. |
| 1043 * |
1043 * |
| 1044 * @param allocator the allocator to use |
1044 * @param allocator (@c CxAllocator*) the allocator to use |
| 1045 * @param str the string where replacements should be applied |
1045 * @param str (@c cxstring) the string where replacements should be applied |
| 1046 * @param pattern the pattern to search for |
1046 * @param pattern (@c cxstring) the pattern to search for |
| 1047 * @param replacement the replacement string |
1047 * @param replacement (@c cxstring) the replacement string |
| 1048 * @return the resulting string after applying the replacements |
1048 * @return (@c cxmutstr) the resulting string after applying the replacements |
| 1049 */ |
1049 */ |
| 1050 #define cx_strreplace_a(allocator, str, pattern, replacement) \ |
1050 #define cx_strreplace_a(allocator, str, pattern, replacement) \ |
| 1051 cx_strreplacen_a(allocator, str, pattern, replacement, SIZE_MAX) |
1051 cx_strreplacen_a(allocator, str, pattern, replacement, SIZE_MAX) |
| 1052 |
1052 |
| 1053 /** |
1053 /** |
| 1054 * Replaces a pattern in a string with another string. |
1054 * Replaces a pattern in a string with another string. |
| 1055 * |
1055 * |
| 1056 * The pattern is taken literally and is no regular expression. |
1056 * The pattern is taken literally and is no regular expression. |
| 1057 * Replaces at most \p replmax occurrences. |
1057 * Replaces at most @p replmax occurrences. |
| 1058 * |
1058 * |
| 1059 * The returned string will be allocated by \c malloc() and is guaranteed |
1059 * The returned string will be allocated by @c malloc() and is guaranteed |
| 1060 * to be zero-terminated. |
1060 * to be zero-terminated. |
| 1061 * |
1061 * |
| 1062 * If allocation fails, or the input string is empty, |
1062 * If allocation fails, or the input string is empty, |
| 1063 * the returned string will be empty. |
1063 * the returned string will be empty. |
| 1064 * |
1064 * |
| 1065 * @param str the string where replacements should be applied |
1065 * @param str (@c cxstring) the string where replacements should be applied |
| 1066 * @param pattern the pattern to search for |
1066 * @param pattern (@c cxstring) the pattern to search for |
| 1067 * @param replacement the replacement string |
1067 * @param replacement (@c cxstring) the replacement string |
| 1068 * @return the resulting string after applying the replacements |
1068 * @return (@c cxmutstr) the resulting string after applying the replacements |
| 1069 */ |
1069 */ |
| 1070 #define cx_strreplace(str, pattern, replacement) \ |
1070 #define cx_strreplace(str, pattern, replacement) \ |
| 1071 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, SIZE_MAX) |
1071 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, SIZE_MAX) |
| 1072 |
1072 |
| 1073 /** |
1073 /** |
| 1156 /* ------------------------------------------------------------------------- * |
1156 /* ------------------------------------------------------------------------- * |
| 1157 * string to number conversion functions * |
1157 * string to number conversion functions * |
| 1158 * ------------------------------------------------------------------------- */ |
1158 * ------------------------------------------------------------------------- */ |
| 1159 |
1159 |
| 1160 /** |
1160 /** |
| 1161 * \copydoc cx_strtouz_lc() |
1161 * @copydoc cx_strtouz_lc() |
| 1162 */ |
1162 */ |
| 1163 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1163 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1164 int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep); |
1164 int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep); |
| 1165 /** |
1165 /** |
| 1166 * \copydoc cx_strtouz_lc() |
1166 * @copydoc cx_strtouz_lc() |
| 1167 */ |
1167 */ |
| 1168 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1168 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1169 int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep); |
1169 int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep); |
| 1170 /** |
1170 /** |
| 1171 * \copydoc cx_strtouz_lc() |
1171 * @copydoc cx_strtouz_lc() |
| 1172 */ |
1172 */ |
| 1173 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1173 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1174 int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep); |
1174 int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep); |
| 1175 /** |
1175 /** |
| 1176 * \copydoc cx_strtouz_lc() |
1176 * @copydoc cx_strtouz_lc() |
| 1177 */ |
1177 */ |
| 1178 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1178 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1179 int cx_strtoll_lc(cxstring str, long long *output, int base, const char *groupsep); |
1179 int cx_strtoll_lc(cxstring str, long long *output, int base, const char *groupsep); |
| 1180 /** |
1180 /** |
| 1181 * \copydoc cx_strtouz_lc() |
1181 * @copydoc cx_strtouz_lc() |
| 1182 */ |
1182 */ |
| 1183 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1183 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1184 int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep); |
1184 int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep); |
| 1185 /** |
1185 /** |
| 1186 * \copydoc cx_strtouz_lc() |
1186 * @copydoc cx_strtouz_lc() |
| 1187 */ |
1187 */ |
| 1188 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1188 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1189 int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep); |
1189 int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep); |
| 1190 /** |
1190 /** |
| 1191 * \copydoc cx_strtouz_lc() |
1191 * @copydoc cx_strtouz_lc() |
| 1192 */ |
1192 */ |
| 1193 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1193 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1194 int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep); |
1194 int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep); |
| 1195 /** |
1195 /** |
| 1196 * \copydoc cx_strtouz_lc() |
1196 * @copydoc cx_strtouz_lc() |
| 1197 */ |
1197 */ |
| 1198 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1198 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1199 int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep); |
1199 int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep); |
| 1200 /** |
1200 /** |
| 1201 * \copydoc cx_strtouz_lc() |
1201 * @copydoc cx_strtouz_lc() |
| 1202 */ |
1202 */ |
| 1203 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1203 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1204 int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep); |
1204 int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep); |
| 1205 /** |
1205 /** |
| 1206 * \copydoc cx_strtouz_lc() |
1206 * @copydoc cx_strtouz_lc() |
| 1207 */ |
1207 */ |
| 1208 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1208 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1209 int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep); |
1209 int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep); |
| 1210 /** |
1210 /** |
| 1211 * \copydoc cx_strtouz_lc() |
1211 * @copydoc cx_strtouz_lc() |
| 1212 */ |
1212 */ |
| 1213 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1213 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1214 int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep); |
1214 int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep); |
| 1215 /** |
1215 /** |
| 1216 * \copydoc cx_strtouz_lc() |
1216 * @copydoc cx_strtouz_lc() |
| 1217 */ |
1217 */ |
| 1218 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1218 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1219 int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep); |
1219 int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep); |
| 1220 /** |
1220 /** |
| 1221 * \copydoc cx_strtouz_lc() |
1221 * @copydoc cx_strtouz_lc() |
| 1222 */ |
1222 */ |
| 1223 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1223 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1224 int cx_strtoull_lc(cxstring str, unsigned long long *output, int base, const char *groupsep); |
1224 int cx_strtoull_lc(cxstring str, unsigned long long *output, int base, const char *groupsep); |
| 1225 /** |
1225 /** |
| 1226 * \copydoc cx_strtouz_lc() |
1226 * @copydoc cx_strtouz_lc() |
| 1227 */ |
1227 */ |
| 1228 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1228 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1229 int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep); |
1229 int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep); |
| 1230 /** |
1230 /** |
| 1231 * \copydoc cx_strtouz_lc() |
1231 * @copydoc cx_strtouz_lc() |
| 1232 */ |
1232 */ |
| 1233 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1233 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1234 int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep); |
1234 int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep); |
| 1235 /** |
1235 /** |
| 1236 * \copydoc cx_strtouz_lc() |
1236 * @copydoc cx_strtouz_lc() |
| 1237 */ |
1237 */ |
| 1238 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1238 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1239 int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep); |
1239 int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep); |
| 1240 /** |
1240 /** |
| 1241 * \copydoc cx_strtouz_lc() |
1241 * @copydoc cx_strtouz_lc() |
| 1242 */ |
1242 */ |
| 1243 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1243 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1244 int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep); |
1244 int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep); |
| 1245 |
1245 |
| 1246 /** |
1246 /** |
| 1292 * |
1294 * |
| 1293 * @param str the string to convert |
1295 * @param str the string to convert |
| 1294 * @param output a pointer to the float variable where the result shall be stored |
1296 * @param output a pointer to the float variable where the result shall be stored |
| 1295 * @param decsep the decimal separator |
1297 * @param decsep the decimal separator |
| 1296 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
1298 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
| 1297 * @return zero on success, non-zero if conversion was not possible |
1299 * @retval zero success |
| |
1300 * @retval non-zero conversion was not possible |
| 1298 */ |
1301 */ |
| 1299 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1302 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
| 1300 int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep); |
1303 int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep); |
| 1301 |
1304 |
| 1302 #ifndef CX_STR_IMPLEMENTATION |
1305 #ifndef CX_STR_IMPLEMENTATION |
| 1303 /** |
1306 /** |
| 1304 * \copydoc cx_strtouz_lc() |
1307 * @copydoc cx_strtouz_lc() |
| 1305 */ |
1308 */ |
| 1306 #define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc(cx_strcast(str), output, base, groupsep) |
1309 #define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc(cx_strcast(str), output, base, groupsep) |
| 1307 /** |
1310 /** |
| 1308 * \copydoc cx_strtouz_lc() |
1311 * @copydoc cx_strtouz_lc() |
| 1309 */ |
1312 */ |
| 1310 #define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc(cx_strcast(str), output, base, groupsep) |
1313 #define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc(cx_strcast(str), output, base, groupsep) |
| 1311 /** |
1314 /** |
| 1312 * \copydoc cx_strtouz_lc() |
1315 * @copydoc cx_strtouz_lc() |
| 1313 */ |
1316 */ |
| 1314 #define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc(cx_strcast(str), output, base, groupsep) |
1317 #define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc(cx_strcast(str), output, base, groupsep) |
| 1315 /** |
1318 /** |
| 1316 * \copydoc cx_strtouz_lc() |
1319 * @copydoc cx_strtouz_lc() |
| 1317 */ |
1320 */ |
| 1318 #define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc(cx_strcast(str), output, base, groupsep) |
1321 #define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc(cx_strcast(str), output, base, groupsep) |
| 1319 /** |
1322 /** |
| 1320 * \copydoc cx_strtouz_lc() |
1323 * @copydoc cx_strtouz_lc() |
| 1321 */ |
1324 */ |
| 1322 #define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc(cx_strcast(str), output, base, groupsep) |
1325 #define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc(cx_strcast(str), output, base, groupsep) |
| 1323 /** |
1326 /** |
| 1324 * \copydoc cx_strtouz_lc() |
1327 * @copydoc cx_strtouz_lc() |
| 1325 */ |
1328 */ |
| 1326 #define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc(cx_strcast(str), output, base, groupsep) |
1329 #define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc(cx_strcast(str), output, base, groupsep) |
| 1327 /** |
1330 /** |
| 1328 * \copydoc cx_strtouz_lc() |
1331 * @copydoc cx_strtouz_lc() |
| 1329 */ |
1332 */ |
| 1330 #define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc(cx_strcast(str), output, base, groupsep) |
1333 #define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc(cx_strcast(str), output, base, groupsep) |
| 1331 /** |
1334 /** |
| 1332 * \copydoc cx_strtouz_lc() |
1335 * @copydoc cx_strtouz_lc() |
| 1333 */ |
1336 */ |
| 1334 #define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc(cx_strcast(str), output, base, groupsep) |
1337 #define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc(cx_strcast(str), output, base, groupsep) |
| 1335 /** |
1338 /** |
| 1336 * \copydoc cx_strtouz_lc() |
1339 * @copydoc cx_strtouz_lc() |
| 1337 */ |
1340 */ |
| 1338 #define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc(cx_strcast(str), output, base, groupsep) |
1341 #define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc(cx_strcast(str), output, base, groupsep) |
| 1339 /** |
1342 /** |
| 1340 * \copydoc cx_strtouz_lc() |
1343 * @copydoc cx_strtouz_lc() |
| 1341 */ |
1344 */ |
| 1342 #define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc(cx_strcast(str), output, base, groupsep) |
1345 #define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc(cx_strcast(str), output, base, groupsep) |
| 1343 /** |
1346 /** |
| 1344 * \copydoc cx_strtouz_lc() |
1347 * @copydoc cx_strtouz_lc() |
| 1345 */ |
1348 */ |
| 1346 #define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc(cx_strcast(str), output, base, groupsep) |
1349 #define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc(cx_strcast(str), output, base, groupsep) |
| 1347 /** |
1350 /** |
| 1348 * \copydoc cx_strtouz_lc() |
1351 * @copydoc cx_strtouz_lc() |
| 1349 */ |
1352 */ |
| 1350 #define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc(cx_strcast(str), output, base, groupsep) |
1353 #define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc(cx_strcast(str), output, base, groupsep) |
| 1351 /** |
1354 /** |
| 1352 * \copydoc cx_strtouz_lc() |
1355 * @copydoc cx_strtouz_lc() |
| 1353 */ |
1356 */ |
| 1354 #define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc(cx_strcast(str), output, base, groupsep) |
1357 #define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc(cx_strcast(str), output, base, groupsep) |
| 1355 /** |
1358 /** |
| 1356 * \copydoc cx_strtouz_lc() |
1359 * @copydoc cx_strtouz_lc() |
| 1357 */ |
1360 */ |
| 1358 #define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc(cx_strcast(str), output, base, groupsep) |
1361 #define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc(cx_strcast(str), output, base, groupsep) |
| 1359 /** |
1362 /** |
| 1360 * \copydoc cx_strtouz_lc() |
1363 * @copydoc cx_strtouz_lc() |
| 1361 */ |
1364 */ |
| 1362 #define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc(cx_strcast(str), output, base, groupsep) |
1365 #define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc(cx_strcast(str), output, base, groupsep) |
| 1363 /** |
1366 /** |
| 1364 * \copydoc cx_strtouz_lc() |
1367 * @copydoc cx_strtouz_lc() |
| 1365 */ |
1368 */ |
| 1366 #define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc(cx_strcast(str), output, base, groupsep) |
1369 #define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc(cx_strcast(str), output, base, groupsep) |
| 1367 /** |
1370 /** |
| 1368 * \copydoc cx_strtouz_lc() |
1371 * @copydoc cx_strtouz_lc() |
| 1369 */ |
1372 */ |
| 1370 #define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc(cx_strcast(str), output, base, groupsep) |
1373 #define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc(cx_strcast(str), output, base, groupsep) |
| 1371 /** |
1374 /** |
| 1372 * Converts a string to a number. |
1375 * Converts a string to a number. |
| 1373 * |
1376 * |
| 1377 * |
1380 * |
| 1378 * @param str the string to convert |
1381 * @param str the string to convert |
| 1379 * @param output a pointer to the integer variable where the result shall be stored |
1382 * @param output a pointer to the integer variable where the result shall be stored |
| 1380 * @param base 2, 8, 10, or 16 |
1383 * @param base 2, 8, 10, or 16 |
| 1381 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
1384 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
| 1382 * @return zero on success, non-zero if conversion was not possible |
1385 * @retval zero success |
| |
1386 * @retval non-zero conversion was not possible |
| 1383 */ |
1387 */ |
| 1384 #define cx_strtouz_lc(str, output, base, groupsep) cx_strtouz_lc(cx_strcast(str), output, base, groupsep) |
1388 #define cx_strtouz_lc(str, output, base, groupsep) cx_strtouz_lc(cx_strcast(str), output, base, groupsep) |
| 1385 |
1389 |
| 1386 /** |
1390 /** |
| 1387 * \copydoc cx_strtouz() |
1391 * @copydoc cx_strtouz() |
| 1388 */ |
1392 */ |
| 1389 #define cx_strtos(str, output, base) cx_strtos_lc(str, output, base, ",") |
1393 #define cx_strtos(str, output, base) cx_strtos_lc(str, output, base, ",") |
| 1390 /** |
1394 /** |
| 1391 * \copydoc cx_strtouz() |
1395 * @copydoc cx_strtouz() |
| 1392 */ |
1396 */ |
| 1393 #define cx_strtoi(str, output, base) cx_strtoi_lc(str, output, base, ",") |
1397 #define cx_strtoi(str, output, base) cx_strtoi_lc(str, output, base, ",") |
| 1394 /** |
1398 /** |
| 1395 * \copydoc cx_strtouz() |
1399 * @copydoc cx_strtouz() |
| 1396 */ |
1400 */ |
| 1397 #define cx_strtol(str, output, base) cx_strtol_lc(str, output, base, ",") |
1401 #define cx_strtol(str, output, base) cx_strtol_lc(str, output, base, ",") |
| 1398 /** |
1402 /** |
| 1399 * \copydoc cx_strtouz() |
1403 * @copydoc cx_strtouz() |
| 1400 */ |
1404 */ |
| 1401 #define cx_strtoll(str, output, base) cx_strtoll_lc(str, output, base, ",") |
1405 #define cx_strtoll(str, output, base) cx_strtoll_lc(str, output, base, ",") |
| 1402 /** |
1406 /** |
| 1403 * \copydoc cx_strtouz() |
1407 * @copydoc cx_strtouz() |
| 1404 */ |
1408 */ |
| 1405 #define cx_strtoi8(str, output, base) cx_strtoi8_lc(str, output, base, ",") |
1409 #define cx_strtoi8(str, output, base) cx_strtoi8_lc(str, output, base, ",") |
| 1406 /** |
1410 /** |
| 1407 * \copydoc cx_strtouz() |
1411 * @copydoc cx_strtouz() |
| 1408 */ |
1412 */ |
| 1409 #define cx_strtoi16(str, output, base) cx_strtoi16_lc(str, output, base, ",") |
1413 #define cx_strtoi16(str, output, base) cx_strtoi16_lc(str, output, base, ",") |
| 1410 /** |
1414 /** |
| 1411 * \copydoc cx_strtouz() |
1415 * @copydoc cx_strtouz() |
| 1412 */ |
1416 */ |
| 1413 #define cx_strtoi32(str, output, base) cx_strtoi32_lc(str, output, base, ",") |
1417 #define cx_strtoi32(str, output, base) cx_strtoi32_lc(str, output, base, ",") |
| 1414 /** |
1418 /** |
| 1415 * \copydoc cx_strtouz() |
1419 * @copydoc cx_strtouz() |
| 1416 */ |
1420 */ |
| 1417 #define cx_strtoi64(str, output, base) cx_strtoi64_lc(str, output, base, ",") |
1421 #define cx_strtoi64(str, output, base) cx_strtoi64_lc(str, output, base, ",") |
| 1418 /** |
1422 /** |
| 1419 * \copydoc cx_strtouz() |
1423 * @copydoc cx_strtouz() |
| 1420 */ |
1424 */ |
| 1421 #define cx_strtoz(str, output, base) cx_strtoz_lc(str, output, base, ",") |
1425 #define cx_strtoz(str, output, base) cx_strtoz_lc(str, output, base, ",") |
| 1422 /** |
1426 /** |
| 1423 * \copydoc cx_strtouz() |
1427 * @copydoc cx_strtouz() |
| 1424 */ |
1428 */ |
| 1425 #define cx_strtous(str, output, base) cx_strtous_lc(str, output, base, ",") |
1429 #define cx_strtous(str, output, base) cx_strtous_lc(str, output, base, ",") |
| 1426 /** |
1430 /** |
| 1427 * \copydoc cx_strtouz() |
1431 * @copydoc cx_strtouz() |
| 1428 */ |
1432 */ |
| 1429 #define cx_strtou(str, output, base) cx_strtou_lc(str, output, base, ",") |
1433 #define cx_strtou(str, output, base) cx_strtou_lc(str, output, base, ",") |
| 1430 /** |
1434 /** |
| 1431 * \copydoc cx_strtouz() |
1435 * @copydoc cx_strtouz() |
| 1432 */ |
1436 */ |
| 1433 #define cx_strtoul(str, output, base) cx_strtoul_lc(str, output, base, ",") |
1437 #define cx_strtoul(str, output, base) cx_strtoul_lc(str, output, base, ",") |
| 1434 /** |
1438 /** |
| 1435 * \copydoc cx_strtouz() |
1439 * @copydoc cx_strtouz() |
| 1436 */ |
1440 */ |
| 1437 #define cx_strtoull(str, output, base) cx_strtoull_lc(str, output, base, ",") |
1441 #define cx_strtoull(str, output, base) cx_strtoull_lc(str, output, base, ",") |
| 1438 /** |
1442 /** |
| 1439 * \copydoc cx_strtouz() |
1443 * @copydoc cx_strtouz() |
| 1440 */ |
1444 */ |
| 1441 #define cx_strtou8(str, output, base) cx_strtou8_lc(str, output, base, ",") |
1445 #define cx_strtou8(str, output, base) cx_strtou8_lc(str, output, base, ",") |
| 1442 /** |
1446 /** |
| 1443 * \copydoc cx_strtouz() |
1447 * @copydoc cx_strtouz() |
| 1444 */ |
1448 */ |
| 1445 #define cx_strtou16(str, output, base) cx_strtou16_lc(str, output, base, ",") |
1449 #define cx_strtou16(str, output, base) cx_strtou16_lc(str, output, base, ",") |
| 1446 /** |
1450 /** |
| 1447 * \copydoc cx_strtouz() |
1451 * @copydoc cx_strtouz() |
| 1448 */ |
1452 */ |
| 1449 #define cx_strtou32(str, output, base) cx_strtou32_lc(str, output, base, ",") |
1453 #define cx_strtou32(str, output, base) cx_strtou32_lc(str, output, base, ",") |
| 1450 /** |
1454 /** |
| 1451 * \copydoc cx_strtouz() |
1455 * @copydoc cx_strtouz() |
| 1452 */ |
1456 */ |
| 1453 #define cx_strtou64(str, output, base) cx_strtou64_lc(str, output, base, ",") |
1457 #define cx_strtou64(str, output, base) cx_strtou64_lc(str, output, base, ",") |
| 1454 /** |
1458 /** |
| 1455 * Converts a string to a number. |
1459 * Converts a string to a number. |
| 1456 * |
1460 * |
| 1457 * The function returns non-zero when conversion is not possible. |
1461 * The function returns non-zero when conversion is not possible. |
| 1458 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. |
1462 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base. |
| 1459 * It sets errno to ERANGE when the target datatype is too small. |
1463 * It sets errno to ERANGE when the target datatype is too small. |
| 1460 * |
1464 * |
| 1461 * The comma character is treated as group separator and ignored during parsing. |
1465 * The comma character is treated as group separator and ignored during parsing. |
| 1462 * If you want to choose the set of group separators, use the \c _lc variant of this function (e.g. cx_strtouz_lc()). |
1466 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()). |
| 1463 * |
1467 * |
| 1464 * @param str the string to convert |
1468 * @param str the string to convert |
| 1465 * @param output a pointer to the integer variable where the result shall be stored |
1469 * @param output a pointer to the integer variable where the result shall be stored |
| 1466 * @param base 2, 8, 10, or 16 |
1470 * @param base 2, 8, 10, or 16 |
| 1467 * @return zero on success, non-zero if conversion was not possible |
1471 * @retval zero success |
| |
1472 * @retval non-zero conversion was not possible |
| 1468 */ |
1473 */ |
| 1469 #define cx_strtouz(str, output, base) cx_strtouz_lc(str, output, base, ",") |
1474 #define cx_strtouz(str, output, base) cx_strtouz_lc(str, output, base, ",") |
| 1470 |
1475 |
| 1471 /** |
1476 /** |
| 1472 * Converts a string to a single precision floating point number. |
1477 * Converts a string to a single precision floating point number. |
| 1481 * |
1486 * |
| 1482 * @param str the string to convert |
1487 * @param str the string to convert |
| 1483 * @param output a pointer to the float variable where the result shall be stored |
1488 * @param output a pointer to the float variable where the result shall be stored |
| 1484 * @param decsep the decimal separator |
1489 * @param decsep the decimal separator |
| 1485 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
1490 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
| 1486 * @return zero on success, non-zero if conversion was not possible |
1491 * @retval zero success |
| |
1492 * @retval non-zero conversion was not possible |
| 1487 */ |
1493 */ |
| 1488 #define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc(cx_strcast(str), output, decsep, groupsep) |
1494 #define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc(cx_strcast(str), output, decsep, groupsep) |
| 1489 /** |
1495 /** |
| 1490 * Converts a string to a double precision floating point number. |
1496 * Converts a string to a double precision floating point number. |
| |
1497 * |
| |
1498 * The function returns non-zero when conversion is not possible. |
| |
1499 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
| |
1500 * |
| |
1501 * The decimal separator is assumed to be a dot character. |
| |
1502 * The comma character is treated as group separator and ignored during parsing. |
| |
1503 * If you want to choose a different format, use cx_strtof_lc(). |
| |
1504 * |
| |
1505 * @param str the string to convert |
| |
1506 * @param output a pointer to the double variable where the result shall be stored |
| |
1507 * @param decsep the decimal separator |
| |
1508 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
| |
1509 * @retval zero success |
| |
1510 * @retval non-zero conversion was not possible |
| |
1511 */ |
| |
1512 #define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc(cx_strcast(str), output, decsep, groupsep) |
| |
1513 |
| |
1514 /** |
| |
1515 * Converts a string to a single precision floating point number. |
| 1491 * |
1516 * |
| 1492 * The function returns non-zero when conversion is not possible. |
1517 * The function returns non-zero when conversion is not possible. |
| 1493 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
1518 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
| 1494 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. |
1519 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. |
| 1495 * |
1520 * |
| 1497 * The comma character is treated as group separator and ignored during parsing. |
1522 * The comma character is treated as group separator and ignored during parsing. |
| 1498 * If you want to choose a different format, use cx_strtof_lc(). |
1523 * If you want to choose a different format, use cx_strtof_lc(). |
| 1499 * |
1524 * |
| 1500 * @param str the string to convert |
1525 * @param str the string to convert |
| 1501 * @param output a pointer to the float variable where the result shall be stored |
1526 * @param output a pointer to the float variable where the result shall be stored |
| 1502 * @param decsep the decimal separator |
1527 * @retval zero success |
| 1503 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
1528 * @retval non-zero conversion was not possible |
| 1504 * @return zero on success, non-zero if conversion was not possible |
1529 */ |
| 1505 */ |
1530 #define cx_strtof(str, output) cx_strtof_lc(str, output, '.', ",") |
| 1506 #define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc(cx_strcast(str), output, decsep, groupsep) |
1531 /** |
| 1507 |
1532 * Converts a string to a double precision floating point number. |
| 1508 /** |
|
| 1509 * Converts a string to a single precision floating point number. |
|
| 1510 * |
1533 * |
| 1511 * The function returns non-zero when conversion is not possible. |
1534 * The function returns non-zero when conversion is not possible. |
| 1512 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
1535 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
| 1513 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. |
|
| 1514 * |
1536 * |
| 1515 * The decimal separator is assumed to be a dot character. |
1537 * The decimal separator is assumed to be a dot character. |
| 1516 * The comma character is treated as group separator and ignored during parsing. |
1538 * The comma character is treated as group separator and ignored during parsing. |
| 1517 * If you want to choose a different format, use cx_strtof_lc(). |
1539 * If you want to choose a different format, use cx_strtof_lc(). |
| 1518 * |
1540 * |
| 1519 * @param str the string to convert |
1541 * @param str the string to convert |
| 1520 * @param output a pointer to the float variable where the result shall be stored |
1542 * @param output a pointer to the double variable where the result shall be stored |
| 1521 * @return zero on success, non-zero if conversion was not possible |
1543 * @retval zero success |
| 1522 */ |
1544 * @retval non-zero conversion was not possible |
| 1523 #define cx_strtof(str, output) cx_strtof_lc(str, output, '.', ",") |
|
| 1524 /** |
|
| 1525 * Converts a string to a double precision floating point number. |
|
| 1526 * |
|
| 1527 * The function returns non-zero when conversion is not possible. |
|
| 1528 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
|
| 1529 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. |
|
| 1530 * |
|
| 1531 * The decimal separator is assumed to be a dot character. |
|
| 1532 * The comma character is treated as group separator and ignored during parsing. |
|
| 1533 * If you want to choose a different format, use cx_strtof_lc(). |
|
| 1534 * |
|
| 1535 * @param str the string to convert |
|
| 1536 * @param output a pointer to the float variable where the result shall be stored |
|
| 1537 * @return zero on success, non-zero if conversion was not possible |
|
| 1538 */ |
1545 */ |
| 1539 #define cx_strtod(str, output) cx_strtod_lc(str, output, '.', ",") |
1546 #define cx_strtod(str, output) cx_strtod_lc(str, output, '.', ",") |
| 1540 |
1547 |
| 1541 #endif |
1548 #endif |
| 1542 |
1549 |