! @brief public parser interface @param[in] strict whether to expect the last token to be EOF @param[in,out] result parsed JSON value @throw parse_error.101 in case of an unexpected token @throw parse_error.102 if to_unicode fails or surrogate error @throw parse_error.103 if to_unicode fails */
| 10192 | @throw parse_error.103 if to_unicode fails |
| 10193 | */ |
| 10194 | void parse(const bool strict, BasicJsonType& result) |
| 10195 | { |
| 10196 | if (callback) |
| 10197 | { |
| 10198 | json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions); |
| 10199 | sax_parse_internal(&sdp); |
| 10200 | result.assert_invariant(); |
| 10201 | |
| 10202 | // in strict mode, input must be completely read |
| 10203 | if (strict && (get_token() != token_type::end_of_input)) |
| 10204 | { |
| 10205 | sdp.parse_error(m_lexer.get_position(), |
| 10206 | m_lexer.get_token_string(), |
| 10207 | parse_error::create(101, m_lexer.get_position(), |
| 10208 | exception_message(token_type::end_of_input, "value"))); |
| 10209 | } |
| 10210 | |
| 10211 | // in case of an error, return discarded value |
| 10212 | if (sdp.is_errored()) |
| 10213 | { |
| 10214 | result = value_t::discarded; |
| 10215 | return; |
| 10216 | } |
| 10217 | |
| 10218 | // set top-level value to null if it was discarded by the callback |
| 10219 | // function |
| 10220 | if (result.is_discarded()) |
| 10221 | { |
| 10222 | result = nullptr; |
| 10223 | } |
| 10224 | } |
| 10225 | else |
| 10226 | { |
| 10227 | json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions); |
| 10228 | sax_parse_internal(&sdp); |
| 10229 | result.assert_invariant(); |
| 10230 | |
| 10231 | // in strict mode, input must be completely read |
| 10232 | if (strict && (get_token() != token_type::end_of_input)) |
| 10233 | { |
| 10234 | sdp.parse_error(m_lexer.get_position(), |
| 10235 | m_lexer.get_token_string(), |
| 10236 | parse_error::create(101, m_lexer.get_position(), |
| 10237 | exception_message(token_type::end_of_input, "value"))); |
| 10238 | } |
| 10239 | |
| 10240 | // in case of an error, return discarded value |
| 10241 | if (sdp.is_errored()) |
| 10242 | { |
| 10243 | result = value_t::discarded; |
| 10244 | return; |
| 10245 | } |
| 10246 | } |
| 10247 | } |
| 10248 | |
| 10249 | /*! |
| 10250 | @brief public accept interface |
no test coverage detected