From 3811daa8a3b5842019396650d4bf04cef41e4666 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 18 Aug 2018 12:00:14 +0200 Subject: [PATCH] :memo: release preparation --- Makefile | 2 +- README.md | 10 ++ .../nlohmann/detail/input/binary_reader.hpp | 4 +- include/nlohmann/detail/input/json_sax.hpp | 28 ++--- include/nlohmann/detail/input/lexer.hpp | 8 +- include/nlohmann/json.hpp | 60 ++++++++++- single_include/nlohmann/json.hpp | 100 ++++++++++++++---- 7 files changed, 175 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 36b01450..1deb8da5 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ clean: coverage: mkdir build_coverage - cd build_coverage ; CXX=g++-5 cmake .. -GNinja -DJSON_Coverage=ON -DJSON_MultipleHeaders=ON + cd build_coverage ; CXX=g++-7 cmake .. -GNinja -DJSON_Coverage=ON -DJSON_MultipleHeaders=ON cd build_coverage ; ninja cd build_coverage ; ctest -E '.*_default' -j10 cd build_coverage ; ninja lcov_html diff --git a/README.md b/README.md index 1ab9dd98..f3bbf847 100644 --- a/README.md +++ b/README.md @@ -1046,6 +1046,16 @@ I deeply appreciate the help of the following people. - [Carlos O'Ryan](https://github.com/coryan) fixed a typo. - [James Upjohn](https://github.com/jammehcow) fixed a version number in the compilers section. - [Chuck Atkins](https://github.com/chuckatkins) adjusted the CMake files to the CMake packaging guidelines +- [Jan Schöppach](https://github.com/dns13) fixed a typo. +- [martin-mfg](https://github.com/martin-mfg) fixed a typo. +- [Matthias Möller](https://github.com/TinyTinni) removed the dependency from `std::stringstream`. +- [agrianius](https://github.com/agrianius) added code to use alternative string implementations. +- [Daniel599](https://github.com/Daniel599) allowed to use more algorithms with the `items()` function. +- [Julius Rakow](https://github.com/jrakow) fixed the Meson include directory and fixed the links to [cppreference.com](cppreference.com). +- [Sonu Lohani](https://github.com/sonulohani) fixed the compilation with MSVC 2015 in debug mode. +- [grembo](https://github.com/grembo) fixed the test suite and re-enabled several test cases. +- [Hyeon Kim](https://github.com/simnalamburt) introduced the macro `JSON_INTERNAL_CATCH` to control the exception handling inside the library. +- [thyu](https://github.com/thyu) fixed a compiler warning. Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone. diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 048f9364..05ab36f3 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -80,8 +80,10 @@ class binary_reader result = parse_ubjson_internal(); break; + // LCOV_EXCL_START default: - assert(false); // LCOV_EXCL_LINE + assert(false); + // LCOV_EXCL_STOP } // strict mode: next byte must be EOF diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 0c1f1ca6..1705a861 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -249,16 +249,18 @@ class json_sax_dom_parser { case 1: JSON_THROW(*reinterpret_cast(&ex)); - case 2: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE - case 3: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE case 4: JSON_THROW(*reinterpret_cast(&ex)); + // LCOV_EXCL_START + case 2: + JSON_THROW(*reinterpret_cast(&ex)); + case 3: + JSON_THROW(*reinterpret_cast(&ex)); case 5: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE + JSON_THROW(*reinterpret_cast(&ex)); default: - assert(false); // LCOV_EXCL_LINE + assert(false); + // LCOV_EXCL_STOP } } return false; @@ -505,16 +507,18 @@ class json_sax_dom_callback_parser { case 1: JSON_THROW(*reinterpret_cast(&ex)); - case 2: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE - case 3: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE case 4: JSON_THROW(*reinterpret_cast(&ex)); + // LCOV_EXCL_START + case 2: + JSON_THROW(*reinterpret_cast(&ex)); + case 3: + JSON_THROW(*reinterpret_cast(&ex)); case 5: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE + JSON_THROW(*reinterpret_cast(&ex)); default: - assert(false); // LCOV_EXCL_LINE + assert(false); + // LCOV_EXCL_STOP } } return false; diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 09afa60b..44165ff0 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -92,8 +92,10 @@ class lexer return "end of input"; case token_type::literal_or_value: return "'[', '{', or a literal"; + // LCOV_EXCL_START default: // catch non-enum values - return "unknown token"; // LCOV_EXCL_LINE + return "unknown token"; + // LCOV_EXCL_STOP } } @@ -745,11 +747,13 @@ class lexer goto scan_number_any1; } + // LCOV_EXCL_START default: { // all other characters are rejected outside scan_number() - assert(false); // LCOV_EXCL_LINE + assert(false); } + // LCOV_EXCL_STOP } scan_number_minus: diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 7017593a..9546520e 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1276,7 +1276,7 @@ class basic_json was provided), strong guarantee holds: if an exception is thrown, there are no changes to any JSON value. - @since version 3.1.2 + @since version 3.2.0 */ template ::value and @@ -6014,6 +6014,58 @@ class basic_json return parser(i).accept(true); } + /*! + @brief generate SAX events + + The SAX event lister must follow the interface of @ref json_sax. + + This function reads from a compatible input. Examples are: + - an array of 1-byte values + - strings with character/literal type with size of 1 byte + - input streams + - container with contiguous storage of 1-byte values. Compatible container + types include `std::vector`, `std::string`, `std::array`, + `std::valarray`, and `std::initializer_list`. Furthermore, C-style + arrays can be used with `std::begin()`/`std::end()`. User-defined + containers can be used as long as they implement random-access iterators + and a contiguous storage. + + @pre Each element of the container has a size of 1 byte. Violating this + precondition yields undefined behavior. **This precondition is enforced + with a static assertion.** + + @pre The container storage is contiguous. Violating this precondition + yields undefined behavior. **This precondition is enforced with an + assertion.** + @pre Each element of the container has a size of 1 byte. Violating this + precondition yields undefined behavior. **This precondition is enforced + with a static assertion.** + + @warning There is no way to enforce all preconditions at compile-time. If + the function is called with a noncompliant container and with + assertions switched off, the behavior is undefined and will most + likely yield segmentation violation. + + @param[in] i input to read from + @param[in,out] sax SAX event listener + @param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON) + @param[in] strict whether the input has to be consumed completely + + @return return value of the last processed SAX event + + @throw parse_error.101 if a parse error occurs; example: `""unexpected end + of input; expected string literal""` + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails + + @complexity Linear in the length of the input. The parser is a predictive + LL(1) parser. The complexity can be higher if the SAX consumer @a sax has + a super-linear complexity. + + @note A UTF-8 byte order mark is silently ignored. + + @since version 3.2.0 + */ template static bool sax_parse(detail::input_adapter&& i, SAX* sax, input_format_t format = input_format_t::json, @@ -7215,11 +7267,13 @@ class basic_json break; } + // LCOV_EXCL_START default: { // if there exists a parent it cannot be primitive - assert(false); // LCOV_EXCL_LINE + assert(false); } + // LCOV_EXCL_STOP } } }; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 84042f14..f7ff131d 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2307,8 +2307,10 @@ class lexer return "end of input"; case token_type::literal_or_value: return "'[', '{', or a literal"; + // LCOV_EXCL_START default: // catch non-enum values - return "unknown token"; // LCOV_EXCL_LINE + return "unknown token"; + // LCOV_EXCL_STOP } } @@ -2960,11 +2962,13 @@ class lexer goto scan_number_any1; } + // LCOV_EXCL_START default: { // all other characters are rejected outside scan_number() - assert(false); // LCOV_EXCL_LINE + assert(false); } + // LCOV_EXCL_STOP } scan_number_minus: @@ -4025,16 +4029,18 @@ class json_sax_dom_parser { case 1: JSON_THROW(*reinterpret_cast(&ex)); - case 2: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE - case 3: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE case 4: JSON_THROW(*reinterpret_cast(&ex)); + // LCOV_EXCL_START + case 2: + JSON_THROW(*reinterpret_cast(&ex)); + case 3: + JSON_THROW(*reinterpret_cast(&ex)); case 5: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE + JSON_THROW(*reinterpret_cast(&ex)); default: - assert(false); // LCOV_EXCL_LINE + assert(false); + // LCOV_EXCL_STOP } } return false; @@ -4281,16 +4287,18 @@ class json_sax_dom_callback_parser { case 1: JSON_THROW(*reinterpret_cast(&ex)); - case 2: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE - case 3: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE case 4: JSON_THROW(*reinterpret_cast(&ex)); + // LCOV_EXCL_START + case 2: + JSON_THROW(*reinterpret_cast(&ex)); + case 3: + JSON_THROW(*reinterpret_cast(&ex)); case 5: - JSON_THROW(*reinterpret_cast(&ex)); // LCOV_EXCL_LINE + JSON_THROW(*reinterpret_cast(&ex)); default: - assert(false); // LCOV_EXCL_LINE + assert(false); + // LCOV_EXCL_STOP } } return false; @@ -6049,8 +6057,10 @@ class binary_reader result = parse_ubjson_internal(); break; + // LCOV_EXCL_START default: - assert(false); // LCOV_EXCL_LINE + assert(false); + // LCOV_EXCL_STOP } // strict mode: next byte must be EOF @@ -12372,7 +12382,7 @@ class basic_json was provided), strong guarantee holds: if an exception is thrown, there are no changes to any JSON value. - @since version 3.1.2 + @since version 3.2.0 */ template ::value and @@ -17110,6 +17120,58 @@ class basic_json return parser(i).accept(true); } + /*! + @brief generate SAX events + + The SAX event lister must follow the interface of @ref json_sax. + + This function reads from a compatible input. Examples are: + - an array of 1-byte values + - strings with character/literal type with size of 1 byte + - input streams + - container with contiguous storage of 1-byte values. Compatible container + types include `std::vector`, `std::string`, `std::array`, + `std::valarray`, and `std::initializer_list`. Furthermore, C-style + arrays can be used with `std::begin()`/`std::end()`. User-defined + containers can be used as long as they implement random-access iterators + and a contiguous storage. + + @pre Each element of the container has a size of 1 byte. Violating this + precondition yields undefined behavior. **This precondition is enforced + with a static assertion.** + + @pre The container storage is contiguous. Violating this precondition + yields undefined behavior. **This precondition is enforced with an + assertion.** + @pre Each element of the container has a size of 1 byte. Violating this + precondition yields undefined behavior. **This precondition is enforced + with a static assertion.** + + @warning There is no way to enforce all preconditions at compile-time. If + the function is called with a noncompliant container and with + assertions switched off, the behavior is undefined and will most + likely yield segmentation violation. + + @param[in] i input to read from + @param[in,out] sax SAX event listener + @param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON) + @param[in] strict whether the input has to be consumed completely + + @return result of the deserialization + + @throw parse_error.101 if a parse error occurs; example: `""unexpected end + of input; expected string literal""` + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails + + @complexity Linear in the length of the input. The parser is a predictive + LL(1) parser. The complexity can be higher if the SAX consumer @a sax has + a super-linear complexity. + + @note A UTF-8 byte order mark is silently ignored. + + @since version 3.2.0 + */ template static bool sax_parse(detail::input_adapter&& i, SAX* sax, input_format_t format = input_format_t::json, @@ -18311,11 +18373,13 @@ class basic_json break; } + // LCOV_EXCL_START default: { // if there exists a parent it cannot be primitive - assert(false); // LCOV_EXCL_LINE + assert(false); } + // LCOV_EXCL_STOP } } };