src/string.c

changeset 1134
60edcd57d54c
parent 1132
b7fea9b2874c
--- a/src/string.c	Sat Jan 18 14:07:52 2025 +0100
+++ b/src/string.c	Sat Jan 18 14:10:51 2025 +0100
@@ -25,7 +25,6 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-#define CX_STR_IMPLEMENTATION
 #include "cx/string.h"
 
 #include <string.h>
@@ -511,7 +510,7 @@
     return cx_strcasecmp(*left, *right);
 }
 
-cxmutstr cx_strdup_a(
+cxmutstr cx_strdup_a_(
         const CxAllocator *allocator,
         cxstring string
 ) {
@@ -743,7 +742,7 @@
     return result;
 }
 
-CxStrtokCtx cx_strtok(
+CxStrtokCtx cx_strtok_(
         cxstring str,
         cxstring delim,
         size_t limit
@@ -832,19 +831,19 @@
     *output = (rtype) result; \
     return 0
 
-int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep) {
+int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(short, SHRT_MIN, SHRT_MAX);
 }
 
-int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep) {
+int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(int, INT_MIN, INT_MAX);
 }
 
-int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep) {
+int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(long, LONG_MIN, LONG_MAX);
 }
 
-int cx_strtoll_lc(cxstring str, long long *output, int base, const char *groupsep) {
+int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep) {
     // strategy: parse as unsigned, check range, negate if required
     bool neg = false;
     size_t start_unsigned = 0;
@@ -890,28 +889,28 @@
     }
 }
 
-int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep) {
+int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(int8_t, INT8_MIN, INT8_MAX);
 }
 
-int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep) {
+int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(int16_t, INT16_MIN, INT16_MAX);
 }
 
-int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep) {
+int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(int32_t, INT32_MIN, INT32_MAX);
 }
 
-int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep) {
+int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep) {
     assert(sizeof(long long) == sizeof(int64_t)); // should be true on all platforms
     return cx_strtoll_lc(str, (long long*) output, base, groupsep);
 }
 
-int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep) {
+int cx_strtoz_lc_(cxstring str, ssize_t *output, int base, const char *groupsep) {
 #if SSIZE_MAX == INT32_MAX
-    return cx_strtoi32_lc(str, (int32_t*) output, base, groupsep);
+    return cx_strtoi32_lc_(str, (int32_t*) output, base, groupsep);
 #elif SSIZE_MAX == INT64_MAX
-    return cx_strtoll_lc(str, (long long*) output, base, groupsep);
+    return cx_strtoll_lc_(str, (long long*) output, base, groupsep);
 #else
 #error "unsupported ssize_t size"
 #endif
@@ -929,19 +928,19 @@
     *output = (rtype) result; \
     return 0
 
-int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep) {
+int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(unsigned short, USHRT_MAX);
 }
 
-int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep) {
+int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(unsigned int, UINT_MAX);
 }
 
-int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep) {
+int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(unsigned long, ULONG_MAX);
 }
 
-int cx_strtoull_lc(cxstring str, unsigned long long *output, int base, const char *groupsep) {
+int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep) {
     // some sanity checks
     str = cx_strtrim(str);
     if (str.length == 0) {
@@ -1021,37 +1020,37 @@
     return 0;
 }
 
-int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep) {
+int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(uint8_t, UINT8_MAX);
 }
 
-int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep) {
+int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(uint16_t, UINT16_MAX);
 }
 
-int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep) {
+int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(uint32_t, UINT32_MAX);
 }
 
-int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep) {
+int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep) {
     assert(sizeof(unsigned long long) == sizeof(uint64_t)); // should be true on all platforms
     return cx_strtoull_lc(str, (unsigned long long*) output, base, groupsep);
 }
 
-int cx_strtouz_lc(cxstring str, size_t *output, int base, const char *groupsep) {
+int cx_strtouz_lc_(cxstring str, size_t *output, int base, const char *groupsep) {
 #if SIZE_MAX == UINT32_MAX
-    return cx_strtou32_lc(str, (uint32_t*) output, base, groupsep);
+    return cx_strtou32_lc_(str, (uint32_t*) output, base, groupsep);
 #elif SIZE_MAX == UINT64_MAX
-    return cx_strtoull_lc(str, (unsigned long long *) output, base, groupsep);
+    return cx_strtoull_lc_(str, (unsigned long long *) output, base, groupsep);
 #else
 #error "unsupported size_t size"
 #endif
 }
 
-int cx_strtof_lc(cxstring str, float *output, char decsep, const char *groupsep) {
+int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep) {
     // use string to double and add a range check
     double d;
-    int ret = cx_strtod_lc(str, &d, decsep, groupsep);
+    int ret = cx_strtod_lc_(str, &d, decsep, groupsep);
     if (ret != 0) return ret;
     // note: FLT_MIN is the smallest POSITIVE number that can be represented
     double test = d < 0 ? -d : d;
@@ -1068,7 +1067,7 @@
     return c >= '0' && c <= '9';
 }
 
-int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep) {
+int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep) {
     // TODO: overflow check
     // TODO: increase precision
 

mercurial