| 12276 | template<typename SAX> |
| 12277 | JSON_HEDLEY_NON_NULL(2) |
| 12278 | bool sax_parse_internal(SAX* sax) |
| 12279 | { |
| 12280 | // stack to remember the hierarchy of structured values we are parsing |
| 12281 | // true = array; false = object |
| 12282 | std::vector<bool> states; |
| 12283 | // value to avoid a goto (see comment where set to true) |
| 12284 | bool skip_to_state_evaluation = false; |
| 12285 | |
| 12286 | while (true) |
| 12287 | { |
| 12288 | if (!skip_to_state_evaluation) |
| 12289 | { |
| 12290 | // invariant: get_token() was called before each iteration |
| 12291 | switch (last_token) |
| 12292 | { |
| 12293 | case token_type::begin_object: |
| 12294 | { |
| 12295 | if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1)))) |
| 12296 | { |
| 12297 | return false; |
| 12298 | } |
| 12299 | |
| 12300 | // closing } -> we are done |
| 12301 | if (get_token() == token_type::end_object) |
| 12302 | { |
| 12303 | if (JSON_HEDLEY_UNLIKELY(!sax->end_object())) |
| 12304 | { |
| 12305 | return false; |
| 12306 | } |
| 12307 | break; |
| 12308 | } |
| 12309 | |
| 12310 | // parse key |
| 12311 | if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string)) |
| 12312 | { |
| 12313 | return sax->parse_error(m_lexer.get_position(), |
| 12314 | m_lexer.get_token_string(), |
| 12315 | parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr)); |
| 12316 | } |
| 12317 | if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) |
| 12318 | { |
| 12319 | return false; |
| 12320 | } |
| 12321 | |
| 12322 | // parse separator (:) |
| 12323 | if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) |
| 12324 | { |
| 12325 | return sax->parse_error(m_lexer.get_position(), |
| 12326 | m_lexer.get_token_string(), |
| 12327 | parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr)); |
| 12328 | } |
| 12329 | |
| 12330 | // remember we are now inside an object |
| 12331 | states.push_back(false); |
| 12332 | |
| 12333 | // parse values |
| 12334 | get_token(); |
| 12335 | continue; |
nothing calls this directly
no test coverage detected