Polish contribution and related code

This commit is contained in:
Sam Brannen
2023-01-11 13:50:46 +01:00
parent afb8a0d1b1
commit 0415975dd1
13 changed files with 240 additions and 330 deletions

View File

@@ -153,26 +153,25 @@ class BasicJsonWriter {
private static String escape(CharSequence input) {
StringBuilder builder = new StringBuilder();
input.chars().forEach(c -> builder.append(
switch (c) {
case '"' -> "\\\"";
case '\\' -> "\\\\";
case '/' -> "\\/";
case '\b' -> "\\b";
case '\f' -> "\\f";
case '\n' -> "\\n";
case '\r' -> "\\r";
case '\t' -> "\\t";
default -> {
if (c <= 0x1F) {
yield String.format("\\u%04x", c);
}
else {
yield (char) c;
}
}
}
)
);
switch (c) {
case '"' -> "\\\"";
case '\\' -> "\\\\";
case '/' -> "\\/";
case '\b' -> "\\b";
case '\f' -> "\\f";
case '\n' -> "\\n";
case '\r' -> "\\r";
case '\t' -> "\\t";
default -> {
if (c <= 0x1F) {
yield String.format("\\u%04x", c);
}
else {
yield (char) c;
}
}
}
));
return builder.toString();
}