Polish JSON classes
This commit is contained in:
parent
08659baeba
commit
b132b5c317
|
|
@ -321,40 +321,20 @@ public class JSONStringer {
|
|||
* reverse solidus, and the control characters (U+0000 through U+001F)."
|
||||
*/
|
||||
switch (c) {
|
||||
case '"':
|
||||
case '\\':
|
||||
case '/':
|
||||
this.out.append('\\').append(c);
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
this.out.append("\\t");
|
||||
break;
|
||||
|
||||
case '\b':
|
||||
this.out.append("\\b");
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
this.out.append("\\n");
|
||||
break;
|
||||
|
||||
case '\r':
|
||||
this.out.append("\\r");
|
||||
break;
|
||||
|
||||
case '\f':
|
||||
this.out.append("\\f");
|
||||
break;
|
||||
|
||||
default:
|
||||
case '"', '\\', '/' -> this.out.append('\\').append(c);
|
||||
case '\t' -> this.out.append("\\t");
|
||||
case '\b' -> this.out.append("\\b");
|
||||
case '\n' -> this.out.append("\\n");
|
||||
case '\r' -> this.out.append("\\r");
|
||||
case '\f' -> this.out.append("\\f");
|
||||
default -> {
|
||||
if (c <= 0x1F) {
|
||||
this.out.append(String.format("\\u%04x", (int) c));
|
||||
}
|
||||
else {
|
||||
this.out.append(c);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -367,9 +347,7 @@ public class JSONStringer {
|
|||
}
|
||||
|
||||
this.out.append("\n");
|
||||
for (int i = 0; i < this.stack.size(); i++) {
|
||||
this.out.append(this.indent);
|
||||
}
|
||||
this.out.append(this.indent.repeat(this.stack.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -100,8 +100,7 @@ public class JSONTokener {
|
|||
case '[':
|
||||
return readArray();
|
||||
|
||||
case '\'':
|
||||
case '"':
|
||||
case '\'', '"':
|
||||
return nextString((char) c);
|
||||
|
||||
default:
|
||||
|
|
@ -114,10 +113,7 @@ public class JSONTokener {
|
|||
while (this.pos < this.in.length()) {
|
||||
int c = this.in.charAt(this.pos++);
|
||||
switch (c) {
|
||||
case '\t':
|
||||
case ' ':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t', ' ', '\n', '\r':
|
||||
continue;
|
||||
|
||||
case '/':
|
||||
|
|
@ -262,9 +258,7 @@ public class JSONTokener {
|
|||
case 'f':
|
||||
return '\f';
|
||||
|
||||
case '\'':
|
||||
case '"':
|
||||
case '\\':
|
||||
case '\'', '"', '\\':
|
||||
default:
|
||||
return escaped;
|
||||
}
|
||||
|
|
@ -398,8 +392,7 @@ public class JSONTokener {
|
|||
switch (nextCleanInternal()) {
|
||||
case '}':
|
||||
return result;
|
||||
case ';':
|
||||
case ',':
|
||||
case ';', ',':
|
||||
continue;
|
||||
default:
|
||||
throw syntaxError("Unterminated object");
|
||||
|
|
@ -429,8 +422,7 @@ public class JSONTokener {
|
|||
result.put(null);
|
||||
}
|
||||
return result;
|
||||
case ',':
|
||||
case ';':
|
||||
case ',', ';':
|
||||
/* A separator without a value first means "null". */
|
||||
result.put(null);
|
||||
hasTrailingSeparator = true;
|
||||
|
|
@ -444,8 +436,7 @@ public class JSONTokener {
|
|||
switch (nextCleanInternal()) {
|
||||
case ']':
|
||||
return result;
|
||||
case ',':
|
||||
case ';':
|
||||
case ',', ';':
|
||||
hasTrailingSeparator = true;
|
||||
continue;
|
||||
default:
|
||||
|
|
|
|||
Loading…
Reference in New Issue