MCPcopy Create free account
hub / github.com/arun11299/cpp-jwt / parse

Method parse

include/jwt/json/json.hpp:10196–10249  ·  view source on GitHub ↗

! @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 */

Source from the content-addressed store, hash-verified

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

Callers 3

json.hppFile · 0.80
basic_json parseFunction · 0.80
parseFunction · 0.80

Calls 4

createFunction · 0.85
get_token_stringMethod · 0.80
parse_errorMethod · 0.45
is_erroredMethod · 0.45

Tested by

no test coverage detected