! @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 */
| 10263 | @throw parse_error.103 if to_unicode fails |
| 10264 | */ |
| 10265 | void parse(const bool strict, BasicJsonType& result) |
| 10266 | { |
| 10267 | if (callback) |
| 10268 | { |
| 10269 | json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions); |
| 10270 | sax_parse_internal(&sdp); |
| 10271 | result.assert_invariant(); |
| 10272 | |
| 10273 | // in strict mode, input must be completely read |
| 10274 | if (strict && (get_token() != token_type::end_of_input)) |
| 10275 | { |
| 10276 | sdp.parse_error(m_lexer.get_position(), |
| 10277 | m_lexer.get_token_string(), |
| 10278 | parse_error::create(101, m_lexer.get_position(), |
| 10279 | exception_message(token_type::end_of_input, "value"))); |
| 10280 | } |
| 10281 | |
| 10282 | // in case of an error, return discarded value |
| 10283 | if (sdp.is_errored()) |
| 10284 | { |
| 10285 | result = value_t::discarded; |
| 10286 | return; |
| 10287 | } |
| 10288 | |
| 10289 | // set top-level value to null if it was discarded by the callback |
| 10290 | // function |
| 10291 | if (result.is_discarded()) |
| 10292 | { |
| 10293 | result = nullptr; |
| 10294 | } |
| 10295 | } |
| 10296 | else |
| 10297 | { |
| 10298 | json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions); |
| 10299 | sax_parse_internal(&sdp); |
| 10300 | result.assert_invariant(); |
| 10301 | |
| 10302 | // in strict mode, input must be completely read |
| 10303 | if (strict && (get_token() != token_type::end_of_input)) |
| 10304 | { |
| 10305 | sdp.parse_error(m_lexer.get_position(), |
| 10306 | m_lexer.get_token_string(), |
| 10307 | parse_error::create(101, m_lexer.get_position(), |
| 10308 | exception_message(token_type::end_of_input, "value"))); |
| 10309 | } |
| 10310 | |
| 10311 | // in case of an error, return discarded value |
| 10312 | if (sdp.is_errored()) |
| 10313 | { |
| 10314 | result = value_t::discarded; |
| 10315 | return; |
| 10316 | } |
| 10317 | } |
| 10318 | } |
| 10319 | |
| 10320 | /*! |
| 10321 | @brief public accept interface |
no test coverage detected