src/cx/string.h

changeset 1043
256ea5a36b5a
parent 1040
1ecf4dbbc60c
child 1044
776001e4cc96
--- a/src/cx/string.h	Sun Dec 22 11:14:05 2024 +0100
+++ b/src/cx/string.h	Sun Dec 22 11:34:05 2024 +0100
@@ -1115,6 +1115,76 @@
         size_t count
 );
 
+/* ------------------------------------------------------------------------- *
+ *                string to number conversion functions                      *
+ * ------------------------------------------------------------------------- */
+
+
+int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep);
+int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep);
+int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep);
+int cx_strtoll_lc(cxstring str, long int *output, int base, const char *groupsep);
+int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep);
+int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep);
+int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep);
+int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep);
+int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep);
+int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep);
+int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep);
+int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep);
+int cx_strtoull_lc(cxstring str, unsigned long int *output, int base, const char *groupsep);
+int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep);
+int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep);
+int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep);
+int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep);
+int cx_strtouz_lc(cxstring str, size_t *output, int base, const char *groupsep);
+
+#define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc(cx_strcast(str), output, base, groupsep)
+#define cx_strtouz_lc(str, output, base, groupsep) cx_strtouz_lc(cx_strcast(str), output, base, groupsep)
+
+#define cx_strtos(str, output, base) cx_strtos_lc(str, output, base, ",")
+#define cx_strtoi(str, output, base) cx_strtoi_lc(str, output, base, ",")
+#define cx_strtol(str, output, base) cx_strtol_lc(str, output, base, ",")
+#define cx_strtoll(str, output, base) cx_strtoll_lc(str, output, base, ",")
+#define cx_strtoi8(str, output, base) cx_strtoi8_lc(str, output, base, ",")
+#define cx_strtoi16(str, output, base) cx_strtoi16_lc(str, output, base, ",")
+#define cx_strtoi32(str, output, base) cx_strtoi32_lc(str, output, base, ",")
+#define cx_strtoi64(str, output, base) cx_strtoi64_lc(str, output, base, ",")
+#define cx_strtoz(str, output, base) cx_strtoz_lc(str, output, base, ",")
+#define cx_strtous(str, output, base) cx_strtous_lc(str, output, base, ",")
+#define cx_strtou(str, output, base) cx_strtou_lc(str, output, base, ",")
+#define cx_strtoul(str, output, base) cx_strtoul_lc(str, output, base, ",")
+#define cx_strtoull(str, output, base) cx_strtoull_lc(str, output, base, ",")
+#define cx_strtou8(str, output, base) cx_strtou8_lc(str, output, base, ",")
+#define cx_strtou16(str, output, base) cx_strtou16_lc(str, output, base, ",")
+#define cx_strtou32(str, output, base) cx_strtou32_lc(str, output, base, ",")
+#define cx_strtou64(str, output, base) cx_strtou64_lc(str, output, base, ",")
+#define cx_strtouz(str, output, base) cx_strtouz_lc(str, output, base, ",")
+
+int cx_strtof_lc(cxstring str, float *output, char decsep, const char *groupsep);
+int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep);
+
+#define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc(cx_strcast(str), output, decsep, groupsep)
+#define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc(cx_strcast(str), output, decsep, groupsep)
+
+#define cx_strtof(str, output) cx_strtof_lc(str, output, '.', ",")
+#define cx_strtod(str, output) cx_strtod_lc(str, output, '.', ",")
 
 #ifdef __cplusplus
 } // extern "C"

mercurial