Merge branch 'feature/jsontestsuite' into develop
This commit is contained in:
commit
79015b9d0a
322 changed files with 1247 additions and 280 deletions
2
Makefile
2
Makefile
|
@ -75,7 +75,7 @@ clang_sanitize: clean
|
|||
|
||||
# create scanner with re2c
|
||||
re2c: src/json.hpp.re2c
|
||||
$(RE2C) -W --bit-vectors --nested-ifs --no-debug-info $< | $(SED) '1d' > src/json.hpp
|
||||
$(RE2C) -W --utf-8 --encoding-policy fail --bit-vectors --nested-ifs --no-debug-info $< | $(SED) '1d' > src/json.hpp
|
||||
|
||||
# pretty printer
|
||||
pretty:
|
||||
|
|
|
@ -507,6 +507,11 @@ Thanks a lot for helping out!
|
|||
|
||||
- The code contains numerous debug **assertions** which can be switched off by defining the preprocessor macro `NDEBUG`, see the [documentation of `assert`](http://en.cppreference.com/w/cpp/error/assert). In particular, note [`operator[]`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html#a2e26bd0b0168abb61f67ad5bcd5b9fa1) implements **unchecked access** for const objects: If the given key is not present, the behavior is undefined (think of a dereferenced null pointer) and yields an [assertion failure](https://github.com/nlohmann/json/issues/289) if assertions are switched on. If you are not sure whether an element in an object exists, use checked access with the [`at()` function](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html#a674de1ee73e6bf4843fc5dc1351fb726).
|
||||
- As the exact type of a number is not defined in the [JSON specification](http://rfc7159.net/rfc7159), this library tries to choose the best fitting C++ number type automatically. As a result, the type `double` may be used to store numbers which may yield [**floating-point exceptions**](https://github.com/nlohmann/json/issues/181) in certain rare situations if floating-point exceptions have been unmasked in the calling code. These exceptions are not caused by the library and need to be fixed in the calling code, such as by re-masking the exceptions prior to calling library functions.
|
||||
- The library supports **Unicode input** as follows:
|
||||
- Only **UTF-8** encoded input is supported which is the default encoding for JSON according to [RFC 7159](http://rfc7159.net/rfc7159#rfc.section.8.1).
|
||||
- Other encodings such as Latin-1, UTF-16, or UTF-32 are not supported and will yield parse errors.
|
||||
- [Unicode noncharacters](http://www.unicode.org/faq/private_use.html#nonchar1) will not be replaced by the library.
|
||||
- Invalid surrogates (e.g., incomplete pairs such as `\uDEAD`) will yield parse errors.
|
||||
|
||||
|
||||
## Execute unit tests
|
||||
|
@ -517,7 +522,7 @@ To compile and run the tests, you need to execute
|
|||
$ make check
|
||||
|
||||
===============================================================================
|
||||
All tests passed (8905169 assertions in 35 test cases)
|
||||
All tests passed (8905479 assertions in 36 test cases)
|
||||
```
|
||||
|
||||
Alternatively, you can use [CMake](https://cmake.org) and run
|
||||
|
|
607
src/json.hpp
607
src/json.hpp
File diff suppressed because it is too large
Load diff
|
@ -7620,6 +7620,14 @@ class basic_json
|
|||
{
|
||||
// fill buffer
|
||||
fill_line_buffer();
|
||||
|
||||
// skip UTF-8 byte-order mark
|
||||
if (m_line_buffer.size() >= 3 and m_line_buffer.substr(0, 3) == "\xEF\xBB\xBF")
|
||||
{
|
||||
m_line_buffer[0] = ' ';
|
||||
m_line_buffer[1] = ' ';
|
||||
m_line_buffer[2] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
// switch off unwanted functions (due to pointer members)
|
||||
|
@ -7792,8 +7800,8 @@ class basic_json
|
|||
re2c:define:YYCURSOR = m_cursor;
|
||||
re2c:define:YYLIMIT = m_limit;
|
||||
re2c:define:YYMARKER = m_marker;
|
||||
re2c:define:YYFILL = "fill_line_buffer()";
|
||||
re2c:yyfill:parameter = 0;
|
||||
re2c:define:YYFILL = "fill_line_buffer(@@); // LCOV_EXCL_LINE";
|
||||
re2c:define:YYFILL:naked = 1;
|
||||
re2c:indent:string = " ";
|
||||
re2c:indent:top = 1;
|
||||
re2c:labelprefix = "basic_json_parser_";
|
||||
|
@ -7802,10 +7810,6 @@ class basic_json
|
|||
ws = [ \t\n\r]+;
|
||||
ws { continue; }
|
||||
|
||||
// ignore byte-order-mark
|
||||
bom = "\xEF\xBB\xBF";
|
||||
bom { continue; }
|
||||
|
||||
// structural characters
|
||||
"[" { last_token_type = token_type::begin_array; break; }
|
||||
"]" { last_token_type = token_type::end_array; break; }
|
||||
|
@ -7845,10 +7849,10 @@ class basic_json
|
|||
string { last_token_type = token_type::value_string; break; }
|
||||
|
||||
// end of file
|
||||
"\000" { last_token_type = token_type::end_of_input; break; }
|
||||
"\x00" { last_token_type = token_type::end_of_input; break; }
|
||||
|
||||
// anything else is an error
|
||||
. { last_token_type = token_type::parse_error; break; }
|
||||
* { last_token_type = token_type::parse_error; break; }
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -7883,7 +7887,7 @@ class basic_json
|
|||
m_start
|
||||
m_content
|
||||
*/
|
||||
void fill_line_buffer()
|
||||
void fill_line_buffer(size_t n = 0)
|
||||
{
|
||||
// number of processed characters (p)
|
||||
const auto offset_start = m_start - m_content;
|
||||
|
@ -7894,6 +7898,9 @@ class basic_json
|
|||
|
||||
// no stream is used or end of file is reached
|
||||
if (m_stream == nullptr or m_stream->eof())
|
||||
{
|
||||
// skip this part if we are already using the line buffer
|
||||
if (m_start != reinterpret_cast<const lexer_char_t*>(m_line_buffer.data()))
|
||||
{
|
||||
// copy unprocessed characters to line buffer
|
||||
m_line_buffer.clear();
|
||||
|
@ -7901,11 +7908,12 @@ class basic_json
|
|||
{
|
||||
m_line_buffer.append(1, static_cast<const char>(*m_cursor));
|
||||
}
|
||||
}
|
||||
|
||||
// append 5 characters (size of longest keyword "false") to
|
||||
// make sure that there is sufficient space between m_cursor
|
||||
// and m_limit
|
||||
m_line_buffer.append(5, '\0');
|
||||
// append n characters to make sure that there is sufficient
|
||||
// space between m_cursor and m_limit
|
||||
m_line_buffer.append(1, '\x00');
|
||||
m_line_buffer.append(n - 1, '\x01');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -7913,7 +7921,7 @@ class basic_json
|
|||
m_line_buffer.erase(0, static_cast<size_t>(offset_start));
|
||||
// read next line from input stream
|
||||
std::string line;
|
||||
std::getline(*m_stream, line);
|
||||
std::getline(*m_stream, line, '\n');
|
||||
// add line with newline symbol to the line buffer
|
||||
m_line_buffer += line + "\n";
|
||||
}
|
||||
|
@ -8075,6 +8083,11 @@ class basic_json
|
|||
// skip the next 10 characters (xxxx\uyyyy)
|
||||
i += 10;
|
||||
}
|
||||
else if (codepoint >= 0xDC00 and codepoint <= 0xDFFF)
|
||||
{
|
||||
// we found a lone low surrogate
|
||||
throw std::invalid_argument("missing high surrogate");
|
||||
}
|
||||
else
|
||||
{
|
||||
// add unicode character(s)
|
||||
|
|
21
test/data/nst_json_testsuite/LICENSE
Normal file
21
test/data/nst_json_testsuite/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2016 Nicolas Seriot
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
1
test/data/nst_json_testsuite/test_parsing/i_number_neg_int_huge_exp.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/i_number_neg_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[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
[1 true]
|
|
@ -0,0 +1 @@
|
|||
[a蘊
|
|
@ -0,0 +1 @@
|
|||
["": 1]
|
|
@ -0,0 +1 @@
|
|||
[""],
|
1
test/data/nst_json_testsuite/test_parsing/n_array_comma_and_number.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_array_comma_and_number.json
Executable file
|
@ -0,0 +1 @@
|
|||
[,1]
|
1
test/data/nst_json_testsuite/test_parsing/n_array_double_comma.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_array_double_comma.json
Executable file
|
@ -0,0 +1 @@
|
|||
[1,,2]
|
|
@ -0,0 +1 @@
|
|||
["x",,]
|
|
@ -0,0 +1 @@
|
|||
["x"]]
|
|
@ -0,0 +1 @@
|
|||
["",]
|
|
@ -0,0 +1 @@
|
|||
["x"
|
|
@ -0,0 +1 @@
|
|||
[x
|
|
@ -0,0 +1 @@
|
|||
[3[4]]
|
|
@ -0,0 +1 @@
|
|||
[<EFBFBD>]
|
|
@ -0,0 +1 @@
|
|||
[1:2]
|
1
test/data/nst_json_testsuite/test_parsing/n_array_just_comma.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_array_just_comma.json
Executable file
|
@ -0,0 +1 @@
|
|||
[,]
|
1
test/data/nst_json_testsuite/test_parsing/n_array_just_minus.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_array_just_minus.json
Executable file
|
@ -0,0 +1 @@
|
|||
[-]
|
|
@ -0,0 +1 @@
|
|||
[ , ""]
|
|
@ -0,0 +1,3 @@
|
|||
["a",
|
||||
4
|
||||
,1,
|
1
test/data/nst_json_testsuite/test_parsing/n_array_number_and_comma.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_array_number_and_comma.json
Executable file
|
@ -0,0 +1 @@
|
|||
[1,]
|
|
@ -0,0 +1 @@
|
|||
[1,,]
|
|
@ -0,0 +1 @@
|
|||
["a"\f]
|
1
test/data/nst_json_testsuite/test_parsing/n_array_star_inside.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_array_star_inside.json
Executable file
|
@ -0,0 +1 @@
|
|||
[*]
|
|
@ -0,0 +1 @@
|
|||
[""
|
|
@ -0,0 +1 @@
|
|||
[1,
|
|
@ -0,0 +1,3 @@
|
|||
[1,
|
||||
1
|
||||
,1
|
|
@ -0,0 +1 @@
|
|||
[{}
|
|
@ -0,0 +1 @@
|
|||
[fals]
|
|
@ -0,0 +1 @@
|
|||
[nul]
|
|
@ -0,0 +1 @@
|
|||
[tru]
|
|
@ -0,0 +1 @@
|
|||
[++1234]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_+1.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_+1.json
Executable file
|
@ -0,0 +1 @@
|
|||
[+1]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_+Inf.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_+Inf.json
Executable file
|
@ -0,0 +1 @@
|
|||
[+Inf]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_-01.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_-01.json
Executable file
|
@ -0,0 +1 @@
|
|||
[-01]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_-1.0..json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_-1.0..json
Executable file
|
@ -0,0 +1 @@
|
|||
[-1.0.]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_-2..json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_-2..json
Executable file
|
@ -0,0 +1 @@
|
|||
[-2.]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_-NaN.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_-NaN.json
Executable file
|
@ -0,0 +1 @@
|
|||
[-NaN]
|
|
@ -0,0 +1 @@
|
|||
[.-1]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_.2e-3.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_.2e-3.json
Executable file
|
@ -0,0 +1 @@
|
|||
[.2e-3]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_0.1.2.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_0.1.2.json
Executable file
|
@ -0,0 +1 @@
|
|||
[0.1.2]
|
|
@ -0,0 +1 @@
|
|||
[0.3e+]
|
|
@ -0,0 +1 @@
|
|||
[0.3e]
|
|
@ -0,0 +1 @@
|
|||
[0.e1]
|
|
@ -0,0 +1 @@
|
|||
[0E+]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_0_capital_E.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_0_capital_E.json
Executable file
|
@ -0,0 +1 @@
|
|||
[0E]
|
|
@ -0,0 +1 @@
|
|||
[0e+]
|
|
@ -0,0 +1 @@
|
|||
[0e]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_1.0e+.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_1.0e+.json
Executable file
|
@ -0,0 +1 @@
|
|||
[1.0e+]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_1.0e-.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_1.0e-.json
Executable file
|
@ -0,0 +1 @@
|
|||
[1.0e-]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_1.0e.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_1.0e.json
Executable file
|
@ -0,0 +1 @@
|
|||
[1.0e]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_1_000.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_1_000.json
Executable file
|
@ -0,0 +1 @@
|
|||
[1 000.0]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_1eE2.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_1eE2.json
Executable file
|
@ -0,0 +1 @@
|
|||
[1eE2]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_2.e+3.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_2.e+3.json
Executable file
|
@ -0,0 +1 @@
|
|||
[2.e+3]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_2.e-3.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_2.e-3.json
Executable file
|
@ -0,0 +1 @@
|
|||
[2.e-3]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_2.e3.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_2.e3.json
Executable file
|
@ -0,0 +1 @@
|
|||
[2.e3]
|
|
@ -0,0 +1 @@
|
|||
[9.e+]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_Inf.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_Inf.json
Executable file
|
@ -0,0 +1 @@
|
|||
[Inf]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_NaN.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_NaN.json
Executable file
|
@ -0,0 +1 @@
|
|||
[NaN]
|
|
@ -0,0 +1 @@
|
|||
[1]
|
|
@ -0,0 +1 @@
|
|||
[1+2]
|
|
@ -0,0 +1 @@
|
|||
[0x1]
|
|
@ -0,0 +1 @@
|
|||
[0x42]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_infinity.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_infinity.json
Executable file
|
@ -0,0 +1 @@
|
|||
[Infinity]
|
|
@ -0,0 +1 @@
|
|||
[0e+-1]
|
|
@ -0,0 +1 @@
|
|||
[-123.123foo]
|
|
@ -0,0 +1 @@
|
|||
[123å]
|
|
@ -0,0 +1 @@
|
|||
[1e1å]
|
|
@ -0,0 +1 @@
|
|||
[0å]
|
1
test/data/nst_json_testsuite/test_parsing/n_number_minus_infinity.json
Executable file
1
test/data/nst_json_testsuite/test_parsing/n_number_minus_infinity.json
Executable file
|
@ -0,0 +1 @@
|
|||
[-Infinity]
|
|
@ -0,0 +1 @@
|
|||
[-foo]
|
|
@ -0,0 +1 @@
|
|||
[- 1]
|
|
@ -0,0 +1 @@
|
|||
[-012]
|
|
@ -0,0 +1 @@
|
|||
[-.123]
|
|
@ -0,0 +1 @@
|
|||
[-1x]
|
|
@ -0,0 +1 @@
|
|||
[1ea]
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue