WIP: fixed Character.isDigit() issue by making my own isDigit()
This commit is contained in:
@@ -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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user