mirror of
https://github.com/nlohmann/json.git
synced 2024-11-24 23:09:02 +08:00
🔨 replaced lexer's error message by const char*
This commit is contained in:
parent
747f7d36d1
commit
112a6f4e53
23
src/json.hpp
23
src/json.hpp
@ -8896,7 +8896,8 @@ class basic_json
|
||||
}
|
||||
|
||||
++processed_chars;
|
||||
return buffer[buffer_pos++] & 0xFF;;
|
||||
assert(buffer_pos < buffer.size());
|
||||
return buffer[buffer_pos++] & 0xFF;
|
||||
}
|
||||
|
||||
std::string read(size_t offset, size_t length) override
|
||||
@ -8971,7 +8972,7 @@ class basic_json
|
||||
input_buffer_adapter(const input_buffer_adapter&) = delete;
|
||||
input_buffer_adapter& operator=(input_buffer_adapter&) = delete;
|
||||
|
||||
int get_character() override
|
||||
int get_character() noexcept override
|
||||
{
|
||||
if (JSON_LIKELY(cursor < limit))
|
||||
{
|
||||
@ -11510,13 +11511,13 @@ class basic_json
|
||||
}
|
||||
else
|
||||
{
|
||||
error_message = "invalid string: surrogate " + codepoint_to_string(codepoint1) + " must be followed by U+DC00..U+DFFF instead of " + codepoint_to_string(codepoint2);
|
||||
error_message = "invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF";
|
||||
return token_type::parse_error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error_message = "invalid string: surrogate " + codepoint_to_string(codepoint1) + " must be followed by U+DC00..U+DFFF";
|
||||
error_message = "invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF";
|
||||
return token_type::parse_error;
|
||||
}
|
||||
}
|
||||
@ -11524,7 +11525,7 @@ class basic_json
|
||||
{
|
||||
if (JSON_UNLIKELY(0xDC00 <= codepoint1 and codepoint1 <= 0xDFFF))
|
||||
{
|
||||
error_message = "invalid string: surrogate " + codepoint_to_string(codepoint1) + " must follow U+D800..U+DBFF";
|
||||
error_message = "invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
||||
@ -11609,7 +11610,7 @@ class basic_json
|
||||
case 0x1e:
|
||||
case 0x1f:
|
||||
{
|
||||
error_message = "invalid string: control character " + codepoint_to_string(current) + " must be escaped";
|
||||
error_message = "invalid string: control character must be escaped";
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
||||
@ -12450,7 +12451,7 @@ scan_number_done:
|
||||
}
|
||||
|
||||
/// return syntax error message
|
||||
const std::string& get_error_message() const noexcept
|
||||
const char* get_error_message() const noexcept
|
||||
{
|
||||
return error_message;
|
||||
}
|
||||
@ -12544,7 +12545,7 @@ scan_number_done:
|
||||
size_t yylen = 0;
|
||||
|
||||
/// a description of occurred lexer errors
|
||||
std::string error_message = "";
|
||||
const char* error_message = "";
|
||||
|
||||
// number values
|
||||
number_integer_t value_integer = 0;
|
||||
@ -12975,7 +12976,7 @@ scan_number_done:
|
||||
std::string error_msg = "syntax error - ";
|
||||
if (last_token == lexer::token_type::parse_error)
|
||||
{
|
||||
error_msg += m_lexer.get_error_message() + "; last read: '" + m_lexer.get_token_string() + "'";
|
||||
error_msg += std::string(m_lexer.get_error_message()) + "; last read: '" + m_lexer.get_token_string() + "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -12997,7 +12998,7 @@ scan_number_done:
|
||||
std::string error_msg = "syntax error - ";
|
||||
if (last_token == lexer::token_type::parse_error)
|
||||
{
|
||||
error_msg += m_lexer.get_error_message() + "; last read '" + m_lexer.get_token_string() + "'";
|
||||
error_msg += std::string(m_lexer.get_error_message()) + "; last read '" + m_lexer.get_token_string() + "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -14189,7 +14190,7 @@ scan_number_done:
|
||||
|
||||
case patch_operations::copy:
|
||||
{
|
||||
const std::string from_path = get_value("copy", "from", true);;
|
||||
const std::string from_path = get_value("copy", "from", true);
|
||||
const json_pointer from_ptr(from_path);
|
||||
|
||||
// the "from" location must exist - use at()
|
||||
|
@ -98,18 +98,18 @@ TEST_CASE("parser class")
|
||||
// error: tab in string
|
||||
CHECK_THROWS_AS(parse_string("\"\t\"").parse(), json::parse_error);
|
||||
CHECK_THROWS_WITH(parse_string("\"\t\"").parse(),
|
||||
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character U+0009 must be escaped; last read '\"<U+0009>'");
|
||||
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read '\"<U+0009>'");
|
||||
// error: newline in string
|
||||
CHECK_THROWS_AS(parse_string("\"\n\"").parse(), json::parse_error);
|
||||
CHECK_THROWS_AS(parse_string("\"\r\"").parse(), json::parse_error);
|
||||
CHECK_THROWS_WITH(parse_string("\"\n\"").parse(),
|
||||
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character U+000A must be escaped; last read '\"<U+000A>'");
|
||||
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read '\"<U+000A>'");
|
||||
CHECK_THROWS_WITH(parse_string("\"\r\"").parse(),
|
||||
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character U+000D must be escaped; last read '\"<U+000D>'");
|
||||
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read '\"<U+000D>'");
|
||||
// error: backspace in string
|
||||
CHECK_THROWS_AS(parse_string("\"\b\"").parse(), json::parse_error);
|
||||
CHECK_THROWS_WITH(parse_string("\"\b\"").parse(),
|
||||
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character U+0008 must be escaped; last read '\"<U+0008>'");
|
||||
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read '\"<U+0008>'");
|
||||
// improve code coverage
|
||||
CHECK_THROWS_AS(parse_string("\uFF01").parse(), json::parse_error);
|
||||
CHECK_THROWS_AS(parse_string("[-4:1,]").parse(), json::parse_error);
|
||||
@ -910,17 +910,17 @@ TEST_CASE("parser class")
|
||||
// missing part of a surrogate pair
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD80C\""), json::parse_error);
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD80C\""),
|
||||
"[json.exception.parse_error.101] parse error at 8: syntax error - invalid string: surrogate U+D80C must be followed by U+DC00..U+DFFF; last read '\"\\uD80C\"'");
|
||||
"[json.exception.parse_error.101] parse error at 8: syntax error - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read '\"\\uD80C\"'");
|
||||
// invalid surrogate pair
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD80C\\uD80C\""), json::parse_error);
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD80C\\u0000\""), json::parse_error);
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD80C\\uFFFF\""), json::parse_error);
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD80C\\uD80C\""),
|
||||
"[json.exception.parse_error.101] parse error at 13: syntax error - invalid string: surrogate U+D80C must be followed by U+DC00..U+DFFF instead of U+D80C; last read '\"\\uD80C\\uD80C'");
|
||||
"[json.exception.parse_error.101] parse error at 13: syntax error - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read '\"\\uD80C\\uD80C'");
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD80C\\u0000\""),
|
||||
"[json.exception.parse_error.101] parse error at 13: syntax error - invalid string: surrogate U+D80C must be followed by U+DC00..U+DFFF instead of U+0000; last read '\"\\uD80C\\u0000'");
|
||||
"[json.exception.parse_error.101] parse error at 13: syntax error - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read '\"\\uD80C\\u0000'");
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD80C\\uFFFF\""),
|
||||
"[json.exception.parse_error.101] parse error at 13: syntax error - invalid string: surrogate U+D80C must be followed by U+DC00..U+DFFF instead of U+FFFF; last read '\"\\uD80C\\uFFFF'");
|
||||
"[json.exception.parse_error.101] parse error at 13: syntax error - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read '\"\\uD80C\\uFFFF'");
|
||||
}
|
||||
|
||||
SECTION("parse errors (accept)")
|
||||
|
Loading…
Reference in New Issue
Block a user