MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / parse

Method parse

include/behaviortree_cpp/contrib/json.hpp:12261–12313  ·  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

12259 @throw parse_error.103 if to_unicode fails
12260 */
12261 void parse(const bool strict, BasicJsonType& result)
12262 {
12263 if (callback)
12264 {
12265 json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
12266 sax_parse_internal(&sdp);
12267
12268 // in strict mode, input must be completely read
12269 if (strict && (get_token() != token_type::end_of_input))
12270 {
12271 sdp.parse_error(m_lexer.get_position(),
12272 m_lexer.get_token_string(),
12273 parse_error::create(101, m_lexer.get_position(),
12274 exception_message(token_type::end_of_input, "value"), nullptr));
12275 }
12276
12277 // in case of an error, return discarded value
12278 if (sdp.is_errored())
12279 {
12280 result = value_t::discarded;
12281 return;
12282 }
12283
12284 // set top-level value to null if it was discarded by the callback
12285 // function
12286 if (result.is_discarded())
12287 {
12288 result = nullptr;
12289 }
12290 }
12291 else
12292 {
12293 json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
12294 sax_parse_internal(&sdp);
12295
12296 // in strict mode, input must be completely read
12297 if (strict && (get_token() != token_type::end_of_input))
12298 {
12299 sdp.parse_error(m_lexer.get_position(),
12300 m_lexer.get_token_string(),
12301 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr));
12302 }
12303
12304 // in case of an error, return discarded value
12305 if (sdp.is_errored())
12306 {
12307 result = value_t::discarded;
12308 return;
12309 }
12310 }
12311
12312 result.assert_invariant();
12313 }
12314
12315 /*!
12316 @brief public accept interface

Callers 4

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

Calls 4

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

Tested by

no test coverage detected