WIP: fixed Character.isDigit() issue by making my own isDigit()

This commit is contained in:
2026-08-23 10:50:04 +09:00
parent c21f399b69
commit ddc811b63d
@@ -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';
}
}
}