| 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; |
nothing calls this directly
no test coverage detected