Polish JSON classes

pull/33545/head
Moritz Halbritter 2 years ago
parent 08659baeba
commit b132b5c317

@ -321,40 +321,20 @@ public class JSONStringer {
* reverse solidus, and the control characters (U+0000 through U+001F)." * reverse solidus, and the control characters (U+0000 through U+001F)."
*/ */
switch (c) { switch (c) {
case '"': case '"', '\\', '/' -> this.out.append('\\').append(c);
case '\\': case '\t' -> this.out.append("\\t");
case '/': case '\b' -> this.out.append("\\b");
this.out.append('\\').append(c); case '\n' -> this.out.append("\\n");
break; case '\r' -> this.out.append("\\r");
case '\f' -> this.out.append("\\f");
case '\t': default -> {
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:
if (c <= 0x1F) { if (c <= 0x1F) {
this.out.append(String.format("\\u%04x", (int) c)); this.out.append(String.format("\\u%04x", (int) c));
} }
else { else {
this.out.append(c); this.out.append(c);
} }
break; }
} }
} }
@ -367,9 +347,7 @@ public class JSONStringer {
} }
this.out.append("\n"); this.out.append("\n");
for (int i = 0; i < this.stack.size(); i++) { this.out.append(this.indent.repeat(this.stack.size()));
this.out.append(this.indent);
}
} }
/** /**

@ -100,8 +100,7 @@ public class JSONTokener {
case '[': case '[':
return readArray(); return readArray();
case '\'': case '\'', '"':
case '"':
return nextString((char) c); return nextString((char) c);
default: default:
@ -114,10 +113,7 @@ public class JSONTokener {
while (this.pos < this.in.length()) { while (this.pos < this.in.length()) {
int c = this.in.charAt(this.pos++); int c = this.in.charAt(this.pos++);
switch (c) { switch (c) {
case '\t': case '\t', ' ', '\n', '\r':
case ' ':
case '\n':
case '\r':
continue; continue;
case '/': case '/':
@ -262,9 +258,7 @@ public class JSONTokener {
case 'f': case 'f':
return '\f'; return '\f';
case '\'': case '\'', '"', '\\':
case '"':
case '\\':
default: default:
return escaped; return escaped;
} }
@ -398,8 +392,7 @@ public class JSONTokener {
switch (nextCleanInternal()) { switch (nextCleanInternal()) {
case '}': case '}':
return result; return result;
case ';': case ';', ',':
case ',':
continue; continue;
default: default:
throw syntaxError("Unterminated object"); throw syntaxError("Unterminated object");
@ -429,8 +422,7 @@ public class JSONTokener {
result.put(null); result.put(null);
} }
return result; return result;
case ',': case ',', ';':
case ';':
/* A separator without a value first means "null". */ /* A separator without a value first means "null". */
result.put(null); result.put(null);
hasTrailingSeparator = true; hasTrailingSeparator = true;
@ -444,8 +436,7 @@ public class JSONTokener {
switch (nextCleanInternal()) { switch (nextCleanInternal()) {
case ']': case ']':
return result; return result;
case ',': case ',', ';':
case ';':
hasTrailingSeparator = true; hasTrailingSeparator = true;
continue; continue;
default: default:

Loading…
Cancel
Save