mirror of
https://github.com/nlohmann/json.git
synced 2026-02-18 01:16:25 +00:00
Compare commits
54 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d2b5e3771 | ||
|
|
700977d73e | ||
|
|
79015b9d0a | ||
|
|
3716a2fbe8 | ||
|
|
737d43724f | ||
|
|
59c8343851 | ||
|
|
94c16b2c31 | ||
|
|
8f70525374 | ||
|
|
7adccde714 | ||
|
|
8d1e65f297 | ||
|
|
7b4e6cf705 | ||
|
|
a8136c578a | ||
|
|
b820bb3b1f | ||
|
|
b03bbe724d | ||
|
|
7da182472d | ||
|
|
42ea4fb751 | ||
|
|
2fdba9de19 | ||
|
|
a2808322c6 | ||
|
|
a29fcae409 | ||
|
|
3ebe28970a | ||
|
|
79d9fdc016 | ||
|
|
e310850353 | ||
|
|
8057782bb8 | ||
|
|
cb2d41e3a0 | ||
|
|
542a48a16a | ||
|
|
606098f45d | ||
|
|
d91067220f | ||
|
|
67b9f1936d | ||
|
|
bb9d87ad55 | ||
|
|
e7a60d8961 | ||
|
|
470197bd0b | ||
|
|
d3e7f9da67 | ||
|
|
97280bbcfc | ||
|
|
e9fde3e116 | ||
|
|
54bf5f20e9 | ||
|
|
2fa8ea0f74 | ||
|
|
a0ef5a194c | ||
|
|
04b11d78ff | ||
|
|
8173c370f6 | ||
|
|
b6550b35c3 | ||
|
|
b5128b1610 | ||
|
|
963efb1f09 | ||
|
|
d6005e59a5 | ||
|
|
e1b6a23049 | ||
|
|
be61091401 | ||
|
|
e4366688f7 | ||
|
|
5879eb0be3 | ||
|
|
f209be1142 | ||
|
|
625370a1ad | ||
|
|
2c82f25272 | ||
|
|
3586767c05 | ||
|
|
8b39570009 | ||
|
|
e29d6b5f41 | ||
|
|
25ccf7f908 |
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
# define the project
|
||||
project(nlohmann_json VERSION 2.0.5 LANGUAGES CXX)
|
||||
project(nlohmann_json VERSION 2.0.7 LANGUAGES CXX)
|
||||
|
||||
enable_testing()
|
||||
|
||||
@@ -31,7 +31,8 @@ endif()
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file("cmake/config.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}"
|
||||
INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION})
|
||||
INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION}
|
||||
PATH_VARS JSON_INCLUDE_DESTINATION)
|
||||
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}"
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
|
||||
25
ChangeLog.md
25
ChangeLog.md
@@ -1,13 +1,33 @@
|
||||
# Change Log
|
||||
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [v2.0.7](https://github.com/nlohmann/json/releases/tag/v2.0.7) (2016-11-02)
|
||||
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.6...v2.0.7)
|
||||
|
||||
- ""-operators ignore the length parameter [\#340](https://github.com/nlohmann/json/issues/340)
|
||||
|
||||
- Check "Parsing JSON is a Minefield" [\#344](https://github.com/nlohmann/json/issues/344)
|
||||
|
||||
- fix minor grammar/style issue in README.md [\#336](https://github.com/nlohmann/json/pull/336) ([seeekr](https://github.com/seeekr))
|
||||
|
||||
## [v2.0.6](https://github.com/nlohmann/json/releases/tag/v2.0.6) (2016-10-15)
|
||||
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.5...v2.0.6)
|
||||
|
||||
- Add nested object capability to pointers [\#323](https://github.com/nlohmann/json/issues/323)
|
||||
- make has\_mapped\_type struct friendly [\#324](https://github.com/nlohmann/json/pull/324) ([vpetrigo](https://github.com/vpetrigo))
|
||||
|
||||
- Fix usage examples' comments for std::multiset [\#322](https://github.com/nlohmann/json/issues/322)
|
||||
- json\_unit runs forever when executed in build directory [\#319](https://github.com/nlohmann/json/issues/319)
|
||||
|
||||
- Fix usage examples' comments for std::multiset [\#321](https://github.com/nlohmann/json/pull/321) ([vasild](https://github.com/vasild))
|
||||
- Include dir relocation [\#318](https://github.com/nlohmann/json/pull/318) ([ChristophJud](https://github.com/ChristophJud))
|
||||
- trivial documentation fix [\#313](https://github.com/nlohmann/json/pull/313) ([5tefan](https://github.com/5tefan))
|
||||
|
||||
## [v2.0.5](https://github.com/nlohmann/json/releases/tag/v2.0.5) (2016-09-14)
|
||||
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.4...v2.0.5)
|
||||
|
||||
- make json\_benchmarks no longer working in 2.0.4 [\#310](https://github.com/nlohmann/json/issues/310)
|
||||
|
||||
- \[feature request\]: schema validator and comments [\#311](https://github.com/nlohmann/json/issues/311)
|
||||
|
||||
## [v2.0.4](https://github.com/nlohmann/json/releases/tag/v2.0.4) (2016-09-11)
|
||||
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.3...v2.0.4)
|
||||
|
||||
@@ -132,7 +152,6 @@ All notable changes to this project will be documented in this file. This projec
|
||||
- prevent json.hpp from emitting compiler warnings [\#154](https://github.com/nlohmann/json/issues/154)
|
||||
- json::parse\(string\) does not check utf8 bom [\#152](https://github.com/nlohmann/json/issues/152)
|
||||
- unsigned 64bit values output as signed [\#151](https://github.com/nlohmann/json/issues/151)
|
||||
- Wish feature: json5 [\#150](https://github.com/nlohmann/json/issues/150)
|
||||
- overload of at\(\) with default value [\#133](https://github.com/nlohmann/json/issues/133)
|
||||
- Memory leak in face of exceptions [\#118](https://github.com/nlohmann/json/issues/118)
|
||||
- Find and Count for arrays [\#117](https://github.com/nlohmann/json/issues/117)
|
||||
|
||||
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:
|
||||
|
||||
30
README.md
30
README.md
@@ -3,7 +3,7 @@
|
||||
[](https://travis-ci.org/nlohmann/json)
|
||||
[](https://ci.appveyor.com/project/nlohmann/json)
|
||||
[](https://coveralls.io/r/nlohmann/json)
|
||||
[](http://melpon.org/wandbox/permlink/r3wa3rI5yxgQQcrm)
|
||||
[](http://melpon.org/wandbox/permlink/fsf5FqYe6GoX68W6)
|
||||
[](http://nlohmann.github.io/json)
|
||||
[](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT)
|
||||
[](https://github.com/nlohmann/json/releases)
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
There are myriads of [JSON](http://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals:
|
||||
|
||||
- **Intuitive syntax**. In languages such as Python, JSON feels like a first class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you know, what I mean.
|
||||
- **Intuitive syntax**. In languages such as Python, JSON feels like a first class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you'll know what I mean.
|
||||
|
||||
- **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https://github.com/nlohmann/json/blob/develop/src/json.hpp). That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings.
|
||||
|
||||
@@ -283,8 +283,8 @@ json j_uset(c_uset); // only one entry for "one" is used
|
||||
// maybe ["two", "three", "four", "one"]
|
||||
|
||||
std::multiset<std::string> c_mset {"one", "two", "one", "four"};
|
||||
json j_mset(c_mset); // only one entry for "one" is used
|
||||
// maybe ["one", "two", "four"]
|
||||
json j_mset(c_mset); // both entries for "one" are used
|
||||
// maybe ["one", "two", "one", "four"]
|
||||
|
||||
std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"};
|
||||
json j_umset(c_umset); // both entries for "one" are used
|
||||
@@ -494,6 +494,11 @@ I deeply appreciate the help of the following people.
|
||||
- [Damien](https://github.com/dtoma) fixed one of the last conversion warnings.
|
||||
- [Thomas Braun](https://github.com/t-b) fixed a warning in a test case.
|
||||
- [Théo DELRIEU](https://github.com/theodelrieu) patiently and constructively oversaw the long way toward [iterator-range parsing](https://github.com/nlohmann/json/issues/290).
|
||||
- [Stefan](https://github.com/5tefan) fixed a minor issue in the documentation.
|
||||
- [Vasil Dimov](https://github.com/vasild) fixed the documentation regarding conversions from `std::multiset`.
|
||||
- [ChristophJud](https://github.com/ChristophJud) overworked the CMake files to ease project inclusion.
|
||||
- [Vladimir Petrigo](https://github.com/vpetrigo) made a SFINAE hack more readable.
|
||||
- [Denis Andrejew](https://github.com/seeekr) fixed a grammar issue in the README file.
|
||||
|
||||
Thanks a lot for helping out!
|
||||
|
||||
@@ -502,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
|
||||
@@ -512,7 +522,17 @@ To compile and run the tests, you need to execute
|
||||
$ make check
|
||||
|
||||
===============================================================================
|
||||
All tests passed (8905161 assertions in 35 test cases)
|
||||
All tests passed (8905491 assertions in 36 test cases)
|
||||
```
|
||||
|
||||
Alternatively, you can use [CMake](https://cmake.org) and run
|
||||
|
||||
```sh
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ cmake ..
|
||||
$ make
|
||||
$ ctest
|
||||
```
|
||||
|
||||
For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml).
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@PACKAGE_INIT@
|
||||
set_and_check(JSON_INCLUDE_DIR "@PACKAGE_JSON_INCLUDE_DESTINATION@")
|
||||
|
||||
cmake_policy(PUSH)
|
||||
cmake_policy(SET CMP0024 OLD)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/@JSON_TARGETS_FILENAME@)
|
||||
cmake_policy(POP)
|
||||
cmake_policy(POP)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#---------------------------------------------------------------------------
|
||||
DOXYFILE_ENCODING = UTF-8
|
||||
PROJECT_NAME = "JSON for Modern C++"
|
||||
PROJECT_NUMBER = 2.0.5
|
||||
PROJECT_NUMBER = 2.0.7
|
||||
PROJECT_BRIEF =
|
||||
PROJECT_LOGO =
|
||||
OUTPUT_DIRECTORY = .
|
||||
|
||||
@@ -1 +1 @@
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/r3wa3rI5yxgQQcrm"><b>online</b></a>
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/fsf5FqYe6GoX68W6"><b>online</b></a>
|
||||
@@ -39,7 +39,7 @@ int main()
|
||||
|
||||
// create an array from std::multiset
|
||||
std::multiset<std::string> c_mset {"one", "two", "one", "four"};
|
||||
json j_mset(c_mset); // only one entry for "one" is used
|
||||
json j_mset(c_mset); // both entries for "one" are used
|
||||
|
||||
// create an array from std::unordered_multiset
|
||||
std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"};
|
||||
|
||||
@@ -1 +1 @@
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/MghSilgvyh4ZJShY"><b>online</b></a>
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/3BIhBw91FUVuHE1D"><b>online</b></a>
|
||||
@@ -40,7 +40,7 @@ int main()
|
||||
// output the changed array
|
||||
std::cout << j["array"] << '\n';
|
||||
|
||||
// "change" the arry element past the end
|
||||
// "change" the array element past the end
|
||||
j["/array/-"_json_pointer] = 55;
|
||||
// output the changed array
|
||||
std::cout << j["array"] << '\n';
|
||||
|
||||
@@ -1 +1 @@
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/xzFX3E4gYBXFwd04"><b>online</b></a>
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/AYgVTzCodPApT4hT"><b>online</b></a>
|
||||
@@ -268,4 +268,4 @@ The container functions known from STL have been extended to support the differe
|
||||
@author [Niels Lohmann](http://nlohmann.me)
|
||||
@see https://github.com/nlohmann/json to download the source code
|
||||
|
||||
@version 2.0.5
|
||||
@version 2.0.7
|
||||
|
||||
BIN
doc/json.gif
BIN
doc/json.gif
Binary file not shown.
|
Before Width: | Height: | Size: 440 KiB After Width: | Height: | Size: 444 KiB |
705
src/json.hpp
705
src/json.hpp
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++
|
||||
| | |__ | | | | | | version 2.0.5
|
||||
| | |__ | | | | | | version 2.0.7
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
@@ -32,6 +32,7 @@ SOFTWARE.
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <ciso646>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
@@ -106,16 +107,19 @@ such as sequence containers. For instance, `std::map` passes the test as it
|
||||
contains a `mapped_type`, whereas `std::vector` fails the test.
|
||||
|
||||
@sa http://stackoverflow.com/a/7728728/266378
|
||||
@since version 1.0.0
|
||||
@since version 1.0.0, overworked in version 2.0.6
|
||||
*/
|
||||
template<typename T>
|
||||
struct has_mapped_type
|
||||
{
|
||||
private:
|
||||
template<typename C> static char test(typename C::mapped_type*);
|
||||
template<typename C> static char (&test(...))[2];
|
||||
template <typename U, typename = typename U::mapped_type>
|
||||
static int detect(U&&);
|
||||
|
||||
static void detect(...);
|
||||
public:
|
||||
static constexpr bool value = sizeof(test<T>(0)) == 1;
|
||||
static constexpr bool value =
|
||||
std::is_integral<decltype(detect(std::declval<T>()))>::value;
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -7616,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)
|
||||
@@ -7784,24 +7796,20 @@ class basic_json
|
||||
assert(m_start != nullptr);
|
||||
|
||||
/*!re2c
|
||||
re2c:define:YYCTYPE = lexer_char_t;
|
||||
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:indent:string = " ";
|
||||
re2c:indent:top = 1;
|
||||
re2c:labelprefix = "basic_json_parser_";
|
||||
re2c:define:YYCTYPE = lexer_char_t;
|
||||
re2c:define:YYCURSOR = m_cursor;
|
||||
re2c:define:YYLIMIT = m_limit;
|
||||
re2c:define:YYMARKER = m_marker;
|
||||
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_";
|
||||
|
||||
// ignore whitespace
|
||||
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; }
|
||||
@@ -7841,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; }
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -7879,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;
|
||||
@@ -7891,17 +7899,21 @@ class basic_json
|
||||
// no stream is used or end of file is reached
|
||||
if (m_stream == nullptr or m_stream->eof())
|
||||
{
|
||||
// copy unprocessed characters to line buffer
|
||||
m_line_buffer.clear();
|
||||
for (m_cursor = m_start; m_cursor != m_limit; ++m_cursor)
|
||||
// skip this part if we are already using the line buffer
|
||||
if (m_start != reinterpret_cast<const lexer_char_t*>(m_line_buffer.data()))
|
||||
{
|
||||
m_line_buffer.append(1, static_cast<const char>(*m_cursor));
|
||||
// copy unprocessed characters to line buffer
|
||||
m_line_buffer.clear();
|
||||
for (m_cursor = m_start; m_cursor != m_limit; ++m_cursor)
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -7909,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";
|
||||
}
|
||||
@@ -8071,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)
|
||||
@@ -8253,6 +8270,13 @@ class basic_json
|
||||
{
|
||||
// parse with strtod
|
||||
result.m_value.number_float = str_to_float_t(static_cast<number_float_t*>(nullptr), NULL);
|
||||
|
||||
// replace infinity and NAN by null
|
||||
if (not std::isfinite(result.m_value.number_float))
|
||||
{
|
||||
type = value_t::null;
|
||||
result.m_value = basic_json::json_value();
|
||||
}
|
||||
}
|
||||
|
||||
// save the type
|
||||
@@ -8733,6 +8757,12 @@ class basic_json
|
||||
/*!
|
||||
@brief return a reference to the pointed to value
|
||||
|
||||
@note This version does not throw if a value is not present, but tries
|
||||
to create nested values instead. For instance, calling this function
|
||||
with pointer `"/this/that"` on a null value is equivalent to calling
|
||||
`operator[]("this").operator[]("that")` on that value, effectively
|
||||
changing the null value to an object.
|
||||
|
||||
@param[in] ptr a JSON value
|
||||
|
||||
@return reference to the JSON value pointed to by the JSON pointer
|
||||
@@ -8747,6 +8777,29 @@ class basic_json
|
||||
{
|
||||
for (const auto& reference_token : reference_tokens)
|
||||
{
|
||||
// convert null values to arrays or objects before continuing
|
||||
if (ptr->m_type == value_t::null)
|
||||
{
|
||||
// check if reference token is a number
|
||||
const bool nums = std::all_of(reference_token.begin(),
|
||||
reference_token.end(),
|
||||
[](const char x)
|
||||
{
|
||||
return std::isdigit(x);
|
||||
});
|
||||
|
||||
// change value to array for numbers or "-" or to object
|
||||
// otherwise
|
||||
if (nums or reference_token == "-")
|
||||
{
|
||||
*ptr = value_t::array;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr = value_t::object;
|
||||
}
|
||||
}
|
||||
|
||||
switch (ptr->m_type)
|
||||
{
|
||||
case value_t::object:
|
||||
@@ -9854,30 +9907,32 @@ can be used by adding `"_json"` to a string literal and returns a JSON object
|
||||
if no parse error occurred.
|
||||
|
||||
@param[in] s a string representation of a JSON object
|
||||
@param[in] n the length of string @a s
|
||||
@return a JSON object
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
inline nlohmann::json operator "" _json(const char* s, std::size_t)
|
||||
inline nlohmann::json operator "" _json(const char* s, std::size_t n)
|
||||
{
|
||||
return nlohmann::json::parse(s);
|
||||
return nlohmann::json::parse(s, s + n);
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief user-defined string literal for JSON pointer
|
||||
|
||||
This operator implements a user-defined string literal for JSON Pointers. It
|
||||
can be used by adding `"_json"` to a string literal and returns a JSON pointer
|
||||
can be used by adding `"_json_pointer"` to a string literal and returns a JSON pointer
|
||||
object if no parse error occurred.
|
||||
|
||||
@param[in] s a string representation of a JSON Pointer
|
||||
@param[in] n the length of string @a s
|
||||
@return a JSON pointer object
|
||||
|
||||
@since version 2.0.0
|
||||
*/
|
||||
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t)
|
||||
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
|
||||
{
|
||||
return nlohmann::json::json_pointer(s);
|
||||
return nlohmann::json::json_pointer(std::string(s, n));
|
||||
}
|
||||
|
||||
// restore GCC/clang diagnostic settings
|
||||
|
||||
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_int_huge_exp.json
Executable file
@@ -0,0 +1 @@
|
||||
[-1e+9999]
|
||||
@@ -0,0 +1 @@
|
||||
[1.5e+9999]
|
||||
@@ -0,0 +1 @@
|
||||
{"\uDFAA":0}
|
||||
@@ -0,0 +1 @@
|
||||
["\uDADA"]
|
||||
@@ -0,0 +1 @@
|
||||
["\uD888\u1234"]
|
||||
@@ -0,0 +1 @@
|
||||
["\ud800"]
|
||||
@@ -0,0 +1 @@
|
||||
["\ud800abc"]
|
||||
@@ -0,0 +1 @@
|
||||
["譌・ム淫"]
|
||||
@@ -0,0 +1 @@
|
||||
["\uD800\n"]
|
||||
@@ -0,0 +1 @@
|
||||
["\uDd1ea"]
|
||||
@@ -0,0 +1 @@
|
||||
["\uD800\uD800\n"]
|
||||
@@ -0,0 +1 @@
|
||||
["\uDd1e\uD834"]
|
||||
@@ -0,0 +1 @@
|
||||
["\uDFAA"]
|
||||
@@ -0,0 +1 @@
|
||||
["<22><><EFBFBD><EFBFBD>"]
|
||||
@@ -0,0 +1 @@
|
||||
["<22><>"]
|
||||
@@ -0,0 +1 @@
|
||||
["\uDBFF\uDFFE"]
|
||||
@@ -0,0 +1 @@
|
||||
["\uD83F\uDFFE"]
|
||||
@@ -0,0 +1 @@
|
||||
["\uFDD0"]
|
||||
@@ -0,0 +1 @@
|
||||
["\uFFFE"]
|
||||
@@ -0,0 +1 @@
|
||||
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1 @@
|
||||
[1 true]
|
||||
@@ -0,0 +1 @@
|
||||
[a<EFBFBD>]
|
||||
@@ -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]
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user