| 829 | |
| 830 | template <typename Vector, typename ReturnType> |
| 831 | ReturnType readJSONStringInto(Vector & s, ReadBuffer & buf) |
| 832 | { |
| 833 | static constexpr bool throw_exception = std::is_same_v<ReturnType, void>; |
| 834 | |
| 835 | auto error = [](const char * message [[maybe_unused]], int code [[maybe_unused]]) |
| 836 | { |
| 837 | if constexpr (throw_exception) |
| 838 | throw ParsingException(message, code); |
| 839 | return ReturnType(false); |
| 840 | }; |
| 841 | |
| 842 | if (buf.eof() || *buf.position() != '"') |
| 843 | return error("Cannot parse JSON string: expected opening quote", ErrorCodes::CANNOT_PARSE_QUOTED_STRING); |
| 844 | ++buf.position(); |
| 845 | |
| 846 | while (!buf.eof()) |
| 847 | { |
| 848 | char * next_pos = find_first_symbols<'\\', '"'>(buf.position(), buf.buffer().end()); |
| 849 | |
| 850 | appendToStringOrVector(s, buf, next_pos); |
| 851 | buf.position() = next_pos; |
| 852 | |
| 853 | if (!buf.hasPendingData()) |
| 854 | continue; |
| 855 | |
| 856 | if (*buf.position() == '"') |
| 857 | { |
| 858 | ++buf.position(); |
| 859 | return ReturnType(true); |
| 860 | } |
| 861 | |
| 862 | if (*buf.position() == '\\') |
| 863 | parseJSONEscapeSequence<Vector, ReturnType>(s, buf); |
| 864 | } |
| 865 | |
| 866 | return error("Cannot parse JSON string: expected closing quote", ErrorCodes::CANNOT_PARSE_QUOTED_STRING); |
| 867 | } |
| 868 | |
| 869 | void readJSONString(String & s, ReadBuffer & buf) |
| 870 | { |
no test coverage detected