! @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 */
| 12189 | @throw parse_error.103 if to_unicode fails |
| 12190 | */ |
| 12191 | void parse(const bool strict, BasicJsonType& result) |
| 12192 | { |
| 12193 | if (callback) |
| 12194 | { |
| 12195 | json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions); |
| 12196 | sax_parse_internal(&sdp); |
| 12197 | |
| 12198 | // in strict mode, input must be completely read |
| 12199 | if (strict && (get_token() != token_type::end_of_input)) |
| 12200 | { |
| 12201 | sdp.parse_error(m_lexer.get_position(), |
| 12202 | m_lexer.get_token_string(), |
| 12203 | parse_error::create(101, m_lexer.get_position(), |
| 12204 | exception_message(token_type::end_of_input, "value"), nullptr)); |
| 12205 | } |
| 12206 | |
| 12207 | // in case of an error, return discarded value |
| 12208 | if (sdp.is_errored()) |
| 12209 | { |
| 12210 | result = value_t::discarded; |
| 12211 | return; |
| 12212 | } |
| 12213 | |
| 12214 | // set top-level value to null if it was discarded by the callback |
| 12215 | // function |
| 12216 | if (result.is_discarded()) |
| 12217 | { |
| 12218 | result = nullptr; |
| 12219 | } |
| 12220 | } |
| 12221 | else |
| 12222 | { |
| 12223 | json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions); |
| 12224 | sax_parse_internal(&sdp); |
| 12225 | |
| 12226 | // in strict mode, input must be completely read |
| 12227 | if (strict && (get_token() != token_type::end_of_input)) |
| 12228 | { |
| 12229 | sdp.parse_error(m_lexer.get_position(), |
| 12230 | m_lexer.get_token_string(), |
| 12231 | parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr)); |
| 12232 | } |
| 12233 | |
| 12234 | // in case of an error, return discarded value |
| 12235 | if (sdp.is_errored()) |
| 12236 | { |
| 12237 | result = value_t::discarded; |
| 12238 | return; |
| 12239 | } |
| 12240 | } |
| 12241 | |
| 12242 | result.assert_invariant(); |
| 12243 | } |
| 12244 | |
| 12245 | /*! |
| 12246 | @brief public accept interface |
no test coverage detected