From ddc811b63da0e52efb245b2415f32b661c49f01f Mon Sep 17 00:00:00 2001 From: Craig Everett Date: Sun, 23 Aug 2026 10:50:04 +0900 Subject: [PATCH] WIP: fixed Character.isDigit() issue by making my own isDigit() --- .../swiss/qpq/gajumaru/core/encoding/ZJ.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/swiss/qpq/gajumaru/core/encoding/ZJ.java b/src/main/java/swiss/qpq/gajumaru/core/encoding/ZJ.java index 9072abe..9b55bf0 100644 --- a/src/main/java/swiss/qpq/gajumaru/core/encoding/ZJ.java +++ b/src/main/java/swiss/qpq/gajumaru/core/encoding/ZJ.java @@ -276,7 +276,7 @@ public final class ZJ { pos++; } else if (c >= '1' && c <= '9') { pos++; - while (pos < json.length() && Character.isDigit(json.charAt(pos))) pos++; + while (pos < json.length() && isDigit(json.charAt(pos))) pos++; } else { throw new ParseException("Expected digit", pos); } @@ -285,20 +285,20 @@ public final class ZJ { if (pos < json.length() && json.charAt(pos) == '.') { isDecimal = true; pos++; - if (pos >= json.length() || !Character.isDigit(json.charAt(pos))) { + if (pos >= json.length() || !isDigit(json.charAt(pos))) { throw new ParseException("Expected digit after '.'", pos); } - while (pos < json.length() && Character.isDigit(json.charAt(pos))) pos++; + while (pos < json.length() && isDigit(json.charAt(pos))) pos++; } if (pos < json.length() && (json.charAt(pos) == 'e' || json.charAt(pos) == 'E')) { isDecimal = true; pos++; if (pos < json.length() && (json.charAt(pos) == '+' || json.charAt(pos) == '-')) pos++; - if (pos >= json.length() || !Character.isDigit(json.charAt(pos))) { + if (pos >= json.length() || !isDigit(json.charAt(pos))) { throw new ParseException("Expected digit in exponent", pos); } - while (pos < json.length() && Character.isDigit(json.charAt(pos))) pos++; + while (pos < json.length() && isDigit(json.charAt(pos))) pos++; } String s = json.substring(start, pos); @@ -313,5 +313,12 @@ public final class ZJ { private void seek() { while (pos < json.length() && Character.isWhitespace(json.charAt(pos))) pos++; } + + // This is a nitpick but it turns out that Character.isDigit() accepts a bunch of possible + // unicode digits as well as ASCII '0' through '9'. That's normally good, but not for + // parsing JSON! + private static boolean isDigit(char c) { + return c >= '0' && c <= '9'; + } } }