Read the next element from the JSON input stream as a string, converting escaped characters. @return String object @throws JsonException if input stream ends without finding a closing quote @throws UncheckedIOException if an I/O exception is encountered
()
| 651 | * @throws UncheckedIOException if an I/O exception is encountered |
| 652 | */ |
| 653 | private String readString() { |
| 654 | input.read(); // Skip leading quote |
| 655 | |
| 656 | StringBuilder builder = new StringBuilder(); |
| 657 | while (true) { |
| 658 | int c = input.read(); |
| 659 | switch (c) { |
| 660 | case Input.EOF: |
| 661 | throw new JsonException("Unterminated string: " + builder + ". " + input); |
| 662 | case '"': // terminate string |
| 663 | return builder.toString(); |
| 664 | case '\\': // quoted char |
| 665 | readEscape(builder); |
| 666 | break; |
| 667 | default: |
| 668 | // RFC 8259 §7: characters U+0000..U+001F MUST be escaped. |
| 669 | if (c < 0x20) { |
| 670 | throw new JsonException( |
| 671 | String.format( |
| 672 | "Illegal unescaped control character U+%04X in string. %s", c, input)); |
| 673 | } |
| 674 | builder.append((char) c); |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * Convert the escape sequence at the current JSON input stream position, appending the result to |