do not depend on C library locale for ctype functions/macros - json2tsv - JSON to TSV converter
 (HTM) git clone git://git.codemadness.org/json2tsv
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 47732754f1217ac0808253b8c531428d82ec3a18
 (DIR) parent 1ebc23030bb37e0f9399328ec3a6968e35758351
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Tue, 29 Mar 2022 23:50:44 +0200
       
       do not depend on C library locale for ctype functions/macros
       
       Diffstat:
         M json.c                              |      10 ++++++----
       
       1 file changed, 6 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/json.c b/json.c
       @@ -1,4 +1,3 @@
       -#include <ctype.h>
        #include <errno.h>
        #include <stdint.h>
        #include <stdio.h>
       @@ -11,6 +10,9 @@
        
        #include "json.h"
        
       +#define ISDIGIT(c) (((unsigned)c) - '0' < 10)
       +#define ISXDIGIT(c) ((((unsigned)c) - '0' < 10) || ((unsigned)c | 32) - 'a' < 6)
       +
        static int
        codepointtoutf8(long r, char *s)
        {
       @@ -149,7 +151,7 @@ escchr:
                                                        if (capacity(&str, &sz, len, 4) == -1)
                                                                goto end;
                                                        for (i = 12, cp = 0; i >= 0; i -= 4) {
       -                                                        if ((c = GETNEXT()) == EOF || !isxdigit(c))
       +                                                        if ((c = GETNEXT()) == EOF || !ISXDIGIT(c))
                                                                        JSON_INVALID(); /* invalid code point */
                                                                cp |= (hexdigit(c) << i);
                                                        }
       @@ -165,7 +167,7 @@ escchr:
                                                                        goto escchr;
                                                                }
                                                                for (hi = cp, i = 12, lo = 0; i >= 0; i -= 4) {
       -                                                                if ((c = GETNEXT()) == EOF || !isxdigit(c))
       +                                                                if ((c = GETNEXT()) == EOF || !ISXDIGIT(c))
                                                                                JSON_INVALID(); /* invalid code point */
                                                                        lo |= (hexdigit(c) << i);
                                                                }
       @@ -292,7 +294,7 @@ escchr:
                                while (1) {
                                        c = GETNEXT();
                                        if (c == EOF ||
       -                                    (!isdigit(c) && c != 'e' && c != 'E' &&
       +                                    (!ISDIGIT(c) && c != 'e' && c != 'E' &&
                                             c != '+' && c != '-' && c != '.') ||
                                            p + 1 >= sizeof(pri)) {
                                                pri[p] = '\0';