roll own ISDIGIT() macro instead of ctype isdigit() - json2tsv - JSON to TSV co… | |
git clone git://git.codemadness.org/json2tsv | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 55e9552c536fcb18f28d6742cfbec3ae10766473 | |
parent 1f9c82d7086b221cb7a16cb41c3f870f8b08a552 | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Tue, 4 Apr 2023 18:08:05 +0200 | |
roll own ISDIGIT() macro instead of ctype isdigit() | |
This ensures portable and consistent behaviour of checking a digit character. | |
Diffstat: | |
M json.c | 1 + | |
M json2tsv.c | 6 +++--- | |
2 files changed, 4 insertions(+), 3 deletions(-) | |
--- | |
diff --git a/json.c b/json.c | |
@@ -10,6 +10,7 @@ | |
#include "json.h" | |
+/* ctype-like macros, but always compatible with ASCII / UTF-8 */ | |
#define ISDIGIT(c) (((unsigned)c) - '0' < 10) | |
#define ISXDIGIT(c) ((((unsigned)c) - '0' < 10) || ((unsigned)c | 32) - 'a' < … | |
diff --git a/json2tsv.c b/json2tsv.c | |
@@ -1,4 +1,3 @@ | |
-#include <ctype.h> | |
#include <errno.h> | |
#include <limits.h> | |
#include <stdint.h> | |
@@ -14,7 +13,8 @@ | |
#include "json.h" | |
-/* control-character in the ASCII range 0-127: compatible with UTF-8 */ | |
+/* ctype-like macros, but always compatible with ASCII / UTF-8 */ | |
+#define ISDIGIT(c) (((unsigned)c) - '0' < 10) | |
#define ISCNTRL(c) ((c) < ' ' || (c) == 0x7f) | |
static int nflag = 0; /* -n flag: show indices count for arrays */ | |
@@ -148,7 +148,7 @@ readchar(const char *s) | |
s++; | |
if (*s == 'x') | |
return readnum(++s, 16); /* hexadecimal */ | |
- else if (isdigit((unsigned char)*s)) | |
+ else if (ISDIGIT((unsigned char)*s)) | |
return readnum(s, 8); /* octal */ | |
if (*(s + 1)) { |