Commit 9da8770f authored by Niels's avatar Niels

ignore UTF-8 byte order mark (fixes #152)

parent e0d334c4
This diff is collapsed.
...@@ -4437,6 +4437,8 @@ class basic_json ...@@ -4437,6 +4437,8 @@ class basic_json
LL(1) parser. The complexity can be higher if the parser callback function LL(1) parser. The complexity can be higher if the parser callback function
@a cb has a super-linear complexity. @a cb has a super-linear complexity.
@note A UTF-8 byte order mark is silently ignored.
@liveexample{The example below demonstrates the parse function with and @liveexample{The example below demonstrates the parse function with and
without callback function.,parse__string__parser_callback_t} without callback function.,parse__string__parser_callback_t}
...@@ -4462,6 +4464,8 @@ class basic_json ...@@ -4462,6 +4464,8 @@ class basic_json
LL(1) parser. The complexity can be higher if the parser callback function LL(1) parser. The complexity can be higher if the parser callback function
@a cb has a super-linear complexity. @a cb has a super-linear complexity.
@note A UTF-8 byte order mark is silently ignored.
@liveexample{The example below demonstrates the parse function with and @liveexample{The example below demonstrates the parse function with and
without callback function.,parse__istream__parser_callback_t} without callback function.,parse__istream__parser_callback_t}
...@@ -4491,6 +4495,8 @@ class basic_json ...@@ -4491,6 +4495,8 @@ class basic_json
@complexity Linear in the length of the input. The parser is a predictive @complexity Linear in the length of the input. The parser is a predictive
LL(1) parser. LL(1) parser.
@note A UTF-8 byte order mark is silently ignored.
@liveexample{The example below shows how a JSON value is constructed by @liveexample{The example below shows how a JSON value is constructed by
reading a serialization from a stream.,operator_deserialize} reading a serialization from a stream.,operator_deserialize}
...@@ -6000,20 +6006,24 @@ class basic_json ...@@ -6000,20 +6006,24 @@ class basic_json
m_start = m_cursor; m_start = m_cursor;
/*!re2c /*!re2c
re2c:define:YYCTYPE = lexer_char_t; re2c:define:YYCTYPE = lexer_char_t;
re2c:define:YYCURSOR = m_cursor; re2c:define:YYCURSOR = m_cursor;
re2c:define:YYLIMIT = m_limit; re2c:define:YYLIMIT = m_limit;
re2c:define:YYMARKER = m_marker; re2c:define:YYMARKER = m_marker;
re2c:define:YYFILL = "yyfill(); // LCOV_EXCL_LINE"; re2c:define:YYFILL = "yyfill(); // LCOV_EXCL_LINE";
re2c:yyfill:parameter = 0; re2c:yyfill:parameter = 0;
re2c:indent:string = " "; re2c:indent:string = " ";
re2c:indent:top = 1; re2c:indent:top = 1;
re2c:labelprefix = "basic_json_parser_"; re2c:labelprefix = "basic_json_parser_";
// whitespace // ignore whitespace
ws = [ \t\n\r]+; ws = [ \t\n\r]+;
ws { return scan(); } ws { return scan(); }
// ignore byte-order-mark
bom = "\xEF\xBB\xBF";
bom { return scan(); }
// structural characters // structural characters
"[" { return token_type::begin_array; } "[" { return token_type::begin_array; }
"]" { return token_type::end_array; } "]" { return token_type::end_array; }
......
...@@ -10022,6 +10022,14 @@ TEST_CASE("Unicode", "[hide]") ...@@ -10022,6 +10022,14 @@ TEST_CASE("Unicode", "[hide]")
// the array has 1112064 + 1 elemnts (a terminating "null" value) // the array has 1112064 + 1 elemnts (a terminating "null" value)
CHECK(j.size() == 1112065); CHECK(j.size() == 1112065);
} }
SECTION("ignore byte-order-mark")
{
// read a file with a UTF-8 BOM
std::ifstream f("test/json_nlohmann_tests/bom.json");
json j;
CHECK_NOTHROW(j << f);
}
} }
TEST_CASE("regression tests") TEST_CASE("regression tests")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment