MCPcopy Create free account
hub / github.com/LAStools/LAStools / sax_parse_internal

Method sax_parse_internal

src/json.hpp:12352–12642  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12350 template<typename SAX>
12351 JSON_HEDLEY_NON_NULL(2)
12352 bool sax_parse_internal(SAX* sax)
12353 {
12354 // stack to remember the hierarchy of structured values we are parsing
12355 // true = array; false = object
12356 std::vector<bool> states;
12357 // value to avoid a goto (see comment where set to true)
12358 bool skip_to_state_evaluation = false;
12359
12360 while (true)
12361 {
12362 if (!skip_to_state_evaluation)
12363 {
12364 // invariant: get_token() was called before each iteration
12365 switch (last_token)
12366 {
12367 case token_type::begin_object:
12368 {
12369 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))
12370 {
12371 return false;
12372 }
12373
12374 // closing } -> we are done
12375 if (get_token() == token_type::end_object)
12376 {
12377 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
12378 {
12379 return false;
12380 }
12381 break;
12382 }
12383
12384 // parse key
12385 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
12386 {
12387 return sax->parse_error(m_lexer.get_position(),
12388 m_lexer.get_token_string(),
12389 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr));
12390 }
12391 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
12392 {
12393 return false;
12394 }
12395
12396 // parse separator (:)
12397 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
12398 {
12399 return sax->parse_error(m_lexer.get_position(),
12400 m_lexer.get_token_string(),
12401 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr));
12402 }
12403
12404 // remember we are now inside an object
12405 states.push_back(false);
12406
12407 // parse values
12408 get_token();
12409 continue;

Callers

nothing calls this directly

Calls 15

createFunction · 0.85
concatFunction · 0.85
get_token_stringMethod · 0.80
get_stringMethod · 0.80
emptyMethod · 0.80
start_objectMethod · 0.45
end_objectMethod · 0.45
parse_errorMethod · 0.45
keyMethod · 0.45
start_arrayMethod · 0.45
end_arrayMethod · 0.45
number_floatMethod · 0.45

Tested by

no test coverage detected