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
()
| 834 | * @throws UncheckedIOException if an I/O exception is encountered |
| 835 | */ |
| 836 | private String readString() { |
| 837 | input.read(); // Skip leading quote |
| 838 | |
| 839 | // Fast path: an escape-free string that is fully buffered needs no intermediate copies. |
| 840 | String simple = input.readSimpleString(); |
| 841 | if (simple != null) { |
| 842 | return simple; |
| 843 | } |
| 844 | |
| 845 | StringBuilder builder = new StringBuilder(); |
| 846 | while (true) { |
| 847 | int c = input.appendStringContent(builder); |
| 848 | switch (c) { |
| 849 | case Input.EOF: |
| 850 | throw new JsonException("Unterminated string: " + builder + ". " + input); |
| 851 | case '"': // terminate string |
| 852 | input.read(); |
| 853 | return builder.toString(); |
| 854 | case '\\': // quoted char |
| 855 | input.read(); |
| 856 | readEscape(builder); |
| 857 | break; |
| 858 | default: |
| 859 | // RFC 8259 §7: characters U+0000..U+001F MUST be escaped. |
| 860 | input.read(); |
| 861 | throw new JsonException( |
| 862 | String.format("Illegal unescaped control character U+%04X in string. %s", c, input)); |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | /** |
| 868 | * Convert the escape sequence at the current JSON input stream position, appending the result to |