🔨 removed a logic error and improved coverage
This commit is contained in:
parent
922f7a3d0e
commit
8c7f46f7d0
4 changed files with 156 additions and 53 deletions
|
@ -594,7 +594,7 @@ class parser
|
|||
get_token();
|
||||
|
||||
// closing } -> we are done
|
||||
if (last_token == token_type::end_object)
|
||||
if (JSON_UNLIKELY(last_token == token_type::end_object))
|
||||
{
|
||||
return sax->end_object();
|
||||
}
|
||||
|
@ -603,7 +603,12 @@ class parser
|
|||
while (true)
|
||||
{
|
||||
// parse key
|
||||
if (last_token != token_type::value_string)
|
||||
if (JSON_UNLIKELY(last_token != token_type::value_string))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (not sax->key(m_lexer.move_string()))
|
||||
{
|
||||
|
@ -613,9 +618,10 @@ class parser
|
|||
|
||||
// parse separator (:)
|
||||
get_token();
|
||||
if (last_token != token_type::name_separator)
|
||||
if (JSON_UNLIKELY(last_token != token_type::name_separator))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(), m_lexer.get_token_string());
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string());
|
||||
}
|
||||
|
||||
// parse value
|
||||
|
@ -634,13 +640,14 @@ class parser
|
|||
}
|
||||
|
||||
// closing }
|
||||
if (last_token == token_type::end_object)
|
||||
if (JSON_LIKELY(last_token == token_type::end_object))
|
||||
{
|
||||
return sax->end_object();
|
||||
}
|
||||
else
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(), m_lexer.get_token_string());
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -679,13 +686,14 @@ class parser
|
|||
}
|
||||
|
||||
// closing ]
|
||||
if (last_token == token_type::end_array)
|
||||
if (JSON_LIKELY(last_token == token_type::end_array))
|
||||
{
|
||||
return sax->end_array();
|
||||
}
|
||||
else
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(), m_lexer.get_token_string());
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -696,7 +704,8 @@ class parser
|
|||
|
||||
if (JSON_UNLIKELY(not std::isfinite(res)))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(), m_lexer.get_token_string());
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -736,7 +745,8 @@ class parser
|
|||
|
||||
default: // the last token was unexpected
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(), m_lexer.get_token_string());
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1054,8 +1054,6 @@ class basic_json
|
|||
*/
|
||||
using parse_event_t = typename parser::parse_event_t;
|
||||
|
||||
using SAX = typename parser::SAX;
|
||||
|
||||
/*!
|
||||
@brief per-element parser callback type
|
||||
|
||||
|
@ -1107,6 +1105,7 @@ class basic_json
|
|||
*/
|
||||
using parser_callback_t = typename parser::parser_callback_t;
|
||||
|
||||
using SAX = typename parser::SAX;
|
||||
|
||||
//////////////////
|
||||
// constructors //
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue