roll own ISDIGIT() macro instead of ctype isdigit() - 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 55e9552c536fcb18f28d6742cfbec3ae10766473
(DIR) parent 1f9c82d7086b221cb7a16cb41c3f870f8b08a552
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
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(-)
---
(DIR) 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' < 6)
(DIR) 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)) {