src/json.c

changeset 1415
40074e643663
parent 1340
31c61b6dcaa5
--- a/src/json.c	Thu Oct 02 21:31:52 2025 +0200
+++ b/src/json.c	Fri Oct 03 18:58:44 2025 +0200
@@ -32,6 +32,7 @@
 #include <assert.h>
 #include <stdio.h>
 #include <inttypes.h>
+#include <ctype.h>
 
 /*
  * RFC 8259
@@ -127,16 +128,6 @@
     }
 }
 
-static bool json_isdigit(char c) {
-    // TODO: remove once UCX has public API for this
-    return c >= '0' && c <= '9';
-}
-
-static bool json_isspace(char c) {
-    // TODO: remove once UCX has public API for this
-    return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v' || c == '\f';
-}
-
 static int num_isexp(const char *content, size_t length, size_t pos) {
     if (pos >= length) {
         return 0;
@@ -145,7 +136,7 @@
     int ok = 0;
     for (size_t i = pos; i < length; i++) {
         char c = content[i];
-        if (json_isdigit(c)) {
+        if (isdigit((unsigned char)c)) {
             ok = 1;
         } else if (i == pos) {
             if (!(c == '+' || c == '-')) {
@@ -162,7 +153,7 @@
 static CxJsonTokenType token_numbertype(const char *content, size_t length) {
     if (length == 0) return CX_JSON_TOKEN_ERROR;
 
-    if (content[0] != '-' && !json_isdigit(content[0])) {
+    if (content[0] != '-' && !isdigit((unsigned char)content[0])) {
         return CX_JSON_TOKEN_ERROR;
     }
 
@@ -175,7 +166,7 @@
             type = CX_JSON_TOKEN_NUMBER;
         } else if (content[i] == 'e' || content[i] == 'E') {
             return num_isexp(content, length, i + 1) ? CX_JSON_TOKEN_NUMBER : CX_JSON_TOKEN_ERROR;
-        } else if (!json_isdigit(content[i])) {
+        } else if (!isdigit((unsigned char)content[i])) {
             return CX_JSON_TOKEN_ERROR; // char is not a digit, decimal separator or exponent sep
         }
     }
@@ -239,7 +230,7 @@
             return CX_JSON_TOKEN_STRING;
         }
         default: {
-            if (json_isspace(c)) {
+            if (isspace((unsigned char)c)) {
                 return CX_JSON_TOKEN_SPACE;
             }
         }

mercurial