| 10352 | template<typename SAX> |
| 10353 | JSON_HEDLEY_NON_NULL(2) |
| 10354 | bool sax_parse_internal(SAX* sax) |
| 10355 | { |
| 10356 | // stack to remember the hierarchy of structured values we are parsing |
| 10357 | // true = array; false = object |
| 10358 | std::vector<bool> states; |
| 10359 | // value to avoid a goto (see comment where set to true) |
| 10360 | bool skip_to_state_evaluation = false; |
| 10361 | |
| 10362 | while (true) |
| 10363 | { |
| 10364 | if (!skip_to_state_evaluation) |
| 10365 | { |
| 10366 | // invariant: get_token() was called before each iteration |
| 10367 | switch (last_token) |
| 10368 | { |
| 10369 | case token_type::begin_object: |
| 10370 | { |
| 10371 | if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1)))) |
| 10372 | { |
| 10373 | return false; |
| 10374 | } |
| 10375 | |
| 10376 | // closing } -> we are done |
| 10377 | if (get_token() == token_type::end_object) |
| 10378 | { |
| 10379 | if (JSON_HEDLEY_UNLIKELY(!sax->end_object())) |
| 10380 | { |
| 10381 | return false; |
| 10382 | } |
| 10383 | break; |
| 10384 | } |
| 10385 | |
| 10386 | // parse key |
| 10387 | if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string)) |
| 10388 | { |
| 10389 | return sax->parse_error(m_lexer.get_position(), |
| 10390 | m_lexer.get_token_string(), |
| 10391 | parse_error::create(101, m_lexer.get_position(), |
| 10392 | exception_message(token_type::value_string, "object key"))); |
| 10393 | } |
| 10394 | if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) |
| 10395 | { |
| 10396 | return false; |
| 10397 | } |
| 10398 | |
| 10399 | // parse separator (:) |
| 10400 | if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) |
| 10401 | { |
| 10402 | return sax->parse_error(m_lexer.get_position(), |
| 10403 | m_lexer.get_token_string(), |
| 10404 | parse_error::create(101, m_lexer.get_position(), |
| 10405 | exception_message(token_type::name_separator, "object separator"))); |
| 10406 | } |
| 10407 | |
| 10408 | // remember we are now inside an object |
| 10409 | states.push_back(false); |
| 10410 | |
| 10411 | // parse values |
nothing calls this directly
no test coverage detected