Skip to content

Commit e2fe14d

Browse files
author
rikkarth
committed
fix(stleary#871-strictMode): replaced stream with conventional loop for 1.6 compatibility
1 parent 0ff368c commit e2fe14d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/main/java/org/json/JSONTokener.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public String nextTo(char delimiter) throws JSONException {
396396
public String nextTo(String delimiters) throws JSONException {
397397
char c;
398398
StringBuilder sb = new StringBuilder();
399-
for (;;) {
399+
for (; ; ) {
400400
c = this.next();
401401
if (delimiters.indexOf(c) >= 0 || c == 0 ||
402402
c == '\n' || c == '\r') {
@@ -457,9 +457,9 @@ private Object getValue(char c, boolean strictMode) {
457457
if (strictMode) {
458458
Object valueToValidate = nextSimpleValue(c, true);
459459

460-
boolean isNumeric = valueToValidate.toString().chars().allMatch( Character::isDigit );
460+
boolean isNumeric = checkIfValueIsNumeric(valueToValidate);
461461

462-
if(isNumeric){
462+
if (isNumeric) {
463463
return valueToValidate;
464464
}
465465

@@ -475,6 +475,15 @@ private Object getValue(char c, boolean strictMode) {
475475
return nextSimpleValue(c);
476476
}
477477

478+
private boolean checkIfValueIsNumeric(Object valueToValidate) {
479+
for (char c : valueToValidate.toString().toCharArray()) {
480+
if (!Character.isDigit(c)) {
481+
return false;
482+
}
483+
}
484+
return true;
485+
}
486+
478487
/**
479488
* This method is used to get a JSONObject from the JSONTokener. The strictMode parameter controls the behavior of
480489
* the method when parsing the JSONObject.

0 commit comments

Comments
 (0)