:art: use Clang-Format
diff --git a/.clang-format b/.clang-format index 5b9e3fd..571a6ec 100644 --- a/.clang-format +++ b/.clang-format
@@ -1,4 +1,3 @@ -#AccessModifierOffset: 2 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false #AlignConsecutiveBitFields: false @@ -12,7 +11,7 @@ AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: Empty AllowShortCaseLabelsOnASingleLine: false -#AllowShortEnumsOnASingleLine: true +AllowShortEnumsOnASingleLine: true AllowShortFunctionsOnASingleLine: Empty AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: Empty @@ -36,8 +35,8 @@ AfterExternBlock: false BeforeCatch: true BeforeElse: true - #BeforeLambdaBody: false - #BeforeWhile: false + BeforeLambdaBody: false + BeforeWhile: false SplitEmptyFunction: false SplitEmptyRecord: false SplitEmptyNamespace: false @@ -60,7 +59,7 @@ MaxEmptyLinesToKeep: 1 NamespaceIndentation: None ReflowComments: false -SortIncludes: true +SortIncludes: CaseSensitive SortUsingDeclarations: true SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 4d33c67..3e078b3 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md
@@ -50,7 +50,7 @@ ## Note - If you open a pull request, the code will be automatically tested with [Valgrind](http://valgrind.org)'s Memcheck tool to detect memory leaks. Please be aware that the execution with Valgrind _may_ in rare cases yield different behavior than running the code directly. This can result in failing unit tests which run successfully without Valgrind. -- There is a Makefile target `make pretty` which runs [Artistic Style](http://astyle.sourceforge.net) to fix indentation. If possible, run it before opening the pull request. Otherwise, we shall run it afterward. +- There is a Makefile target `make pretty` which runs [Clang-Format](https://clang.llvm.org/docs/ClangFormat.html) to fix indentation. If possible, run it before opening the pull request. Otherwise, we shall run it afterward. ## Please don't
diff --git a/.github/workflows/check_amalgamation.yml b/.github/workflows/check_amalgamation.yml index 0fadb52..88651f7 100644 --- a/.github/workflows/check_amalgamation.yml +++ b/.github/workflows/check_amalgamation.yml
@@ -23,13 +23,6 @@ runs-on: ubuntu-latest env: MAIN_DIR: ${{ github.workspace }}/main - INCLUDE_DIR: ${{ github.workspace }}/main/single_include/nlohmann - TOOL_DIR: ${{ github.workspace }}/tools/tools/amalgamate - ASTYLE_FLAGS: > - --style=allman --indent=spaces=4 --indent-modifiers --indent-switches --indent-preproc-block - --indent-preproc-define --indent-col1-comments --pad-oper --pad-header --align-pointer=type - --align-reference=type --add-brackets --convert-tabs --close-templates --lineend=linux --preserve-date - --formatted steps: - name: Checkout pull request @@ -44,27 +37,7 @@ path: tools ref: develop - - name: Install astyle - run: | - sudo apt-get update - sudo apt-get install astyle - - name: Check amalgamation run: | cd $MAIN_DIR - - rm -fr $INCLUDE_DIR/json.hpp~ $INCLUDE_DIR/json_fwd.hpp~ - cp $INCLUDE_DIR/json.hpp $INCLUDE_DIR/json.hpp~ - cp $INCLUDE_DIR/json_fwd.hpp $INCLUDE_DIR/json_fwd.hpp~ - - python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json.json -s . - python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json_fwd.json -s . - echo "Format (1)" - astyle $ASTYLE_FLAGS --suffix=none --quiet $INCLUDE_DIR/json.hpp $INCLUDE_DIR/json_fwd.hpp - - diff $INCLUDE_DIR/json.hpp~ $INCLUDE_DIR/json.hpp - diff $INCLUDE_DIR/json_fwd.hpp~ $INCLUDE_DIR/json_fwd.hpp - - astyle $ASTYLE_FLAGS $(find docs/examples include tests -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort) - echo Check - find $MAIN_DIR -name '*.orig' -exec false {} \+ + make check-amalgamation
diff --git a/Makefile b/Makefile index a1b4e73..9c0cfe5 100644 --- a/Makefile +++ b/Makefile
@@ -142,33 +142,9 @@ # Code format and source amalgamation ########################################################################## -# call the Artistic Style pretty printer on all source files -pretty: - astyle \ - --style=allman \ - --indent=spaces=4 \ - --indent-modifiers \ - --indent-switches \ - --indent-preproc-block \ - --indent-preproc-define \ - --indent-col1-comments \ - --pad-oper \ - --pad-header \ - --align-pointer=type \ - --align-reference=type \ - --add-braces \ - --squeeze-lines=2 \ - --convert-tabs \ - --close-templates \ - --lineend=linux \ - --preserve-date \ - --suffix=none \ - --formatted \ - $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) docs/examples/*.cpp - # call the Clang-Format on all source files -pretty_format: - for FILE in $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/examples/*.cpp; do echo $$FILE; clang-format -i $$FILE; done +pretty: + clang-format --Werror --verbose -i $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) # create single header files and pretty print amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE)
diff --git a/README.md b/README.md index 9109027..91c4774 100644 --- a/README.md +++ b/README.md
@@ -1774,8 +1774,8 @@ - [**amalgamate.py - Amalgamate C source and header files**](https://github.com/edlund/amalgamate) to create a single header file - [**American fuzzy lop**](https://lcamtuf.coredump.cx/afl/) for fuzz testing - [**AppVeyor**](https://www.appveyor.com) for [continuous integration](https://ci.appveyor.com/project/nlohmann/json) on Windows -- [**Artistic Style**](http://astyle.sourceforge.net) for automatic source code indentation - [**Clang**](https://clang.llvm.org) for compilation with code sanitizers +- [**Clang-Format**](https://clang.llvm.org/docs/ClangFormat.html) for automatic source code indentation - [**CMake**](https://cmake.org) for build automation - [**Codacy**](https://www.codacy.com) for further [code analysis](https://www.codacy.com/app/nlohmann/json) - [**Coveralls**](https://coveralls.io) to measure [code coverage](https://coveralls.io/github/nlohmann/json)
diff --git a/cmake/ci.cmake b/cmake/ci.cmake index bbb2d4c..df977eb 100644 --- a/cmake/ci.cmake +++ b/cmake/ci.cmake
@@ -8,16 +8,16 @@ include(FindPython3) find_package(Python3 COMPONENTS Interpreter) -find_program(ASTYLE_TOOL NAMES astyle) -execute_process(COMMAND ${ASTYLE_TOOL} --version OUTPUT_VARIABLE ASTYLE_TOOL_VERSION ERROR_VARIABLE ASTYLE_TOOL_VERSION) -string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" ASTYLE_TOOL_VERSION "${ASTYLE_TOOL_VERSION}") -message(STATUS "🔖 Artistic Style ${ASTYLE_TOOL_VERSION} (${ASTYLE_TOOL})") - find_program(CLANG_TOOL NAMES clang++-HEAD clang++ clang++-17 clang++-16 clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++) execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION) string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}") message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})") +find_program(CLANG_FORMAT_TOOL NAMES clang-format) +execute_process(COMMAND ${CLANG_FORMAT_TOOL} --version OUTPUT_VARIABLE CLANG_FORMAT_TOOL_VERSION ERROR_VARIABLE CLANG_FORMAT_TOOL_VERSION) +string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_FORMAT_TOOL_VERSION "${CLANG_FORMAT_TOOL_VERSION}") +message(STATUS "🔖 Clang-Format ${CLANG_FORMAT_TOOL_VERSION} (${CLANG_FORMAT_TOOL})") + find_program(CLANG_TIDY_TOOL NAMES clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11 clang-tidy) execute_process(COMMAND ${CLANG_TIDY_TOOL} --version OUTPUT_VARIABLE CLANG_TIDY_TOOL_VERSION ERROR_VARIABLE CLANG_TIDY_TOOL_VERSION) string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TIDY_TOOL_VERSION "${CLANG_TIDY_TOOL_VERSION}") @@ -581,33 +581,8 @@ # Check if header is amalgamated and sources are properly indented. ############################################################################### -set(ASTYLE_FLAGS --style=allman --indent=spaces=4 --indent-modifiers --indent-switches --indent-preproc-block --indent-preproc-define --indent-col1-comments --pad-oper --pad-header --align-pointer=type --align-reference=type --add-brackets --convert-tabs --close-templates --lineend=linux --preserve-date --formatted) - -file(GLOB_RECURSE INDENT_FILES - ${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp - ${PROJECT_SOURCE_DIR}/tests/src/*.cpp - ${PROJECT_SOURCE_DIR}/tests/src/*.hpp - ${PROJECT_SOURCE_DIR}/tests/benchmarks/src/benchmarks.cpp - ${PROJECT_SOURCE_DIR}/docs/examples/*.cpp -) - -set(include_dir ${PROJECT_SOURCE_DIR}/single_include/nlohmann) -set(tool_dir ${PROJECT_SOURCE_DIR}/tools/amalgamate) add_custom_target(ci_test_amalgamation - COMMAND rm -fr ${include_dir}/json.hpp~ ${include_dir}/json_fwd.hpp~ - COMMAND cp ${include_dir}/json.hpp ${include_dir}/json.hpp~ - COMMAND cp ${include_dir}/json_fwd.hpp ${include_dir}/json_fwd.hpp~ - - COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json.json -s . - COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json_fwd.json -s . - COMMAND ${ASTYLE_TOOL} ${ASTYLE_FLAGS} --suffix=none --quiet ${include_dir}/json.hpp ${include_dir}/json_fwd.hpp - - COMMAND diff ${include_dir}/json.hpp~ ${include_dir}/json.hpp - COMMAND diff ${include_dir}/json_fwd.hpp~ ${include_dir}/json_fwd.hpp - - COMMAND ${ASTYLE_TOOL} ${ASTYLE_FLAGS} ${INDENT_FILES} - COMMAND for FILE in `find . -name '*.orig'`\; do false \; done - + COMMAND make check-amalgamation WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Check amalgamation and indentation" )
diff --git a/include/nlohmann/adl_serializer.hpp b/include/nlohmann/adl_serializer.hpp index 56a606c..7bea4c4 100644 --- a/include/nlohmann/adl_serializer.hpp +++ b/include/nlohmann/adl_serializer.hpp
@@ -24,9 +24,9 @@ /// @brief convert a JSON value to any value type /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/ template<typename BasicJsonType, typename TargetType = ValueType> - static auto from_json(BasicJsonType && j, TargetType& val) noexcept( + static auto from_json(BasicJsonType&& j, TargetType& val) noexcept( noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val))) - -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void()) + -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void()) { ::nlohmann::from_json(std::forward<BasicJsonType>(j), val); } @@ -34,19 +34,19 @@ /// @brief convert a JSON value to any value type /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/ template<typename BasicJsonType, typename TargetType = ValueType> - static auto from_json(BasicJsonType && j) noexcept( - noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))) - -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})) + static auto from_json(BasicJsonType&& j) noexcept( + noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType>{}))) + -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType>{})) { - return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}); + return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType>{}); } /// @brief convert any value type to a JSON value /// @sa https://json.nlohmann.me/api/adl_serializer/to_json/ template<typename BasicJsonType, typename TargetType = ValueType> - static auto to_json(BasicJsonType& j, TargetType && val) noexcept( + static auto to_json(BasicJsonType& j, TargetType&& val) noexcept( noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val)))) - -> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void()) + -> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void()) { ::nlohmann::to_json(j, std::forward<TargetType>(val)); }
diff --git a/include/nlohmann/byte_container_with_subtype.hpp b/include/nlohmann/byte_container_with_subtype.hpp index 91382cd..20036c2 100644 --- a/include/nlohmann/byte_container_with_subtype.hpp +++ b/include/nlohmann/byte_container_with_subtype.hpp
@@ -8,9 +8,9 @@ #pragma once -#include <cstdint> // uint8_t, uint64_t -#include <tuple> // tie -#include <utility> // move +#include <cstdint> // uint8_t, uint64_t +#include <tuple> // tie +#include <utility> // move #include <nlohmann/detail/abi_macros.hpp> @@ -27,31 +27,31 @@ /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype() noexcept(noexcept(container_type())) - : container_type() + : container_type() {} /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b))) - : container_type(b) + : container_type(b) {} /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b)))) - : container_type(std::move(b)) + : container_type(std::move(b)) {} /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b))) - : container_type(b) - , m_subtype(subtype_) - , m_has_subtype(true) + : container_type(b) + , m_subtype(subtype_) + , m_has_subtype(true) {} /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b)))) - : container_type(std::move(b)) - , m_subtype(subtype_) - , m_has_subtype(true) + : container_type(std::move(b)) + , m_subtype(subtype_) + , m_has_subtype(true) {} bool operator==(const byte_container_with_subtype& rhs) const
diff --git a/include/nlohmann/detail/abi_macros.hpp b/include/nlohmann/detail/abi_macros.hpp index f48b9eb..ed31cd1 100644 --- a/include/nlohmann/detail/abi_macros.hpp +++ b/include/nlohmann/detail/abi_macros.hpp
@@ -47,54 +47,52 @@ #endif // Construct the namespace ABI tags component -#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b +#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi##a##b #define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) -#define NLOHMANN_JSON_ABI_TAGS \ - NLOHMANN_JSON_ABI_TAGS_CONCAT( \ - NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ - NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) +#define NLOHMANN_JSON_ABI_TAGS \ + NLOHMANN_JSON_ABI_TAGS_CONCAT( \ + NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ + NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) // Construct the namespace version component #define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ - _v ## major ## _ ## minor ## _ ## patch + _v##major##_##minor##_##patch #define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) #if NLOHMANN_JSON_NAMESPACE_NO_VERSION -#define NLOHMANN_JSON_NAMESPACE_VERSION + #define NLOHMANN_JSON_NAMESPACE_VERSION #else -#define NLOHMANN_JSON_NAMESPACE_VERSION \ - NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ - NLOHMANN_JSON_VERSION_MINOR, \ - NLOHMANN_JSON_VERSION_PATCH) + #define NLOHMANN_JSON_NAMESPACE_VERSION \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH) #endif // Combine namespace components -#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b +#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a##b #define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) #ifndef NLOHMANN_JSON_NAMESPACE -#define NLOHMANN_JSON_NAMESPACE \ - nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ - NLOHMANN_JSON_ABI_TAGS, \ + #define NLOHMANN_JSON_NAMESPACE \ + nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ NLOHMANN_JSON_NAMESPACE_VERSION) #endif #ifndef NLOHMANN_JSON_NAMESPACE_BEGIN -#define NLOHMANN_JSON_NAMESPACE_BEGIN \ - namespace nlohmann \ - { \ - inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ - NLOHMANN_JSON_ABI_TAGS, \ - NLOHMANN_JSON_NAMESPACE_VERSION) \ - { + #define NLOHMANN_JSON_NAMESPACE_BEGIN \ + namespace nlohmann { \ + inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) { #endif #ifndef NLOHMANN_JSON_NAMESPACE_END -#define NLOHMANN_JSON_NAMESPACE_END \ - } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ - } // namespace nlohmann + #define NLOHMANN_JSON_NAMESPACE_END \ + } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ + } // namespace nlohmann #endif
diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index aa2f0cb..bbfd63c 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp
@@ -8,17 +8,17 @@ #pragma once -#include <algorithm> // transform -#include <array> // array -#include <forward_list> // forward_list -#include <iterator> // inserter, front_inserter, end -#include <map> // map -#include <string> // string -#include <tuple> // tuple, make_tuple -#include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible -#include <unordered_map> // unordered_map -#include <utility> // pair, declval -#include <valarray> // valarray +#include <algorithm> // transform +#include <array> // array +#include <forward_list> // forward_list +#include <iterator> // inserter, front_inserter, end +#include <map> // map +#include <string> // string +#include <tuple> // tuple, make_tuple +#include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible +#include <unordered_map> // unordered_map +#include <utility> // pair, declval +#include <valarray> // valarray #include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/macro_scope.hpp> @@ -30,8 +30,7 @@ #include <nlohmann/detail/value_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename BasicJsonType> inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n) @@ -44,10 +43,7 @@ } // overloads for basic_json template parameters -template < typename BasicJsonType, typename ArithmeticType, - enable_if_t < std::is_arithmetic<ArithmeticType>::value&& - !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, - int > = 0 > +template<typename BasicJsonType, typename ArithmeticType, enable_if_t<std::is_arithmetic<ArithmeticType>::value && !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, int> = 0> void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) { switch (static_cast<value_t>(j)) @@ -100,13 +96,12 @@ s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); } -template < - typename BasicJsonType, typename StringType, - enable_if_t < - std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value - && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value - && !std::is_same<typename BasicJsonType::string_t, StringType>::value - && !is_json_ref<StringType>::value, int > = 0 > +template< + typename BasicJsonType, + typename StringType, + enable_if_t< + std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value && !std::is_same<typename BasicJsonType::string_t, StringType>::value && !is_json_ref<StringType>::value, + int> = 0> inline void from_json(const BasicJsonType& j, StringType& s) { if (JSON_HEDLEY_UNLIKELY(!j.is_string())) @@ -136,8 +131,7 @@ } #if !JSON_DISABLE_ENUM_SERIALIZATION -template<typename BasicJsonType, typename EnumType, - enable_if_t<std::is_enum<EnumType>::value, int> = 0> +template<typename BasicJsonType, typename EnumType, enable_if_t<std::is_enum<EnumType>::value, int> = 0> inline void from_json(const BasicJsonType& j, EnumType& e) { typename std::underlying_type<EnumType>::type val; @@ -147,8 +141,7 @@ #endif // JSON_DISABLE_ENUM_SERIALIZATION // forward_list doesn't have an insert method -template<typename BasicJsonType, typename T, typename Allocator, - enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> +template<typename BasicJsonType, typename T, typename Allocator, enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> inline void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) @@ -156,16 +149,13 @@ JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); } l.clear(); - std::transform(j.rbegin(), j.rend(), - std::front_inserter(l), [](const BasicJsonType & i) - { + std::transform(j.rbegin(), j.rend(), std::front_inserter(l), [](const BasicJsonType& i) { return i.template get<T>(); }); } // valarray doesn't have an insert method -template<typename BasicJsonType, typename T, - enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> +template<typename BasicJsonType, typename T, enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> inline void from_json(const BasicJsonType& j, std::valarray<T>& l) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) @@ -173,16 +163,14 @@ JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); } l.resize(j.size()); - std::transform(j.begin(), j.end(), std::begin(l), - [](const BasicJsonType & elem) - { + std::transform(j.begin(), j.end(), std::begin(l), [](const BasicJsonType& elem) { return elem.template get<T>(); }); } template<typename BasicJsonType, typename T, std::size_t N> auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) --> decltype(j.template get<T>(), void()) + -> decltype(j.template get<T>(), void()) { for (std::size_t i = 0; i < N; ++i) { @@ -197,9 +185,8 @@ } template<typename BasicJsonType, typename T, std::size_t N> -auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, - priority_tag<2> /*unused*/) --> decltype(j.template get<T>(), void()) +auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, priority_tag<2> /*unused*/) + -> decltype(j.template get<T>(), void()) { for (std::size_t i = 0; i < N; ++i) { @@ -207,23 +194,17 @@ } } -template<typename BasicJsonType, typename ConstructibleArrayType, - enable_if_t< - std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, - int> = 0> +template<typename BasicJsonType, typename ConstructibleArrayType, enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, int> = 0> auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/) --> decltype( - arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()), - j.template get<typename ConstructibleArrayType::value_type>(), - void()) + -> decltype(arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()), + j.template get<typename ConstructibleArrayType::value_type>(), + void()) { using std::end; ConstructibleArrayType ret; ret.reserve(j.size()); - std::transform(j.begin(), j.end(), - std::inserter(ret, end(ret)), [](const BasicJsonType & i) - { + std::transform(j.begin(), j.end(), std::inserter(ret, end(ret)), [](const BasicJsonType& i) { // get<BasicJsonType>() returns *this, this won't call a from_json // method when value_type is BasicJsonType return i.template get<typename ConstructibleArrayType::value_type>(); @@ -231,65 +212,56 @@ arr = std::move(ret); } -template<typename BasicJsonType, typename ConstructibleArrayType, - enable_if_t< - std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, - int> = 0> -inline void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, - priority_tag<0> /*unused*/) +template<typename BasicJsonType, typename ConstructibleArrayType, enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, int> = 0> +inline void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<0> /*unused*/) { using std::end; ConstructibleArrayType ret; std::transform( - j.begin(), j.end(), std::inserter(ret, end(ret)), - [](const BasicJsonType & i) - { - // get<BasicJsonType>() returns *this, this won't call a from_json - // method when value_type is BasicJsonType - return i.template get<typename ConstructibleArrayType::value_type>(); - }); + j.begin(), + j.end(), + std::inserter(ret, end(ret)), + [](const BasicJsonType& i) { + // get<BasicJsonType>() returns *this, this won't call a from_json + // method when value_type is BasicJsonType + return i.template get<typename ConstructibleArrayType::value_type>(); + }); arr = std::move(ret); } -template < typename BasicJsonType, typename ConstructibleArrayType, - enable_if_t < - is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&& - !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&& - !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&& - !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&& - !is_basic_json<ConstructibleArrayType>::value, - int > = 0 > +template<typename BasicJsonType, typename ConstructibleArrayType, enable_if_t<is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value && !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value && !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value && !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value && !is_basic_json<ConstructibleArrayType>::value, int> = 0> auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr) --> decltype(from_json_array_impl(j, arr, priority_tag<3> {}), -j.template get<typename ConstructibleArrayType::value_type>(), -void()) + -> decltype(from_json_array_impl(j, arr, priority_tag<3>{}), + j.template get<typename ConstructibleArrayType::value_type>(), + void()) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); } - from_json_array_impl(j, arr, priority_tag<3> {}); + from_json_array_impl(j, arr, priority_tag<3>{}); } -template < typename BasicJsonType, typename T, std::size_t... Idx > +template<typename BasicJsonType, typename T, std::size_t... Idx> std::array<T, sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j, - identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/) + identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, + index_sequence<Idx...> /*unused*/) { - return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } }; + return {{std::forward<BasicJsonType>(j).at(Idx).template get<T>()...}}; } -template < typename BasicJsonType, typename T, std::size_t N > +template<typename BasicJsonType, typename T, std::size_t N> auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag) --> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {})) + -> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N>{})) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); } - return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}); + return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N>{}); } template<typename BasicJsonType> @@ -303,8 +275,7 @@ bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>(); } -template<typename BasicJsonType, typename ConstructibleObjectType, - enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0> +template<typename BasicJsonType, typename ConstructibleObjectType, enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0> inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) { if (JSON_HEDLEY_UNLIKELY(!j.is_object())) @@ -316,12 +287,12 @@ const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>(); using value_type = typename ConstructibleObjectType::value_type; std::transform( - inner_object->begin(), inner_object->end(), + inner_object->begin(), + inner_object->end(), std::inserter(ret, ret.begin()), - [](typename BasicJsonType::object_t::value_type const & p) - { - return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>()); - }); + [](typename BasicJsonType::object_t::value_type const& p) { + return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>()); + }); obj = std::move(ret); } @@ -329,14 +300,7 @@ // (BooleanType, etc..); note: Is it really necessary to provide explicit // overloads for boolean_t etc. in case of a custom BooleanType which is not // an arithmetic type? -template < typename BasicJsonType, typename ArithmeticType, - enable_if_t < - std::is_arithmetic<ArithmeticType>::value&& - !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&& - !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&& - !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&& - !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, - int > = 0 > +template<typename BasicJsonType, typename ArithmeticType, enable_if_t<std::is_arithmetic<ArithmeticType>::value && !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value && !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value && !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value && !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, int> = 0> inline void from_json(const BasicJsonType& j, ArithmeticType& val) { switch (static_cast<value_t>(j)) @@ -379,7 +343,7 @@ return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).template get<Args>()...); } -template < typename BasicJsonType, class A1, class A2 > +template<typename BasicJsonType, class A1, class A2> std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/) { return {std::forward<BasicJsonType>(j).at(0).template get<A1>(), @@ -389,36 +353,34 @@ template<typename BasicJsonType, typename A1, typename A2> inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> /*unused*/) { - p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {}); + p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>>{}, priority_tag<0>{}); } template<typename BasicJsonType, typename... Args> std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> /*unused*/, priority_tag<2> /*unused*/) { - return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {}); + return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...>{}); } template<typename BasicJsonType, typename... Args> inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> /*unused*/) { - t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {}); + t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...>{}); } template<typename BasicJsonType, typename TupleRelated> auto from_json(BasicJsonType&& j, TupleRelated&& t) --> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {})) + -> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3>{})) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); } - return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}); + return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3>{}); } -template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator, - typename = enable_if_t < !std::is_constructible < - typename BasicJsonType::string_t, Key >::value >> +template<typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator, typename = enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, Key>::value>> inline void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) @@ -436,9 +398,7 @@ } } -template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator, - typename = enable_if_t < !std::is_constructible < - typename BasicJsonType::string_t, Key >::value >> +template<typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator, typename = enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, Key>::value>> inline void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) @@ -472,8 +432,8 @@ { template<typename BasicJsonType, typename T> auto operator()(const BasicJsonType& j, T&& val) const - noexcept(noexcept(from_json(j, std::forward<T>(val)))) - -> decltype(from_json(j, std::forward<T>(val))) + noexcept(noexcept(from_json(j, std::forward<T>(val)))) + -> decltype(from_json(j, std::forward<T>(val))) { return from_json(j, std::forward<T>(val)); } @@ -485,10 +445,10 @@ /// namespace to hold default `from_json` function /// to see why this is required: /// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html -namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) +namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) { #endif -JSON_INLINE_VARIABLE constexpr const auto& from_json = // NOLINT(misc-definitions-in-headers) +JSON_INLINE_VARIABLE constexpr const auto& from_json = // NOLINT(misc-definitions-in-headers) detail::static_const<detail::from_json_fn>::value; #ifndef JSON_HAS_CPP_17 } // namespace
diff --git a/include/nlohmann/detail/conversions/to_chars.hpp b/include/nlohmann/detail/conversions/to_chars.hpp index e10741c..51f2b4a 100644 --- a/include/nlohmann/detail/conversions/to_chars.hpp +++ b/include/nlohmann/detail/conversions/to_chars.hpp
@@ -9,18 +9,17 @@ #pragma once -#include <array> // array -#include <cmath> // signbit, isfinite -#include <cstdint> // intN_t, uintN_t -#include <cstring> // memcpy, memmove -#include <limits> // numeric_limits -#include <type_traits> // conditional +#include <array> // array +#include <cmath> // signbit, isfinite +#include <cstdint> // intN_t, uintN_t +#include <cstring> // memcpy, memmove +#include <limits> // numeric_limits +#include <type_traits> // conditional #include <nlohmann/detail/macro_scope.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /*! @brief implements the Grisu2 algorithm for binary to decimal floating-point @@ -41,8 +40,7 @@ Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language Design and Implementation, PLDI 1996 */ -namespace dtoa_impl -{ +namespace dtoa_impl { template<typename Target, typename Source> Target reinterpret_bits(const Source source) @@ -54,14 +52,17 @@ return target; } -struct diyfp // f * 2^e +struct diyfp // f * 2^e { - static constexpr int kPrecision = 64; // = q + static constexpr int kPrecision = 64; // = q std::uint64_t f = 0; int e = 0; - constexpr diyfp(std::uint64_t f_, int e_) noexcept : f(f_), e(e_) {} + constexpr diyfp(std::uint64_t f_, int e_) noexcept + : f(f_) + , e(e_) + {} /*! @brief returns x - y @@ -133,7 +134,7 @@ // Effectively we only need to add the highest bit in p_lo to p_hi (and // Q_hi + 1 does not overflow). - Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up + Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u); @@ -201,12 +202,12 @@ static_assert(std::numeric_limits<FloatType>::is_iec559, "internal error: dtoa_short requires an IEEE-754 floating-point implementation"); - constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit) - constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1); - constexpr int kMinExp = 1 - kBias; - constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1); // = 2^(p-1) + constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit) + constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1); + constexpr int kMinExp = 1 - kBias; + constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1); // = 2^(p-1) - using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type; + using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t>::type; const auto bits = static_cast<std::uint64_t>(reinterpret_bits<bits_type>(value)); const std::uint64_t E = bits >> (kPrecision - 1); @@ -214,8 +215,8 @@ const bool is_denormal = E == 0; const diyfp v = is_denormal - ? diyfp(F, kMinExp) - : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias); + ? diyfp(F, kMinExp) + : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias); // Compute the boundaries m- and m+ of the floating-point value // v = f * 2^e. @@ -241,8 +242,8 @@ const bool lower_boundary_is_closer = F == 0 && E > 1; const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1); const diyfp m_minus = lower_boundary_is_closer - ? diyfp(4 * v.f - 1, v.e - 2) // (B) - : diyfp(2 * v.f - 1, v.e - 1); // (A) + ? diyfp(4 * v.f - 1, v.e - 2) // (B) + : diyfp(2 * v.f - 1, v.e - 1); // (A) // Determine the normalized w+ = m+. const diyfp w_plus = diyfp::normalize(m_plus); @@ -311,7 +312,7 @@ constexpr int kAlpha = -60; constexpr int kGamma = -32; -struct cached_power // c = f * 2^e ~= 10^k +struct cached_power // c = f * 2^e ~= 10^k { std::uint64_t f; int e; @@ -381,96 +382,95 @@ constexpr int kCachedPowersDecStep = 8; static constexpr std::array<cached_power, 79> kCachedPowers = - { { - { 0xAB70FE17C79AC6CA, -1060, -300 }, - { 0xFF77B1FCBEBCDC4F, -1034, -292 }, - { 0xBE5691EF416BD60C, -1007, -284 }, - { 0x8DD01FAD907FFC3C, -980, -276 }, - { 0xD3515C2831559A83, -954, -268 }, - { 0x9D71AC8FADA6C9B5, -927, -260 }, - { 0xEA9C227723EE8BCB, -901, -252 }, - { 0xAECC49914078536D, -874, -244 }, - { 0x823C12795DB6CE57, -847, -236 }, - { 0xC21094364DFB5637, -821, -228 }, - { 0x9096EA6F3848984F, -794, -220 }, - { 0xD77485CB25823AC7, -768, -212 }, - { 0xA086CFCD97BF97F4, -741, -204 }, - { 0xEF340A98172AACE5, -715, -196 }, - { 0xB23867FB2A35B28E, -688, -188 }, - { 0x84C8D4DFD2C63F3B, -661, -180 }, - { 0xC5DD44271AD3CDBA, -635, -172 }, - { 0x936B9FCEBB25C996, -608, -164 }, - { 0xDBAC6C247D62A584, -582, -156 }, - { 0xA3AB66580D5FDAF6, -555, -148 }, - { 0xF3E2F893DEC3F126, -529, -140 }, - { 0xB5B5ADA8AAFF80B8, -502, -132 }, - { 0x87625F056C7C4A8B, -475, -124 }, - { 0xC9BCFF6034C13053, -449, -116 }, - { 0x964E858C91BA2655, -422, -108 }, - { 0xDFF9772470297EBD, -396, -100 }, - { 0xA6DFBD9FB8E5B88F, -369, -92 }, - { 0xF8A95FCF88747D94, -343, -84 }, - { 0xB94470938FA89BCF, -316, -76 }, - { 0x8A08F0F8BF0F156B, -289, -68 }, - { 0xCDB02555653131B6, -263, -60 }, - { 0x993FE2C6D07B7FAC, -236, -52 }, - { 0xE45C10C42A2B3B06, -210, -44 }, - { 0xAA242499697392D3, -183, -36 }, - { 0xFD87B5F28300CA0E, -157, -28 }, - { 0xBCE5086492111AEB, -130, -20 }, - { 0x8CBCCC096F5088CC, -103, -12 }, - { 0xD1B71758E219652C, -77, -4 }, - { 0x9C40000000000000, -50, 4 }, - { 0xE8D4A51000000000, -24, 12 }, - { 0xAD78EBC5AC620000, 3, 20 }, - { 0x813F3978F8940984, 30, 28 }, - { 0xC097CE7BC90715B3, 56, 36 }, - { 0x8F7E32CE7BEA5C70, 83, 44 }, - { 0xD5D238A4ABE98068, 109, 52 }, - { 0x9F4F2726179A2245, 136, 60 }, - { 0xED63A231D4C4FB27, 162, 68 }, - { 0xB0DE65388CC8ADA8, 189, 76 }, - { 0x83C7088E1AAB65DB, 216, 84 }, - { 0xC45D1DF942711D9A, 242, 92 }, - { 0x924D692CA61BE758, 269, 100 }, - { 0xDA01EE641A708DEA, 295, 108 }, - { 0xA26DA3999AEF774A, 322, 116 }, - { 0xF209787BB47D6B85, 348, 124 }, - { 0xB454E4A179DD1877, 375, 132 }, - { 0x865B86925B9BC5C2, 402, 140 }, - { 0xC83553C5C8965D3D, 428, 148 }, - { 0x952AB45CFA97A0B3, 455, 156 }, - { 0xDE469FBD99A05FE3, 481, 164 }, - { 0xA59BC234DB398C25, 508, 172 }, - { 0xF6C69A72A3989F5C, 534, 180 }, - { 0xB7DCBF5354E9BECE, 561, 188 }, - { 0x88FCF317F22241E2, 588, 196 }, - { 0xCC20CE9BD35C78A5, 614, 204 }, - { 0x98165AF37B2153DF, 641, 212 }, - { 0xE2A0B5DC971F303A, 667, 220 }, - { 0xA8D9D1535CE3B396, 694, 228 }, - { 0xFB9B7CD9A4A7443C, 720, 236 }, - { 0xBB764C4CA7A44410, 747, 244 }, - { 0x8BAB8EEFB6409C1A, 774, 252 }, - { 0xD01FEF10A657842C, 800, 260 }, - { 0x9B10A4E5E9913129, 827, 268 }, - { 0xE7109BFBA19C0C9D, 853, 276 }, - { 0xAC2820D9623BF429, 880, 284 }, - { 0x80444B5E7AA7CF85, 907, 292 }, - { 0xBF21E44003ACDD2D, 933, 300 }, - { 0x8E679C2F5E44FF8F, 960, 308 }, - { 0xD433179D9C8CB841, 986, 316 }, - { 0x9E19DB92B4E31BA9, 1013, 324 }, - } - }; + { + {0xAB70FE17C79AC6CA, -1060, -300}, + {0xFF77B1FCBEBCDC4F, -1034, -292}, + {0xBE5691EF416BD60C, -1007, -284}, + {0x8DD01FAD907FFC3C, -980, -276}, + {0xD3515C2831559A83, -954, -268}, + {0x9D71AC8FADA6C9B5, -927, -260}, + {0xEA9C227723EE8BCB, -901, -252}, + {0xAECC49914078536D, -874, -244}, + {0x823C12795DB6CE57, -847, -236}, + {0xC21094364DFB5637, -821, -228}, + {0x9096EA6F3848984F, -794, -220}, + {0xD77485CB25823AC7, -768, -212}, + {0xA086CFCD97BF97F4, -741, -204}, + {0xEF340A98172AACE5, -715, -196}, + {0xB23867FB2A35B28E, -688, -188}, + {0x84C8D4DFD2C63F3B, -661, -180}, + {0xC5DD44271AD3CDBA, -635, -172}, + {0x936B9FCEBB25C996, -608, -164}, + {0xDBAC6C247D62A584, -582, -156}, + {0xA3AB66580D5FDAF6, -555, -148}, + {0xF3E2F893DEC3F126, -529, -140}, + {0xB5B5ADA8AAFF80B8, -502, -132}, + {0x87625F056C7C4A8B, -475, -124}, + {0xC9BCFF6034C13053, -449, -116}, + {0x964E858C91BA2655, -422, -108}, + {0xDFF9772470297EBD, -396, -100}, + {0xA6DFBD9FB8E5B88F, -369, -92}, + {0xF8A95FCF88747D94, -343, -84}, + {0xB94470938FA89BCF, -316, -76}, + {0x8A08F0F8BF0F156B, -289, -68}, + {0xCDB02555653131B6, -263, -60}, + {0x993FE2C6D07B7FAC, -236, -52}, + {0xE45C10C42A2B3B06, -210, -44}, + {0xAA242499697392D3, -183, -36}, + {0xFD87B5F28300CA0E, -157, -28}, + {0xBCE5086492111AEB, -130, -20}, + {0x8CBCCC096F5088CC, -103, -12}, + {0xD1B71758E219652C, -77, -4}, + {0x9C40000000000000, -50, 4}, + {0xE8D4A51000000000, -24, 12}, + {0xAD78EBC5AC620000, 3, 20}, + {0x813F3978F8940984, 30, 28}, + {0xC097CE7BC90715B3, 56, 36}, + {0x8F7E32CE7BEA5C70, 83, 44}, + {0xD5D238A4ABE98068, 109, 52}, + {0x9F4F2726179A2245, 136, 60}, + {0xED63A231D4C4FB27, 162, 68}, + {0xB0DE65388CC8ADA8, 189, 76}, + {0x83C7088E1AAB65DB, 216, 84}, + {0xC45D1DF942711D9A, 242, 92}, + {0x924D692CA61BE758, 269, 100}, + {0xDA01EE641A708DEA, 295, 108}, + {0xA26DA3999AEF774A, 322, 116}, + {0xF209787BB47D6B85, 348, 124}, + {0xB454E4A179DD1877, 375, 132}, + {0x865B86925B9BC5C2, 402, 140}, + {0xC83553C5C8965D3D, 428, 148}, + {0x952AB45CFA97A0B3, 455, 156}, + {0xDE469FBD99A05FE3, 481, 164}, + {0xA59BC234DB398C25, 508, 172}, + {0xF6C69A72A3989F5C, 534, 180}, + {0xB7DCBF5354E9BECE, 561, 188}, + {0x88FCF317F22241E2, 588, 196}, + {0xCC20CE9BD35C78A5, 614, 204}, + {0x98165AF37B2153DF, 641, 212}, + {0xE2A0B5DC971F303A, 667, 220}, + {0xA8D9D1535CE3B396, 694, 228}, + {0xFB9B7CD9A4A7443C, 720, 236}, + {0xBB764C4CA7A44410, 747, 244}, + {0x8BAB8EEFB6409C1A, 774, 252}, + {0xD01FEF10A657842C, 800, 260}, + {0x9B10A4E5E9913129, 827, 268}, + {0xE7109BFBA19C0C9D, 853, 276}, + {0xAC2820D9623BF429, 880, 284}, + {0x80444B5E7AA7CF85, 907, 292}, + {0xBF21E44003ACDD2D, 933, 300}, + {0x8E679C2F5E44FF8F, 960, 308}, + {0xD433179D9C8CB841, 986, 316}, + {0x9E19DB92B4E31BA9, 1013, 324}, + }}; // This computation gives exactly the same results for k as // k = ceil((kAlpha - e - 1) * 0.30102999566398114) // for |e| <= 1500, but doesn't require floating-point operations. // NB: log_10(2) ~= 78913 / 2^18 JSON_ASSERT(e >= -1500); - JSON_ASSERT(e <= 1500); + JSON_ASSERT(e <= 1500); const int f = kAlpha - e - 1; const int k = (f * 78913) / (1 << 18) + static_cast<int>(f > 0); @@ -501,50 +501,49 @@ if (n >= 100000000) { pow10 = 100000000; - return 9; + return 9; } if (n >= 10000000) { pow10 = 10000000; - return 8; + return 8; } if (n >= 1000000) { pow10 = 1000000; - return 7; + return 7; } if (n >= 100000) { pow10 = 100000; - return 6; + return 6; } if (n >= 10000) { pow10 = 10000; - return 5; + return 5; } if (n >= 1000) { pow10 = 1000; - return 4; + return 4; } if (n >= 100) { pow10 = 100; - return 3; + return 3; } if (n >= 10) { pow10 = 10; - return 2; + return 2; } pow10 = 1; return 1; } -inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta, - std::uint64_t rest, std::uint64_t ten_k) +inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta, std::uint64_t rest, std::uint64_t ten_k) { JSON_ASSERT(len >= 1); JSON_ASSERT(dist <= delta); @@ -570,9 +569,7 @@ // The tests are written in this order to avoid overflow in unsigned // integer arithmetic. - while (rest < dist - && delta - rest >= ten_k - && (rest + ten_k < dist || dist - rest > rest + ten_k - dist)) + while (rest < dist && delta - rest >= ten_k && (rest + ten_k < dist || dist - rest > rest + ten_k - dist)) { JSON_ASSERT(buf[len - 1] != '0'); buf[len - 1]--; @@ -584,8 +581,7 @@ Generates V = buffer * 10^decimal_exponent, such that M- <= V <= M+. M- and M+ must be normalized and share the same exponent -60 <= e <= -32. */ -inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, - diyfp M_minus, diyfp w, diyfp M_plus) +inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus) { static_assert(kAlpha >= -60, "internal error"); static_assert(kGamma <= -32, "internal error"); @@ -605,8 +601,8 @@ JSON_ASSERT(M_plus.e >= kAlpha); JSON_ASSERT(M_plus.e <= kGamma); - std::uint64_t delta = diyfp::sub(M_plus, M_minus).f; // (significand of (M+ - M-), implicit exponent is e) - std::uint64_t dist = diyfp::sub(M_plus, w ).f; // (significand of (M+ - w ), implicit exponent is e) + std::uint64_t delta = diyfp::sub(M_plus, M_minus).f; // (significand of (M+ - M-), implicit exponent is e) + std::uint64_t dist = diyfp::sub(M_plus, w).f; // (significand of (M+ - w ), implicit exponent is e) // Split M+ = f * 2^e into two parts p1 and p2 (note: e < 0): // @@ -617,8 +613,8 @@ const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e); - auto p1 = static_cast<std::uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.) - std::uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e + auto p1 = static_cast<std::uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.) + std::uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e // 1) // @@ -661,7 +657,7 @@ // = (buffer * 10 + d) * 10^(n-1) + (r + p2 * 2^e) // JSON_ASSERT(d <= 9); - buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d + buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d // // M+ = buffer * 10^(n-1) + (r + p2 * 2^e) // @@ -760,15 +756,15 @@ // JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10); p2 *= 10; - const std::uint64_t d = p2 >> -one.e; // d = (10 * p2) div 2^-e - const std::uint64_t r = p2 & (one.f - 1); // r = (10 * p2) mod 2^-e + const std::uint64_t d = p2 >> -one.e; // d = (10 * p2) div 2^-e + const std::uint64_t r = p2 & (one.f - 1); // r = (10 * p2) mod 2^-e // // M+ = buffer * 10^-m + 10^-m * (1/10 * (d * 2^-e + r) * 2^e // = buffer * 10^-m + 10^-m * (1/10 * (d + r * 2^e)) // = (buffer * 10 + d) * 10^(-m-1) + 10^(-m-1) * r * 2^e // JSON_ASSERT(d <= 9); - buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d + buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d // // M+ = buffer * 10^(-m-1) + 10^(-m-1) * r * 2^e // @@ -784,7 +780,7 @@ // p2 * 2^e <= 10^m * delta * 2^e // p2 <= 10^m * delta delta *= 10; - dist *= 10; + dist *= 10; if (p2 <= delta) { break; @@ -825,8 +821,7 @@ The buffer must be large enough, i.e. >= max_digits10. */ JSON_HEDLEY_NON_NULL(1) -inline void grisu2(char* buf, int& len, int& decimal_exponent, - diyfp m_minus, diyfp v, diyfp m_plus) +inline void grisu2(char* buf, int& len, int& decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus) { JSON_ASSERT(m_plus.e == m_minus.e); JSON_ASSERT(m_plus.e == v.e); @@ -842,12 +837,12 @@ const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e); - const diyfp c_minus_k(cached.f, cached.e); // = c ~= 10^-k + const diyfp c_minus_k(cached.f, cached.e); // = c ~= 10^-k // The exponent of the products is = v.e + c_minus_k.e + q and is in the range [alpha,gamma] - const diyfp w = diyfp::mul(v, c_minus_k); + const diyfp w = diyfp::mul(v, c_minus_k); const diyfp w_minus = diyfp::mul(m_minus, c_minus_k); - const diyfp w_plus = diyfp::mul(m_plus, c_minus_k); + const diyfp w_plus = diyfp::mul(m_plus, c_minus_k); // ----(---+---)---------------(---+---)---------------(---+---)---- // w- w w+ @@ -871,9 +866,9 @@ // Note that this does not mean that Grisu2 always generates the shortest // possible number in the interval (m-, m+). const diyfp M_minus(w_minus.f + 1, w_minus.e); - const diyfp M_plus (w_plus.f - 1, w_plus.e ); + const diyfp M_plus(w_plus.f - 1, w_plus.e); - decimal_exponent = -cached.k; // = -(-k) = k + decimal_exponent = -cached.k; // = -(-k) = k grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus); } @@ -909,7 +904,7 @@ // NB: If the neighbors are computed for single-precision numbers, there is a single float // (7.0385307e-26f) which can't be recovered using strtod. The resulting double precision // value is off by 1 ulp. -#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if) +#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if) const boundaries w = compute_boundaries(static_cast<double>(value)); #else const boundaries w = compute_boundaries(value); @@ -928,7 +923,7 @@ inline char* append_exponent(char* buf, int e) { JSON_ASSERT(e > -1000); - JSON_ASSERT(e < 1000); + JSON_ASSERT(e < 1000); if (e < 0) { @@ -977,8 +972,7 @@ */ JSON_HEDLEY_NON_NULL(1) JSON_HEDLEY_RETURNS_NON_NULL -inline char* format_buffer(char* buf, int len, int decimal_exponent, - int min_exp, int max_exp) +inline char* format_buffer(char* buf, int len, int decimal_exponent, int min_exp, int max_exp) { JSON_ASSERT(min_exp < 0); JSON_ASSERT(max_exp > 0); @@ -1062,9 +1056,9 @@ template<typename FloatType> JSON_HEDLEY_NON_NULL(1, 2) JSON_HEDLEY_RETURNS_NON_NULL -char* to_chars(char* first, const char* last, FloatType value) + char* to_chars(char* first, const char* last, FloatType value) { - static_cast<void>(last); // maybe unused - fix warning + static_cast<void>(last); // maybe unused - fix warning JSON_ASSERT(std::isfinite(value)); // Use signbit(value) instead of (value < 0) since signbit works for -0. @@ -1075,10 +1069,10 @@ } #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" #endif - if (value == 0) // +-0 + if (value == 0) // +-0 { *first++ = '0'; // Make it look like a floating-point number (#362, #378) @@ -1087,7 +1081,7 @@ return first; } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index e39b779..1efce1a 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp
@@ -8,14 +8,14 @@ #pragma once -#include <algorithm> // copy -#include <iterator> // begin, end -#include <string> // string -#include <tuple> // tuple, get -#include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type -#include <utility> // move, forward, declval, pair -#include <valarray> // valarray -#include <vector> // vector +#include <algorithm> // copy +#include <iterator> // begin, end +#include <string> // string +#include <tuple> // tuple, get +#include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type +#include <utility> // move, forward, declval, pair +#include <valarray> // valarray +#include <vector> // vector #include <nlohmann/detail/iterators/iteration_proxy.hpp> #include <nlohmann/detail/macro_scope.hpp> @@ -25,8 +25,7 @@ #include <nlohmann/detail/value_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { ////////////////// // constructors // @@ -39,7 +38,8 @@ * https://github.com/nlohmann/json/issues/2865 for more information. */ -template<value_t> struct external_constructor; +template<value_t> +struct external_constructor; template<> struct external_constructor<value_t::boolean> @@ -75,9 +75,7 @@ j.assert_invariant(); } - template < typename BasicJsonType, typename CompatibleStringType, - enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value, - int > = 0 > + template<typename BasicJsonType, typename CompatibleStringType, enable_if_t<!std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value, int> = 0> static void construct(BasicJsonType& j, const CompatibleStringType& str) { j.m_data.m_value.destroy(j.m_data.m_type); @@ -171,9 +169,7 @@ j.assert_invariant(); } - template < typename BasicJsonType, typename CompatibleArrayType, - enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value, - int > = 0 > + template<typename BasicJsonType, typename CompatibleArrayType, enable_if_t<!std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value, int> = 0> static void construct(BasicJsonType& j, const CompatibleArrayType& arr) { using std::begin; @@ -201,8 +197,7 @@ j.assert_invariant(); } - template<typename BasicJsonType, typename T, - enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> + template<typename BasicJsonType, typename T, enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> static void construct(BasicJsonType& j, const std::valarray<T>& arr) { j.m_data.m_value.destroy(j.m_data.m_type); @@ -241,8 +236,7 @@ j.assert_invariant(); } - template < typename BasicJsonType, typename CompatibleObjectType, - enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int > = 0 > + template<typename BasicJsonType, typename CompatibleObjectType, enable_if_t<!std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int> = 0> static void construct(BasicJsonType& j, const CompatibleObjectType& obj) { using std::begin; @@ -260,28 +254,19 @@ // to_json // ///////////// -template<typename BasicJsonType, typename T, - enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0> +template<typename BasicJsonType, typename T, enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0> inline void to_json(BasicJsonType& j, T b) noexcept { external_constructor<value_t::boolean>::construct(j, b); } -template < typename BasicJsonType, typename BoolRef, - enable_if_t < - ((std::is_same<std::vector<bool>::reference, BoolRef>::value - && !std::is_same <std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value) - || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value - && !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>, - typename BasicJsonType::boolean_t >::value)) - && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value, int > = 0 > +template<typename BasicJsonType, typename BoolRef, enable_if_t<((std::is_same<std::vector<bool>::reference, BoolRef>::value && !std::is_same<std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value) || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value && !std::is_same<detail::uncvref_t<std::vector<bool>::const_reference>, typename BasicJsonType::boolean_t>::value)) && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value, int> = 0> inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept { external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b)); } -template<typename BasicJsonType, typename CompatibleString, - enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0> +template<typename BasicJsonType, typename CompatibleString, enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0> inline void to_json(BasicJsonType& j, const CompatibleString& s) { external_constructor<value_t::string>::construct(j, s); @@ -293,30 +278,26 @@ external_constructor<value_t::string>::construct(j, std::move(s)); } -template<typename BasicJsonType, typename FloatType, - enable_if_t<std::is_floating_point<FloatType>::value, int> = 0> +template<typename BasicJsonType, typename FloatType, enable_if_t<std::is_floating_point<FloatType>::value, int> = 0> inline void to_json(BasicJsonType& j, FloatType val) noexcept { external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val)); } -template<typename BasicJsonType, typename CompatibleNumberUnsignedType, - enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0> +template<typename BasicJsonType, typename CompatibleNumberUnsignedType, enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0> inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept { external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val)); } -template<typename BasicJsonType, typename CompatibleNumberIntegerType, - enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0> +template<typename BasicJsonType, typename CompatibleNumberIntegerType, enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0> inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept { external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val)); } #if !JSON_DISABLE_ENUM_SERIALIZATION -template<typename BasicJsonType, typename EnumType, - enable_if_t<std::is_enum<EnumType>::value, int> = 0> +template<typename BasicJsonType, typename EnumType, enable_if_t<std::is_enum<EnumType>::value, int> = 0> inline void to_json(BasicJsonType& j, EnumType e) noexcept { using underlying_type = typename std::underlying_type<EnumType>::type; @@ -330,14 +311,7 @@ external_constructor<value_t::array>::construct(j, e); } -template < typename BasicJsonType, typename CompatibleArrayType, - enable_if_t < is_compatible_array_type<BasicJsonType, - CompatibleArrayType>::value&& - !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&& - !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&& - !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&& - !is_basic_json<CompatibleArrayType>::value, - int > = 0 > +template<typename BasicJsonType, typename CompatibleArrayType, enable_if_t<is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value && !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value && !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value && !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value && !is_basic_json<CompatibleArrayType>::value, int> = 0> inline void to_json(BasicJsonType& j, const CompatibleArrayType& arr) { external_constructor<value_t::array>::construct(j, arr); @@ -349,8 +323,7 @@ external_constructor<value_t::binary>::construct(j, bin); } -template<typename BasicJsonType, typename T, - enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> +template<typename BasicJsonType, typename T, enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> inline void to_json(BasicJsonType& j, const std::valarray<T>& arr) { external_constructor<value_t::array>::construct(j, std::move(arr)); @@ -362,8 +335,7 @@ external_constructor<value_t::array>::construct(j, std::move(arr)); } -template < typename BasicJsonType, typename CompatibleObjectType, - enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value, int > = 0 > +template<typename BasicJsonType, typename CompatibleObjectType, enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value && !is_basic_json<CompatibleObjectType>::value, int> = 0> inline void to_json(BasicJsonType& j, const CompatibleObjectType& obj) { external_constructor<value_t::object>::construct(j, obj); @@ -375,40 +347,41 @@ external_constructor<value_t::object>::construct(j, std::move(obj)); } -template < - typename BasicJsonType, typename T, std::size_t N, - enable_if_t < !std::is_constructible<typename BasicJsonType::string_t, - const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - int > = 0 > -inline void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) +template< + typename BasicJsonType, + typename T, + std::size_t N, + enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, + const T (&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + int> = 0> +inline void to_json(BasicJsonType& j, const T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) { external_constructor<value_t::array>::construct(j, arr); } -template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value, int > = 0 > +template<typename BasicJsonType, typename T1, typename T2, enable_if_t<std::is_constructible<BasicJsonType, T1>::value && std::is_constructible<BasicJsonType, T2>::value, int> = 0> inline void to_json(BasicJsonType& j, const std::pair<T1, T2>& p) { - j = { p.first, p.second }; + j = {p.first, p.second}; } // for https://github.com/nlohmann/json/pull/1134 -template<typename BasicJsonType, typename T, - enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0> +template<typename BasicJsonType, typename T, enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0> inline void to_json(BasicJsonType& j, const T& b) { - j = { {b.key(), b.value()} }; + j = {{b.key(), b.value()}}; } template<typename BasicJsonType, typename Tuple, std::size_t... Idx> inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/) { - j = { std::get<Idx>(t)... }; + j = {std::get<Idx>(t)...}; } -template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int > = 0> +template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int> = 0> inline void to_json(BasicJsonType& j, const T& t) { - to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {}); + to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value>{}); } #if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM @@ -423,7 +396,7 @@ { template<typename BasicJsonType, typename T> auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j, std::forward<T>(val)))) - -> decltype(to_json(j, std::forward<T>(val)), void()) + -> decltype(to_json(j, std::forward<T>(val)), void()) { return to_json(j, std::forward<T>(val)); } @@ -434,10 +407,10 @@ /// namespace to hold default `to_json` function /// to see why this is required: /// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html -namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) +namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) { #endif -JSON_INLINE_VARIABLE constexpr const auto& to_json = // NOLINT(misc-definitions-in-headers) +JSON_INLINE_VARIABLE constexpr const auto& to_json = // NOLINT(misc-definitions-in-headers) detail::static_const<detail::to_json_fn>::value; #ifndef JSON_HAS_CPP_17 } // namespace
diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index 5974d7b..430b9ac 100644 --- a/include/nlohmann/detail/exceptions.hpp +++ b/include/nlohmann/detail/exceptions.hpp
@@ -8,26 +8,25 @@ #pragma once -#include <cstddef> // nullptr_t -#include <exception> // exception +#include <cstddef> // nullptr_t +#include <exception> // exception #if JSON_DIAGNOSTICS - #include <numeric> // accumulate + #include <numeric> // accumulate #endif -#include <stdexcept> // runtime_error -#include <string> // to_string -#include <vector> // vector +#include <stdexcept> // runtime_error +#include <string> // to_string +#include <vector> // vector -#include <nlohmann/detail/value_t.hpp> -#include <nlohmann/detail/string_escape.hpp> #include <nlohmann/detail/input/position_t.hpp> #include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/meta/cpp_future.hpp> #include <nlohmann/detail/meta/type_traits.hpp> #include <nlohmann/detail/string_concat.hpp> +#include <nlohmann/detail/string_escape.hpp> +#include <nlohmann/detail/value_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { //////////////// // exceptions // @@ -45,11 +44,14 @@ } /// the id of the exception - const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) + const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) protected: JSON_HEDLEY_NON_NULL(3) - exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} // NOLINT(bugprone-throw-keyword-missing) + exception(int id_, const char* what_arg) + : id(id_) + , m(what_arg) + {} // NOLINT(bugprone-throw-keyword-missing) static std::string name(const std::string& ename, int id_) { @@ -96,16 +98,16 @@ break; } - case value_t::null: // LCOV_EXCL_LINE - case value_t::string: // LCOV_EXCL_LINE - case value_t::boolean: // LCOV_EXCL_LINE - case value_t::number_integer: // LCOV_EXCL_LINE - case value_t::number_unsigned: // LCOV_EXCL_LINE - case value_t::number_float: // LCOV_EXCL_LINE - case value_t::binary: // LCOV_EXCL_LINE - case value_t::discarded: // LCOV_EXCL_LINE - default: // LCOV_EXCL_LINE - break; // LCOV_EXCL_LINE + case value_t::null: // LCOV_EXCL_LINE + case value_t::string: // LCOV_EXCL_LINE + case value_t::boolean: // LCOV_EXCL_LINE + case value_t::number_integer: // LCOV_EXCL_LINE + case value_t::number_unsigned: // LCOV_EXCL_LINE + case value_t::number_float: // LCOV_EXCL_LINE + case value_t::binary: // LCOV_EXCL_LINE + case value_t::discarded: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + break; // LCOV_EXCL_LINE } } @@ -114,9 +116,7 @@ return ""; } - auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, - [](const std::string & a, const std::string & b) - { + auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, [](const std::string& a, const std::string& b) { return concat(a, '/', detail::escape(b)); }); return concat('(', str, ") "); @@ -148,17 +148,14 @@ template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0> static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context) { - const std::string w = concat(exception::name("parse_error", id_), "parse error", - position_string(pos), ": ", exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("parse_error", id_), "parse error", position_string(pos), ": ", exception::diagnostics(context), what_arg); return {id_, pos.chars_read_total, w.c_str()}; } template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0> static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, BasicJsonContext context) { - const std::string w = concat(exception::name("parse_error", id_), "parse error", - (byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""), - ": ", exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("parse_error", id_), "parse error", (byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""), ": ", exception::diagnostics(context), what_arg); return {id_, byte_, w.c_str()}; } @@ -175,12 +172,13 @@ private: parse_error(int id_, std::size_t byte_, const char* what_arg) - : exception(id_, what_arg), byte(byte_) {} + : exception(id_, what_arg) + , byte(byte_) + {} static std::string position_string(const position_t& pos) { - return concat(" at line ", std::to_string(pos.lines_read + 1), - ", column ", std::to_string(pos.chars_read_current_line)); + return concat(" at line ", std::to_string(pos.lines_read + 1), ", column ", std::to_string(pos.chars_read_current_line)); } }; @@ -199,7 +197,8 @@ private: JSON_HEDLEY_NON_NULL(3) invalid_iterator(int id_, const char* what_arg) - : exception(id_, what_arg) {} + : exception(id_, what_arg) + {} }; /// @brief exception indicating executing a member function with a wrong type @@ -216,7 +215,9 @@ private: JSON_HEDLEY_NON_NULL(3) - type_error(int id_, const char* what_arg) : exception(id_, what_arg) {} + type_error(int id_, const char* what_arg) + : exception(id_, what_arg) + {} }; /// @brief exception indicating access out of the defined range @@ -233,7 +234,9 @@ private: JSON_HEDLEY_NON_NULL(3) - out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {} + out_of_range(int id_, const char* what_arg) + : exception(id_, what_arg) + {} }; /// @brief exception indicating other library errors @@ -250,7 +253,9 @@ private: JSON_HEDLEY_NON_NULL(3) - other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} + other_error(int id_, const char* what_arg) + : exception(id_, what_arg) + {} }; } // namespace detail
diff --git a/include/nlohmann/detail/hash.hpp b/include/nlohmann/detail/hash.hpp index 4464e8e..64bff1c 100644 --- a/include/nlohmann/detail/hash.hpp +++ b/include/nlohmann/detail/hash.hpp
@@ -8,16 +8,15 @@ #pragma once -#include <cstdint> // uint8_t -#include <cstddef> // size_t -#include <functional> // hash +#include <cstddef> // size_t +#include <cstdint> // uint8_t +#include <functional> // hash #include <nlohmann/detail/abi_macros.hpp> #include <nlohmann/detail/value_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { // boost::hash_combine inline std::size_t combine(std::size_t seed, std::size_t h) noexcept @@ -59,7 +58,7 @@ auto seed = combine(type, j.size()); for (const auto& element : j.items()) { - const auto h = std::hash<string_t> {}(element.key()); + const auto h = std::hash<string_t>{}(element.key()); seed = combine(seed, h); seed = combine(seed, hash(element.value())); } @@ -78,50 +77,50 @@ case BasicJsonType::value_t::string: { - const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>()); + const auto h = std::hash<string_t>{}(j.template get_ref<const string_t&>()); return combine(type, h); } case BasicJsonType::value_t::boolean: { - const auto h = std::hash<bool> {}(j.template get<bool>()); + const auto h = std::hash<bool>{}(j.template get<bool>()); return combine(type, h); } case BasicJsonType::value_t::number_integer: { - const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>()); + const auto h = std::hash<number_integer_t>{}(j.template get<number_integer_t>()); return combine(type, h); } case BasicJsonType::value_t::number_unsigned: { - const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>()); + const auto h = std::hash<number_unsigned_t>{}(j.template get<number_unsigned_t>()); return combine(type, h); } case BasicJsonType::value_t::number_float: { - const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>()); + const auto h = std::hash<number_float_t>{}(j.template get<number_float_t>()); return combine(type, h); } case BasicJsonType::value_t::binary: { auto seed = combine(type, j.get_binary().size()); - const auto h = std::hash<bool> {}(j.get_binary().has_subtype()); + const auto h = std::hash<bool>{}(j.get_binary().has_subtype()); seed = combine(seed, h); seed = combine(seed, static_cast<std::size_t>(j.get_binary().subtype())); for (const auto byte : j.get_binary()) { - seed = combine(seed, std::hash<std::uint8_t> {}(byte)); + seed = combine(seed, std::hash<std::uint8_t>{}(byte)); } return seed; } - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE - return 0; // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + return 0; // LCOV_EXCL_LINE } }
diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index a6e100e..e2509d5 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp
@@ -8,18 +8,18 @@ #pragma once -#include <algorithm> // generate_n -#include <array> // array -#include <cmath> // ldexp -#include <cstddef> // size_t -#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t -#include <cstdio> // snprintf -#include <cstring> // memcpy -#include <iterator> // back_inserter -#include <limits> // numeric_limits -#include <string> // char_traits, string -#include <utility> // make_pair, move -#include <vector> // vector +#include <algorithm> // generate_n +#include <array> // array +#include <cmath> // ldexp +#include <cstddef> // size_t +#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t +#include <cstdio> // snprintf +#include <cstring> // memcpy +#include <iterator> // back_inserter +#include <limits> // numeric_limits +#include <string> // char_traits, string +#include <utility> // make_pair, move +#include <vector> // vector #include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/input/input_adapters.hpp> @@ -32,8 +32,7 @@ #include <nlohmann/detail/value_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /// how to treat CBOR tags enum class cbor_tag_handler_t @@ -80,16 +79,18 @@ @param[in] adapter input adapter to read from */ - explicit binary_reader(InputAdapterType&& adapter, const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format) + explicit binary_reader(InputAdapterType&& adapter, const input_format_t format = input_format_t::json) noexcept + : ia(std::move(adapter)) + , input_format(format) { - (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {}; + (void)detail::is_sax_static_asserts<SAX, BasicJsonType>{}; } // make class move-only binary_reader(const binary_reader&) = delete; - binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) binary_reader& operator=(const binary_reader&) = delete; - binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) ~binary_reader() = default; /*! @@ -128,9 +129,9 @@ result = parse_ubjson_internal(); break; - case input_format_t::json: // LCOV_EXCL_LINE - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + case input_format_t::json: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } // strict mode: next byte must be EOF @@ -147,8 +148,7 @@ if (JSON_HEDLEY_UNLIKELY(current != char_traits<char_type>::eof())) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read, - exception_message(input_format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read, exception_message(input_format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr)); } } @@ -174,7 +174,7 @@ return false; } - if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/false))) + if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/ false))) { return false; } @@ -224,8 +224,7 @@ if (JSON_HEDLEY_UNLIKELY(len < 1)) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format_t::bson, concat("string length must be at least 1, is ", std::to_string(len)), "string"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, concat("string length must be at least 1, is ", std::to_string(len)), "string"), nullptr)); } return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != char_traits<char_type>::eof(); @@ -246,8 +245,7 @@ if (JSON_HEDLEY_UNLIKELY(len < 0)) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format_t::bson, concat("byte array length cannot be negative, is ", std::to_string(len)), "binary"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, concat("byte array length cannot be negative, is ", std::to_string(len)), "binary"), nullptr)); } // All BSON binary values have a subtype @@ -273,65 +271,64 @@ { switch (element_type) { - case 0x01: // double + case 0x01: // double { double number{}; return get_number<double, true>(input_format_t::bson, number) && sax->number_float(static_cast<number_float_t>(number), ""); } - case 0x02: // string + case 0x02: // string { std::int32_t len{}; string_t value; return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value); } - case 0x03: // object + case 0x03: // object { return parse_bson_internal(); } - case 0x04: // array + case 0x04: // array { return parse_bson_array(); } - case 0x05: // binary + case 0x05: // binary { std::int32_t len{}; binary_t value; return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value); } - case 0x08: // boolean + case 0x08: // boolean { return sax->boolean(get() != 0); } - case 0x0A: // null + case 0x0A: // null { return sax->null(); } - case 0x10: // int32 + case 0x10: // int32 { std::int32_t value{}; return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value); } - case 0x12: // int64 + case 0x12: // int64 { std::int64_t value{}; return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value); } - default: // anything else not supported (yet) + default: // anything else not supported (yet) { std::array<char, 3> cr{{}}; - static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) const std::string cr_str{cr.data()}; - return sax->parse_error(element_type_parse_position, cr_str, - parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr)); + return sax->parse_error(element_type_parse_position, cr_str, parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr)); } } } @@ -396,7 +393,7 @@ return false; } - if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/true))) + if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/ true))) { return false; } @@ -452,25 +449,25 @@ case 0x17: return sax->number_unsigned(static_cast<number_unsigned_t>(current)); - case 0x18: // Unsigned integer (one-byte uint8_t follows) + case 0x18: // Unsigned integer (one-byte uint8_t follows) { std::uint8_t number{}; return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); } - case 0x19: // Unsigned integer (two-byte uint16_t follows) + case 0x19: // Unsigned integer (two-byte uint16_t follows) { std::uint16_t number{}; return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); } - case 0x1A: // Unsigned integer (four-byte uint32_t follows) + case 0x1A: // Unsigned integer (four-byte uint32_t follows) { std::uint32_t number{}; return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); } - case 0x1B: // Unsigned integer (eight-byte uint64_t follows) + case 0x1B: // Unsigned integer (eight-byte uint64_t follows) { std::uint64_t number{}; return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); @@ -503,29 +500,28 @@ case 0x37: return sax->number_integer(static_cast<std::int8_t>(0x20 - 1 - current)); - case 0x38: // Negative integer (one-byte uint8_t follows) + case 0x38: // Negative integer (one-byte uint8_t follows) { std::uint8_t number{}; return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number); } - case 0x39: // Negative integer -1-n (two-byte uint16_t follows) + case 0x39: // Negative integer -1-n (two-byte uint16_t follows) { std::uint16_t number{}; return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number); } - case 0x3A: // Negative integer -1-n (four-byte uint32_t follows) + case 0x3A: // Negative integer -1-n (four-byte uint32_t follows) { std::uint32_t number{}; return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number); } - case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows) + case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows) { std::uint64_t number{}; - return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - - static_cast<number_integer_t>(number)); + return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - static_cast<number_integer_t>(number)); } // Binary data (0x00..0x17 bytes follow) @@ -553,11 +549,11 @@ case 0x55: case 0x56: case 0x57: - case 0x58: // Binary data (one-byte uint8_t for n follows) - case 0x59: // Binary data (two-byte uint16_t for n follow) - case 0x5A: // Binary data (four-byte uint32_t for n follow) - case 0x5B: // Binary data (eight-byte uint64_t for n follow) - case 0x5F: // Binary data (indefinite length) + case 0x58: // Binary data (one-byte uint8_t for n follows) + case 0x59: // Binary data (two-byte uint16_t for n follow) + case 0x5A: // Binary data (four-byte uint32_t for n follow) + case 0x5B: // Binary data (eight-byte uint64_t for n follow) + case 0x5F: // Binary data (indefinite length) { binary_t b; return get_cbor_binary(b) && sax->binary(b); @@ -588,11 +584,11 @@ case 0x75: case 0x76: case 0x77: - case 0x78: // UTF-8 string (one-byte uint8_t for n follows) - case 0x79: // UTF-8 string (two-byte uint16_t for n follow) - case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) - case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) - case 0x7F: // UTF-8 string (indefinite length) + case 0x78: // UTF-8 string (one-byte uint8_t for n follows) + case 0x79: // UTF-8 string (two-byte uint16_t for n follow) + case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) + case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) + case 0x7F: // UTF-8 string (indefinite length) { string_t s; return get_cbor_string(s) && sax->string(s); @@ -624,33 +620,34 @@ case 0x96: case 0x97: return get_cbor_array( - conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler); + conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), + tag_handler); - case 0x98: // array (one-byte uint8_t for n follows) + case 0x98: // array (one-byte uint8_t for n follows) { std::uint8_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler); } - case 0x99: // array (two-byte uint16_t for n follow) + case 0x99: // array (two-byte uint16_t for n follow) { std::uint16_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler); } - case 0x9A: // array (four-byte uint32_t for n follow) + case 0x9A: // array (four-byte uint32_t for n follow) { std::uint32_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler); } - case 0x9B: // array (eight-byte uint64_t for n follow) + case 0x9B: // array (eight-byte uint64_t for n follow) { std::uint64_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler); } - case 0x9F: // array (indefinite length) + case 0x9F: // array (indefinite length) return get_cbor_array(static_cast<std::size_t>(-1), tag_handler); // map (0x00..0x17 pairs of data items follow) @@ -680,34 +677,34 @@ case 0xB7: return get_cbor_object(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler); - case 0xB8: // map (one-byte uint8_t for n follows) + case 0xB8: // map (one-byte uint8_t for n follows) { std::uint8_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler); } - case 0xB9: // map (two-byte uint16_t for n follow) + case 0xB9: // map (two-byte uint16_t for n follow) { std::uint16_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler); } - case 0xBA: // map (four-byte uint32_t for n follow) + case 0xBA: // map (four-byte uint32_t for n follow) { std::uint32_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler); } - case 0xBB: // map (eight-byte uint64_t for n follow) + case 0xBB: // map (eight-byte uint64_t for n follow) { std::uint64_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler); } - case 0xBF: // map (indefinite length) + case 0xBF: // map (indefinite length) return get_cbor_object(static_cast<std::size_t>(-1), tag_handler); - case 0xC6: // tagged item + case 0xC6: // tagged item case 0xC7: case 0xC8: case 0xC9: @@ -722,18 +719,17 @@ case 0xD2: case 0xD3: case 0xD4: - case 0xD8: // tagged item (1 bytes follow) - case 0xD9: // tagged item (2 bytes follow) - case 0xDA: // tagged item (4 bytes follow) - case 0xDB: // tagged item (8 bytes follow) + case 0xD8: // tagged item (1 bytes follow) + case 0xD9: // tagged item (2 bytes follow) + case 0xDA: // tagged item (4 bytes follow) + case 0xDB: // tagged item (8 bytes follow) { switch (tag_handler) { case cbor_tag_handler_t::error: { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr)); } case cbor_tag_handler_t::ignore: @@ -813,21 +809,21 @@ } default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE return false; // LCOV_EXCL_LINE } } - case 0xF4: // false + case 0xF4: // false return sax->boolean(false); - case 0xF5: // true + case 0xF5: // true return sax->boolean(true); - case 0xF6: // null + case 0xF6: // null return sax->null(); - case 0xF9: // Half-Precision Float (two-byte IEEE 754) + case 0xF9: // Half-Precision Float (two-byte IEEE 754) { const auto byte1_raw = get(); if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number"))) @@ -852,11 +848,10 @@ // half-precision floating-point numbers in the C language // is shown in Fig. 3. const auto half = static_cast<unsigned int>((byte1 << 8u) + byte2); - const double val = [&half] - { + const double val = [&half] { const int exp = (half >> 10u) & 0x1Fu; const unsigned int mant = half & 0x3FFu; - JSON_ASSERT(0 <= exp&& exp <= 32); + JSON_ASSERT(0 <= exp && exp <= 32); JSON_ASSERT(mant <= 1024); switch (exp) { @@ -864,34 +859,34 @@ return std::ldexp(mant, -24); case 31: return (mant == 0) - ? std::numeric_limits<double>::infinity() - : std::numeric_limits<double>::quiet_NaN(); + ? std::numeric_limits<double>::infinity() + : std::numeric_limits<double>::quiet_NaN(); default: return std::ldexp(mant + 1024, exp - 25); } }(); return sax->number_float((half & 0x8000u) != 0 - ? static_cast<number_float_t>(-val) - : static_cast<number_float_t>(val), ""); + ? static_cast<number_float_t>(-val) + : static_cast<number_float_t>(val), + ""); } - case 0xFA: // Single-Precision Float (four-byte IEEE 754) + case 0xFA: // Single-Precision Float (four-byte IEEE 754) { float number{}; return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), ""); } - case 0xFB: // Double-Precision Float (eight-byte IEEE 754) + case 0xFB: // Double-Precision Float (eight-byte IEEE 754) { double number{}; return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), ""); } - default: // anything else (0xFF is handled inside the other types) + default: // anything else (0xFF is handled inside the other types) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr)); } } } @@ -945,31 +940,31 @@ return get_string(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result); } - case 0x78: // UTF-8 string (one-byte uint8_t for n follows) + case 0x78: // UTF-8 string (one-byte uint8_t for n follows) { std::uint8_t len{}; return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); } - case 0x79: // UTF-8 string (two-byte uint16_t for n follow) + case 0x79: // UTF-8 string (two-byte uint16_t for n follow) { std::uint16_t len{}; return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); } - case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) + case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) { std::uint32_t len{}; return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); } - case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) + case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) { std::uint64_t len{}; return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); } - case 0x7F: // UTF-8 string (indefinite length) + case 0x7F: // UTF-8 string (indefinite length) { while (get() != 0xFF) { @@ -986,8 +981,7 @@ default: { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, - exception_message(input_format_t::cbor, concat("expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token), "string"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, concat("expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token), "string"), nullptr)); } } } @@ -1041,35 +1035,35 @@ return get_binary(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result); } - case 0x58: // Binary data (one-byte uint8_t for n follows) + case 0x58: // Binary data (one-byte uint8_t for n follows) { std::uint8_t len{}; return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result); } - case 0x59: // Binary data (two-byte uint16_t for n follow) + case 0x59: // Binary data (two-byte uint16_t for n follow) { std::uint16_t len{}; return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result); } - case 0x5A: // Binary data (four-byte uint32_t for n follow) + case 0x5A: // Binary data (four-byte uint32_t for n follow) { std::uint32_t len{}; return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result); } - case 0x5B: // Binary data (eight-byte uint64_t for n follow) + case 0x5B: // Binary data (eight-byte uint64_t for n follow) { std::uint64_t len{}; return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result); } - case 0x5F: // Binary data (indefinite length) + case 0x5F: // Binary data (indefinite length) { while (get() != 0xFF) { @@ -1086,8 +1080,7 @@ default: { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, - exception_message(input_format_t::cbor, concat("expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x", last_token), "binary"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, concat("expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x", last_token), "binary"), nullptr)); } } } @@ -1402,118 +1395,118 @@ case 0xBD: case 0xBE: case 0xBF: - case 0xD9: // str 8 - case 0xDA: // str 16 - case 0xDB: // str 32 + case 0xD9: // str 8 + case 0xDA: // str 16 + case 0xDB: // str 32 { string_t s; return get_msgpack_string(s) && sax->string(s); } - case 0xC0: // nil + case 0xC0: // nil return sax->null(); - case 0xC2: // false + case 0xC2: // false return sax->boolean(false); - case 0xC3: // true + case 0xC3: // true return sax->boolean(true); - case 0xC4: // bin 8 - case 0xC5: // bin 16 - case 0xC6: // bin 32 - case 0xC7: // ext 8 - case 0xC8: // ext 16 - case 0xC9: // ext 32 - case 0xD4: // fixext 1 - case 0xD5: // fixext 2 - case 0xD6: // fixext 4 - case 0xD7: // fixext 8 - case 0xD8: // fixext 16 + case 0xC4: // bin 8 + case 0xC5: // bin 16 + case 0xC6: // bin 32 + case 0xC7: // ext 8 + case 0xC8: // ext 16 + case 0xC9: // ext 32 + case 0xD4: // fixext 1 + case 0xD5: // fixext 2 + case 0xD6: // fixext 4 + case 0xD7: // fixext 8 + case 0xD8: // fixext 16 { binary_t b; return get_msgpack_binary(b) && sax->binary(b); } - case 0xCA: // float 32 + case 0xCA: // float 32 { float number{}; return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), ""); } - case 0xCB: // float 64 + case 0xCB: // float 64 { double number{}; return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), ""); } - case 0xCC: // uint 8 + case 0xCC: // uint 8 { std::uint8_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); } - case 0xCD: // uint 16 + case 0xCD: // uint 16 { std::uint16_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); } - case 0xCE: // uint 32 + case 0xCE: // uint 32 { std::uint32_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); } - case 0xCF: // uint 64 + case 0xCF: // uint 64 { std::uint64_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); } - case 0xD0: // int 8 + case 0xD0: // int 8 { std::int8_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_integer(number); } - case 0xD1: // int 16 + case 0xD1: // int 16 { std::int16_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_integer(number); } - case 0xD2: // int 32 + case 0xD2: // int 32 { std::int32_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_integer(number); } - case 0xD3: // int 64 + case 0xD3: // int 64 { std::int64_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_integer(number); } - case 0xDC: // array 16 + case 0xDC: // array 16 { std::uint16_t len{}; return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast<std::size_t>(len)); } - case 0xDD: // array 32 + case 0xDD: // array 32 { std::uint32_t len{}; return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len)); } - case 0xDE: // map 16 + case 0xDE: // map 16 { std::uint16_t len{}; return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast<std::size_t>(len)); } - case 0xDF: // map 32 + case 0xDF: // map 32 { std::uint32_t len{}; return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len)); @@ -1554,11 +1547,10 @@ case 0xFF: return sax->number_integer(static_cast<std::int8_t>(current)); - default: // anything else + default: // anything else { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format_t::msgpack, concat("invalid byte: 0x", last_token), "value"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::msgpack, concat("invalid byte: 0x", last_token), "value"), nullptr)); } } } @@ -1619,19 +1611,19 @@ return get_string(input_format_t::msgpack, static_cast<unsigned int>(current) & 0x1Fu, result); } - case 0xD9: // str 8 + case 0xD9: // str 8 { std::uint8_t len{}; return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); } - case 0xDA: // str 16 + case 0xDA: // str 16 { std::uint16_t len{}; return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); } - case 0xDB: // str 32 + case 0xDB: // str 32 { std::uint32_t len{}; return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); @@ -1640,8 +1632,7 @@ default: { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, - exception_message(input_format_t::msgpack, concat("expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token), "string"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::msgpack, concat("expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token), "string"), nullptr)); } } } @@ -1659,36 +1650,35 @@ bool get_msgpack_binary(binary_t& result) { // helper function to set the subtype - auto assign_and_return_true = [&result](std::int8_t subtype) - { + auto assign_and_return_true = [&result](std::int8_t subtype) { result.set_subtype(static_cast<std::uint8_t>(subtype)); return true; }; switch (current) { - case 0xC4: // bin 8 + case 0xC4: // bin 8 { std::uint8_t len{}; return get_number(input_format_t::msgpack, len) && get_binary(input_format_t::msgpack, len, result); } - case 0xC5: // bin 16 + case 0xC5: // bin 16 { std::uint16_t len{}; return get_number(input_format_t::msgpack, len) && get_binary(input_format_t::msgpack, len, result); } - case 0xC6: // bin 32 + case 0xC6: // bin 32 { std::uint32_t len{}; return get_number(input_format_t::msgpack, len) && get_binary(input_format_t::msgpack, len, result); } - case 0xC7: // ext 8 + case 0xC7: // ext 8 { std::uint8_t len{}; std::int8_t subtype{}; @@ -1698,7 +1688,7 @@ assign_and_return_true(subtype); } - case 0xC8: // ext 16 + case 0xC8: // ext 16 { std::uint16_t len{}; std::int8_t subtype{}; @@ -1708,7 +1698,7 @@ assign_and_return_true(subtype); } - case 0xC9: // ext 32 + case 0xC9: // ext 32 { std::uint32_t len{}; std::int8_t subtype{}; @@ -1718,7 +1708,7 @@ assign_and_return_true(subtype); } - case 0xD4: // fixext 1 + case 0xD4: // fixext 1 { std::int8_t subtype{}; return get_number(input_format_t::msgpack, subtype) && @@ -1726,7 +1716,7 @@ assign_and_return_true(subtype); } - case 0xD5: // fixext 2 + case 0xD5: // fixext 2 { std::int8_t subtype{}; return get_number(input_format_t::msgpack, subtype) && @@ -1734,7 +1724,7 @@ assign_and_return_true(subtype); } - case 0xD6: // fixext 4 + case 0xD6: // fixext 4 { std::int8_t subtype{}; return get_number(input_format_t::msgpack, subtype) && @@ -1742,7 +1732,7 @@ assign_and_return_true(subtype); } - case 0xD7: // fixext 8 + case 0xD7: // fixext 8 { std::int8_t subtype{}; return get_number(input_format_t::msgpack, subtype) && @@ -1750,7 +1740,7 @@ assign_and_return_true(subtype); } - case 0xD8: // fixext 16 + case 0xD8: // fixext 16 { std::int8_t subtype{}; return get_number(input_format_t::msgpack, subtype) && @@ -2034,10 +2024,9 @@ } if (number < 0) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, - exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); } - result = static_cast<std::size_t>(number); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): number is not a char + result = static_cast<std::size_t>(number); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): number is not a char return true; } @@ -2050,8 +2039,7 @@ } if (number < 0) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, - exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); } result = static_cast<std::size_t>(number); return true; @@ -2066,8 +2054,7 @@ } if (number < 0) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, - exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); } result = static_cast<std::size_t>(number); return true; @@ -2082,13 +2069,11 @@ } if (number < 0) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, - exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); } if (!value_in_range_of<std::size_t>(number)) { - return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, - exception_message(input_format, "integer value overflow", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "integer value overflow", "size"), nullptr)); } result = static_cast<std::size_t>(number); return true; @@ -2137,8 +2122,7 @@ } if (!value_in_range_of<std::size_t>(number)) { - return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, - exception_message(input_format, "integer value overflow", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "integer value overflow", "size"), nullptr)); } result = detail::conditional_static_cast<std::size_t>(number); return true; @@ -2150,7 +2134,7 @@ { break; } - if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array + if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array { return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimensional vector is not allowed", "size"), nullptr)); } @@ -2159,16 +2143,16 @@ { return false; } - if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1)) // return normal array size if 1D row vector + if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1)) // return normal array size if 1D row vector { result = dim.at(dim.size() - 1); return true; } if (!dim.empty()) // if ndarray, convert to an object in JData annotated array format { - for (auto i : dim) // test if any dimension in an ndarray is 0, if so, return a 1D empty container + for (auto i : dim) // test if any dimension in an ndarray is 0, if so, return a 1D empty container { - if ( i == 0 ) + if (i == 0) { result = 0; return true; @@ -2184,7 +2168,7 @@ for (auto i : dim) { result *= i; - if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type() + if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type() { return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr)); } @@ -2230,8 +2214,8 @@ */ bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result, bool inside_ndarray = false) { - result.first = npos; // size - result.second = 0; // type + result.first = npos; // size + result.second = 0; // type bool is_ndarray = false; get_ignore_noop(); @@ -2239,12 +2223,10 @@ if (current == '$') { result.second = get(); // must not ignore 'N', because 'N' maybe the type - if (input_format == input_format_t::bjdata - && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second))) + if (input_format == input_format_t::bjdata && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second))) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format, concat("marker 0x", last_token, " is not a permitted optimized array type"), "type"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, concat("marker 0x", last_token, " is not a permitted optimized array type"), "type"), nullptr)); } if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "type"))) @@ -2260,8 +2242,7 @@ return false; } auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr)); } const bool is_error = get_ubjson_size_value(result.first, is_ndarray); @@ -2269,10 +2250,9 @@ { if (inside_ndarray) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, - exception_message(input_format, "ndarray can not be recursive", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, exception_message(input_format, "ndarray can not be recursive", "size"), nullptr)); } - result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters + result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters } return is_error; } @@ -2282,8 +2262,7 @@ const bool is_error = get_ubjson_size_value(result.first, is_ndarray); if (input_format == input_format_t::bjdata && is_ndarray) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, - exception_message(input_format, "ndarray requires both type and size", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, exception_message(input_format, "ndarray requires both type and size", "size"), nullptr)); } return is_error; } @@ -2399,11 +2378,10 @@ // half-precision floating-point numbers in the C language // is shown in Fig. 3. const auto half = static_cast<unsigned int>((byte2 << 8u) + byte1); - const double val = [&half] - { + const double val = [&half] { const int exp = (half >> 10u) & 0x1Fu; const unsigned int mant = half & 0x3FFu; - JSON_ASSERT(0 <= exp&& exp <= 32); + JSON_ASSERT(0 <= exp && exp <= 32); JSON_ASSERT(mant <= 1024); switch (exp) { @@ -2411,15 +2389,16 @@ return std::ldexp(mant, -24); case 31: return (mant == 0) - ? std::numeric_limits<double>::infinity() - : std::numeric_limits<double>::quiet_NaN(); + ? std::numeric_limits<double>::infinity() + : std::numeric_limits<double>::quiet_NaN(); default: return std::ldexp(mant + 1024, exp - 25); } }(); return sax->number_float((half & 0x8000u) != 0 - ? static_cast<number_float_t>(-val) - : static_cast<number_float_t>(val), ""); + ? static_cast<number_float_t>(-val) + : static_cast<number_float_t>(val), + ""); } case 'd': @@ -2449,8 +2428,7 @@ if (JSON_HEDLEY_UNLIKELY(current > 127)) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, - exception_message(input_format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"), nullptr)); } string_t s(1, static_cast<typename string_t::value_type>(current)); return sax->string(s); @@ -2468,7 +2446,7 @@ case '{': // object return get_ubjson_object(); - default: // anything else + default: // anything else break; } auto last_token = get_token_string(); @@ -2492,19 +2470,17 @@ if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) { size_and_type.second &= ~(static_cast<char_int_type>(1) << 8); // use bit 8 to indicate ndarray, here we remove the bit to restore the type marker - auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](const bjd_type & p, char_int_type t) - { + auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](const bjd_type& p, char_int_type t) { return p.first < t; }); string_t key = "_ArrayType_"; if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second)) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr)); } - string_t type = it->second; // sax->string() takes a reference + string_t type = it->second; // sax->string() takes a reference if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type))) { return false; @@ -2516,7 +2492,7 @@ } key = "_ArrayData_"; - if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) )) + if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first))) { return false; } @@ -2598,8 +2574,7 @@ if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format, "BJData object does not support ND-array size in optimized format", "object"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, "BJData object does not support ND-array size in optimized format", "object"), nullptr)); } string_t key; @@ -2703,8 +2678,7 @@ if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input)) { - return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, - exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); + return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); } switch (result_number) @@ -2730,8 +2704,7 @@ case token_type::end_of_input: case token_type::literal_or_value: default: - return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, - exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); + return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); } } @@ -2762,8 +2735,7 @@ do { get(); - } - while (current == 'N'); + } while (current == 'N'); return current; } @@ -2803,7 +2775,7 @@ } else { - vec[i] = static_cast<std::uint8_t>(current); // LCOV_EXCL_LINE + vec[i] = static_cast<std::uint8_t>(current); // LCOV_EXCL_LINE } } @@ -2888,8 +2860,7 @@ { if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof())) { - return sax->parse_error(chars_read, "<end of file>", - parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr)); + return sax->parse_error(chars_read, "<end of file>", parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr)); } return true; } @@ -2900,7 +2871,7 @@ std::string get_token_string() const { std::array<char, 3> cr{{}}; - static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) return std::string{cr.data()}; } @@ -2938,9 +2909,9 @@ error_msg += "BJData"; break; - case input_format_t::json: // LCOV_EXCL_LINE - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + case input_format_t::json: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } return concat(error_msg, ' ', context, ": ", detail); @@ -2973,23 +2944,23 @@ #define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \ make_array<bjd_type>( \ - bjd_type{'C', "char"}, \ - bjd_type{'D', "double"}, \ - bjd_type{'I', "int16"}, \ - bjd_type{'L', "int64"}, \ - bjd_type{'M', "uint64"}, \ - bjd_type{'U', "uint8"}, \ - bjd_type{'d', "single"}, \ - bjd_type{'i', "int8"}, \ - bjd_type{'l', "int32"}, \ - bjd_type{'m', "uint32"}, \ - bjd_type{'u', "uint16"}) + bjd_type{'C', "char"}, \ + bjd_type{'D', "double"}, \ + bjd_type{'I', "int16"}, \ + bjd_type{'L', "int64"}, \ + bjd_type{'M', "uint64"}, \ + bjd_type{'U', "uint8"}, \ + bjd_type{'d', "single"}, \ + bjd_type{'i', "int8"}, \ + bjd_type{'l', "int32"}, \ + bjd_type{'m', "uint32"}, \ + bjd_type{'u', "uint16"}) - JSON_PRIVATE_UNLESS_TESTED: - // lookup tables - // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) - const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = - JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_; + JSON_PRIVATE_UNLESS_TESTED : + // lookup tables + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = + JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_; using bjd_type = std::pair<char_int_type, string_t>; // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) @@ -3001,8 +2972,8 @@ }; #ifndef JSON_HAS_CPP_17 - template<typename BasicJsonType, typename InputAdapterType, typename SAX> - constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos; +template<typename BasicJsonType, typename InputAdapterType, typename SAX> +constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos; #endif } // namespace detail
diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index 33fca3e..769775d 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp
@@ -8,15 +8,15 @@ #pragma once -#include <array> // array -#include <cstddef> // size_t -#include <cstring> // strlen -#include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next -#include <memory> // shared_ptr, make_shared, addressof -#include <numeric> // accumulate -#include <string> // string, char_traits -#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer -#include <utility> // pair, declval +#include <array> // array +#include <cstddef> // size_t +#include <cstring> // strlen +#include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next +#include <memory> // shared_ptr, make_shared, addressof +#include <numeric> // accumulate +#include <string> // string, char_traits +#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer +#include <utility> // pair, declval #ifndef JSON_NO_IO #include <cstdio> // FILE * @@ -28,11 +28,18 @@ #include <nlohmann/detail/meta/type_traits.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /// the supported input formats -enum class input_format_t { json, cbor, msgpack, ubjson, bson, bjdata }; +enum class input_format_t +{ + json, + cbor, + msgpack, + ubjson, + bson, + bjdata +}; //////////////////// // input adapters // @@ -50,7 +57,7 @@ JSON_HEDLEY_NON_NULL(2) explicit file_input_adapter(std::FILE* f) noexcept - : m_file(f) + : m_file(f) { JSON_ASSERT(m_file != nullptr); } @@ -97,7 +104,8 @@ } explicit input_stream_adapter(std::istream& i) - : is(&i), sb(i.rdbuf()) + : is(&i) + , sb(i.rdbuf()) {} // delete because of pointer members @@ -106,7 +114,8 @@ input_stream_adapter& operator=(input_stream_adapter&&) = delete; input_stream_adapter(input_stream_adapter&& rhs) noexcept - : is(rhs.is), sb(rhs.sb) + : is(rhs.is) + , sb(rhs.sb) { rhs.is = nullptr; rhs.sb = nullptr; @@ -142,7 +151,8 @@ using char_type = typename std::iterator_traits<IteratorType>::value_type; iterator_input_adapter(IteratorType first, IteratorType last) - : current(std::move(first)), end(std::move(last)) + : current(std::move(first)) + , end(std::move(last)) {} typename char_traits<char_type>::int_type get_character() @@ -301,7 +311,8 @@ using char_type = char; wide_string_input_adapter(BaseInputAdapter base) - : base_adapter(base) {} + : base_adapter(base) + {} typename std::char_traits<char>::int_type get_character() noexcept { @@ -387,26 +398,26 @@ // Enables ADL on begin(container) and end(container) // Encloses the using declarations in namespace for not to leak them to outside scope -namespace container_input_adapter_factory_impl -{ +namespace container_input_adapter_factory_impl { using std::begin; using std::end; template<typename ContainerType, typename Enable = void> -struct container_input_adapter_factory {}; +struct container_input_adapter_factory +{}; template<typename ContainerType> -struct container_input_adapter_factory< ContainerType, - void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>> - { - using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))); - - static adapter_type create(const ContainerType& container) +struct container_input_adapter_factory<ContainerType, + void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>> { - return input_adapter(begin(container), end(container)); -} - }; + using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))); + + static adapter_type create(const ContainerType& container) + { + return input_adapter(begin(container), end(container)); + } +}; } // namespace container_input_adapter_factory_impl @@ -437,13 +448,13 @@ using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>())); // Null-delimited strings, and the like. -template < typename CharT, - typename std::enable_if < - std::is_pointer<CharT>::value&& - !std::is_array<CharT>::value&& - std::is_integral<typename std::remove_pointer<CharT>::type>::value&& - sizeof(typename std::remove_pointer<CharT>::type) == 1, - int >::type = 0 > +template<typename CharT, + typename std::enable_if< + std::is_pointer<CharT>::value && + !std::is_array<CharT>::value && + std::is_integral<typename std::remove_pointer<CharT>::type>::value && + sizeof(typename std::remove_pointer<CharT>::type) == 1, + int>::type = 0> contiguous_bytes_input_adapter input_adapter(CharT b) { auto length = std::strlen(reinterpret_cast<const char*>(b)); @@ -452,7 +463,7 @@ } template<typename T, std::size_t N> -auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) +auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) { return input_adapter(array, array + N); } @@ -463,25 +474,27 @@ class span_input_adapter { public: - template < typename CharT, - typename std::enable_if < - std::is_pointer<CharT>::value&& - std::is_integral<typename std::remove_pointer<CharT>::type>::value&& - sizeof(typename std::remove_pointer<CharT>::type) == 1, - int >::type = 0 > + template<typename CharT, + typename std::enable_if< + std::is_pointer<CharT>::value && + std::is_integral<typename std::remove_pointer<CharT>::type>::value && + sizeof(typename std::remove_pointer<CharT>::type) == 1, + int>::type = 0> span_input_adapter(CharT b, std::size_t l) - : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {} + : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) + {} template<class IteratorType, typename std::enable_if< std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value, int>::type = 0> span_input_adapter(IteratorType first, IteratorType last) - : ia(input_adapter(first, last)) {} + : ia(input_adapter(first, last)) + {} contiguous_bytes_input_adapter&& get() { - return std::move(ia); // NOLINT(hicpp-move-const-arg,performance-move-const-arg) + return std::move(ia); // NOLINT(hicpp-move-const-arg,performance-move-const-arg) } private:
diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index c772521..90b2ac9 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp
@@ -9,9 +9,9 @@ #pragma once #include <cstddef> -#include <string> // string -#include <utility> // move -#include <vector> // vector +#include <string> // string +#include <utility> // move +#include <vector> // vector #include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/macro_scope.hpp> @@ -142,8 +142,7 @@ virtual ~json_sax() = default; }; -namespace detail -{ +namespace detail { /*! @brief SAX implementation to create a JSON value from SAX events @@ -173,14 +172,15 @@ @param[in] allow_exceptions_ whether parse errors yield exceptions */ explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true) - : root(r), allow_exceptions(allow_exceptions_) + : root(r) + , allow_exceptions(allow_exceptions_) {} // make class move-only json_sax_dom_parser(const json_sax_dom_parser&) = delete; - json_sax_dom_parser(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + json_sax_dom_parser(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete; - json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) ~json_sax_dom_parser() = default; bool null() @@ -280,8 +280,7 @@ } template<class Exception> - bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, - const Exception& ex) + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex) { errored = true; static_cast<void>(ex); @@ -306,7 +305,8 @@ */ template<typename Value> JSON_HEDLEY_RETURNS_NON_NULL - BasicJsonType* handle_value(Value&& v) + BasicJsonType* + handle_value(Value&& v) { if (ref_stack.empty()) { @@ -331,7 +331,7 @@ /// the parsed JSON value BasicJsonType& root; /// stack to model hierarchy of values - std::vector<BasicJsonType*> ref_stack {}; + std::vector<BasicJsonType*> ref_stack{}; /// helper to hold the reference for the next object element BasicJsonType* object_element = nullptr; /// whether a syntax error occurred @@ -355,16 +355,18 @@ json_sax_dom_callback_parser(BasicJsonType& r, const parser_callback_t cb, const bool allow_exceptions_ = true) - : root(r), callback(cb), allow_exceptions(allow_exceptions_) + : root(r) + , callback(cb) + , allow_exceptions(allow_exceptions_) { keep_stack.push_back(true); } // make class move-only json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete; - json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete; - json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) ~json_sax_dom_callback_parser() = default; bool null() @@ -530,8 +532,7 @@ } template<class Exception> - bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, - const Exception& ex) + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex) { errored = true; static_cast<void>(ex); @@ -590,7 +591,7 @@ if (ref_stack.empty()) { root = std::move(value); - return {true, & root}; + return {true, &root}; } // skip this value if we already decided to skip the parent @@ -607,7 +608,7 @@ if (ref_stack.back()->is_array()) { ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value)); - return {true, & (ref_stack.back()->m_data.m_value.array->back())}; + return {true, &(ref_stack.back()->m_data.m_value.array->back())}; } // object @@ -630,11 +631,11 @@ /// the parsed JSON value BasicJsonType& root; /// stack to model hierarchy of values - std::vector<BasicJsonType*> ref_stack {}; + std::vector<BasicJsonType*> ref_stack{}; /// stack to manage which values to keep - std::vector<bool> keep_stack {}; + std::vector<bool> keep_stack{}; /// stack to manage which object keys to keep - std::vector<bool> key_keep_stack {}; + std::vector<bool> key_keep_stack{}; /// helper to hold the reference for the next object element BasicJsonType* object_element = nullptr; /// whether a syntax error occurred
diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 4b3bf77..6fabf35 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp
@@ -8,15 +8,15 @@ #pragma once -#include <array> // array -#include <clocale> // localeconv -#include <cstddef> // size_t -#include <cstdio> // snprintf -#include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull -#include <initializer_list> // initializer_list -#include <string> // char_traits, string -#include <utility> // move -#include <vector> // vector +#include <array> // array +#include <clocale> // localeconv +#include <cstddef> // size_t +#include <cstdio> // snprintf +#include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull +#include <initializer_list> // initializer_list +#include <string> // char_traits, string +#include <utility> // move +#include <vector> // vector #include <nlohmann/detail/input/input_adapters.hpp> #include <nlohmann/detail/input/position_t.hpp> @@ -24,8 +24,7 @@ #include <nlohmann/detail/meta/type_traits.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /////////// // lexer // @@ -97,7 +96,7 @@ case token_type::literal_or_value: return "'[', '{', or a literal"; // LCOV_EXCL_START - default: // catch non-enum values + default: // catch non-enum values return "unknown token"; // LCOV_EXCL_STOP } @@ -122,16 +121,16 @@ using token_type = typename lexer_base<BasicJsonType>::token_type; explicit lexer(InputAdapterType&& adapter, bool ignore_comments_ = false) noexcept - : ia(std::move(adapter)) - , ignore_comments(ignore_comments_) - , decimal_point_char(static_cast<char_int_type>(get_decimal_point())) + : ia(std::move(adapter)) + , ignore_comments(ignore_comments_) + , decimal_point_char(static_cast<char_int_type>(get_decimal_point())) {} // delete because of pointer members lexer(const lexer&) = delete; - lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) lexer& operator=(lexer&) = delete; - lexer& operator=(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + lexer& operator=(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) ~lexer() = default; private: @@ -173,7 +172,7 @@ JSON_ASSERT(current == 'u'); int codepoint = 0; - const auto factors = { 12u, 8u, 4u, 0u }; + const auto factors = {12u, 8u, 4u, 0u}; for (const auto factor : factors) { get(); @@ -223,7 +222,7 @@ for (auto range = ranges.begin(); range != ranges.end(); ++range) { get(); - if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range))) // NOLINT(bugprone-inc-dec-in-conditions) + if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range))) // NOLINT(bugprone-inc-dec-in-conditions) { add(current); } @@ -320,7 +319,7 @@ case 'u': { const int codepoint1 = get_codepoint(); - int codepoint = codepoint1; // start with codepoint1 + int codepoint = codepoint1; // start with codepoint1 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1)) { @@ -347,14 +346,14 @@ { // overwrite codepoint codepoint = static_cast<int>( - // high surrogate occupies the most significant 22 bits - (static_cast<unsigned int>(codepoint1) << 10u) - // low surrogate occupies the least significant 15 bits - + static_cast<unsigned int>(codepoint2) - // there is still the 0xD800, 0xDC00 and 0x10000 noise - // in the result, so we have to subtract with: - // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 - - 0x35FDC00u); + // high surrogate occupies the most significant 22 bits + (static_cast<unsigned int>(codepoint1) << 10u) + // low surrogate occupies the least significant 15 bits + + static_cast<unsigned int>(codepoint2) + // there is still the 0xD800, 0xDC00 and 0x10000 noise + // in the result, so we have to subtract with: + // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 + - 0x35FDC00u); } else { @@ -1006,8 +1005,8 @@ } // all other characters are rejected outside scan_number() - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } scan_number_minus: @@ -1245,7 +1244,7 @@ // we are done scanning a number) unget(); - char* endptr = nullptr; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + char* endptr = nullptr; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) errno = 0; // try to parse integers first and fall back to floats @@ -1298,8 +1297,7 @@ @param[in] return_type the token type to return on success */ JSON_HEDLEY_NON_NULL(2) - token_type scan_literal(const char_type* literal_text, const std::size_t length, - token_type return_type) + token_type scan_literal(const char_type* literal_text, const std::size_t length, token_type return_type) { JSON_ASSERT(char_traits<char_type>::to_char_type(current) == literal_text[0]); for (std::size_t i = 1; i < length; ++i) @@ -1456,7 +1454,7 @@ { // escape control characters std::array<char, 9> cs{{}}; - static_cast<void>((std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + static_cast<void>((std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) result += cs.data(); } else @@ -1503,8 +1501,7 @@ do { get(); - } - while (current == ' ' || current == '\t' || current == '\n' || current == '\r'); + } while (current == ' ' || current == '\t' || current == '\n' || current == '\r'); } token_type scan() @@ -1609,13 +1606,13 @@ bool next_unget = false; /// the start position of the current token - position_t position {}; + position_t position{}; /// raw input token string (for error messages) - std::vector<char_type> token_string {}; + std::vector<char_type> token_string{}; /// buffer for variable-length tokens (numbers, strings) - string_t token_buffer {}; + string_t token_buffer{}; /// a description of occurred lexer errors const char* error_message = "";
diff --git a/include/nlohmann/detail/input/parser.hpp b/include/nlohmann/detail/input/parser.hpp index bdf85ba..b90b021 100644 --- a/include/nlohmann/detail/input/parser.hpp +++ b/include/nlohmann/detail/input/parser.hpp
@@ -8,12 +8,12 @@ #pragma once -#include <cmath> // isfinite -#include <cstdint> // uint8_t -#include <functional> // function -#include <string> // string -#include <utility> // move -#include <vector> // vector +#include <cmath> // isfinite +#include <cstdint> // uint8_t +#include <functional> // function +#include <string> // string +#include <utility> // move +#include <vector> // vector #include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/input/input_adapters.hpp> @@ -25,8 +25,7 @@ #include <nlohmann/detail/value_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { //////////// // parser // //////////// @@ -72,9 +71,9 @@ const parser_callback_t<BasicJsonType> cb = nullptr, const bool allow_exceptions_ = true, const bool skip_comments = false) - : callback(cb) - , m_lexer(std::move(adapter), skip_comments) - , allow_exceptions(allow_exceptions_) + : callback(cb) + , m_lexer(std::move(adapter), skip_comments) + , allow_exceptions(allow_exceptions_) { // read first token get_token(); @@ -102,8 +101,7 @@ { sdp.parse_error(m_lexer.get_position(), m_lexer.get_token_string(), - parse_error::create(101, m_lexer.get_position(), - exception_message(token_type::end_of_input, "value"), nullptr)); + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr)); } // in case of an error, return discarded value @@ -160,7 +158,7 @@ JSON_HEDLEY_NON_NULL(2) bool sax_parse(SAX* sax, const bool strict = true) { - (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {}; + (void)detail::is_sax_static_asserts<SAX, BasicJsonType>{}; const bool result = sax_parse_internal(sax); // strict mode: next byte must be EOF @@ -347,8 +345,7 @@ { return sax->parse_error(m_lexer.get_position(), m_lexer.get_token_string(), - parse_error::create(101, m_lexer.get_position(), - "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr)); + parse_error::create(101, m_lexer.get_position(), "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr)); } return sax->parse_error(m_lexer.get_position(), @@ -361,7 +358,7 @@ case token_type::name_separator: case token_type::value_separator: case token_type::literal_or_value: - default: // the last token was unexpected + default: // the last token was unexpected { return sax->parse_error(m_lexer.get_position(), m_lexer.get_token_string(), @@ -488,8 +485,7 @@ if (last_token == token_type::parse_error) { - error_msg += concat(m_lexer.get_error_message(), "; last read: '", - m_lexer.get_token_string(), '\''); + error_msg += concat(m_lexer.get_error_message(), "; last read: '", m_lexer.get_token_string(), '\''); } else {
diff --git a/include/nlohmann/detail/input/position_t.hpp b/include/nlohmann/detail/input/position_t.hpp index 8ac7c78..5bda498 100644 --- a/include/nlohmann/detail/input/position_t.hpp +++ b/include/nlohmann/detail/input/position_t.hpp
@@ -8,13 +8,12 @@ #pragma once -#include <cstddef> // size_t +#include <cstddef> // size_t #include <nlohmann/detail/abi_macros.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /// struct to capture the start position of the current token struct position_t
diff --git a/include/nlohmann/detail/iterators/internal_iterator.hpp b/include/nlohmann/detail/iterators/internal_iterator.hpp index 2991ee6..b706454 100644 --- a/include/nlohmann/detail/iterators/internal_iterator.hpp +++ b/include/nlohmann/detail/iterators/internal_iterator.hpp
@@ -12,8 +12,7 @@ #include <nlohmann/detail/iterators/primitive_iterator.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /*! @brief an iterator value @@ -21,14 +20,15 @@ @note This structure could easily be a union, but MSVC currently does not allow unions members with complex constructors, see https://github.com/nlohmann/json/pull/105. */ -template<typename BasicJsonType> struct internal_iterator +template<typename BasicJsonType> +struct internal_iterator { /// iterator for JSON objects - typename BasicJsonType::object_t::iterator object_iterator {}; + typename BasicJsonType::object_t::iterator object_iterator{}; /// iterator for JSON arrays - typename BasicJsonType::array_t::iterator array_iterator {}; + typename BasicJsonType::array_t::iterator array_iterator{}; /// generic iterator for all other types - primitive_iterator_t primitive_iterator {}; + primitive_iterator_t primitive_iterator{}; }; } // namespace detail
diff --git a/include/nlohmann/detail/iterators/iter_impl.hpp b/include/nlohmann/detail/iterators/iter_impl.hpp index 4447091..d50ca28 100644 --- a/include/nlohmann/detail/iterators/iter_impl.hpp +++ b/include/nlohmann/detail/iterators/iter_impl.hpp
@@ -8,8 +8,8 @@ #pragma once -#include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next -#include <type_traits> // conditional, is_const, remove_const +#include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next +#include <type_traits> // conditional, is_const, remove_const #include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/iterators/internal_iterator.hpp> @@ -20,12 +20,13 @@ #include <nlohmann/detail/value_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { // forward declare, to be able to friend it later on -template<typename IteratorType> class iteration_proxy; -template<typename IteratorType> class iteration_proxy_value; +template<typename IteratorType> +class iteration_proxy; +template<typename IteratorType> +class iteration_proxy_value; /*! @brief a template for a bidirectional iterator for the @ref basic_json class @@ -44,7 +45,7 @@ iterators in version 3.0.0 (see https://github.com/nlohmann/json/issues/593) */ template<typename BasicJsonType> -class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) +class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) { /// the iterator with BasicJsonType of different const-ness using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>; @@ -60,8 +61,7 @@ static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value, "iter_impl only accepts (const) basic_json"); // superficial check for the LegacyBidirectionalIterator named requirement - static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value - && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value, + static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value, "basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement."); public: @@ -78,13 +78,13 @@ using difference_type = typename BasicJsonType::difference_type; /// defines a pointer to the type iterated over (value_type) using pointer = typename std::conditional<std::is_const<BasicJsonType>::value, - typename BasicJsonType::const_pointer, - typename BasicJsonType::pointer>::type; + typename BasicJsonType::const_pointer, + typename BasicJsonType::pointer>::type; /// defines a reference to the type iterated over (value_type) using reference = typename std::conditional<std::is_const<BasicJsonType>::value, - typename BasicJsonType::const_reference, - typename BasicJsonType::reference>::type; + typename BasicJsonType::const_reference, + typename BasicJsonType::reference>::type; iter_impl() = default; ~iter_impl() = default; @@ -97,7 +97,8 @@ @pre object != nullptr @post The iterator is initialized; i.e. `m_object != nullptr`. */ - explicit iter_impl(pointer object) noexcept : m_object(object) + explicit iter_impl(pointer object) noexcept + : m_object(object) { JSON_ASSERT(m_object != nullptr); @@ -148,7 +149,8 @@ information refer to: https://github.com/nlohmann/json/issues/1608 */ iter_impl(const iter_impl<const BasicJsonType>& other) noexcept - : m_object(other.m_object), m_it(other.m_it) + : m_object(other.m_object) + , m_it(other.m_it) {} /*! @@ -173,7 +175,8 @@ @note It is not checked whether @a other is initialized. */ iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept - : m_object(other.m_object), m_it(other.m_it) + : m_object(other.m_object) + , m_it(other.m_it) {} /*! @@ -182,19 +185,20 @@ @return const/non-const iterator @note It is not checked whether @a other is initialized. */ - iter_impl& operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept // NOLINT(cert-oop54-cpp) + iter_impl& operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept // NOLINT(cert-oop54-cpp) { m_object = other.m_object; m_it = other.m_it; return *this; } - JSON_PRIVATE_UNLESS_TESTED: - /*! + JSON_PRIVATE_UNLESS_TESTED : + /*! @brief set the iterator to the first value @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - void set_begin() noexcept + void + set_begin() noexcept { JSON_ASSERT(m_object != nullptr); @@ -363,7 +367,7 @@ @brief post-increment (it++) @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - iter_impl operator++(int)& // NOLINT(cert-dcl21-cpp) + iter_impl operator++(int) & // NOLINT(cert-dcl21-cpp) { auto result = *this; ++(*this); @@ -414,7 +418,7 @@ @brief post-decrement (it--) @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - iter_impl operator--(int)& // NOLINT(cert-dcl21-cpp) + iter_impl operator--(int) & // NOLINT(cert-dcl21-cpp) { auto result = *this; --(*this); @@ -465,7 +469,7 @@ @brief comparison: equal @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr > + template<typename IterImpl, detail::enable_if_t<(std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t> = nullptr> bool operator==(const IterImpl& other) const { // if objects are not the same, the comparison is undefined @@ -501,7 +505,7 @@ @brief comparison: not equal @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr > + template<typename IterImpl, detail::enable_if_t<(std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t> = nullptr> bool operator!=(const IterImpl& other) const { return !operator==(other); @@ -548,7 +552,7 @@ */ bool operator<=(const iter_impl& other) const { - return !other.operator < (*this); + return !other.operator<(*this); } /*! @@ -740,11 +744,11 @@ return operator*(); } - JSON_PRIVATE_UNLESS_TESTED: - /// associated JSON instance - pointer m_object = nullptr; + JSON_PRIVATE_UNLESS_TESTED : + /// associated JSON instance + pointer m_object = nullptr; /// the actual iterator of the associated instance - internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {}; + internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it{}; }; } // namespace detail
diff --git a/include/nlohmann/detail/iterators/iteration_proxy.hpp b/include/nlohmann/detail/iterators/iteration_proxy.hpp index 76293de..457b4ef 100644 --- a/include/nlohmann/detail/iterators/iteration_proxy.hpp +++ b/include/nlohmann/detail/iterators/iteration_proxy.hpp
@@ -8,14 +8,14 @@ #pragma once -#include <cstddef> // size_t -#include <iterator> // input_iterator_tag -#include <string> // string, to_string -#include <tuple> // tuple_size, get, tuple_element -#include <utility> // move +#include <cstddef> // size_t +#include <iterator> // input_iterator_tag +#include <string> // string, to_string +#include <tuple> // tuple_size, get, tuple_element +#include <utility> // move #if JSON_HAS_RANGES - #include <ranges> // enable_borrowed_range + #include <ranges> // enable_borrowed_range #endif #include <nlohmann/detail/abi_macros.hpp> @@ -23,25 +23,25 @@ #include <nlohmann/detail/value_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename string_type> -void int_to_string( string_type& target, std::size_t value ) +void int_to_string(string_type& target, std::size_t value) { // For ADL using std::to_string; target = to_string(value); } -template<typename IteratorType> class iteration_proxy_value +template<typename IteratorType> +class iteration_proxy_value { public: using difference_type = std::ptrdiff_t; using value_type = iteration_proxy_value; - using pointer = value_type *; - using reference = value_type &; + using pointer = value_type*; + using reference = value_type&; using iterator_category = std::input_iterator_tag; - using string_type = typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type; + using string_type = typename std::remove_cv<typename std::remove_reference<decltype(std::declval<IteratorType>().key())>::type>::type; private: /// the iterator @@ -57,22 +57,16 @@ public: explicit iteration_proxy_value() = default; - explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0) - noexcept(std::is_nothrow_move_constructible<IteratorType>::value - && std::is_nothrow_default_constructible<string_type>::value) - : anchor(std::move(it)) - , array_index(array_index_) + explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0) noexcept(std::is_nothrow_move_constructible<IteratorType>::value && std::is_nothrow_default_constructible<string_type>::value) + : anchor(std::move(it)) + , array_index(array_index_) {} iteration_proxy_value(iteration_proxy_value const&) = default; iteration_proxy_value& operator=(iteration_proxy_value const&) = default; // older GCCs are a bit fussy and require explicit noexcept specifiers on defaulted functions - iteration_proxy_value(iteration_proxy_value&&) - noexcept(std::is_nothrow_move_constructible<IteratorType>::value - && std::is_nothrow_move_constructible<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations) - iteration_proxy_value& operator=(iteration_proxy_value&&) - noexcept(std::is_nothrow_move_assignable<IteratorType>::value - && std::is_nothrow_move_assignable<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations) + iteration_proxy_value(iteration_proxy_value&&) noexcept(std::is_nothrow_move_constructible<IteratorType>::value && std::is_nothrow_move_constructible<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations) + iteration_proxy_value& operator=(iteration_proxy_value&&) noexcept(std::is_nothrow_move_assignable<IteratorType>::value && std::is_nothrow_move_assignable<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations) ~iteration_proxy_value() = default; /// dereference operator (needed for range-based for) @@ -90,7 +84,7 @@ return *this; } - iteration_proxy_value operator++(int)& // NOLINT(cert-dcl21-cpp) + iteration_proxy_value operator++(int) & // NOLINT(cert-dcl21-cpp) { auto tmp = iteration_proxy_value(anchor, array_index); ++anchor; @@ -122,7 +116,7 @@ { if (array_index != array_index_last) { - int_to_string( array_index_str, array_index ); + int_to_string(array_index_str, array_index); array_index_last = array_index; } return array_index_str; @@ -154,7 +148,8 @@ }; /// proxy class for the items() function -template<typename IteratorType> class iteration_proxy +template<typename IteratorType> +class iteration_proxy { private: /// the container to iterate @@ -165,7 +160,8 @@ /// construct iteration proxy from a container explicit iteration_proxy(typename IteratorType::reference cont) noexcept - : container(&cont) {} + : container(&cont) + {} iteration_proxy(iteration_proxy const&) = default; iteration_proxy& operator=(iteration_proxy const&) = default; @@ -210,8 +206,7 @@ // Structured Bindings Support to the iteration_proxy_value class // For further reference see https://blog.tartanllama.xyz/structured-bindings/ // And see https://github.com/nlohmann/json/pull/1391 -namespace std -{ +namespace std { #if defined(__clang__) // Fix: https://github.com/nlohmann/json/issues/1401 @@ -219,16 +214,16 @@ #pragma clang diagnostic ignored "-Wmismatched-tags" #endif template<typename IteratorType> -class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp) - : public std::integral_constant<std::size_t, 2> {}; +class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp) + : public std::integral_constant<std::size_t, 2> +{}; template<std::size_t N, typename IteratorType> -class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp) +class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp) { public: - using type = decltype( - get<N>(std::declval < - ::nlohmann::detail::iteration_proxy_value<IteratorType >> ())); + using type = decltype(get<N>(std::declval< + ::nlohmann::detail::iteration_proxy_value<IteratorType>>())); }; #if defined(__clang__) #pragma clang diagnostic pop @@ -237,6 +232,6 @@ } // namespace std #if JSON_HAS_RANGES - template <typename IteratorType> - inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> = true; +template<typename IteratorType> +inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> = true; #endif
diff --git a/include/nlohmann/detail/iterators/iterator_traits.hpp b/include/nlohmann/detail/iterators/iterator_traits.hpp index 84cc27a..4fd2e9c 100644 --- a/include/nlohmann/detail/iterators/iterator_traits.hpp +++ b/include/nlohmann/detail/iterators/iterator_traits.hpp
@@ -8,24 +8,23 @@ #pragma once -#include <iterator> // random_access_iterator_tag +#include <iterator> // random_access_iterator_tag #include <nlohmann/detail/abi_macros.hpp> -#include <nlohmann/detail/meta/void_t.hpp> #include <nlohmann/detail/meta/cpp_future.hpp> +#include <nlohmann/detail/meta/void_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename It, typename = void> -struct iterator_types {}; +struct iterator_types +{}; template<typename It> -struct iterator_types < +struct iterator_types< It, - void_t<typename It::difference_type, typename It::value_type, typename It::pointer, - typename It::reference, typename It::iterator_category >> + void_t<typename It::difference_type, typename It::value_type, typename It::pointer, typename It::reference, typename It::iterator_category>> { using difference_type = typename It::difference_type; using value_type = typename It::value_type; @@ -42,8 +41,8 @@ }; template<typename T> -struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >> - : iterator_types<T> +struct iterator_traits<T, enable_if_t<!std::is_pointer<T>::value>> + : iterator_types<T> { };
diff --git a/include/nlohmann/detail/iterators/json_reverse_iterator.hpp b/include/nlohmann/detail/iterators/json_reverse_iterator.hpp index 006d549..b61e2ba 100644 --- a/include/nlohmann/detail/iterators/json_reverse_iterator.hpp +++ b/include/nlohmann/detail/iterators/json_reverse_iterator.hpp
@@ -8,15 +8,14 @@ #pragma once -#include <cstddef> // ptrdiff_t -#include <iterator> // reverse_iterator -#include <utility> // declval +#include <cstddef> // ptrdiff_t +#include <iterator> // reverse_iterator +#include <utility> // declval #include <nlohmann/detail/abi_macros.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { ////////////////////// // reverse_iterator // @@ -52,13 +51,16 @@ /// create reverse iterator from iterator explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept - : base_iterator(it) {} + : base_iterator(it) + {} /// create reverse iterator from base class - explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {} + explicit json_reverse_iterator(const base_iterator& it) noexcept + : base_iterator(it) + {} /// post-increment (it++) - json_reverse_iterator operator++(int)& // NOLINT(cert-dcl21-cpp) + json_reverse_iterator operator++(int) & // NOLINT(cert-dcl21-cpp) { return static_cast<json_reverse_iterator>(base_iterator::operator++(1)); } @@ -70,7 +72,7 @@ } /// post-decrement (it--) - json_reverse_iterator operator--(int)& // NOLINT(cert-dcl21-cpp) + json_reverse_iterator operator--(int) & // NOLINT(cert-dcl21-cpp) { return static_cast<json_reverse_iterator>(base_iterator::operator--(1)); } @@ -122,7 +124,7 @@ reference value() const { auto it = --this->base(); - return it.operator * (); + return it.operator*(); } };
diff --git a/include/nlohmann/detail/iterators/primitive_iterator.hpp b/include/nlohmann/detail/iterators/primitive_iterator.hpp index 0b6e849..5d6b53b 100644 --- a/include/nlohmann/detail/iterators/primitive_iterator.hpp +++ b/include/nlohmann/detail/iterators/primitive_iterator.hpp
@@ -8,14 +8,13 @@ #pragma once -#include <cstddef> // ptrdiff_t -#include <limits> // numeric_limits +#include <cstddef> // ptrdiff_t +#include <limits> // numeric_limits #include <nlohmann/detail/macro_scope.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /* @brief an iterator for primitive JSON types @@ -33,9 +32,9 @@ static constexpr difference_type begin_value = 0; static constexpr difference_type end_value = begin_value + 1; - JSON_PRIVATE_UNLESS_TESTED: - /// iterator as signed integer type - difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)(); + JSON_PRIVATE_UNLESS_TESTED : + /// iterator as signed integer type + difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)(); public: constexpr difference_type get_value() const noexcept @@ -95,7 +94,7 @@ return *this; } - primitive_iterator_t operator++(int)& noexcept // NOLINT(cert-dcl21-cpp) + primitive_iterator_t operator++(int) & noexcept // NOLINT(cert-dcl21-cpp) { auto result = *this; ++m_it; @@ -108,7 +107,7 @@ return *this; } - primitive_iterator_t operator--(int)& noexcept // NOLINT(cert-dcl21-cpp) + primitive_iterator_t operator--(int) & noexcept // NOLINT(cert-dcl21-cpp) { auto result = *this; --m_it;
diff --git a/include/nlohmann/detail/json_custom_base_class.hpp b/include/nlohmann/detail/json_custom_base_class.hpp index d1e2916..76fd8dc 100644 --- a/include/nlohmann/detail/json_custom_base_class.hpp +++ b/include/nlohmann/detail/json_custom_base_class.hpp
@@ -8,13 +8,12 @@ #pragma once -#include <type_traits> // conditional, is_same +#include <type_traits> // conditional, is_same #include <nlohmann/detail/abi_macros.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /*! @brief Default base class of the @ref basic_json class. @@ -26,14 +25,14 @@ By default, this class is used because it is empty and thus has no effect on the behavior of @ref basic_json. */ -struct json_default_base {}; +struct json_default_base +{}; template<class T> -using json_base_class = typename std::conditional < - std::is_same<T, void>::value, - json_default_base, - T - >::type; +using json_base_class = typename std::conditional< + std::is_same<T, void>::value, + json_default_base, + T>::type; } // namespace detail NLOHMANN_JSON_NAMESPACE_END
diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 4fdcd9a..e3237d6 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp
@@ -8,18 +8,18 @@ #pragma once -#include <algorithm> // all_of -#include <cctype> // isdigit -#include <cerrno> // errno, ERANGE -#include <cstdlib> // strtoull +#include <algorithm> // all_of +#include <cctype> // isdigit +#include <cerrno> // errno, ERANGE +#include <cstdlib> // strtoull #ifndef JSON_NO_IO - #include <iosfwd> // ostream -#endif // JSON_NO_IO -#include <limits> // max -#include <numeric> // accumulate -#include <string> // string -#include <utility> // move -#include <vector> // vector + #include <iosfwd> // ostream +#endif // JSON_NO_IO +#include <limits> // max +#include <numeric> // accumulate +#include <string> // string +#include <utility> // move +#include <vector> // vector #include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/macro_scope.hpp> @@ -60,17 +60,14 @@ /// @brief create JSON pointer /// @sa https://json.nlohmann.me/api/json_pointer/json_pointer/ explicit json_pointer(const string_t& s = "") - : reference_tokens(split(s)) + : reference_tokens(split(s)) {} /// @brief return a string representation of the JSON pointer /// @sa https://json.nlohmann.me/api/json_pointer/to_string/ string_t to_string() const { - return std::accumulate(reference_tokens.begin(), reference_tokens.end(), - string_t{}, - [](const string_t& a, const string_t& b) - { + return std::accumulate(reference_tokens.begin(), reference_tokens.end(), string_t{}, [](const string_t& a, const string_t& b) { return detail::concat(a, '/', detail::escape(b)); }); } @@ -128,7 +125,7 @@ /// @brief create a new JSON pointer by appending the unescaped token at the end of the JSON pointer /// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/ - friend json_pointer operator/(const json_pointer& lhs, string_t token) // NOLINT(performance-unnecessary-value-param) + friend json_pointer operator/(const json_pointer& lhs, string_t token) // NOLINT(performance-unnecessary-value-param) { return json_pointer(lhs) /= std::move(token); } @@ -229,11 +226,11 @@ const char* p = s.c_str(); char* p_end = nullptr; - errno = 0; // strtoull doesn't reset errno - const unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) - if (p == p_end // invalid input or empty string - || errno == ERANGE // out of range - || JSON_HEDLEY_UNLIKELY(static_cast<std::size_t>(p_end - p) != s.size())) // incomplete read + errno = 0; // strtoull doesn't reset errno + const unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) + if (p == p_end // invalid input or empty string + || errno == ERANGE // out of range + || JSON_HEDLEY_UNLIKELY(static_cast<std::size_t>(p_end - p) != s.size())) // incomplete read { JSON_THROW(detail::out_of_range::create(404, detail::concat("unresolved reference token '", s, "'"), nullptr)); } @@ -242,14 +239,13 @@ // https://github.com/nlohmann/json/pull/2203 if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)())) // NOLINT(runtime/int) { - JSON_THROW(detail::out_of_range::create(410, detail::concat("array index ", s, " exceeds size_type"), nullptr)); // LCOV_EXCL_LINE + JSON_THROW(detail::out_of_range::create(410, detail::concat("array index ", s, " exceeds size_type"), nullptr)); // LCOV_EXCL_LINE } return static_cast<size_type>(res); } - JSON_PRIVATE_UNLESS_TESTED: - json_pointer top() const + JSON_PRIVATE_UNLESS_TESTED : json_pointer top() const { if (JSON_HEDLEY_UNLIKELY(empty())) { @@ -360,16 +356,14 @@ { // check if reference token is a number const bool nums = - std::all_of(reference_token.begin(), reference_token.end(), - [](const unsigned char x) - { - return std::isdigit(x); - }); + std::all_of(reference_token.begin(), reference_token.end(), [](const unsigned char x) { + return std::isdigit(x); + }); // change value to array for numbers or "-" or to object otherwise *ptr = (nums || reference_token == "-") - ? detail::value_t::array - : detail::value_t::object; + ? detail::value_t::array + : detail::value_t::object; } switch (ptr->type()) @@ -437,9 +431,7 @@ if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) { // "-" always fails the range check - JSON_THROW(detail::out_of_range::create(402, detail::concat( - "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), - ") is out of range"), ptr)); + JSON_THROW(detail::out_of_range::create(402, detail::concat("array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), ") is out of range"), ptr)); } // note: at performs range check @@ -544,9 +536,7 @@ if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) { // "-" always fails the range check - JSON_THROW(detail::out_of_range::create(402, detail::concat( - "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), - ") is out of range"), ptr)); + JSON_THROW(detail::out_of_range::create(402, detail::concat("array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), ") is out of range"), ptr)); } // note: at performs range check @@ -685,14 +675,14 @@ for ( // search for the first slash after the first character std::size_t slash = reference_string.find_first_of('/', 1), - // set the beginning of the first reference token + // set the beginning of the first reference token start = 1; // we can stop if start == 0 (if slash == string_t::npos) start != 0; // set the beginning of the next reference token // (will eventually be 0 if slash == string_t::npos) start = (slash == string_t::npos) ? 0 : slash + 1, - // find next slash + // find next slash slash = reference_string.find_first_of('/', start)) { // use the text between the beginning of the reference token @@ -701,8 +691,8 @@ // check reference tokens are properly escaped for (std::size_t pos = reference_token.find_first_of('~'); - pos != string_t::npos; - pos = reference_token.find_first_of('~', pos + 1)) + pos != string_t::npos; + pos = reference_token.find_first_of('~', pos + 1)) { JSON_ASSERT(reference_token[pos] == '~'); @@ -751,7 +741,8 @@ for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i) { flatten(detail::concat(reference_string, '/', std::to_string(i)), - value.m_data.m_value.array->operator[](i), result); + value.m_data.m_value.array->operator[](i), + result); } } break; @@ -839,7 +830,7 @@ return result; } - json_pointer<string_t> convert()&& + json_pointer<string_t> convert() && { json_pointer<string_t> result; result.reference_tokens = std::move(reference_tokens); @@ -866,9 +857,9 @@ /// @brief 3-way compares two JSON pointers template<typename RefStringTypeRhs> - std::strong_ordering operator<=>(const json_pointer<RefStringTypeRhs>& rhs) const noexcept // *NOPAD* + std::strong_ordering operator<= > (const json_pointer<RefStringTypeRhs>& rhs) const noexcept // *NOPAD* { - return reference_tokens <=> rhs.reference_tokens; // *NOPAD* + return reference_tokens <= > rhs.reference_tokens; // *NOPAD* } #else /// @brief compares two JSON pointers for equality
diff --git a/include/nlohmann/detail/json_ref.hpp b/include/nlohmann/detail/json_ref.hpp index b8bb6a7..7eaea97 100644 --- a/include/nlohmann/detail/json_ref.hpp +++ b/include/nlohmann/detail/json_ref.hpp
@@ -15,8 +15,7 @@ #include <nlohmann/detail/meta/type_traits.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename BasicJsonType> class json_ref @@ -25,22 +24,22 @@ using value_type = BasicJsonType; json_ref(value_type&& value) - : owned_value(std::move(value)) + : owned_value(std::move(value)) {} json_ref(const value_type& value) - : value_ref(&value) + : value_ref(&value) {} json_ref(std::initializer_list<json_ref> init) - : owned_value(init) + : owned_value(init) {} - template < + template< class... Args, - enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 > - json_ref(Args && ... args) - : owned_value(std::forward<Args>(args)...) + enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0> + json_ref(Args&&... args) + : owned_value(std::forward<Args>(args)...) {} // class should be movable only @@ -66,7 +65,7 @@ value_type const* operator->() const { - return &** this; + return &**this; } private:
diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index 97127a6..2593997 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp
@@ -8,9 +8,9 @@ #pragma once -#include <utility> // declval, pair #include <nlohmann/detail/meta/detected.hpp> #include <nlohmann/thirdparty/hedley/hedley.hpp> +#include <utility> // declval, pair // This file contains all internal macro definitions (except those affecting ABI) // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them @@ -37,7 +37,7 @@ #define JSON_HAS_CPP_20 #define JSON_HAS_CPP_17 #define JSON_HAS_CPP_14 - #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 #define JSON_HAS_CPP_17 #define JSON_HAS_CPP_14 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) @@ -114,8 +114,7 @@ #endif #ifndef JSON_HAS_THREE_WAY_COMPARISON - #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \ - && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L + #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L #define JSON_HAS_THREE_WAY_COMPARISON 1 #else #define JSON_HAS_THREE_WAY_COMPARISON 0 @@ -164,14 +163,14 @@ #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) #define JSON_THROW(exception) throw exception #define JSON_TRY try - #define JSON_CATCH(exception) catch(exception) - #define JSON_INTERNAL_CATCH(exception) catch(exception) + #define JSON_CATCH(exception) catch (exception) + #define JSON_INTERNAL_CATCH(exception) catch (exception) #else #include <cstdlib> #define JSON_THROW(exception) std::abort() - #define JSON_TRY if(true) - #define JSON_CATCH(exception) if(false) - #define JSON_INTERNAL_CATCH(exception) if(false) + #define JSON_TRY if (true) + #define JSON_CATCH(exception) if (false) + #define JSON_INTERNAL_CATCH(exception) if (false) #endif // override exception macros @@ -196,7 +195,7 @@ // allow overriding assert #if !defined(JSON_ASSERT) - #include <cassert> // assert + #include <cassert> // assert #define JSON_ASSERT(x) assert(x) #endif @@ -212,119 +211,119 @@ @def NLOHMANN_JSON_SERIALIZE_ENUM @since version 3.4.0 */ -#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ - template<typename BasicJsonType> \ - inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ - { \ - static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ - static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ - auto it = std::find_if(std::begin(m), std::end(m), \ - [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \ - { \ - return ej_pair.first == e; \ - }); \ - j = ((it != std::end(m)) ? it : std::begin(m))->second; \ - } \ - template<typename BasicJsonType> \ - inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ - { \ - static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ - static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ - auto it = std::find_if(std::begin(m), std::end(m), \ - [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \ - { \ - return ej_pair.second == j; \ - }); \ - e = ((it != std::end(m)) ? it : std::begin(m))->first; \ +#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ + template<typename BasicJsonType> \ + inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool { \ + return ej_pair.first == e; \ + }); \ + j = ((it != std::end(m)) ? it : std::begin(m))->second; \ + } \ + template<typename BasicJsonType> \ + inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool { \ + return ej_pair.second == j; \ + }); \ + e = ((it != std::end(m)) ? it : std::begin(m))->first; \ } // Ugly macros to avoid uglier copy-paste when specializing basic_json. They // may be removed in the future once the class is split. -#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ - template<template<typename, typename, typename...> class ObjectType, \ - template<typename, typename...> class ArrayType, \ - class StringType, class BooleanType, class NumberIntegerType, \ - class NumberUnsignedType, class NumberFloatType, \ - template<typename> class AllocatorType, \ - template<typename, typename = void> class JSONSerializer, \ - class BinaryType, \ +#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ + template<template<typename, typename, typename...> class ObjectType, \ + template<typename, typename...> \ + class ArrayType, \ + class StringType, \ + class BooleanType, \ + class NumberIntegerType, \ + class NumberUnsignedType, \ + class NumberFloatType, \ + template<typename> \ + class AllocatorType, \ + template<typename, typename = void> \ + class JSONSerializer, \ + class BinaryType, \ class CustomBaseClass> -#define NLOHMANN_BASIC_JSON_TPL \ - basic_json<ObjectType, ArrayType, StringType, BooleanType, \ - NumberIntegerType, NumberUnsignedType, NumberFloatType, \ - AllocatorType, JSONSerializer, BinaryType, CustomBaseClass> +#define NLOHMANN_BASIC_JSON_TPL \ + basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass> // Macros to simplify conversion from/to types -#define NLOHMANN_JSON_EXPAND( x ) x -#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME -#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \ - NLOHMANN_JSON_PASTE64, \ - NLOHMANN_JSON_PASTE63, \ - NLOHMANN_JSON_PASTE62, \ - NLOHMANN_JSON_PASTE61, \ - NLOHMANN_JSON_PASTE60, \ - NLOHMANN_JSON_PASTE59, \ - NLOHMANN_JSON_PASTE58, \ - NLOHMANN_JSON_PASTE57, \ - NLOHMANN_JSON_PASTE56, \ - NLOHMANN_JSON_PASTE55, \ - NLOHMANN_JSON_PASTE54, \ - NLOHMANN_JSON_PASTE53, \ - NLOHMANN_JSON_PASTE52, \ - NLOHMANN_JSON_PASTE51, \ - NLOHMANN_JSON_PASTE50, \ - NLOHMANN_JSON_PASTE49, \ - NLOHMANN_JSON_PASTE48, \ - NLOHMANN_JSON_PASTE47, \ - NLOHMANN_JSON_PASTE46, \ - NLOHMANN_JSON_PASTE45, \ - NLOHMANN_JSON_PASTE44, \ - NLOHMANN_JSON_PASTE43, \ - NLOHMANN_JSON_PASTE42, \ - NLOHMANN_JSON_PASTE41, \ - NLOHMANN_JSON_PASTE40, \ - NLOHMANN_JSON_PASTE39, \ - NLOHMANN_JSON_PASTE38, \ - NLOHMANN_JSON_PASTE37, \ - NLOHMANN_JSON_PASTE36, \ - NLOHMANN_JSON_PASTE35, \ - NLOHMANN_JSON_PASTE34, \ - NLOHMANN_JSON_PASTE33, \ - NLOHMANN_JSON_PASTE32, \ - NLOHMANN_JSON_PASTE31, \ - NLOHMANN_JSON_PASTE30, \ - NLOHMANN_JSON_PASTE29, \ - NLOHMANN_JSON_PASTE28, \ - NLOHMANN_JSON_PASTE27, \ - NLOHMANN_JSON_PASTE26, \ - NLOHMANN_JSON_PASTE25, \ - NLOHMANN_JSON_PASTE24, \ - NLOHMANN_JSON_PASTE23, \ - NLOHMANN_JSON_PASTE22, \ - NLOHMANN_JSON_PASTE21, \ - NLOHMANN_JSON_PASTE20, \ - NLOHMANN_JSON_PASTE19, \ - NLOHMANN_JSON_PASTE18, \ - NLOHMANN_JSON_PASTE17, \ - NLOHMANN_JSON_PASTE16, \ - NLOHMANN_JSON_PASTE15, \ - NLOHMANN_JSON_PASTE14, \ - NLOHMANN_JSON_PASTE13, \ - NLOHMANN_JSON_PASTE12, \ - NLOHMANN_JSON_PASTE11, \ - NLOHMANN_JSON_PASTE10, \ - NLOHMANN_JSON_PASTE9, \ - NLOHMANN_JSON_PASTE8, \ - NLOHMANN_JSON_PASTE7, \ - NLOHMANN_JSON_PASTE6, \ - NLOHMANN_JSON_PASTE5, \ - NLOHMANN_JSON_PASTE4, \ - NLOHMANN_JSON_PASTE3, \ - NLOHMANN_JSON_PASTE2, \ - NLOHMANN_JSON_PASTE1)(__VA_ARGS__)) +#define NLOHMANN_JSON_EXPAND(x) x +#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME, ...) NAME +#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \ + NLOHMANN_JSON_PASTE64, \ + NLOHMANN_JSON_PASTE63, \ + NLOHMANN_JSON_PASTE62, \ + NLOHMANN_JSON_PASTE61, \ + NLOHMANN_JSON_PASTE60, \ + NLOHMANN_JSON_PASTE59, \ + NLOHMANN_JSON_PASTE58, \ + NLOHMANN_JSON_PASTE57, \ + NLOHMANN_JSON_PASTE56, \ + NLOHMANN_JSON_PASTE55, \ + NLOHMANN_JSON_PASTE54, \ + NLOHMANN_JSON_PASTE53, \ + NLOHMANN_JSON_PASTE52, \ + NLOHMANN_JSON_PASTE51, \ + NLOHMANN_JSON_PASTE50, \ + NLOHMANN_JSON_PASTE49, \ + NLOHMANN_JSON_PASTE48, \ + NLOHMANN_JSON_PASTE47, \ + NLOHMANN_JSON_PASTE46, \ + NLOHMANN_JSON_PASTE45, \ + NLOHMANN_JSON_PASTE44, \ + NLOHMANN_JSON_PASTE43, \ + NLOHMANN_JSON_PASTE42, \ + NLOHMANN_JSON_PASTE41, \ + NLOHMANN_JSON_PASTE40, \ + NLOHMANN_JSON_PASTE39, \ + NLOHMANN_JSON_PASTE38, \ + NLOHMANN_JSON_PASTE37, \ + NLOHMANN_JSON_PASTE36, \ + NLOHMANN_JSON_PASTE35, \ + NLOHMANN_JSON_PASTE34, \ + NLOHMANN_JSON_PASTE33, \ + NLOHMANN_JSON_PASTE32, \ + NLOHMANN_JSON_PASTE31, \ + NLOHMANN_JSON_PASTE30, \ + NLOHMANN_JSON_PASTE29, \ + NLOHMANN_JSON_PASTE28, \ + NLOHMANN_JSON_PASTE27, \ + NLOHMANN_JSON_PASTE26, \ + NLOHMANN_JSON_PASTE25, \ + NLOHMANN_JSON_PASTE24, \ + NLOHMANN_JSON_PASTE23, \ + NLOHMANN_JSON_PASTE22, \ + NLOHMANN_JSON_PASTE21, \ + NLOHMANN_JSON_PASTE20, \ + NLOHMANN_JSON_PASTE19, \ + NLOHMANN_JSON_PASTE18, \ + NLOHMANN_JSON_PASTE17, \ + NLOHMANN_JSON_PASTE16, \ + NLOHMANN_JSON_PASTE15, \ + NLOHMANN_JSON_PASTE14, \ + NLOHMANN_JSON_PASTE13, \ + NLOHMANN_JSON_PASTE12, \ + NLOHMANN_JSON_PASTE11, \ + NLOHMANN_JSON_PASTE10, \ + NLOHMANN_JSON_PASTE9, \ + NLOHMANN_JSON_PASTE8, \ + NLOHMANN_JSON_PASTE7, \ + NLOHMANN_JSON_PASTE6, \ + NLOHMANN_JSON_PASTE5, \ + NLOHMANN_JSON_PASTE4, \ + NLOHMANN_JSON_PASTE3, \ + NLOHMANN_JSON_PASTE2, \ + NLOHMANN_JSON_PASTE1)(__VA_ARGS__)) #define NLOHMANN_JSON_PASTE2(func, v1) func(v1) #define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2) #define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3) @@ -398,32 +397,64 @@ @def NLOHMANN_DEFINE_TYPE_INTRUSIVE @since version 3.9.0 */ -#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \ - friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } \ + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) \ + } -#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ - friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } \ + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) \ + { \ + const Type nlohmann_json_default_obj{}; \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) \ + } -#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ - friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } /*! @brief macro @def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE @since version 3.9.0 */ -#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \ - inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } \ + inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) \ + } -#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ - inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } -#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ - inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } \ + inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) \ + { \ + const Type nlohmann_json_default_obj{}; \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) \ + } // inspired from https://stackoverflow.com/a/26745591 // allows to call any std function as if (e.g. with begin): @@ -434,30 +465,30 @@ #define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \ namespace detail { \ using std::std_name; \ - \ + \ template<typename... T> \ using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \ } \ - \ + \ namespace detail2 { \ struct std_name##_tag \ { \ }; \ - \ + \ template<typename... T> \ std_name##_tag std_name(T&&...); \ - \ + \ template<typename... T> \ using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \ - \ + \ template<typename... T> \ struct would_call_std_##std_name \ { \ static constexpr auto const value = ::nlohmann::detail:: \ - is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \ + is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \ }; \ - } /* namespace detail2 */ \ - \ + } /* namespace detail2 */ \ + \ template<typename... T> \ struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \ { \
diff --git a/include/nlohmann/detail/meta/cpp_future.hpp b/include/nlohmann/detail/meta/cpp_future.hpp index 412b5aa..a5687bc 100644 --- a/include/nlohmann/detail/meta/cpp_future.hpp +++ b/include/nlohmann/detail/meta/cpp_future.hpp
@@ -9,16 +9,15 @@ #pragma once -#include <array> // array -#include <cstddef> // size_t -#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type -#include <utility> // index_sequence, make_index_sequence, index_sequence_for +#include <array> // array +#include <cstddef> // size_t +#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type +#include <utility> // index_sequence, make_index_sequence, index_sequence_for #include <nlohmann/detail/macro_scope.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename T> using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type; @@ -28,8 +27,8 @@ // the following utilities are natively available in C++14 using std::enable_if_t; using std::index_sequence; -using std::make_index_sequence; using std::index_sequence_for; +using std::make_index_sequence; #else @@ -61,7 +60,7 @@ // // will be deduced to `0, 1, 2, 3, 4`. // user_function(make_integer_sequence<int, 5>()); // } -template <typename T, T... Ints> +template<typename T, T... Ints> struct integer_sequence { using value_type = T; @@ -76,38 +75,37 @@ // A helper template for an `integer_sequence` of `size_t`, // `absl::index_sequence` is designed to be a drop-in replacement for C++14's // `std::index_sequence`. -template <size_t... Ints> +template<size_t... Ints> using index_sequence = integer_sequence<size_t, Ints...>; -namespace utility_internal -{ +namespace utility_internal { -template <typename Seq, size_t SeqSize, size_t Rem> +template<typename Seq, size_t SeqSize, size_t Rem> struct Extend; // Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency. -template <typename T, T... Ints, size_t SeqSize> +template<typename T, T... Ints, size_t SeqSize> struct Extend<integer_sequence<T, Ints...>, SeqSize, 0> { - using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >; + using type = integer_sequence<T, Ints..., (Ints + SeqSize)...>; }; -template <typename T, T... Ints, size_t SeqSize> +template<typename T, T... Ints, size_t SeqSize> struct Extend<integer_sequence<T, Ints...>, SeqSize, 1> { - using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >; + using type = integer_sequence<T, Ints..., (Ints + SeqSize)..., 2 * SeqSize>; }; // Recursion helper for 'make_integer_sequence<T, N>'. // 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'. -template <typename T, size_t N> +template<typename T, size_t N> struct Gen { using type = - typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type; + typename Extend<typename Gen<T, N / 2>::type, N / 2, N % 2>::type; }; -template <typename T> +template<typename T> struct Gen<T, 0> { using type = integer_sequence<T>; @@ -122,7 +120,7 @@ // This template alias is equivalent to // `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in // replacement for C++14's `std::make_integer_sequence`. -template <typename T, T N> +template<typename T, T N> using make_integer_sequence = typename utility_internal::Gen<T, N>::type; // make_index_sequence @@ -130,7 +128,7 @@ // This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`, // and is designed to be a drop-in replacement for C++14's // `std::make_index_sequence`. -template <size_t N> +template<size_t N> using make_index_sequence = make_integer_sequence<size_t, N>; // index_sequence_for @@ -138,7 +136,7 @@ // Converts a typename pack into an index sequence of the same length, and // is designed to be a drop-in replacement for C++14's // `std::index_sequence_for()` -template <typename... Ts> +template<typename... Ts> using index_sequence_for = make_index_sequence<sizeof...(Ts)>; //// END OF CODE FROM GOOGLE ABSEIL @@ -146,8 +144,12 @@ #endif // dispatch utility (taken from ranges-v3) -template<unsigned N> struct priority_tag : priority_tag < N - 1 > {}; -template<> struct priority_tag<0> {}; +template<unsigned N> +struct priority_tag : priority_tag<N - 1> +{}; +template<> +struct priority_tag<0> +{}; // taken from ranges-v3 template<typename T> @@ -157,14 +159,14 @@ }; #ifndef JSON_HAS_CPP_17 - template<typename T> - constexpr T static_const<T>::value; +template<typename T> +constexpr T static_const<T>::value; #endif template<typename T, typename... Args> -inline constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args) +inline constexpr std::array<T, sizeof...(Args)> make_array(Args&&... args) { - return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}}; + return std::array<T, sizeof...(Args)>{{static_cast<T>(std::forward<Args>(args))...}}; } } // namespace detail
diff --git a/include/nlohmann/detail/meta/detected.hpp b/include/nlohmann/detail/meta/detected.hpp index 1db9bf9..ba048a0 100644 --- a/include/nlohmann/detail/meta/detected.hpp +++ b/include/nlohmann/detail/meta/detected.hpp
@@ -13,8 +13,7 @@ #include <nlohmann/detail/meta/void_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { // https://en.cppreference.com/w/cpp/experimental/is_detected struct nonesuch @@ -29,7 +28,8 @@ template<class Default, class AlwaysVoid, - template<class...> class Op, + template<class...> + class Op, class... Args> struct detector { @@ -48,7 +48,8 @@ using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t; template<template<class...> class Op, class... Args> -struct is_detected_lazy : is_detected<Op, Args...> { }; +struct is_detected_lazy : is_detected<Op, Args...> +{}; template<template<class...> class Op, class... Args> using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
diff --git a/include/nlohmann/detail/meta/identity_tag.hpp b/include/nlohmann/detail/meta/identity_tag.hpp index 269deff..1933065 100644 --- a/include/nlohmann/detail/meta/identity_tag.hpp +++ b/include/nlohmann/detail/meta/identity_tag.hpp
@@ -11,11 +11,12 @@ #include <nlohmann/detail/abi_macros.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { // dispatching helper struct -template <class T> struct identity_tag {}; +template<class T> +struct identity_tag +{}; } // namespace detail NLOHMANN_JSON_NAMESPACE_END
diff --git a/include/nlohmann/detail/meta/is_sax.hpp b/include/nlohmann/detail/meta/is_sax.hpp index 4e02bc1..e7f1e82 100644 --- a/include/nlohmann/detail/meta/is_sax.hpp +++ b/include/nlohmann/detail/meta/is_sax.hpp
@@ -8,17 +8,16 @@ #pragma once -#include <cstdint> // size_t -#include <utility> // declval -#include <string> // string +#include <cstdint> // size_t +#include <string> // string +#include <utility> // declval #include <nlohmann/detail/abi_macros.hpp> #include <nlohmann/detail/meta/detected.hpp> #include <nlohmann/detail/meta/type_traits.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename T> using null_function_t = decltype(std::declval<T&>().null()); @@ -37,7 +36,8 @@ template<typename T, typename Float, typename String> using number_float_function_t = decltype(std::declval<T&>().number_float( - std::declval<Float>(), std::declval<const String&>())); + std::declval<Float>(), + std::declval<const String&>())); template<typename T, typename String> using string_function_t = @@ -67,8 +67,9 @@ template<typename T, typename Exception> using parse_error_function_t = decltype(std::declval<T&>().parse_error( - std::declval<std::size_t>(), std::declval<const std::string&>(), - std::declval<const Exception&>())); + std::declval<std::size_t>(), + std::declval<const std::string&>(), + std::declval<const Exception&>())); template<typename SAX, typename BasicJsonType> struct is_sax @@ -123,15 +124,12 @@ static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, "Missing/invalid function: bool boolean(bool)"); static_assert( - is_detected_exact<bool, number_integer_function_t, SAX, - number_integer_t>::value, + is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value, "Missing/invalid function: bool number_integer(number_integer_t)"); static_assert( - is_detected_exact<bool, number_unsigned_function_t, SAX, - number_unsigned_t>::value, + is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value, "Missing/invalid function: bool number_unsigned(number_unsigned_t)"); - static_assert(is_detected_exact<bool, number_float_function_t, SAX, - number_float_t, string_t>::value, + static_assert(is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value, "Missing/invalid function: bool number_float(number_float_t, const string_t&)"); static_assert( is_detected_exact<bool, string_function_t, SAX, string_t>::value,
diff --git a/include/nlohmann/detail/meta/std_fs.hpp b/include/nlohmann/detail/meta/std_fs.hpp index fd18039..eb11dc9 100644 --- a/include/nlohmann/detail/meta/std_fs.hpp +++ b/include/nlohmann/detail/meta/std_fs.hpp
@@ -11,18 +11,16 @@ #include <nlohmann/detail/macro_scope.hpp> #if JSON_HAS_EXPERIMENTAL_FILESYSTEM -#include <experimental/filesystem> + #include <experimental/filesystem> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { namespace std_fs = std::experimental::filesystem; } // namespace detail NLOHMANN_JSON_NAMESPACE_END #elif JSON_HAS_FILESYSTEM -#include <filesystem> + #include <filesystem> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { namespace std_fs = std::filesystem; } // namespace detail NLOHMANN_JSON_NAMESPACE_END
diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index e1b000d..bb71c5b 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp
@@ -8,11 +8,11 @@ #pragma once -#include <limits> // numeric_limits -#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type -#include <utility> // declval -#include <tuple> // tuple -#include <string> // char_traits +#include <limits> // numeric_limits +#include <string> // char_traits +#include <tuple> // tuple +#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type +#include <utility> // declval #include <nlohmann/detail/iterators/iterator_traits.hpp> #include <nlohmann/detail/macro_scope.hpp> @@ -31,8 +31,7 @@ @since version 2.1.0 */ -namespace detail -{ +namespace detail { ///////////// // helpers // @@ -47,19 +46,20 @@ // In this case, T has to be properly CV-qualified to constraint the function arguments // (e.g. to_json(BasicJsonType&, const T&)) -template<typename> struct is_basic_json : std::false_type {}; +template<typename> +struct is_basic_json : std::false_type +{}; NLOHMANN_BASIC_JSON_TPL_DECLARATION -struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {}; +struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type +{}; // used by exceptions create() member functions // true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t // false_type otherwise template<typename BasicJsonContext> -struct is_basic_json_context : - std::integral_constant < bool, - is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value - || std::is_same<BasicJsonContext, std::nullptr_t>::value > +struct is_basic_json_context : std::integral_constant<bool, + is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value || std::is_same<BasicJsonContext, std::nullptr_t>::value> {}; ////////////////////// @@ -70,10 +70,12 @@ class json_ref; template<typename> -struct is_json_ref : std::false_type {}; +struct is_json_ref : std::false_type +{}; template<typename T> -struct is_json_ref<json_ref<T>> : std::true_type {}; +struct is_json_ref<json_ref<T>> : std::true_type +{}; ////////////////////////// // aliases for detected // @@ -111,63 +113,64 @@ // trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists template<typename BasicJsonType, typename T, typename = void> -struct has_from_json : std::false_type {}; +struct has_from_json : std::false_type +{}; // trait checking if j.get<T> is valid // use this trait instead of std::is_constructible or std::is_convertible, // both rely on, or make use of implicit conversions, and thus fail when T // has several constructors/operator= (see https://github.com/nlohmann/json/issues/958) -template <typename BasicJsonType, typename T> +template<typename BasicJsonType, typename T> struct is_getable { static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value; }; template<typename BasicJsonType, typename T> -struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >> +struct has_from_json<BasicJsonType, T, enable_if_t<!is_basic_json<T>::value>> { using serializer = typename BasicJsonType::template json_serializer<T, void>; static constexpr bool value = - is_detected_exact<void, from_json_function, serializer, - const BasicJsonType&, T&>::value; + is_detected_exact<void, from_json_function, serializer, const BasicJsonType&, T&>::value; }; // This trait checks if JSONSerializer<T>::from_json(json const&) exists // this overload is used for non-default-constructible user-defined-types template<typename BasicJsonType, typename T, typename = void> -struct has_non_default_from_json : std::false_type {}; +struct has_non_default_from_json : std::false_type +{}; template<typename BasicJsonType, typename T> -struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >> +struct has_non_default_from_json<BasicJsonType, T, enable_if_t<!is_basic_json<T>::value>> { using serializer = typename BasicJsonType::template json_serializer<T, void>; static constexpr bool value = - is_detected_exact<T, from_json_function, serializer, - const BasicJsonType&>::value; + is_detected_exact<T, from_json_function, serializer, const BasicJsonType&>::value; }; // This trait checks if BasicJsonType::json_serializer<T>::to_json exists // Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion. template<typename BasicJsonType, typename T, typename = void> -struct has_to_json : std::false_type {}; +struct has_to_json : std::false_type +{}; template<typename BasicJsonType, typename T> -struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >> +struct has_to_json<BasicJsonType, T, enable_if_t<!is_basic_json<T>::value>> { using serializer = typename BasicJsonType::template json_serializer<T, void>; static constexpr bool value = - is_detected_exact<void, to_json_function, serializer, BasicJsonType&, - T>::value; + is_detected_exact<void, to_json_function, serializer, BasicJsonType&, T>::value; }; template<typename T> using detect_key_compare = typename T::key_compare; template<typename T> -struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {}; +struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> +{}; // obtains the actual object key comparator template<typename BasicJsonType> @@ -175,8 +178,9 @@ { using object_t = typename BasicJsonType::object_t; using object_comparator_t = typename BasicJsonType::default_object_comparator_t; - using type = typename std::conditional < has_key_compare<object_t>::value, - typename object_t::key_compare, object_comparator_t>::type; + using type = typename std::conditional<has_key_compare<object_t>::value, + typename object_t::key_compare, + object_comparator_t>::type; }; template<typename BasicJsonType> @@ -244,54 +248,72 @@ /////////////////// // https://en.cppreference.com/w/cpp/types/conjunction -template<class...> struct conjunction : std::true_type { }; -template<class B> struct conjunction<B> : B { }; +template<class...> +struct conjunction : std::true_type +{}; +template<class B> +struct conjunction<B> : B +{}; template<class B, class... Bn> struct conjunction<B, Bn...> -: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {}; + : std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type +{}; // https://en.cppreference.com/w/cpp/types/negation -template<class B> struct negation : std::integral_constant < bool, !B::value > { }; +template<class B> +struct negation : std::integral_constant<bool, !B::value> +{}; // Reimplementation of is_constructible and is_default_constructible, due to them being broken for // std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367). // This causes compile errors in e.g. clang 3.5 or gcc 4.9. -template <typename T> -struct is_default_constructible : std::is_default_constructible<T> {}; +template<typename T> +struct is_default_constructible : std::is_default_constructible<T> +{}; -template <typename T1, typename T2> +template<typename T1, typename T2> struct is_default_constructible<std::pair<T1, T2>> - : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {}; + : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> +{}; -template <typename T1, typename T2> +template<typename T1, typename T2> struct is_default_constructible<const std::pair<T1, T2>> - : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {}; + : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> +{}; -template <typename... Ts> +template<typename... Ts> struct is_default_constructible<std::tuple<Ts...>> - : conjunction<is_default_constructible<Ts>...> {}; + : conjunction<is_default_constructible<Ts>...> +{}; -template <typename... Ts> +template<typename... Ts> struct is_default_constructible<const std::tuple<Ts...>> - : conjunction<is_default_constructible<Ts>...> {}; + : conjunction<is_default_constructible<Ts>...> +{}; -template <typename T, typename... Args> -struct is_constructible : std::is_constructible<T, Args...> {}; +template<typename T, typename... Args> +struct is_constructible : std::is_constructible<T, Args...> +{}; -template <typename T1, typename T2> -struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {}; +template<typename T1, typename T2> +struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> +{}; -template <typename T1, typename T2> -struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {}; +template<typename T1, typename T2> +struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> +{}; -template <typename... Ts> -struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {}; +template<typename... Ts> +struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> +{}; -template <typename... Ts> -struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {}; +template<typename... Ts> +struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> +{}; template<typename T, typename = void> -struct is_iterator_traits : std::false_type {}; +struct is_iterator_traits : std::false_type +{}; template<typename T> struct is_iterator_traits<iterator_traits<T>> @@ -338,44 +360,49 @@ // and is written by Xiang Fan who agreed to using it in this library. template<typename T, typename = void> -struct is_complete_type : std::false_type {}; +struct is_complete_type : std::false_type +{}; template<typename T> -struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {}; +struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type +{}; -template<typename BasicJsonType, typename CompatibleObjectType, - typename = void> -struct is_compatible_object_type_impl : std::false_type {}; +template<typename BasicJsonType, typename CompatibleObjectType, typename = void> +struct is_compatible_object_type_impl : std::false_type +{}; template<typename BasicJsonType, typename CompatibleObjectType> -struct is_compatible_object_type_impl < - BasicJsonType, CompatibleObjectType, - enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&& - is_detected<key_type_t, CompatibleObjectType>::value >> +struct is_compatible_object_type_impl< + BasicJsonType, + CompatibleObjectType, + enable_if_t<is_detected<mapped_type_t, CompatibleObjectType>::value && + is_detected<key_type_t, CompatibleObjectType>::value>> { using object_t = typename BasicJsonType::object_t; // macOS's is_constructible does not play well with nonesuch... static constexpr bool value = is_constructible<typename object_t::key_type, - typename CompatibleObjectType::key_type>::value && + typename CompatibleObjectType::key_type>::value && is_constructible<typename object_t::mapped_type, - typename CompatibleObjectType::mapped_type>::value; + typename CompatibleObjectType::mapped_type>::value; }; template<typename BasicJsonType, typename CompatibleObjectType> struct is_compatible_object_type - : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {}; + : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> +{}; -template<typename BasicJsonType, typename ConstructibleObjectType, - typename = void> -struct is_constructible_object_type_impl : std::false_type {}; +template<typename BasicJsonType, typename ConstructibleObjectType, typename = void> +struct is_constructible_object_type_impl : std::false_type +{}; template<typename BasicJsonType, typename ConstructibleObjectType> -struct is_constructible_object_type_impl < - BasicJsonType, ConstructibleObjectType, - enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&& - is_detected<key_type_t, ConstructibleObjectType>::value >> +struct is_constructible_object_type_impl< + BasicJsonType, + ConstructibleObjectType, + enable_if_t<is_detected<mapped_type_t, ConstructibleObjectType>::value && + is_detected<key_type_t, ConstructibleObjectType>::value>> { using object_t = typename BasicJsonType::object_t; @@ -384,21 +411,22 @@ (std::is_move_assignable<ConstructibleObjectType>::value || std::is_copy_assignable<ConstructibleObjectType>::value) && (is_constructible<typename ConstructibleObjectType::key_type, - typename object_t::key_type>::value && - std::is_same < - typename object_t::mapped_type, - typename ConstructibleObjectType::mapped_type >::value)) || + typename object_t::key_type>::value && + std::is_same< + typename object_t::mapped_type, + typename ConstructibleObjectType::mapped_type>::value)) || (has_from_json<BasicJsonType, - typename ConstructibleObjectType::mapped_type>::value || - has_non_default_from_json < - BasicJsonType, - typename ConstructibleObjectType::mapped_type >::value); + typename ConstructibleObjectType::mapped_type>::value || + has_non_default_from_json< + BasicJsonType, + typename ConstructibleObjectType::mapped_type>::value); }; template<typename BasicJsonType, typename ConstructibleObjectType> struct is_constructible_object_type - : is_constructible_object_type_impl<BasicJsonType, - ConstructibleObjectType> {}; + : is_constructible_object_type_impl<BasicJsonType, + ConstructibleObjectType> +{}; template<typename BasicJsonType, typename CompatibleStringType> struct is_compatible_string_type @@ -418,88 +446,98 @@ #endif static constexpr auto value = - conjunction < - is_constructible<laundered_type, typename BasicJsonType::string_t>, - is_detected_exact<typename BasicJsonType::string_t::value_type, - value_type_t, laundered_type >>::value; + conjunction< + is_constructible<laundered_type, typename BasicJsonType::string_t>, + is_detected_exact<typename BasicJsonType::string_t::value_type, + value_type_t, + laundered_type>>::value; }; template<typename BasicJsonType, typename CompatibleArrayType, typename = void> -struct is_compatible_array_type_impl : std::false_type {}; +struct is_compatible_array_type_impl : std::false_type +{}; template<typename BasicJsonType, typename CompatibleArrayType> -struct is_compatible_array_type_impl < - BasicJsonType, CompatibleArrayType, - enable_if_t < - is_detected<iterator_t, CompatibleArrayType>::value&& - is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&& -// special case for types like std::filesystem::path whose iterator's value_type are themselves -// c.f. https://github.com/nlohmann/json/pull/3073 - !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >> +struct is_compatible_array_type_impl< + BasicJsonType, + CompatibleArrayType, + enable_if_t< + is_detected<iterator_t, CompatibleArrayType>::value && + is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value && + // special case for types like std::filesystem::path whose iterator's value_type are themselves + // c.f. https://github.com/nlohmann/json/pull/3073 + !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value>> { static constexpr bool value = is_constructible<BasicJsonType, - range_value_t<CompatibleArrayType>>::value; + range_value_t<CompatibleArrayType>>::value; }; template<typename BasicJsonType, typename CompatibleArrayType> struct is_compatible_array_type - : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {}; + : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> +{}; template<typename BasicJsonType, typename ConstructibleArrayType, typename = void> -struct is_constructible_array_type_impl : std::false_type {}; +struct is_constructible_array_type_impl : std::false_type +{}; template<typename BasicJsonType, typename ConstructibleArrayType> -struct is_constructible_array_type_impl < - BasicJsonType, ConstructibleArrayType, +struct is_constructible_array_type_impl< + BasicJsonType, + ConstructibleArrayType, enable_if_t<std::is_same<ConstructibleArrayType, - typename BasicJsonType::value_type>::value >> - : std::true_type {}; + typename BasicJsonType::value_type>::value>> + : std::true_type +{}; template<typename BasicJsonType, typename ConstructibleArrayType> -struct is_constructible_array_type_impl < - BasicJsonType, ConstructibleArrayType, - enable_if_t < !std::is_same<ConstructibleArrayType, - typename BasicJsonType::value_type>::value&& - !is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value&& - is_default_constructible<ConstructibleArrayType>::value&& -(std::is_move_assignable<ConstructibleArrayType>::value || - std::is_copy_assignable<ConstructibleArrayType>::value)&& -is_detected<iterator_t, ConstructibleArrayType>::value&& -is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&& -is_detected<range_value_t, ConstructibleArrayType>::value&& -// special case for types like std::filesystem::path whose iterator's value_type are themselves -// c.f. https://github.com/nlohmann/json/pull/3073 -!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&& - is_complete_type < - detected_t<range_value_t, ConstructibleArrayType >>::value >> +struct is_constructible_array_type_impl< + BasicJsonType, + ConstructibleArrayType, + enable_if_t<!std::is_same<ConstructibleArrayType, + typename BasicJsonType::value_type>::value && + !is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value && + is_default_constructible<ConstructibleArrayType>::value && + (std::is_move_assignable<ConstructibleArrayType>::value || + std::is_copy_assignable<ConstructibleArrayType>::value) && + is_detected<iterator_t, ConstructibleArrayType>::value && + is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value && + is_detected<range_value_t, ConstructibleArrayType>::value && + // special case for types like std::filesystem::path whose iterator's value_type are themselves + // c.f. https://github.com/nlohmann/json/pull/3073 + !std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value && + is_complete_type< + detected_t<range_value_t, ConstructibleArrayType>>::value>> { using value_type = range_value_t<ConstructibleArrayType>; static constexpr bool value = std::is_same<value_type, - typename BasicJsonType::array_t::value_type>::value || + typename BasicJsonType::array_t::value_type>::value || has_from_json<BasicJsonType, - value_type>::value || - has_non_default_from_json < - BasicJsonType, - value_type >::value; + value_type>::value || + has_non_default_from_json< + BasicJsonType, + value_type>::value; }; template<typename BasicJsonType, typename ConstructibleArrayType> struct is_constructible_array_type - : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {}; + : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> +{}; -template<typename RealIntegerType, typename CompatibleNumberIntegerType, - typename = void> -struct is_compatible_integer_type_impl : std::false_type {}; +template<typename RealIntegerType, typename CompatibleNumberIntegerType, typename = void> +struct is_compatible_integer_type_impl : std::false_type +{}; template<typename RealIntegerType, typename CompatibleNumberIntegerType> -struct is_compatible_integer_type_impl < - RealIntegerType, CompatibleNumberIntegerType, - enable_if_t < std::is_integral<RealIntegerType>::value&& - std::is_integral<CompatibleNumberIntegerType>::value&& - !std::is_same<bool, CompatibleNumberIntegerType>::value >> +struct is_compatible_integer_type_impl< + RealIntegerType, + CompatibleNumberIntegerType, + enable_if_t<std::is_integral<RealIntegerType>::value && + std::is_integral<CompatibleNumberIntegerType>::value && + !std::is_same<bool, CompatibleNumberIntegerType>::value>> { // is there an assert somewhere on overflows? using RealLimits = std::numeric_limits<RealIntegerType>; @@ -507,23 +545,26 @@ static constexpr auto value = is_constructible<RealIntegerType, - CompatibleNumberIntegerType>::value && + CompatibleNumberIntegerType>::value && CompatibleLimits::is_integer && RealLimits::is_signed == CompatibleLimits::is_signed; }; template<typename RealIntegerType, typename CompatibleNumberIntegerType> struct is_compatible_integer_type - : is_compatible_integer_type_impl<RealIntegerType, - CompatibleNumberIntegerType> {}; + : is_compatible_integer_type_impl<RealIntegerType, + CompatibleNumberIntegerType> +{}; template<typename BasicJsonType, typename CompatibleType, typename = void> -struct is_compatible_type_impl: std::false_type {}; +struct is_compatible_type_impl : std::false_type +{}; template<typename BasicJsonType, typename CompatibleType> -struct is_compatible_type_impl < - BasicJsonType, CompatibleType, - enable_if_t<is_complete_type<CompatibleType>::value >> +struct is_compatible_type_impl< + BasicJsonType, + CompatibleType, + enable_if_t<is_complete_type<CompatibleType>::value>> { static constexpr bool value = has_to_json<BasicJsonType, CompatibleType>::value; @@ -531,60 +572,60 @@ template<typename BasicJsonType, typename CompatibleType> struct is_compatible_type - : is_compatible_type_impl<BasicJsonType, CompatibleType> {}; + : is_compatible_type_impl<BasicJsonType, CompatibleType> +{}; template<typename T1, typename T2> -struct is_constructible_tuple : std::false_type {}; +struct is_constructible_tuple : std::false_type +{}; template<typename T1, typename... Args> -struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {}; +struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> +{}; template<typename BasicJsonType, typename T> -struct is_json_iterator_of : std::false_type {}; +struct is_json_iterator_of : std::false_type +{}; template<typename BasicJsonType> -struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::iterator> : std::true_type {}; +struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::iterator> : std::true_type +{}; template<typename BasicJsonType> struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type {}; // checks if a given type T is a template specialization of Primary -template<template <typename...> class Primary, typename T> -struct is_specialization_of : std::false_type {}; +template<template<typename...> class Primary, typename T> +struct is_specialization_of : std::false_type +{}; -template<template <typename...> class Primary, typename... Args> -struct is_specialization_of<Primary, Primary<Args...>> : std::true_type {}; +template<template<typename...> class Primary, typename... Args> +struct is_specialization_of<Primary, Primary<Args...>> : std::true_type +{}; template<typename T> using is_json_pointer = is_specialization_of<::nlohmann::json_pointer, uncvref_t<T>>; // checks if A and B are comparable using Compare functor template<typename Compare, typename A, typename B, typename = void> -struct is_comparable : std::false_type {}; +struct is_comparable : std::false_type +{}; template<typename Compare, typename A, typename B> -struct is_comparable<Compare, A, B, void_t< -decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())), -decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>())) ->> : std::true_type {}; +struct is_comparable<Compare, A, B, void_t<decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())), decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))>> : std::true_type +{}; template<typename T> using detect_is_transparent = typename T::is_transparent; // type trait to check if KeyType can be used as object key (without a BasicJsonType) // see is_usable_as_basic_json_key_type below -template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, - bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>> -using is_usable_as_key_type = typename std::conditional < - is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value - && !(ExcludeObjectKeyType && std::is_same<KeyType, - ObjectKeyType>::value) - && (!RequireTransparentComparator - || is_detected <detect_is_transparent, Comparator>::value) - && !is_json_pointer<KeyType>::value, - std::true_type, - std::false_type >::type; +template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>> +using is_usable_as_key_type = typename std::conditional< + is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value && !(ExcludeObjectKeyType && std::is_same<KeyType, ObjectKeyType>::value) && (!RequireTransparentComparator || is_detected<detect_is_transparent, Comparator>::value) && !is_json_pointer<KeyType>::value, + std::true_type, + std::false_type>::type; // type trait to check if KeyType can be used as object key // true if: @@ -592,48 +633,55 @@ // - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type // - the comparator is transparent or RequireTransparentComparator is false // - KeyType is not a JSON iterator or json_pointer -template<typename BasicJsonType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, - bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>> -using is_usable_as_basic_json_key_type = typename std::conditional < - is_usable_as_key_type<typename BasicJsonType::object_comparator_t, - typename BasicJsonType::object_t::key_type, KeyTypeCVRef, - RequireTransparentComparator, ExcludeObjectKeyType>::value - && !is_json_iterator_of<BasicJsonType, KeyType>::value, - std::true_type, - std::false_type >::type; +template<typename BasicJsonType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>> +using is_usable_as_basic_json_key_type = typename std::conditional< + is_usable_as_key_type<typename BasicJsonType::object_comparator_t, + typename BasicJsonType::object_t::key_type, + KeyTypeCVRef, + RequireTransparentComparator, + ExcludeObjectKeyType>::value && + !is_json_iterator_of<BasicJsonType, KeyType>::value, + std::true_type, + std::false_type>::type; template<typename ObjectType, typename KeyType> using detect_erase_with_key_type = decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>())); // type trait to check if object_t has an erase() member functions accepting KeyType template<typename BasicJsonType, typename KeyType> -using has_erase_with_key_type = typename std::conditional < - is_detected < - detect_erase_with_key_type, - typename BasicJsonType::object_t, KeyType >::value, - std::true_type, - std::false_type >::type; +using has_erase_with_key_type = typename std::conditional< + is_detected< + detect_erase_with_key_type, + typename BasicJsonType::object_t, + KeyType>::value, + std::true_type, + std::false_type>::type; // a naive helper to check if a type is an ordered_map (exploits the fact that // ordered_map inherits capacity() from std::vector) -template <typename T> +template<typename T> struct is_ordered_map { using one = char; struct two { - char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) }; - template <typename C> static one test( decltype(&C::capacity) ) ; - template <typename C> static two test(...); + template<typename C> + static one test(decltype(&C::capacity)); + template<typename C> + static two test(...); - enum { value = sizeof(test<T>(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + enum + { + value = sizeof(test<T>(nullptr)) == sizeof(char) + }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) }; // to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) -template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 > +template<typename T, typename U, enable_if_t<!std::is_same<T, U>::value, int> = 0> T conditional_static_cast(U value) { return static_cast<T>(value); @@ -656,17 +704,14 @@ // there's a disjunction trait in another PR; replace when merged template<typename... Types> -using same_sign = std::integral_constant < bool, - all_signed<Types...>::value || all_unsigned<Types...>::value >; +using same_sign = std::integral_constant<bool, + all_signed<Types...>::value || all_unsigned<Types...>::value>; template<typename OfType, typename T> -using never_out_of_range = std::integral_constant < bool, - (std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType))) - || (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T)) >; +using never_out_of_range = std::integral_constant<bool, + (std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType))) || (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T))>; -template<typename OfType, typename T, - bool OfTypeSigned = std::is_signed<OfType>::value, - bool TSigned = std::is_signed<T>::value> +template<typename OfType, typename T, bool OfTypeSigned = std::is_signed<OfType>::value, bool TSigned = std::is_signed<T>::value> struct value_in_range_of_impl2; template<typename OfType, typename T> @@ -705,14 +750,11 @@ static constexpr bool test(T val) { using CommonType = typename std::common_type<OfType, T>::type; - return static_cast<CommonType>(val) >= static_cast<CommonType>((std::numeric_limits<OfType>::min)()) - && static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)()); + return static_cast<CommonType>(val) >= static_cast<CommonType>((std::numeric_limits<OfType>::min)()) && static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)()); } }; -template<typename OfType, typename T, - bool NeverOutOfRange = never_out_of_range<OfType, T>::value, - typename = detail::enable_if_t<all_integral<OfType, T>::value>> +template<typename OfType, typename T, bool NeverOutOfRange = never_out_of_range<OfType, T>::value, typename = detail::enable_if_t<all_integral<OfType, T>::value>> struct value_in_range_of_impl1; template<typename OfType, typename T> @@ -746,8 +788,7 @@ // is_c_string /////////////////////////////////////////////////////////////////////////////// -namespace impl -{ +namespace impl { template<typename T> inline constexpr bool is_c_string() @@ -756,16 +797,15 @@ using TUnCVExt = typename std::remove_cv<TUnExt>::type; using TUnPtr = typename std::remove_pointer<T>::type; using TUnCVPtr = typename std::remove_cv<TUnPtr>::type; - return - (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value) - || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value); + return (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value) || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value); } } // namespace impl // checks whether T is a [cv] char */[cv] char[] C string template<typename T> -struct is_c_string : bool_constant<impl::is_c_string<T>()> {}; +struct is_c_string : bool_constant<impl::is_c_string<T>()> +{}; template<typename T> using is_c_string_uncvref = is_c_string<uncvref_t<T>>; @@ -774,8 +814,7 @@ // is_transparent /////////////////////////////////////////////////////////////////////////////// -namespace impl -{ +namespace impl { template<typename T> inline constexpr bool is_transparent() @@ -787,7 +826,8 @@ // checks whether T has a member named is_transparent template<typename T> -struct is_transparent : bool_constant<impl::is_transparent<T>()> {}; +struct is_transparent : bool_constant<impl::is_transparent<T>()> +{}; ///////////////////////////////////////////////////////////////////////////////
diff --git a/include/nlohmann/detail/meta/void_t.hpp b/include/nlohmann/detail/meta/void_t.hpp index 99615c7..795edaa 100644 --- a/include/nlohmann/detail/meta/void_t.hpp +++ b/include/nlohmann/detail/meta/void_t.hpp
@@ -11,14 +11,15 @@ #include <nlohmann/detail/abi_macros.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { -template<typename ...Ts> struct make_void +template<typename... Ts> +struct make_void { using type = void; }; -template<typename ...Ts> using void_t = typename make_void<Ts...>::type; +template<typename... Ts> +using void_t = typename make_void<Ts...>::type; } // namespace detail NLOHMANN_JSON_NAMESPACE_END
diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index f475d57..e10c353 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp
@@ -8,16 +8,16 @@ #pragma once -#include <algorithm> // reverse -#include <array> // array -#include <map> // map -#include <cmath> // isnan, isinf -#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t -#include <cstring> // memcpy -#include <limits> // numeric_limits -#include <string> // string -#include <utility> // move -#include <vector> // vector +#include <algorithm> // reverse +#include <array> // array +#include <cmath> // isnan, isinf +#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t +#include <cstring> // memcpy +#include <limits> // numeric_limits +#include <map> // map +#include <string> // string +#include <utility> // move +#include <vector> // vector #include <nlohmann/detail/input/binary_reader.hpp> #include <nlohmann/detail/macro_scope.hpp> @@ -25,8 +25,7 @@ #include <nlohmann/detail/string_concat.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /////////////////// // binary writer // @@ -48,7 +47,8 @@ @param[in] adapter output adapter to write to */ - explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter)) + explicit binary_writer(output_adapter_t<CharType> adapter) + : oa(std::move(adapter)) { JSON_ASSERT(oa); } @@ -99,8 +99,8 @@ case value_t::boolean: { oa->write_character(j.m_data.m_value.boolean - ? to_char_type(0xF5) - : to_char_type(0xF4)); + ? to_char_type(0xF5) + : to_char_type(0xF4)); break; } @@ -414,17 +414,17 @@ { switch (j.type()) { - case value_t::null: // nil + case value_t::null: // nil { oa->write_character(to_char_type(0xC0)); break; } - case value_t::boolean: // true and false + case value_t::boolean: // true and false { oa->write_character(j.m_data.m_value.boolean - ? to_char_type(0xC3) - : to_char_type(0xC2)); + ? to_char_type(0xC3) + : to_char_type(0xC2)); break; } @@ -626,30 +626,29 @@ switch (N) { case 1: - output_type = 0xD4; // fixext 1 + output_type = 0xD4; // fixext 1 break; case 2: - output_type = 0xD5; // fixext 2 + output_type = 0xD5; // fixext 2 break; case 4: - output_type = 0xD6; // fixext 4 + output_type = 0xD6; // fixext 4 break; case 8: - output_type = 0xD7; // fixext 8 + output_type = 0xD7; // fixext 8 break; case 16: - output_type = 0xD8; // fixext 16 + output_type = 0xD8; // fixext 16 break; default: - output_type = 0xC7; // ext 8 + output_type = 0xC7; // ext 8 fixed = false; break; } - } else { - output_type = 0xC4; // bin 8 + output_type = 0xC4; // bin 8 fixed = false; } @@ -662,8 +661,8 @@ else if (N <= (std::numeric_limits<std::uint16_t>::max)()) { const std::uint8_t output_type = use_ext - ? 0xC8 // ext 16 - : 0xC5; // bin 16 + ? 0xC8 // ext 16 + : 0xC5; // bin 16 oa->write_character(to_char_type(output_type)); write_number(static_cast<std::uint16_t>(N)); @@ -671,8 +670,8 @@ else if (N <= (std::numeric_limits<std::uint32_t>::max)()) { const std::uint8_t output_type = use_ext - ? 0xC9 // ext 32 - : 0xC6; // bin 32 + ? 0xC9 // ext 32 + : 0xC6; // bin 32 oa->write_character(to_char_type(output_type)); write_number(static_cast<std::uint32_t>(N)); @@ -736,9 +735,7 @@ @param[in] add_prefix whether prefixes need to be used for this value @param[in] use_bjdata whether write in BJData format, default is false */ - void write_ubjson(const BasicJsonType& j, const bool use_count, - const bool use_type, const bool add_prefix = true, - const bool use_bjdata = false) + void write_ubjson(const BasicJsonType& j, const bool use_count, const bool use_type, const bool add_prefix = true, const bool use_bjdata = false) { switch (j.type()) { @@ -756,8 +753,8 @@ if (add_prefix) { oa->write_character(j.m_data.m_value.boolean - ? to_char_type('T') - : to_char_type('F')); + ? to_char_type('T') + : to_char_type('F')); } break; } @@ -805,13 +802,11 @@ { JSON_ASSERT(use_count); const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata); - const bool same_prefix = std::all_of(j.begin() + 1, j.end(), - [this, first_prefix, use_bjdata](const BasicJsonType & v) - { + const bool same_prefix = std::all_of(j.begin() + 1, j.end(), [this, first_prefix, use_bjdata](const BasicJsonType& v) { return ubjson_prefix(v, use_bjdata) == first_prefix; }); - std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type + std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end())) { @@ -903,13 +898,11 @@ { JSON_ASSERT(use_count); const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata); - const bool same_prefix = std::all_of(j.begin(), j.end(), - [this, first_prefix, use_bjdata](const BasicJsonType & v) - { + const bool same_prefix = std::all_of(j.begin(), j.end(), [this, first_prefix, use_bjdata](const BasicJsonType& v) { return ubjson_prefix(v, use_bjdata) == first_prefix; }); - std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type + std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end())) { @@ -966,7 +959,7 @@ static_cast<void>(j); } - return /*id*/ 1ul + name.size() + /*zero-terminator*/1u; + return /*id*/ 1ul + name.size() + /*zero-terminator*/ 1u; } /*! @@ -975,7 +968,7 @@ void write_bson_entry_header(const string_t& name, const std::uint8_t element_type) { - oa->write_character(to_char_type(element_type)); // boolean + oa->write_character(to_char_type(element_type)); // boolean oa->write_characters( reinterpret_cast<const CharType*>(name.c_str()), name.size() + 1u); @@ -1037,8 +1030,8 @@ static std::size_t calc_bson_integer_size(const std::int64_t value) { return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)() - ? sizeof(std::int32_t) - : sizeof(std::int64_t); + ? sizeof(std::int32_t) + : sizeof(std::int64_t); } /*! @@ -1049,12 +1042,12 @@ { if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()) { - write_bson_entry_header(name, 0x10); // int32 + write_bson_entry_header(name, 0x10); // int32 write_number<std::int32_t>(static_cast<std::int32_t>(value), true); } else { - write_bson_entry_header(name, 0x12); // int64 + write_bson_entry_header(name, 0x12); // int64 write_number<std::int64_t>(static_cast<std::int64_t>(value), true); } } @@ -1065,8 +1058,8 @@ static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept { return (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) - ? sizeof(std::int32_t) - : sizeof(std::int64_t); + ? sizeof(std::int32_t) + : sizeof(std::int64_t); } /*! @@ -1097,7 +1090,7 @@ void write_bson_object_entry(const string_t& name, const typename BasicJsonType::object_t& value) { - write_bson_entry_header(name, 0x03); // object + write_bson_entry_header(name, 0x03); // object write_bson_object(value); } @@ -1108,8 +1101,7 @@ { std::size_t array_index = 0ul; - const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast<std::size_t>(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el) - { + const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast<std::size_t>(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type& el) { return result + calc_bson_element_size(std::to_string(array_index++), el); }); @@ -1130,7 +1122,7 @@ void write_bson_array(const string_t& name, const typename BasicJsonType::array_t& value) { - write_bson_entry_header(name, 0x04); // array + write_bson_entry_header(name, 0x04); // array write_number<std::int32_t>(static_cast<std::int32_t>(calc_bson_array_size(value)), true); std::size_t array_index = 0ul; @@ -1162,7 +1154,7 @@ @return The calculated size for the BSON document entry for @a j with the given @a name. */ static std::size_t calc_bson_element_size(const string_t& name, - const BasicJsonType& j) + const BasicJsonType& j) { const auto header_size = calc_bson_entry_header_size(name, j); switch (j.type()) @@ -1197,7 +1189,7 @@ // LCOV_EXCL_START case value_t::discarded: default: - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) return 0ul; // LCOV_EXCL_STOP } @@ -1244,7 +1236,7 @@ // LCOV_EXCL_START case value_t::discarded: default: - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) return; // LCOV_EXCL_STOP } @@ -1258,9 +1250,7 @@ */ static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value) { - const std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast<std::size_t>(0), - [](size_t result, const typename BasicJsonType::object_t::value_type & el) - { + const std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast<std::size_t>(0), [](size_t result, const typename BasicJsonType::object_t::value_type& el) { return result += calc_bson_element_size(el.first, el.second); }); @@ -1316,8 +1306,7 @@ //////////// // UBJSON: write number (floating point) - template<typename NumberType, typename std::enable_if< - std::is_floating_point<NumberType>::value, int>::type = 0> + template<typename NumberType, typename std::enable_if<std::is_floating_point<NumberType>::value, int>::type = 0> void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix, const bool use_bjdata) @@ -1330,8 +1319,7 @@ } // UBJSON: write number (unsigned integer) - template<typename NumberType, typename std::enable_if< - std::is_unsigned<NumberType>::value, int>::type = 0> + template<typename NumberType, typename std::enable_if<std::is_unsigned<NumberType>::value, int>::type = 0> void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix, const bool use_bjdata) @@ -1417,9 +1405,7 @@ } // UBJSON: write number (signed integer) - template < typename NumberType, typename std::enable_if < - std::is_signed<NumberType>::value&& - !std::is_floating_point<NumberType>::value, int >::type = 0 > + template<typename NumberType, typename std::enable_if<std::is_signed<NumberType>::value && !std::is_floating_point<NumberType>::value, int>::type = 0> void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix, const bool use_bjdata) @@ -1542,7 +1528,7 @@ return 'L'; } // anything else is treated as high-precision number - return 'H'; // LCOV_EXCL_LINE + return 'H'; // LCOV_EXCL_LINE } case value_t::number_unsigned: @@ -1580,7 +1566,7 @@ return 'M'; } // anything else is treated as high-precision number - return 'H'; // LCOV_EXCL_LINE + return 'H'; // LCOV_EXCL_LINE } case value_t::number_float: @@ -1589,7 +1575,7 @@ case value_t::string: return 'S'; - case value_t::array: // fallthrough + case value_t::array: // fallthrough case value_t::binary: return '['; @@ -1617,9 +1603,7 @@ */ bool write_bjdata_ndarray(const typename BasicJsonType::object_t& value, const bool use_count, const bool use_type) { - std::map<string_t, CharType> bjdtype = {{"uint8", 'U'}, {"int8", 'i'}, {"uint16", 'u'}, {"int16", 'I'}, - {"uint32", 'm'}, {"int32", 'l'}, {"uint64", 'M'}, {"int64", 'L'}, {"single", 'd'}, {"double", 'D'}, {"char", 'C'} - }; + std::map<string_t, CharType> bjdtype = {{"uint8", 'U'}, {"int8", 'i'}, {"uint16", 'u'}, {"int16", 'I'}, {"uint32", 'm'}, {"int32", 'l'}, {"uint64", 'M'}, {"int64", 'L'}, {"single", 'd'}, {"double", 'D'}, {"char", 'C'}}; string_t key = "_ArrayType_"; auto it = bjdtype.find(static_cast<string_t>(value.at(key))); @@ -1648,7 +1632,7 @@ oa->write_character('#'); key = "_ArraySize_"; - write_ubjson(value.at(key), use_count, use_type, true, true); + write_ubjson(value.at(key), use_count, use_type, true, true); key = "_ArrayData_"; if (dtype == 'U' || dtype == 'C') @@ -1761,27 +1745,27 @@ void write_compact_float(const number_float_t n, detail::input_format_t format) { #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" #endif if (static_cast<double>(n) >= static_cast<double>(std::numeric_limits<float>::lowest()) && - static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) && - static_cast<double>(static_cast<float>(n)) == static_cast<double>(n)) + static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) && + static_cast<double>(static_cast<float>(n)) == static_cast<double>(n)) { oa->write_character(format == detail::input_format_t::cbor - ? get_cbor_float_prefix(static_cast<float>(n)) - : get_msgpack_float_prefix(static_cast<float>(n))); + ? get_cbor_float_prefix(static_cast<float>(n)) + : get_msgpack_float_prefix(static_cast<float>(n))); write_number(static_cast<float>(n)); } else { oa->write_character(format == detail::input_format_t::cbor - ? get_cbor_float_prefix(n) - : get_msgpack_float_prefix(n)); + ? get_cbor_float_prefix(n) + : get_msgpack_float_prefix(n)); write_number(n); } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif } @@ -1790,15 +1774,15 @@ // between uint8_t and CharType. In case CharType is not unsigned, // such a conversion is required to allow values greater than 128. // See <https://github.com/nlohmann/json/issues/1286> for a discussion. - template < typename C = CharType, - enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * = nullptr > + template<typename C = CharType, + enable_if_t<std::is_signed<C>::value && std::is_signed<char>::value>* = nullptr> static constexpr CharType to_char_type(std::uint8_t x) noexcept { return *reinterpret_cast<char*>(&x); } - template < typename C = CharType, - enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * = nullptr > + template<typename C = CharType, + enable_if_t<std::is_signed<C>::value && std::is_unsigned<char>::value>* = nullptr> static CharType to_char_type(std::uint8_t x) noexcept { static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t"); @@ -1815,12 +1799,7 @@ return x; } - template < typename InputCharType, typename C = CharType, - enable_if_t < - std::is_signed<C>::value && - std::is_signed<char>::value && - std::is_same<char, typename std::remove_cv<InputCharType>::type>::value - > * = nullptr > + template<typename InputCharType, typename C = CharType, enable_if_t<std::is_signed<C>::value && std::is_signed<char>::value && std::is_same<char, typename std::remove_cv<InputCharType>::type>::value>* = nullptr> static constexpr CharType to_char_type(InputCharType x) noexcept { return x;
diff --git a/include/nlohmann/detail/output/output_adapters.hpp b/include/nlohmann/detail/output/output_adapters.hpp index 626f7c0..9fde874 100644 --- a/include/nlohmann/detail/output/output_adapters.hpp +++ b/include/nlohmann/detail/output/output_adapters.hpp
@@ -8,26 +8,26 @@ #pragma once -#include <algorithm> // copy -#include <cstddef> // size_t -#include <iterator> // back_inserter -#include <memory> // shared_ptr, make_shared -#include <string> // basic_string -#include <vector> // vector +#include <algorithm> // copy +#include <cstddef> // size_t +#include <iterator> // back_inserter +#include <memory> // shared_ptr, make_shared +#include <string> // basic_string +#include <vector> // vector #ifndef JSON_NO_IO #include <ios> // streamsize #include <ostream> // basic_ostream -#endif // JSON_NO_IO +#endif // JSON_NO_IO #include <nlohmann/detail/macro_scope.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /// abstract output adapter interface -template<typename CharType> struct output_adapter_protocol +template<typename CharType> +struct output_adapter_protocol { virtual void write_character(CharType c) = 0; virtual void write_characters(const CharType* s, std::size_t length) = 0; @@ -50,7 +50,7 @@ { public: explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept - : v(vec) + : v(vec) {} void write_character(CharType c) override @@ -75,7 +75,7 @@ { public: explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept - : stream(s) + : stream(s) {} void write_character(CharType c) override @@ -100,7 +100,7 @@ { public: explicit output_string_adapter(StringType& s) noexcept - : str(s) + : str(s) {} void write_character(CharType c) override @@ -124,15 +124,18 @@ public: template<typename AllocatorType = std::allocator<CharType>> output_adapter(std::vector<CharType, AllocatorType>& vec) - : oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {} + : oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) + {} #ifndef JSON_NO_IO output_adapter(std::basic_ostream<CharType>& s) - : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {} + : oa(std::make_shared<output_stream_adapter<CharType>>(s)) + {} #endif // JSON_NO_IO output_adapter(StringType& s) - : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {} + : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) + {} operator output_adapter_t<CharType>() {
diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index ed20b0d..f389b04 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp
@@ -9,18 +9,18 @@ #pragma once -#include <algorithm> // reverse, remove, fill, find, none_of -#include <array> // array -#include <clocale> // localeconv, lconv -#include <cmath> // labs, isfinite, isnan, signbit -#include <cstddef> // size_t, ptrdiff_t -#include <cstdint> // uint8_t -#include <cstdio> // snprintf -#include <limits> // numeric_limits -#include <string> // string, char_traits -#include <iomanip> // setfill, setw -#include <type_traits> // is_same -#include <utility> // move +#include <algorithm> // reverse, remove, fill, find, none_of +#include <array> // array +#include <clocale> // localeconv, lconv +#include <cmath> // labs, isfinite, isnan, signbit +#include <cstddef> // size_t, ptrdiff_t +#include <cstdint> // uint8_t +#include <cstdio> // snprintf +#include <iomanip> // setfill, setw +#include <limits> // numeric_limits +#include <string> // string, char_traits +#include <type_traits> // is_same +#include <utility> // move #include <nlohmann/detail/conversions/to_chars.hpp> #include <nlohmann/detail/exceptions.hpp> @@ -32,8 +32,7 @@ #include <nlohmann/detail/value_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /////////////////// // serialization // @@ -42,9 +41,9 @@ /// how to treat decoding errors enum class error_handler_t { - strict, ///< throw a type_error exception in case of invalid UTF-8 - replace, ///< replace invalid UTF-8 sequences with U+FFFD - ignore ///< ignore invalid UTF-8 sequences + strict, ///< throw a type_error exception in case of invalid UTF-8 + replace, ///< replace invalid UTF-8 sequences with U+FFFD + ignore ///< ignore invalid UTF-8 sequences }; template<typename BasicJsonType> @@ -64,15 +63,14 @@ @param[in] ichar indentation character to use @param[in] error_handler_ how to react on decoding errors */ - serializer(output_adapter_t<char> s, const char ichar, - error_handler_t error_handler_ = error_handler_t::strict) - : o(std::move(s)) - , loc(std::localeconv()) - , thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep))) - , decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point))) - , indent_char(ichar) - , indent_string(512, indent_char) - , error_handler(error_handler_) + serializer(output_adapter_t<char> s, const char ichar, error_handler_t error_handler_ = error_handler_t::strict) + : o(std::move(s)) + , loc(std::localeconv()) + , thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(*(loc->thousands_sep))) + , decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(*(loc->decimal_point))) + , indent_char(ichar) + , indent_string(512, indent_char) + , error_handler(error_handler_) {} // delete because of pointer members @@ -206,7 +204,8 @@ // first n-1 elements for (auto i = val.m_data.m_value.array->cbegin(); - i != val.m_data.m_value.array->cend() - 1; ++i) + i != val.m_data.m_value.array->cend() - 1; + ++i) { o->write_characters(indent_string.c_str(), new_indent); dump(*i, true, ensure_ascii, indent_step, new_indent); @@ -228,7 +227,8 @@ // first n-1 elements for (auto i = val.m_data.m_value.array->cbegin(); - i != val.m_data.m_value.array->cend() - 1; ++i) + i != val.m_data.m_value.array->cend() - 1; + ++i) { dump(*i, false, ensure_ascii, indent_step, current_indent); o->write_character(','); @@ -272,7 +272,8 @@ if (!val.m_data.m_value.binary->empty()) { for (auto i = val.m_data.m_value.binary->cbegin(); - i != val.m_data.m_value.binary->cend() - 1; ++i) + i != val.m_data.m_value.binary->cend() - 1; + ++i) { dump_integer(*i); o->write_characters(", ", 2); @@ -303,7 +304,8 @@ if (!val.m_data.m_value.binary->empty()) { for (auto i = val.m_data.m_value.binary->cbegin(); - i != val.m_data.m_value.binary->cend() - 1; ++i) + i != val.m_data.m_value.binary->cend() - 1; + ++i) { dump_integer(*i); o->write_character(','); @@ -368,13 +370,13 @@ return; } - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } } - JSON_PRIVATE_UNLESS_TESTED: - /*! + JSON_PRIVATE_UNLESS_TESTED : + /*! @brief dump escaped string Escape a string by replacing certain special characters by a sequence of an @@ -388,7 +390,8 @@ @complexity Linear in the length of string @a s. */ - void dump_escaped(const string_t& s, const bool ensure_ascii) + void + dump_escaped(const string_t& s, const bool ensure_ascii) { std::uint32_t codepoint{}; std::uint8_t state = UTF8_ACCEPT; @@ -408,49 +411,49 @@ { switch (codepoint) { - case 0x08: // backspace + case 0x08: // backspace { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = 'b'; break; } - case 0x09: // horizontal tab + case 0x09: // horizontal tab { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = 't'; break; } - case 0x0A: // newline + case 0x0A: // newline { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = 'n'; break; } - case 0x0C: // formfeed + case 0x0C: // formfeed { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = 'f'; break; } - case 0x0D: // carriage return + case 0x0D: // carriage return { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = 'r'; break; } - case 0x22: // quotation mark + case 0x22: // quotation mark { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = '\"'; break; } - case 0x5C: // reverse solidus + case 0x5C: // reverse solidus { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = '\\'; @@ -466,16 +469,13 @@ if (codepoint <= 0xFFFF) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", - static_cast<std::uint16_t>(codepoint))); + static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", static_cast<std::uint16_t>(codepoint))); bytes += 6; } else { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", - static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)), - static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu)))); + static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)), static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu)))); bytes += 12; } } @@ -567,8 +567,8 @@ break; } - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } break; } @@ -628,8 +628,8 @@ break; } - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } } } @@ -684,13 +684,13 @@ } // templates to avoid warnings about useless casts - template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value, int> = 0> + template<typename NumberType, enable_if_t<std::is_signed<NumberType>::value, int> = 0> bool is_negative_number(NumberType x) { return x < 0; } - template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value, int > = 0 > + template<typename NumberType, enable_if_t<std::is_unsigned<NumberType>::value, int> = 0> bool is_negative_number(NumberType /*unused*/) { return false; @@ -705,29 +705,112 @@ @param[in] x integer number (signed or unsigned) to dump @tparam NumberType either @a number_integer_t or @a number_unsigned_t */ - template < typename NumberType, detail::enable_if_t < - std::is_integral<NumberType>::value || - std::is_same<NumberType, number_unsigned_t>::value || - std::is_same<NumberType, number_integer_t>::value || - std::is_same<NumberType, binary_char_t>::value, - int > = 0 > + template<typename NumberType, detail::enable_if_t<std::is_integral<NumberType>::value || std::is_same<NumberType, number_unsigned_t>::value || std::is_same<NumberType, number_integer_t>::value || std::is_same<NumberType, binary_char_t>::value, int> = 0> void dump_integer(NumberType x) { - static constexpr std::array<std::array<char, 2>, 100> digits_to_99 - { + static constexpr std::array<std::array<char, 2>, 100> digits_to_99{ { - {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}}, - {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}}, - {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}}, - {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}}, - {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}}, - {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}}, - {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}}, - {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}}, - {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}}, - {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}}, - } - }; + {{'0', '0'}}, + {{'0', '1'}}, + {{'0', '2'}}, + {{'0', '3'}}, + {{'0', '4'}}, + {{'0', '5'}}, + {{'0', '6'}}, + {{'0', '7'}}, + {{'0', '8'}}, + {{'0', '9'}}, + {{'1', '0'}}, + {{'1', '1'}}, + {{'1', '2'}}, + {{'1', '3'}}, + {{'1', '4'}}, + {{'1', '5'}}, + {{'1', '6'}}, + {{'1', '7'}}, + {{'1', '8'}}, + {{'1', '9'}}, + {{'2', '0'}}, + {{'2', '1'}}, + {{'2', '2'}}, + {{'2', '3'}}, + {{'2', '4'}}, + {{'2', '5'}}, + {{'2', '6'}}, + {{'2', '7'}}, + {{'2', '8'}}, + {{'2', '9'}}, + {{'3', '0'}}, + {{'3', '1'}}, + {{'3', '2'}}, + {{'3', '3'}}, + {{'3', '4'}}, + {{'3', '5'}}, + {{'3', '6'}}, + {{'3', '7'}}, + {{'3', '8'}}, + {{'3', '9'}}, + {{'4', '0'}}, + {{'4', '1'}}, + {{'4', '2'}}, + {{'4', '3'}}, + {{'4', '4'}}, + {{'4', '5'}}, + {{'4', '6'}}, + {{'4', '7'}}, + {{'4', '8'}}, + {{'4', '9'}}, + {{'5', '0'}}, + {{'5', '1'}}, + {{'5', '2'}}, + {{'5', '3'}}, + {{'5', '4'}}, + {{'5', '5'}}, + {{'5', '6'}}, + {{'5', '7'}}, + {{'5', '8'}}, + {{'5', '9'}}, + {{'6', '0'}}, + {{'6', '1'}}, + {{'6', '2'}}, + {{'6', '3'}}, + {{'6', '4'}}, + {{'6', '5'}}, + {{'6', '6'}}, + {{'6', '7'}}, + {{'6', '8'}}, + {{'6', '9'}}, + {{'7', '0'}}, + {{'7', '1'}}, + {{'7', '2'}}, + {{'7', '3'}}, + {{'7', '4'}}, + {{'7', '5'}}, + {{'7', '6'}}, + {{'7', '7'}}, + {{'7', '8'}}, + {{'7', '9'}}, + {{'8', '0'}}, + {{'8', '1'}}, + {{'8', '2'}}, + {{'8', '3'}}, + {{'8', '4'}}, + {{'8', '5'}}, + {{'8', '6'}}, + {{'8', '7'}}, + {{'8', '8'}}, + {{'8', '9'}}, + {{'9', '0'}}, + {{'9', '1'}}, + {{'9', '2'}}, + {{'9', '3'}}, + {{'9', '4'}}, + {{'9', '5'}}, + {{'9', '6'}}, + {{'9', '7'}}, + {{'9', '8'}}, + {{'9', '9'}}, + }}; // special case for "0" if (x == 0) @@ -737,7 +820,7 @@ } // use a pointer to fill the buffer - auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg) + auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg) number_unsigned_t abs_value; @@ -810,9 +893,8 @@ // guaranteed to round-trip, using strtof and strtod, resp. // // NB: The test below works if <long double> == <double>. - static constexpr bool is_ieee_single_or_double - = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) || - (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024); + static constexpr bool is_ieee_single_or_double = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) || + (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024); dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>()); } @@ -864,11 +946,9 @@ // determine if we need to append ".0" const bool value_is_int_like = - std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, - [](char c) - { - return c == '.' || c == 'e'; - }); + std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, [](char c) { + return c == '.' || c == 'e'; + }); if (value_is_int_like) { @@ -900,31 +980,416 @@ static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept { static const std::array<std::uint8_t, 400> utf8d = - { { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00..1F - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20..3F - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40..5F - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60..7F - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // 80..9F - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // A0..BF - 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C0..DF - 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF - 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF - 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, // s1..s2 - 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // s3..s4 - 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, // s5..s6 - 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // s7..s8 - } - }; + { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, // 00..1F + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, // 20..3F + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, // 40..5F + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, // 60..7F + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, // 80..9F + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, // A0..BF + 8, + 8, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, // C0..DF + 0xA, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x4, + 0x3, + 0x3, // E0..EF + 0xB, + 0x6, + 0x6, + 0x6, + 0x5, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, // F0..FF + 0x0, + 0x1, + 0x2, + 0x3, + 0x5, + 0x8, + 0x7, + 0x1, + 0x1, + 0x1, + 0x4, + 0x6, + 0x1, + 0x1, + 0x1, + 0x1, // s0..s0 + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 1, + 0, + 1, + 1, + 1, + 1, + 1, + 1, // s1..s2 + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 2, + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, // s3..s4 + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 3, + 1, + 3, + 1, + 1, + 1, + 1, + 1, + 1, // s5..s6 + 1, + 3, + 1, + 1, + 1, + 1, + 1, + 3, + 1, + 3, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 3, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 // s7..s8 + }}; JSON_ASSERT(byte < utf8d.size()); const std::uint8_t type = utf8d[byte]; codep = (state != UTF8_ACCEPT) - ? (byte & 0x3fu) | (codep << 6u) - : (0xFFu >> type) & (byte); + ? (byte & 0x3fu) | (codep << 6u) + : (0xFFu >> type) & (byte); const std::size_t index = 256u + static_cast<size_t>(state) * 16u + static_cast<size_t>(type); JSON_ASSERT(index < utf8d.size()); @@ -939,8 +1404,8 @@ */ number_unsigned_t remove_sign(number_unsigned_t x) { - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE - return x; // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + return x; // LCOV_EXCL_LINE } /* @@ -954,7 +1419,7 @@ */ inline number_unsigned_t remove_sign(number_integer_t x) noexcept { - JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression) + JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression) return static_cast<number_unsigned_t>(-(x + 1)) + 1; }
diff --git a/include/nlohmann/detail/string_concat.hpp b/include/nlohmann/detail/string_concat.hpp index f49e8d2..7bb7c9b 100644 --- a/include/nlohmann/detail/string_concat.hpp +++ b/include/nlohmann/detail/string_concat.hpp
@@ -8,16 +8,15 @@ #pragma once -#include <cstring> // strlen -#include <string> // string -#include <utility> // forward +#include <cstring> // strlen +#include <string> // string +#include <utility> // forward #include <nlohmann/detail/meta/cpp_future.hpp> #include <nlohmann/detail/meta/detected.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { inline std::size_t concat_length() { @@ -25,26 +24,26 @@ } template<typename... Args> -inline std::size_t concat_length(const char* cstr, const Args& ... rest); +inline std::size_t concat_length(const char* cstr, const Args&... rest); template<typename StringType, typename... Args> -inline std::size_t concat_length(const StringType& str, const Args& ... rest); +inline std::size_t concat_length(const StringType& str, const Args&... rest); template<typename... Args> -inline std::size_t concat_length(const char /*c*/, const Args& ... rest) +inline std::size_t concat_length(const char /*c*/, const Args&... rest) { return 1 + concat_length(rest...); } template<typename... Args> -inline std::size_t concat_length(const char* cstr, const Args& ... rest) +inline std::size_t concat_length(const char* cstr, const Args&... rest) { // cppcheck-suppress ignoredReturnValue return ::strlen(cstr) + concat_length(rest...); } template<typename StringType, typename... Args> -inline std::size_t concat_length(const StringType& str, const Args& ... rest) +inline std::size_t concat_length(const StringType& str, const Args&... rest) { return str.size() + concat_length(rest...); } @@ -54,13 +53,13 @@ {} template<typename StringType, typename Arg> -using string_can_append = decltype(std::declval<StringType&>().append(std::declval < Arg && > ())); +using string_can_append = decltype(std::declval<StringType&>().append(std::declval<Arg&&>())); template<typename StringType, typename Arg> using detect_string_can_append = is_detected<string_can_append, StringType, Arg>; template<typename StringType, typename Arg> -using string_can_append_op = decltype(std::declval<StringType&>() += std::declval < Arg && > ()); +using string_can_append_op = decltype(std::declval<StringType&>() += std::declval<Arg&&>()); template<typename StringType, typename Arg> using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>; @@ -77,64 +76,45 @@ template<typename StringType, typename Arg> using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>; -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && detect_string_can_append_op<OutStringType, Arg>::value, int > = 0 > -inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest); +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && detect_string_can_append_op<OutStringType, Arg>::value, int> = 0> +inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest); -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && !detect_string_can_append_op<OutStringType, Arg>::value - && detect_string_can_append_iter<OutStringType, Arg>::value, int > = 0 > -inline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest); +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && detect_string_can_append_iter<OutStringType, Arg>::value, int> = 0> +inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest); -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && !detect_string_can_append_op<OutStringType, Arg>::value - && !detect_string_can_append_iter<OutStringType, Arg>::value - && detect_string_can_append_data<OutStringType, Arg>::value, int > = 0 > -inline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest); +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && !detect_string_can_append_iter<OutStringType, Arg>::value && detect_string_can_append_data<OutStringType, Arg>::value, int> = 0> +inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest); -template<typename OutStringType, typename Arg, typename... Args, - enable_if_t<detect_string_can_append<OutStringType, Arg>::value, int> = 0> -inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest) +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<detect_string_can_append<OutStringType, Arg>::value, int> = 0> +inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest) { out.append(std::forward<Arg>(arg)); concat_into(out, std::forward<Args>(rest)...); } -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && detect_string_can_append_op<OutStringType, Arg>::value, int > > -inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest) +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && detect_string_can_append_op<OutStringType, Arg>::value, int>> +inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest) { out += std::forward<Arg>(arg); concat_into(out, std::forward<Args>(rest)...); } -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && !detect_string_can_append_op<OutStringType, Arg>::value - && detect_string_can_append_iter<OutStringType, Arg>::value, int > > -inline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest) +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && detect_string_can_append_iter<OutStringType, Arg>::value, int>> +inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest) { out.append(arg.begin(), arg.end()); concat_into(out, std::forward<Args>(rest)...); } -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && !detect_string_can_append_op<OutStringType, Arg>::value - && !detect_string_can_append_iter<OutStringType, Arg>::value - && detect_string_can_append_data<OutStringType, Arg>::value, int > > -inline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest) +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && !detect_string_can_append_iter<OutStringType, Arg>::value && detect_string_can_append_data<OutStringType, Arg>::value, int>> +inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest) { out.append(arg.data(), arg.size()); concat_into(out, std::forward<Args>(rest)...); } template<typename OutStringType = std::string, typename... Args> -inline OutStringType concat(Args && ... args) +inline OutStringType concat(Args&&... args) { OutStringType str; str.reserve(concat_length(args...));
diff --git a/include/nlohmann/detail/string_escape.hpp b/include/nlohmann/detail/string_escape.hpp index 7f1b5c5..14cb78c 100644 --- a/include/nlohmann/detail/string_escape.hpp +++ b/include/nlohmann/detail/string_escape.hpp
@@ -11,8 +11,7 @@ #include <nlohmann/detail/abi_macros.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /*! @brief replace all occurrences of a substring by another string @@ -28,14 +27,13 @@ @since version 2.0.0 */ template<typename StringType> -inline void replace_substring(StringType& s, const StringType& f, - const StringType& t) +inline void replace_substring(StringType& s, const StringType& f, const StringType& t) { JSON_ASSERT(!f.empty()); - for (auto pos = s.find(f); // find first occurrence of f - pos != StringType::npos; // make sure f was found - s.replace(pos, f.size(), t), // replace with t, and - pos = s.find(f, pos + t.size())) // find next occurrence of f + for (auto pos = s.find(f); // find first occurrence of f + pos != StringType::npos; // make sure f was found + s.replace(pos, f.size(), t), // replace with t, and + pos = s.find(f, pos + t.size())) // find next occurrence of f {} }
diff --git a/include/nlohmann/detail/value_t.hpp b/include/nlohmann/detail/value_t.hpp index 07688fe..337d4d4 100644 --- a/include/nlohmann/detail/value_t.hpp +++ b/include/nlohmann/detail/value_t.hpp
@@ -8,19 +8,18 @@ #pragma once -#include <array> // array -#include <cstddef> // size_t -#include <cstdint> // uint8_t -#include <string> // string +#include <array> // array +#include <cstddef> // size_t +#include <cstdint> // uint8_t +#include <string> // string #include <nlohmann/detail/macro_scope.hpp> #if JSON_HAS_THREE_WAY_COMPARISON - #include <compare> // partial_ordering + #include <compare> // partial_ordering #endif NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /////////////////////////// // JSON type enumeration // @@ -78,24 +77,29 @@ @since version 1.0.0 */ #if JSON_HAS_THREE_WAY_COMPARISON - inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) noexcept // *NOPAD* +inline std::partial_ordering operator<= > (const value_t lhs, const value_t rhs) noexcept // *NOPAD* #else - inline bool operator<(const value_t lhs, const value_t rhs) noexcept +inline bool operator<(const value_t lhs, const value_t rhs) noexcept #endif { static constexpr std::array<std::uint8_t, 9> order = {{ - 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, - 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, - 6 /* binary */ - } - }; + 0 /* null */, + 3 /* object */, + 4 /* array */, + 5 /* string */, + 1 /* boolean */, + 2 /* integer */, + 2 /* unsigned */, + 2 /* float */, + 6 /* binary */ + }}; const auto l_index = static_cast<std::size_t>(lhs); const auto r_index = static_cast<std::size_t>(rhs); #if JSON_HAS_THREE_WAY_COMPARISON if (l_index < order.size() && r_index < order.size()) { - return order[l_index] <=> order[r_index]; // *NOPAD* + return order[l_index] <= > order[r_index]; // *NOPAD* } return std::partial_ordering::unordered; #else @@ -110,7 +114,7 @@ #if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__) inline bool operator<(const value_t lhs, const value_t rhs) noexcept { - return std::is_lt(lhs <=> rhs); // *NOPAD* + return std::is_lt(lhs <= > rhs); // *NOPAD* } #endif
diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 95d6bf1..d0b55b1 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp
@@ -18,18 +18,18 @@ #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ -#include <algorithm> // all_of, find, for_each -#include <cstddef> // nullptr_t, ptrdiff_t, size_t -#include <functional> // hash, less -#include <initializer_list> // initializer_list +#include <algorithm> // all_of, find, for_each +#include <cstddef> // nullptr_t, ptrdiff_t, size_t +#include <functional> // hash, less +#include <initializer_list> // initializer_list #ifndef JSON_NO_IO - #include <iosfwd> // istream, ostream -#endif // JSON_NO_IO -#include <iterator> // random_access_iterator_tag -#include <memory> // unique_ptr -#include <string> // string, stoi, to_string -#include <utility> // declval, forward, move, pair, swap -#include <vector> // vector + #include <iosfwd> // istream, ostream +#endif // JSON_NO_IO +#include <iterator> // random_access_iterator_tag +#include <memory> // unique_ptr +#include <string> // string, stoi, to_string +#include <utility> // declval, forward, move, pair, swap +#include <vector> // vector #include <nlohmann/adl_serializer.hpp> #include <nlohmann/byte_container_with_subtype.hpp> @@ -50,13 +50,13 @@ #include <nlohmann/detail/json_pointer.hpp> #include <nlohmann/detail/json_ref.hpp> #include <nlohmann/detail/macro_scope.hpp> -#include <nlohmann/detail/string_concat.hpp> -#include <nlohmann/detail/string_escape.hpp> #include <nlohmann/detail/meta/cpp_future.hpp> #include <nlohmann/detail/meta/type_traits.hpp> #include <nlohmann/detail/output/binary_writer.hpp> #include <nlohmann/detail/output/output_adapters.hpp> #include <nlohmann/detail/output/serializer.hpp> +#include <nlohmann/detail/string_concat.hpp> +#include <nlohmann/detail/string_escape.hpp> #include <nlohmann/detail/value_t.hpp> #include <nlohmann/json_fwd.hpp> #include <nlohmann/ordered_map.hpp> @@ -94,11 +94,12 @@ @nosubgrouping */ NLOHMANN_BASIC_JSON_TPL_DECLARATION -class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) - : public ::nlohmann::detail::json_base_class<CustomBaseClass> +class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) + : public ::nlohmann::detail::json_base_class<CustomBaseClass> { private: - template<detail::value_t> friend struct detail::external_constructor; + template<detail::value_t> + friend struct detail::external_constructor; template<typename> friend class ::nlohmann::json_pointer; @@ -124,20 +125,21 @@ using basic_json_t = NLOHMANN_BASIC_JSON_TPL; using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>; - JSON_PRIVATE_UNLESS_TESTED: - // convenience aliases for types residing in namespace detail; - using lexer = ::nlohmann::detail::lexer_base<basic_json>; + JSON_PRIVATE_UNLESS_TESTED : + // convenience aliases for types residing in namespace detail; + using lexer = ::nlohmann::detail::lexer_base<basic_json>; template<typename InputAdapterType> static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser( InputAdapterType adapter, - detail::parser_callback_t<basic_json>cb = nullptr, + detail::parser_callback_t<basic_json> cb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false - ) + const bool ignore_comments = false) { return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter), - std::move(cb), allow_exceptions, ignore_comments); + std::move(cb), + allow_exceptions, + ignore_comments); } private: @@ -148,17 +150,18 @@ using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>; template<typename Iterator> using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>; - template<typename Base> using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>; + template<typename Base> + using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>; template<typename CharType> using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>; template<typename InputType> using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>; - template<typename CharType> using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>; + template<typename CharType> + using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>; - JSON_PRIVATE_UNLESS_TESTED: - using serializer = ::nlohmann::detail::serializer<basic_json>; + JSON_PRIVATE_UNLESS_TESTED : using serializer = ::nlohmann::detail::serializer<basic_json>; public: using value_t = detail::value_t; @@ -253,9 +256,7 @@ result["name"] = "JSON for Modern C++"; result["url"] = "https://github.com/nlohmann/json"; result["version"]["string"] = - detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR), '.', - std::to_string(NLOHMANN_JSON_VERSION_MINOR), '.', - std::to_string(NLOHMANN_JSON_VERSION_PATCH)); + detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR), '.', std::to_string(NLOHMANN_JSON_VERSION_MINOR), '.', std::to_string(NLOHMANN_JSON_VERSION_PATCH)); result["version"]["major"] = NLOHMANN_JSON_VERSION_MAJOR; result["version"]["minor"] = NLOHMANN_JSON_VERSION_MINOR; result["version"]["patch"] = NLOHMANN_JSON_VERSION_PATCH; @@ -273,26 +274,34 @@ #endif #if defined(__ICC) || defined(__INTEL_COMPILER) - result["compiler"] = {{"family", "icc"}, {"version", __INTEL_COMPILER}}; + result["compiler"] = {{"family", "icc"}, { "version", + __INTEL_COMPILER }}; #elif defined(__clang__) - result["compiler"] = {{"family", "clang"}, {"version", __clang_version__}}; + result["compiler"] = {{"family", "clang"}, { "version", + __clang_version__ }}; #elif defined(__GNUC__) || defined(__GNUG__) - result["compiler"] = {{"family", "gcc"}, {"version", detail::concat( - std::to_string(__GNUC__), '.', - std::to_string(__GNUC_MINOR__), '.', - std::to_string(__GNUC_PATCHLEVEL__)) - } - }; + result["compiler"] = {{"family", "gcc"}, { "version", + detail::concat( + std::to_string(__GNUC__), + '.', + std::to_string(__GNUC_MINOR__), + '.', + std::to_string(__GNUC_PATCHLEVEL__)) + }}; #elif defined(__HP_cc) || defined(__HP_aCC) result["compiler"] = "hp" #elif defined(__IBMCPP__) - result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}}; + result["compiler"] = {{"family", "ilecpp"}, { "version", + __IBMCPP__ }}; #elif defined(_MSC_VER) - result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}}; + result["compiler"] = {{"family", "msvc"}, { "version", + _MSC_VER }}; #elif defined(__PGI) - result["compiler"] = {{"family", "pgcpp"}, {"version", __PGI}}; + result["compiler"] = {{"family", "pgcpp"}, { "version", + __PGI }}; #elif defined(__SUNPRO_CC) - result["compiler"] = {{"family", "sunpro"}, {"version", __SUNPRO_CC}}; + result["compiler"] = {{"family", "sunpro"}, { "version", + __SUNPRO_CC }}; #else result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}}; #endif @@ -331,10 +340,10 @@ /// @brief a type for an object /// @sa https://json.nlohmann.me/api/basic_json/object_t/ using object_t = ObjectType<StringType, - basic_json, - default_object_comparator_t, - AllocatorType<std::pair<const StringType, - basic_json>>>; + basic_json, + default_object_comparator_t, + AllocatorType<std::pair<const StringType, + basic_json>>>; /// @brief a type for an array /// @sa https://json.nlohmann.me/api/basic_json/array_t/ @@ -371,17 +380,14 @@ /// @} private: - /// helper for exception-safe object creation template<typename T, typename... Args> - JSON_HEDLEY_RETURNS_NON_NULL - static T* create(Args&& ... args) + JSON_HEDLEY_RETURNS_NON_NULL static T* create(Args&&... args) { AllocatorType<T> alloc; using AllocatorTraits = std::allocator_traits<AllocatorType<T>>; - auto deleter = [&](T * obj) - { + auto deleter = [&](T* obj) { AllocatorTraits::deallocate(alloc, obj, 1); }; std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter); @@ -394,8 +400,8 @@ // JSON value storage // //////////////////////// - JSON_PRIVATE_UNLESS_TESTED: - /*! + JSON_PRIVATE_UNLESS_TESTED : + /*! @brief a JSON value The actual storage for a JSON value of the @ref basic_json class. This @@ -420,7 +426,7 @@ @since version 1.0.0 */ - union json_value + union json_value { /// object (stored with pointer to save storage) object_t* object; @@ -442,13 +448,21 @@ /// default constructor (for null values) json_value() = default; /// constructor for booleans - json_value(boolean_t v) noexcept : boolean(v) {} + json_value(boolean_t v) noexcept + : boolean(v) + {} /// constructor for numbers (integer) - json_value(number_integer_t v) noexcept : number_integer(v) {} + json_value(number_integer_t v) noexcept + : number_integer(v) + {} /// constructor for numbers (unsigned) - json_value(number_unsigned_t v) noexcept : number_unsigned(v) {} + json_value(number_unsigned_t v) noexcept + : number_unsigned(v) + {} /// constructor for numbers (floating-point) - json_value(number_float_t v) noexcept : number_float(v) {} + json_value(number_float_t v) noexcept + : number_float(v) + {} /// constructor for empty values of a given type json_value(value_t t) { @@ -514,7 +528,7 @@ object = nullptr; // silence warning, see #821 if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) { - JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.11.3", nullptr)); // LCOV_EXCL_LINE + JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.11.3", nullptr)); // LCOV_EXCL_LINE } break; } @@ -522,34 +536,54 @@ } /// constructor for strings - json_value(const string_t& value) : string(create<string_t>(value)) {} + json_value(const string_t& value) + : string(create<string_t>(value)) + {} /// constructor for rvalue strings - json_value(string_t&& value) : string(create<string_t>(std::move(value))) {} + json_value(string_t&& value) + : string(create<string_t>(std::move(value))) + {} /// constructor for objects - json_value(const object_t& value) : object(create<object_t>(value)) {} + json_value(const object_t& value) + : object(create<object_t>(value)) + {} /// constructor for rvalue objects - json_value(object_t&& value) : object(create<object_t>(std::move(value))) {} + json_value(object_t&& value) + : object(create<object_t>(std::move(value))) + {} /// constructor for arrays - json_value(const array_t& value) : array(create<array_t>(value)) {} + json_value(const array_t& value) + : array(create<array_t>(value)) + {} /// constructor for rvalue arrays - json_value(array_t&& value) : array(create<array_t>(std::move(value))) {} + json_value(array_t&& value) + : array(create<array_t>(std::move(value))) + {} /// constructor for binary arrays - json_value(const typename binary_t::container_type& value) : binary(create<binary_t>(value)) {} + json_value(const typename binary_t::container_type& value) + : binary(create<binary_t>(value)) + {} /// constructor for rvalue binary arrays - json_value(typename binary_t::container_type&& value) : binary(create<binary_t>(std::move(value))) {} + json_value(typename binary_t::container_type&& value) + : binary(create<binary_t>(std::move(value))) + {} /// constructor for binary arrays (internal type) - json_value(const binary_t& value) : binary(create<binary_t>(value)) {} + json_value(const binary_t& value) + : binary(create<binary_t>(value)) + {} /// constructor for rvalue binary arrays (internal type) - json_value(binary_t&& value) : binary(create<binary_t>(std::move(value))) {} + json_value(binary_t&& value) + : binary(create<binary_t>(std::move(value))) + {} void destroy(value_t t) { @@ -557,8 +591,7 @@ (t == value_t::object && object == nullptr) || (t == value_t::array && array == nullptr) || (t == value_t::string && string == nullptr) || - (t == value_t::binary && binary == nullptr) - ) + (t == value_t::binary && binary == nullptr)) { //not initialized (e.g. due to exception in the ctor) return; @@ -690,12 +723,11 @@ JSON_TRY { // cppcheck-suppress assertWithSideEffect - JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json & j) - { + JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json& j) { return j.m_parent == this; })); } - JSON_CATCH(...) {} // LCOV_EXCL_LINE + JSON_CATCH(...) {} // LCOV_EXCL_LINE #endif static_cast<void>(check_parents); } @@ -765,20 +797,20 @@ } } - // ordered_json uses a vector internally, so pointers could have - // been invalidated; see https://github.com/nlohmann/json/issues/2962 -#ifdef JSON_HEDLEY_MSVC_VERSION -#pragma warning(push ) -#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr -#endif + // ordered_json uses a vector internally, so pointers could have + // been invalidated; see https://github.com/nlohmann/json/issues/2962 + #ifdef JSON_HEDLEY_MSVC_VERSION + #pragma warning(push) + #pragma warning(disable : 4127) // ignore warning to replace if with if constexpr + #endif if (detail::is_ordered_map<object_t>::value) { set_parents(); return j; } -#ifdef JSON_HEDLEY_MSVC_VERSION -#pragma warning( pop ) -#endif + #ifdef JSON_HEDLEY_MSVC_VERSION + #pragma warning(pop) + #endif j.m_parent = this; #else @@ -813,28 +845,29 @@ /// @brief create an empty value with a given type /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(const value_t v) - : m_data(v) + : m_data(v) { assert_invariant(); } /// @brief create a null object /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ - basic_json(std::nullptr_t = nullptr) noexcept // NOLINT(bugprone-exception-escape) - : basic_json(value_t::null) + basic_json(std::nullptr_t = nullptr) noexcept // NOLINT(bugprone-exception-escape) + : basic_json(value_t::null) { assert_invariant(); } /// @brief create a JSON value from compatible types /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ - template < typename CompatibleType, - typename U = detail::uncvref_t<CompatibleType>, - detail::enable_if_t < - !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value, int > = 0 > - basic_json(CompatibleType && val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape) - JSONSerializer<U>::to_json(std::declval<basic_json_t&>(), - std::forward<CompatibleType>(val)))) + template<typename CompatibleType, + typename U = detail::uncvref_t<CompatibleType>, + detail::enable_if_t< + !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value, + int> = 0> + basic_json(CompatibleType&& val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape) + JSONSerializer<U>::to_json(std::declval<basic_json_t&>(), + std::forward<CompatibleType>(val)))) { JSONSerializer<U>::to_json(*this, std::forward<CompatibleType>(val)); set_parents(); @@ -843,9 +876,10 @@ /// @brief create a JSON value from an existing one /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ - template < typename BasicJsonType, - detail::enable_if_t < - detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value, int > = 0 > + template<typename BasicJsonType, + detail::enable_if_t< + detail::is_basic_json<BasicJsonType>::value && !std::is_same<basic_json, BasicJsonType>::value, + int> = 0> basic_json(const BasicJsonType& val) { using other_boolean_t = typename BasicJsonType::boolean_t; @@ -889,8 +923,8 @@ case value_t::discarded: m_data.m_type = value_t::discarded; break; - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } JSON_ASSERT(m_data.m_type == val.type()); set_parents(); @@ -905,9 +939,7 @@ { // check if each element is an array with two elements whose first // element is a string - bool is_an_object = std::all_of(init.begin(), init.end(), - [](const detail::json_ref<basic_json>& element_ref) - { + bool is_an_object = std::all_of(init.begin(), init.end(), [](const detail::json_ref<basic_json>& element_ref) { // The cast is to ensure op[size_type] is called, bearing in mind size_type may not be int; // (many string types can be constructed from 0 via its null-pointer guise, so we get a // broken call to op[key_type], the wrong semantics and a 4804 warning on Windows) @@ -1017,8 +1049,8 @@ /// @brief construct an array with count copies of given value /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ - basic_json(size_type cnt, const basic_json& val): - m_data{cnt, val} + basic_json(size_type cnt, const basic_json& val) + : m_data{cnt, val} { set_parents(); assert_invariant(); @@ -1026,9 +1058,7 @@ /// @brief construct a JSON container given an iterator range /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ - template < class InputIT, typename std::enable_if < - std::is_same<InputIT, typename basic_json_t::iterator>::value || - std::is_same<InputIT, typename basic_json_t::const_iterator>::value, int >::type = 0 > + template<class InputIT, typename std::enable_if<std::is_same<InputIT, typename basic_json_t::iterator>::value || std::is_same<InputIT, typename basic_json_t::const_iterator>::value, int>::type = 0> basic_json(InputIT first, InputIT last) { JSON_ASSERT(first.m_object != nullptr); @@ -1052,8 +1082,7 @@ case value_t::number_unsigned: case value_t::string: { - if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin() - || !last.m_it.primitive_iterator.is_end())) + if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin() || !last.m_it.primitive_iterator.is_end())) { JSON_THROW(invalid_iterator::create(204, "iterators out of range", first.m_object)); } @@ -1104,7 +1133,7 @@ case value_t::object: { m_data.m_value.object = create<object_t>(first.m_it.object_iterator, - last.m_it.object_iterator); + last.m_it.object_iterator); break; } @@ -1137,13 +1166,16 @@ template<typename JsonRef, detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>, - std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 > - basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {} + std::is_same<typename JsonRef::value_type, basic_json>>::value, + int> = 0> + basic_json(const JsonRef& ref) + : basic_json(ref.moved_or_copied()) + {} /// @brief copy constructor /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(const basic_json& other) - : json_base_class_t(other) + : json_base_class_t(other) { m_data.m_type = other.m_data.m_type; // check of passed value is valid @@ -1212,8 +1244,8 @@ /// @brief move constructor /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(basic_json&& other) noexcept - : json_base_class_t(std::forward<json_base_class_t>(other)), - m_data(std::move(other.m_data)) + : json_base_class_t(std::forward<json_base_class_t>(other)) + , m_data(std::move(other.m_data)) { // check that passed value is valid other.assert_invariant(false); @@ -1228,13 +1260,12 @@ /// @brief copy assignment /// @sa https://json.nlohmann.me/api/basic_json/operator=/ - basic_json& operator=(basic_json other) noexcept ( - std::is_nothrow_move_constructible<value_t>::value&& - std::is_nothrow_move_assignable<value_t>::value&& - std::is_nothrow_move_constructible<json_value>::value&& - std::is_nothrow_move_assignable<json_value>::value&& - std::is_nothrow_move_assignable<json_base_class_t>::value - ) + basic_json& operator=(basic_json other) noexcept( + std::is_nothrow_move_constructible<value_t>::value && + std::is_nothrow_move_assignable<value_t>::value && + std::is_nothrow_move_constructible<json_value>::value && + std::is_nothrow_move_assignable<json_value>::value && + std::is_nothrow_move_assignable<json_base_class_t>::value) { // check that passed value is valid other.assert_invariant(); @@ -1540,8 +1571,7 @@ /// @brief get a pointer value (implicit) /// @sa https://json.nlohmann.me/api/basic_json/get_ptr/ - template<typename PointerType, typename std::enable_if< - std::is_pointer<PointerType>::value, int>::type = 0> + template<typename PointerType, typename std::enable_if<std::is_pointer<PointerType>::value, int>::type = 0> auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>())) { // delegate the call to get_impl_ptr<>() @@ -1550,9 +1580,7 @@ /// @brief get a pointer value (implicit) /// @sa https://json.nlohmann.me/api/basic_json/get_ptr/ - template < typename PointerType, typename std::enable_if < - std::is_pointer<PointerType>::value&& - std::is_const<typename std::remove_pointer<PointerType>::type>::value, int >::type = 0 > + template<typename PointerType, typename std::enable_if<std::is_pointer<PointerType>::value && std::is_const<typename std::remove_pointer<PointerType>::type>::value, int>::type = 0> constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>())) { // delegate the call to get_impl_ptr<>() const @@ -1598,13 +1626,13 @@ @since version 2.1.0 */ - template < typename ValueType, - detail::enable_if_t < - detail::is_default_constructible<ValueType>::value&& - detail::has_from_json<basic_json_t, ValueType>::value, - int > = 0 > + template<typename ValueType, + detail::enable_if_t< + detail::is_default_constructible<ValueType>::value && + detail::has_from_json<basic_json_t, ValueType>::value, + int> = 0> ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept( - JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>()))) + JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>()))) { auto ret = ValueType(); JSONSerializer<ValueType>::from_json(*this, ret); @@ -1641,12 +1669,12 @@ @since version 2.1.0 */ - template < typename ValueType, - detail::enable_if_t < - detail::has_non_default_from_json<basic_json_t, ValueType>::value, - int > = 0 > + template<typename ValueType, + detail::enable_if_t< + detail::has_non_default_from_json<basic_json_t, ValueType>::value, + int> = 0> ValueType get_impl(detail::priority_tag<1> /*unused*/) const noexcept(noexcept( - JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>()))) + JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>()))) { return JSONSerializer<ValueType>::from_json(*this); } @@ -1666,10 +1694,10 @@ @since version 3.2.0 */ - template < typename BasicJsonType, - detail::enable_if_t < - detail::is_basic_json<BasicJsonType>::value, - int > = 0 > + template<typename BasicJsonType, + detail::enable_if_t< + detail::is_basic_json<BasicJsonType>::value, + int> = 0> BasicJsonType get_impl(detail::priority_tag<2> /*unused*/) const { return *this; @@ -1707,7 +1735,7 @@ std::is_pointer<PointerType>::value, int> = 0> constexpr auto get_impl(detail::priority_tag<4> /*unused*/) const noexcept - -> decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>()) + -> decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>()) { // delegate the call to get_ptr return get_ptr<PointerType>(); @@ -1737,20 +1765,21 @@ @since version 2.1.0 */ - template < typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>> + template<typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>> #if defined(JSON_HAS_CPP_14) constexpr #endif - auto get() const noexcept( - noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))) - -> decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {})) + auto + get() const noexcept( + noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4>{}))) + -> decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4>{})) { // we cannot static_assert on ValueTypeCV being non-const, because // there is support for get<const basic_json_t>(), which is why we // still need the uncvref static_assert(!std::is_reference<ValueTypeCV>::value, "get() cannot be used with reference types, you might want to use get_ref()"); - return get_impl<ValueType>(detail::priority_tag<4> {}); + return get_impl<ValueType>(detail::priority_tag<4>{}); } /*! @@ -1780,8 +1809,7 @@ @since version 1.0.0 */ - template<typename PointerType, typename std::enable_if< - std::is_pointer<PointerType>::value, int>::type = 0> + template<typename PointerType, typename std::enable_if<std::is_pointer<PointerType>::value, int>::type = 0> auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>()) { // delegate the call to get_ptr @@ -1790,13 +1818,13 @@ /// @brief get a value (explicit) /// @sa https://json.nlohmann.me/api/basic_json/get_to/ - template < typename ValueType, - detail::enable_if_t < - !detail::is_basic_json<ValueType>::value&& - detail::has_from_json<basic_json_t, ValueType>::value, - int > = 0 > - ValueType & get_to(ValueType& v) const noexcept(noexcept( - JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v))) + template<typename ValueType, + detail::enable_if_t< + !detail::is_basic_json<ValueType>::value && + detail::has_from_json<basic_json_t, ValueType>::value, + int> = 0> + ValueType& get_to(ValueType& v) const noexcept(noexcept( + JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v))) { JSONSerializer<ValueType>::from_json(*this, v); return v; @@ -1805,23 +1833,26 @@ // specialization to allow calling get_to with a basic_json value // see https://github.com/nlohmann/json/issues/2175 template<typename ValueType, - detail::enable_if_t < + detail::enable_if_t< detail::is_basic_json<ValueType>::value, int> = 0> - ValueType & get_to(ValueType& v) const + ValueType& get_to(ValueType& v) const { v = *this; return v; } - template < - typename T, std::size_t N, - typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - detail::enable_if_t < - detail::has_from_json<basic_json_t, Array>::value, int > = 0 > - Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - noexcept(noexcept(JSONSerializer<Array>::from_json( - std::declval<const basic_json_t&>(), v))) + template< + typename T, + std::size_t N, + typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + detail::enable_if_t< + detail::has_from_json<basic_json_t, Array>::value, + int> = 0> + Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + noexcept(noexcept(JSONSerializer<Array>::from_json( + std::declval<const basic_json_t&>(), + v))) { JSONSerializer<Array>::from_json(*this, v); return v; @@ -1829,8 +1860,7 @@ /// @brief get a reference value (implicit) /// @sa https://json.nlohmann.me/api/basic_json/get_ref/ - template<typename ReferenceType, typename std::enable_if< - std::is_reference<ReferenceType>::value, int>::type = 0> + template<typename ReferenceType, typename std::enable_if<std::is_reference<ReferenceType>::value, int>::type = 0> ReferenceType get_ref() { // delegate call to get_ref_impl @@ -1839,9 +1869,7 @@ /// @brief get a reference value (implicit) /// @sa https://json.nlohmann.me/api/basic_json/get_ref/ - template < typename ReferenceType, typename std::enable_if < - std::is_reference<ReferenceType>::value&& - std::is_const<typename std::remove_reference<ReferenceType>::type>::value, int >::type = 0 > + template<typename ReferenceType, typename std::enable_if<std::is_reference<ReferenceType>::value && std::is_const<typename std::remove_reference<ReferenceType>::type>::value, int>::type = 0> ReferenceType get_ref() const { // delegate call to get_ref_impl @@ -1877,23 +1905,16 @@ @since version 1.0.0 */ - template < typename ValueType, typename std::enable_if < - detail::conjunction < - detail::negation<std::is_pointer<ValueType>>, - detail::negation<std::is_same<ValueType, std::nullptr_t>>, - detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>, - detail::negation<std::is_same<ValueType, typename string_t::value_type>>, - detail::negation<detail::is_basic_json<ValueType>>, - detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>, + template<typename ValueType, typename std::enable_if<detail::conjunction<detail::negation<std::is_pointer<ValueType>>, detail::negation<std::is_same<ValueType, std::nullptr_t>>, detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>, detail::negation<std::is_same<ValueType, typename string_t::value_type>>, detail::negation<detail::is_basic_json<ValueType>>, detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>, #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914)) - detail::negation<std::is_same<ValueType, std::string_view>>, + detail::negation<std::is_same<ValueType, std::string_view>>, #endif #if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI - detail::negation<std::is_same<ValueType, std::any>>, + detail::negation<std::is_same<ValueType, std::any>>, #endif - detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType> - >::value, int >::type = 0 > - JSON_EXPLICIT operator ValueType() const + detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>>::value, + int>::type = 0> + JSON_EXPLICIT operator ValueType() const { // delegate the call to get<>() const return get<ValueType>(); @@ -1944,7 +1965,7 @@ { return set_parent(m_data.m_value.array->at(idx)); } - JSON_CATCH (std::out_of_range&) + JSON_CATCH(std::out_of_range&) { // create better exception explanation JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); @@ -1967,7 +1988,7 @@ { return m_data.m_value.array->at(idx); } - JSON_CATCH (std::out_of_range&) + JSON_CATCH(std::out_of_range&) { // create better exception explanation JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); @@ -1999,9 +2020,8 @@ /// @brief access specified object element with bounds checking /// @sa https://json.nlohmann.me/api/basic_json/at/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - reference at(KeyType && key) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + reference at(KeyType&& key) { // at only works for objects if (JSON_HEDLEY_UNLIKELY(!is_object())) @@ -2037,9 +2057,8 @@ /// @brief access specified object element with bounds checking /// @sa https://json.nlohmann.me/api/basic_json/at/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - const_reference at(KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + const_reference at(KeyType&& key) const { // at only works for objects if (JSON_HEDLEY_UNLIKELY(!is_object())) @@ -2167,9 +2186,8 @@ /// @brief access specified object element /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int > = 0 > - reference operator[](KeyType && key) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + reference operator[](KeyType&& key) { // implicitly convert null value to an empty object if (is_null()) @@ -2191,9 +2209,8 @@ /// @brief access specified object element /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int > = 0 > - const_reference operator[](KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + const_reference operator[](KeyType&& key) const { // const operator[] only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -2208,21 +2225,21 @@ private: template<typename KeyType> - using is_comparable_with_object_key = detail::is_comparable < - object_comparator_t, const typename object_t::key_type&, KeyType >; + using is_comparable_with_object_key = detail::is_comparable< + object_comparator_t, + const typename object_t::key_type&, + KeyType>; template<typename ValueType> - using value_return_type = std::conditional < + using value_return_type = std::conditional< detail::is_c_string_uncvref<ValueType>::value, - string_t, typename std::decay<ValueType>::type >; + string_t, + typename std::decay<ValueType>::type>; public: /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, detail::enable_if_t < - !detail::is_transparent<object_comparator_t>::value - && detail::is_getable<basic_json_t, ValueType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > + template<class ValueType, detail::enable_if_t<!detail::is_transparent<object_comparator_t>::value && detail::is_getable<basic_json_t, ValueType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const { // value only works for objects @@ -2243,12 +2260,8 @@ /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type, - detail::enable_if_t < - !detail::is_transparent<object_comparator_t>::value - && detail::is_getable<basic_json_t, ReturnType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - ReturnType value(const typename object_t::key_type& key, ValueType && default_value) const + template<class ValueType, class ReturnType = typename value_return_type<ValueType>::type, detail::enable_if_t<!detail::is_transparent<object_comparator_t>::value && detail::is_getable<basic_json_t, ReturnType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + ReturnType value(const typename object_t::key_type& key, ValueType&& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -2268,13 +2281,8 @@ /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, class KeyType, detail::enable_if_t < - detail::is_transparent<object_comparator_t>::value - && !detail::is_json_pointer<KeyType>::value - && is_comparable_with_object_key<KeyType>::value - && detail::is_getable<basic_json_t, ValueType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - ValueType value(KeyType && key, const ValueType& default_value) const + template<class ValueType, class KeyType, detail::enable_if_t<detail::is_transparent<object_comparator_t>::value && !detail::is_json_pointer<KeyType>::value && is_comparable_with_object_key<KeyType>::value && detail::is_getable<basic_json_t, ValueType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + ValueType value(KeyType&& key, const ValueType& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -2294,14 +2302,8 @@ /// @brief access specified object element via JSON Pointer with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type, - detail::enable_if_t < - detail::is_transparent<object_comparator_t>::value - && !detail::is_json_pointer<KeyType>::value - && is_comparable_with_object_key<KeyType>::value - && detail::is_getable<basic_json_t, ReturnType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - ReturnType value(KeyType && key, ValueType && default_value) const + template<class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type, detail::enable_if_t<detail::is_transparent<object_comparator_t>::value && !detail::is_json_pointer<KeyType>::value && is_comparable_with_object_key<KeyType>::value && detail::is_getable<basic_json_t, ReturnType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + ReturnType value(KeyType&& key, ValueType&& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -2321,9 +2323,7 @@ /// @brief access specified object element via JSON Pointer with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, detail::enable_if_t < - detail::is_getable<basic_json_t, ValueType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > + template<class ValueType, detail::enable_if_t<detail::is_getable<basic_json_t, ValueType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> ValueType value(const json_pointer& ptr, const ValueType& default_value) const { // value only works for objects @@ -2334,7 +2334,7 @@ { return ptr.get_checked(this).template get<ValueType>(); } - JSON_INTERNAL_CATCH (out_of_range&) + JSON_INTERNAL_CATCH(out_of_range&) { return default_value; } @@ -2345,11 +2345,8 @@ /// @brief access specified object element via JSON Pointer with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type, - detail::enable_if_t < - detail::is_getable<basic_json_t, ReturnType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - ReturnType value(const json_pointer& ptr, ValueType && default_value) const + template<class ValueType, class ReturnType = typename value_return_type<ValueType>::type, detail::enable_if_t<detail::is_getable<basic_json_t, ReturnType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + ReturnType value(const json_pointer& ptr, ValueType&& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -2359,7 +2356,7 @@ { return ptr.get_checked(this).template get<ReturnType>(); } - JSON_INTERNAL_CATCH (out_of_range&) + JSON_INTERNAL_CATCH(out_of_range&) { return std::forward<ValueType>(default_value); } @@ -2368,23 +2365,16 @@ JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); } - template < class ValueType, class BasicJsonType, detail::enable_if_t < - detail::is_basic_json<BasicJsonType>::value - && detail::is_getable<basic_json_t, ValueType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + template<class ValueType, class BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value && detail::is_getable<basic_json_t, ValueType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, const ValueType& default_value) const { return value(ptr.convert(), default_value); } - template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type, - detail::enable_if_t < - detail::is_basic_json<BasicJsonType>::value - && detail::is_getable<basic_json_t, ReturnType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) - ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType && default_value) const + template<class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value && detail::is_getable<basic_json_t, ReturnType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType&& default_value) const { return value(ptr.convert(), std::forward<ValueType>(default_value)); } @@ -2423,9 +2413,7 @@ /// @brief remove element given an iterator /// @sa https://json.nlohmann.me/api/basic_json/erase/ - template < class IteratorType, detail::enable_if_t < - std::is_same<IteratorType, typename basic_json_t::iterator>::value || - std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int > = 0 > + template<class IteratorType, detail::enable_if_t<std::is_same<IteratorType, typename basic_json_t::iterator>::value || std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int> = 0> IteratorType erase(IteratorType pos) { // make sure iterator fits the current value @@ -2493,9 +2481,7 @@ /// @brief remove elements given an iterator range /// @sa https://json.nlohmann.me/api/basic_json/erase/ - template < class IteratorType, detail::enable_if_t < - std::is_same<IteratorType, typename basic_json_t::iterator>::value || - std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int > = 0 > + template<class IteratorType, detail::enable_if_t<std::is_same<IteratorType, typename basic_json_t::iterator>::value || std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int> = 0> IteratorType erase(IteratorType first, IteratorType last) { // make sure iterator fits the current value @@ -2515,8 +2501,7 @@ case value_t::string: case value_t::binary: { - if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin() - || !last.m_it.primitive_iterator.is_end())) + if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin() || !last.m_it.primitive_iterator.is_end())) { JSON_THROW(invalid_iterator::create(204, "iterators out of range", this)); } @@ -2544,14 +2529,14 @@ case value_t::object: { result.m_it.object_iterator = m_data.m_value.object->erase(first.m_it.object_iterator, - last.m_it.object_iterator); + last.m_it.object_iterator); break; } case value_t::array: { result.m_it.array_iterator = m_data.m_value.array->erase(first.m_it.array_iterator, - last.m_it.array_iterator); + last.m_it.array_iterator); break; } @@ -2565,9 +2550,8 @@ } private: - template < typename KeyType, detail::enable_if_t < - detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int > = 0 > - size_type erase_internal(KeyType && key) + template<typename KeyType, detail::enable_if_t<detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int> = 0> + size_type erase_internal(KeyType&& key) { // this erase only works for objects if (JSON_HEDLEY_UNLIKELY(!is_object())) @@ -2578,9 +2562,8 @@ return m_data.m_value.object->erase(std::forward<KeyType>(key)); } - template < typename KeyType, detail::enable_if_t < - !detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int > = 0 > - size_type erase_internal(KeyType && key) + template<typename KeyType, detail::enable_if_t<!detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int> = 0> + size_type erase_internal(KeyType&& key) { // this erase only works for objects if (JSON_HEDLEY_UNLIKELY(!is_object())) @@ -2598,7 +2581,6 @@ } public: - /// @brief remove element from a JSON object given a key /// @sa https://json.nlohmann.me/api/basic_json/erase/ size_type erase(const typename object_t::key_type& key) @@ -2610,9 +2592,8 @@ /// @brief remove element from a JSON object given a key /// @sa https://json.nlohmann.me/api/basic_json/erase/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - size_type erase(KeyType && key) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + size_type erase(KeyType&& key) { return erase_internal(std::forward<KeyType>(key)); } @@ -2676,9 +2657,8 @@ /// @brief find an element in a JSON object /// @sa https://json.nlohmann.me/api/basic_json/find/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - iterator find(KeyType && key) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + iterator find(KeyType&& key) { auto result = end(); @@ -2692,9 +2672,8 @@ /// @brief find an element in a JSON object /// @sa https://json.nlohmann.me/api/basic_json/find/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - const_iterator find(KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + const_iterator find(KeyType&& key) const { auto result = cend(); @@ -2716,9 +2695,8 @@ /// @brief returns the number of occurrences of a key in a JSON object /// @sa https://json.nlohmann.me/api/basic_json/count/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - size_type count(KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + size_type count(KeyType&& key) const { // return 0 for all nonobject types return is_object() ? m_data.m_value.object->count(std::forward<KeyType>(key)) : 0; @@ -2733,9 +2711,8 @@ /// @brief check the existence of an element in a JSON object /// @sa https://json.nlohmann.me/api/basic_json/contains/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - bool contains(KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + bool contains(KeyType&& key) const { return is_object() && m_data.m_value.object->find(std::forward<KeyType>(key)) != m_data.m_value.object->end(); } @@ -2748,7 +2725,7 @@ } template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) bool contains(const typename ::nlohmann::json_pointer<BasicJsonType>& ptr) const { return ptr.contains(this); @@ -3187,7 +3164,8 @@ { basic_json&& key = init.begin()->moved_or_copied(); push_back(typename object_t::value_type( - std::move(key.get_ref<string_t&>()), (init.begin() + 1)->moved_or_copied())); + std::move(key.get_ref<string_t&>()), + (init.begin() + 1)->moved_or_copied())); } else { @@ -3206,7 +3184,7 @@ /// @brief add an object to an array /// @sa https://json.nlohmann.me/api/basic_json/emplace_back/ template<class... Args> - reference emplace_back(Args&& ... args) + reference emplace_back(Args&&... args) { // emplace_back only works for null objects or arrays if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) @@ -3231,7 +3209,7 @@ /// @brief add an object to an object if key does not exist /// @sa https://json.nlohmann.me/api/basic_json/emplace/ template<class... Args> - std::pair<iterator, bool> emplace(Args&& ... args) + std::pair<iterator, bool> emplace(Args&&... args) { // emplace only works for null objects or arrays if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object()))) @@ -3263,7 +3241,7 @@ /// @note: This uses std::distance to support GCC 4.8, /// see https://github.com/nlohmann/json/pull/1257 template<typename... Args> - iterator insert_iterator(const_iterator pos, Args&& ... args) + iterator insert_iterator(const_iterator pos, Args&&... args) { iterator result(this); JSON_ASSERT(m_data.m_value.array != nullptr); @@ -3459,12 +3437,11 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(reference other) noexcept ( - std::is_nothrow_move_constructible<value_t>::value&& - std::is_nothrow_move_assignable<value_t>::value&& - std::is_nothrow_move_constructible<json_value>::value&& // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap) - std::is_nothrow_move_assignable<json_value>::value - ) + void swap(reference other) noexcept( + std::is_nothrow_move_constructible<value_t>::value && + std::is_nothrow_move_assignable<value_t>::value && + std::is_nothrow_move_constructible<json_value>::value && // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + std::is_nothrow_move_assignable<json_value>::value) { std::swap(m_data.m_type, other.m_data.m_type); std::swap(m_data.m_value, other.m_data.m_value); @@ -3476,19 +3453,18 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - friend void swap(reference left, reference right) noexcept ( - std::is_nothrow_move_constructible<value_t>::value&& - std::is_nothrow_move_assignable<value_t>::value&& - std::is_nothrow_move_constructible<json_value>::value&& // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap) - std::is_nothrow_move_assignable<json_value>::value - ) + friend void swap(reference left, reference right) noexcept( + std::is_nothrow_move_constructible<value_t>::value && + std::is_nothrow_move_assignable<value_t>::value && + std::is_nothrow_move_constructible<json_value>::value && // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + std::is_nothrow_move_assignable<json_value>::value) { left.swap(right); } /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(array_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + void swap(array_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) { // swap only works for arrays if (JSON_HEDLEY_LIKELY(is_array())) @@ -3504,7 +3480,7 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(object_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + void swap(object_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) { // swap only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -3520,7 +3496,7 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(string_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + void swap(string_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) { // swap only works for strings if (JSON_HEDLEY_LIKELY(is_string())) @@ -3536,7 +3512,7 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(binary_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + void swap(binary_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) { // swap only works for strings if (JSON_HEDLEY_LIKELY(is_binary())) @@ -3552,7 +3528,7 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(typename binary_t::container_type& other) // NOLINT(bugprone-exception-escape) + void swap(typename binary_t::container_type& other) // NOLINT(bugprone-exception-escape) { // swap only works for strings if (JSON_HEDLEY_LIKELY(is_binary())) @@ -3577,87 +3553,87 @@ // note parentheses around operands are necessary; see // https://github.com/nlohmann/json/issues/1530 -#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \ - const auto lhs_type = lhs.type(); \ - const auto rhs_type = rhs.type(); \ - \ - if (lhs_type == rhs_type) /* NOLINT(readability/braces) */ \ - { \ - switch (lhs_type) \ - { \ - case value_t::array: \ - return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array); \ - \ - case value_t::object: \ - return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object); \ - \ - case value_t::null: \ - return (null_result); \ - \ - case value_t::string: \ - return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string); \ - \ - case value_t::boolean: \ - return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean); \ - \ - case value_t::number_integer: \ - return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer); \ - \ - case value_t::number_unsigned: \ - return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned); \ - \ - case value_t::number_float: \ - return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float); \ - \ - case value_t::binary: \ - return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary); \ - \ - case value_t::discarded: \ - default: \ - return (unordered_result); \ - } \ - } \ - else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \ - { \ +#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \ + const auto lhs_type = lhs.type(); \ + const auto rhs_type = rhs.type(); \ + \ + if (lhs_type == rhs_type) /* NOLINT(readability/braces) */ \ + { \ + switch (lhs_type) \ + { \ + case value_t::array: \ + return (*lhs.m_data.m_value.array)op(*rhs.m_data.m_value.array); \ + \ + case value_t::object: \ + return (*lhs.m_data.m_value.object)op(*rhs.m_data.m_value.object); \ + \ + case value_t::null: \ + return (null_result); \ + \ + case value_t::string: \ + return (*lhs.m_data.m_value.string)op(*rhs.m_data.m_value.string); \ + \ + case value_t::boolean: \ + return (lhs.m_data.m_value.boolean)op(rhs.m_data.m_value.boolean); \ + \ + case value_t::number_integer: \ + return (lhs.m_data.m_value.number_integer)op(rhs.m_data.m_value.number_integer); \ + \ + case value_t::number_unsigned: \ + return (lhs.m_data.m_value.number_unsigned)op(rhs.m_data.m_value.number_unsigned); \ + \ + case value_t::number_float: \ + return (lhs.m_data.m_value.number_float)op(rhs.m_data.m_value.number_float); \ + \ + case value_t::binary: \ + return (*lhs.m_data.m_value.binary)op(*rhs.m_data.m_value.binary); \ + \ + case value_t::discarded: \ + default: \ + return (unordered_result); \ + } \ + } \ + else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \ + { \ return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float; \ - } \ - else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \ - { \ + } \ + else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \ + { \ return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer); \ - } \ - else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \ - { \ + } \ + else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \ + { \ return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float; \ - } \ - else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \ - { \ + } \ + else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \ + { \ return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned); \ - } \ - else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \ - { \ + } \ + else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \ + { \ return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \ - } \ - else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \ - { \ + } \ + else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \ + { \ return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \ - } \ - else if(compares_unordered(lhs, rhs))\ - {\ - return (unordered_result);\ - }\ - \ + } \ + else if (compares_unordered(lhs, rhs)) \ + { \ + return (unordered_result); \ + } \ + \ return (default_result); - JSON_PRIVATE_UNLESS_TESTED: - // returns true if: - // - any operand is NaN and the other operand is of number type - // - any operand is discarded - // in legacy mode, discarded values are considered ordered if - // an operation is computed as an odd number of inverses of others - static bool compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept + JSON_PRIVATE_UNLESS_TESTED : + // returns true if: + // - any operand is NaN and the other operand is of number type + // - any operand is discarded + // in legacy mode, discarded values are considered ordered if + // an operation is computed as an odd number of inverses of others + static bool + compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept { - if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number()) - || (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number())) + if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number()) || (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number())) { return true; } @@ -3681,22 +3657,21 @@ /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ bool operator==(const_reference rhs) const noexcept { -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" -#endif + #ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" + #endif const_reference lhs = *this; - JSON_IMPLEMENT_OPERATOR( ==, true, false, false) -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + JSON_IMPLEMENT_OPERATOR(==, true, false, false) + #ifdef __GNUC__ + #pragma GCC diagnostic pop + #endif } /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ template<typename ScalarType> - requires std::is_scalar_v<ScalarType> - bool operator==(ScalarType rhs) const noexcept + requires std::is_scalar_v<ScalarType> bool operator==(ScalarType rhs) const noexcept { return *this == basic_json(rhs); } @@ -3714,27 +3689,27 @@ /// @brief comparison: 3-way /// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/ - std::partial_ordering operator<=>(const_reference rhs) const noexcept // *NOPAD* + std::partial_ordering operator<= > (const_reference rhs) const noexcept // *NOPAD* { const_reference lhs = *this; // default_result is used if we cannot compare values. In that case, // we compare types. - JSON_IMPLEMENT_OPERATOR(<=>, // *NOPAD* + JSON_IMPLEMENT_OPERATOR(<= >, // *NOPAD* std::partial_ordering::equivalent, std::partial_ordering::unordered, - lhs_type <=> rhs_type) // *NOPAD* + lhs_type <= > rhs_type) // *NOPAD* } /// @brief comparison: 3-way /// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/ template<typename ScalarType> - requires std::is_scalar_v<ScalarType> - std::partial_ordering operator<=>(ScalarType rhs) const noexcept // *NOPAD* + requires std::is_scalar_v<ScalarType> + std::partial_ordering operator<= > (ScalarType rhs) const noexcept // *NOPAD* { - return *this <=> basic_json(rhs); // *NOPAD* + return *this <= > basic_json(rhs); // *NOPAD* } -#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON // all operators that are computed as an odd number of inverses of others // need to be overloaded to emulate the legacy comparison behavior @@ -3753,8 +3728,7 @@ /// @brief comparison: less than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_le/ template<typename ScalarType> - requires std::is_scalar_v<ScalarType> - bool operator<=(ScalarType rhs) const noexcept + requires std::is_scalar_v<ScalarType> bool operator<=(ScalarType rhs) const noexcept { return *this <= basic_json(rhs); } @@ -3774,31 +3748,29 @@ /// @brief comparison: greater than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ template<typename ScalarType> - requires std::is_scalar_v<ScalarType> - bool operator>=(ScalarType rhs) const noexcept + requires std::is_scalar_v<ScalarType> bool operator>=(ScalarType rhs) const noexcept { return *this >= basic_json(rhs); } -#endif + #endif #else /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ friend bool operator==(const_reference lhs, const_reference rhs) noexcept { -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" -#endif - JSON_IMPLEMENT_OPERATOR( ==, true, false, false) -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + #ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" + #endif + JSON_IMPLEMENT_OPERATOR(==, true, false, false) + #ifdef __GNUC__ + #pragma GCC diagnostic pop + #endif } /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator==(const_reference lhs, ScalarType rhs) noexcept { return lhs == basic_json(rhs); @@ -3806,8 +3778,7 @@ /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator==(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) == rhs; @@ -3826,8 +3797,7 @@ /// @brief comparison: not equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept { return lhs != basic_json(rhs); @@ -3835,8 +3805,7 @@ /// @brief comparison: not equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) != rhs; @@ -3849,13 +3818,12 @@ // default_result is used if we cannot compare values. In that case, // we compare types. Note we have to call the operator explicitly, // because MSVC has problems otherwise. - JSON_IMPLEMENT_OPERATOR( <, false, false, operator<(lhs_type, rhs_type)) + JSON_IMPLEMENT_OPERATOR(<, false, false, operator<(lhs_type, rhs_type)) } /// @brief comparison: less than /// @sa https://json.nlohmann.me/api/basic_json/operator_lt/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator<(const_reference lhs, ScalarType rhs) noexcept { return lhs < basic_json(rhs); @@ -3863,8 +3831,7 @@ /// @brief comparison: less than /// @sa https://json.nlohmann.me/api/basic_json/operator_lt/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator<(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) < rhs; @@ -3883,8 +3850,7 @@ /// @brief comparison: less than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_le/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept { return lhs <= basic_json(rhs); @@ -3892,8 +3858,7 @@ /// @brief comparison: less than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_le/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) <= rhs; @@ -3913,8 +3878,7 @@ /// @brief comparison: greater than /// @sa https://json.nlohmann.me/api/basic_json/operator_gt/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator>(const_reference lhs, ScalarType rhs) noexcept { return lhs > basic_json(rhs); @@ -3922,8 +3886,7 @@ /// @brief comparison: greater than /// @sa https://json.nlohmann.me/api/basic_json/operator_gt/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator>(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) > rhs; @@ -3942,8 +3905,7 @@ /// @brief comparison: greater than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept { return lhs >= basic_json(rhs); @@ -3951,8 +3913,7 @@ /// @brief comparison: greater than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) >= rhs; @@ -4011,11 +3972,10 @@ /// @brief deserialize from a compatible input /// @sa https://json.nlohmann.me/api/basic_json/parse/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json parse(InputType&& i, - const parser_callback_t cb = nullptr, - const bool allow_exceptions = true, - const bool ignore_comments = false) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json parse(InputType&& i, + const parser_callback_t cb = nullptr, + const bool allow_exceptions = true, + const bool ignore_comments = false) { basic_json result; parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(true, result); @@ -4025,12 +3985,11 @@ /// @brief deserialize from a pair of character iterators /// @sa https://json.nlohmann.me/api/basic_json/parse/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json parse(IteratorType first, - IteratorType last, - const parser_callback_t cb = nullptr, - const bool allow_exceptions = true, - const bool ignore_comments = false) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json parse(IteratorType first, + IteratorType last, + const parser_callback_t cb = nullptr, + const bool allow_exceptions = true, + const bool ignore_comments = false) { basic_json result; parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(true, result); @@ -4061,8 +4020,7 @@ /// @brief check if the input is valid JSON /// @sa https://json.nlohmann.me/api/basic_json/accept/ template<typename IteratorType> - static bool accept(IteratorType first, IteratorType last, - const bool ignore_comments = false) + static bool accept(IteratorType first, IteratorType last, const bool ignore_comments = false) { return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true); } @@ -4077,32 +4035,26 @@ /// @brief generate SAX events /// @sa https://json.nlohmann.me/api/basic_json/sax_parse/ - template <typename InputType, typename SAX> + template<typename InputType, typename SAX> JSON_HEDLEY_NON_NULL(2) - static bool sax_parse(InputType&& i, SAX* sax, - input_format_t format = input_format_t::json, - const bool strict = true, - const bool ignore_comments = false) + static bool sax_parse(InputType&& i, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, const bool ignore_comments = false) { auto ia = detail::input_adapter(std::forward<InputType>(i)); return format == input_format_t::json - ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) - : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) + : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); } /// @brief generate SAX events /// @sa https://json.nlohmann.me/api/basic_json/sax_parse/ template<class IteratorType, class SAX> JSON_HEDLEY_NON_NULL(3) - static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, - input_format_t format = input_format_t::json, - const bool strict = true, - const bool ignore_comments = false) + static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, const bool ignore_comments = false) { auto ia = detail::input_adapter(std::move(first), std::move(last)); return format == input_format_t::json - ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) - : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) + : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); } /// @brief generate SAX events @@ -4110,20 +4062,16 @@ /// @deprecated This function is deprecated since 3.8.0 and will be removed in /// version 4.0.0 of the library. Please use /// sax_parse(ptr, ptr + len) instead. - template <typename SAX> + template<typename SAX> JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...)) - JSON_HEDLEY_NON_NULL(2) - static bool sax_parse(detail::span_input_adapter&& i, SAX* sax, - input_format_t format = input_format_t::json, - const bool strict = true, - const bool ignore_comments = false) + JSON_HEDLEY_NON_NULL(2) static bool sax_parse(detail::span_input_adapter&& i, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, const bool ignore_comments = false) { auto ia = i.get(); return format == input_format_t::json - // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) - // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); } #ifndef JSON_NO_IO /// @brief deserialize from stream @@ -4181,12 +4129,12 @@ } } - JSON_PRIVATE_UNLESS_TESTED: - ////////////////////// - // member variables // - ////////////////////// + JSON_PRIVATE_UNLESS_TESTED : + ////////////////////// + // member variables // + ////////////////////// - struct data + struct data { /// the type of the current element value_t m_type = value_t::null; @@ -4195,12 +4143,13 @@ json_value m_value = {}; data(const value_t v) - : m_type(v), m_value(v) + : m_type(v) + , m_value(v) { } data(size_type cnt, const basic_json& val) - : m_type(value_t::array) + : m_type(value_t::array) { m_value.array = create<array_t>(cnt, val); } @@ -4281,8 +4230,8 @@ /// @brief create a UBJSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ static std::vector<std::uint8_t> to_ubjson(const basic_json& j, - const bool use_size = false, - const bool use_type = false) + const bool use_size = false, + const bool use_type = false) { std::vector<std::uint8_t> result; to_ubjson(j, result, use_size, use_type); @@ -4291,16 +4240,14 @@ /// @brief create a UBJSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ - static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o, - const bool use_size = false, const bool use_type = false) + static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o, const bool use_size = false, const bool use_type = false) { binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type); } /// @brief create a UBJSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ - static void to_ubjson(const basic_json& j, detail::output_adapter<char> o, - const bool use_size = false, const bool use_type = false) + static void to_ubjson(const basic_json& j, detail::output_adapter<char> o, const bool use_size = false, const bool use_type = false) { binary_writer<char>(o).write_ubjson(j, use_size, use_type); } @@ -4308,8 +4255,8 @@ /// @brief create a BJData serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ static std::vector<std::uint8_t> to_bjdata(const basic_json& j, - const bool use_size = false, - const bool use_type = false) + const bool use_size = false, + const bool use_type = false) { std::vector<std::uint8_t> result; to_bjdata(j, result, use_size, use_type); @@ -4318,16 +4265,14 @@ /// @brief create a BJData serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ - static void to_bjdata(const basic_json& j, detail::output_adapter<std::uint8_t> o, - const bool use_size = false, const bool use_type = false) + static void to_bjdata(const basic_json& j, detail::output_adapter<std::uint8_t> o, const bool use_size = false, const bool use_type = false) { binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type, true, true); } /// @brief create a BJData serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ - static void to_bjdata(const basic_json& j, detail::output_adapter<char> o, - const bool use_size = false, const bool use_type = false) + static void to_bjdata(const basic_json& j, detail::output_adapter<char> o, const bool use_size = false, const bool use_type = false) { binary_writer<char>(o).write_ubjson(j, use_size, use_type, true, true); } @@ -4358,11 +4303,10 @@ /// @brief create a JSON value from an input in CBOR format /// @sa https://json.nlohmann.me/api/basic_json/from_cbor/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_cbor(InputType&& i, - const bool strict = true, - const bool allow_exceptions = true, - const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_cbor(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true, + const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -4374,11 +4318,7 @@ /// @brief create a JSON value from an input in CBOR format /// @sa https://json.nlohmann.me/api/basic_json/from_cbor/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_cbor(IteratorType first, IteratorType last, - const bool strict = true, - const bool allow_exceptions = true, - const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_cbor(IteratorType first, IteratorType last, const bool strict = true, const bool allow_exceptions = true, const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -4389,11 +4329,7 @@ template<typename T> JSON_HEDLEY_WARN_UNUSED_RESULT - JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len)) - static basic_json from_cbor(const T* ptr, std::size_t len, - const bool strict = true, - const bool allow_exceptions = true, - const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len)) static basic_json from_cbor(const T* ptr, std::size_t len, const bool strict = true, const bool allow_exceptions = true, const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) { return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler); } @@ -4416,10 +4352,9 @@ /// @brief create a JSON value from an input in MessagePack format /// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_msgpack(InputType&& i, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_msgpack(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -4431,10 +4366,7 @@ /// @brief create a JSON value from an input in MessagePack format /// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_msgpack(IteratorType first, IteratorType last, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_msgpack(IteratorType first, IteratorType last, const bool strict = true, const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -4445,10 +4377,7 @@ template<typename T> JSON_HEDLEY_WARN_UNUSED_RESULT - JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len)) - static basic_json from_msgpack(const T* ptr, std::size_t len, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len)) static basic_json from_msgpack(const T* ptr, std::size_t len, const bool strict = true, const bool allow_exceptions = true) { return from_msgpack(ptr, ptr + len, strict, allow_exceptions); } @@ -4470,10 +4399,9 @@ /// @brief create a JSON value from an input in UBJSON format /// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_ubjson(InputType&& i, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_ubjson(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -4485,10 +4413,7 @@ /// @brief create a JSON value from an input in UBJSON format /// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_ubjson(IteratorType first, IteratorType last, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_ubjson(IteratorType first, IteratorType last, const bool strict = true, const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -4499,10 +4424,7 @@ template<typename T> JSON_HEDLEY_WARN_UNUSED_RESULT - JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len)) - static basic_json from_ubjson(const T* ptr, std::size_t len, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len)) static basic_json from_ubjson(const T* ptr, std::size_t len, const bool strict = true, const bool allow_exceptions = true) { return from_ubjson(ptr, ptr + len, strict, allow_exceptions); } @@ -4524,10 +4446,9 @@ /// @brief create a JSON value from an input in BJData format /// @sa https://json.nlohmann.me/api/basic_json/from_bjdata/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_bjdata(InputType&& i, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bjdata(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -4539,10 +4460,7 @@ /// @brief create a JSON value from an input in BJData format /// @sa https://json.nlohmann.me/api/basic_json/from_bjdata/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_bjdata(IteratorType first, IteratorType last, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bjdata(IteratorType first, IteratorType last, const bool strict = true, const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -4554,10 +4472,9 @@ /// @brief create a JSON value from an input in BSON format /// @sa https://json.nlohmann.me/api/basic_json/from_bson/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_bson(InputType&& i, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bson(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -4569,10 +4486,7 @@ /// @brief create a JSON value from an input in BSON format /// @sa https://json.nlohmann.me/api/basic_json/from_bson/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_bson(IteratorType first, IteratorType last, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bson(IteratorType first, IteratorType last, const bool strict = true, const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -4583,10 +4497,7 @@ template<typename T> JSON_HEDLEY_WARN_UNUSED_RESULT - JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len)) - static basic_json from_bson(const T* ptr, std::size_t len, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len)) static basic_json from_bson(const T* ptr, std::size_t len, const bool strict = true, const bool allow_exceptions = true) { return from_bson(ptr, ptr + len, strict, allow_exceptions); } @@ -4621,7 +4532,7 @@ } template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr) { return ptr.get_unchecked(this); @@ -4635,7 +4546,7 @@ } template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) const_reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr) const { return ptr.get_unchecked(this); @@ -4649,7 +4560,7 @@ } template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr) { return ptr.get_checked(this); @@ -4663,7 +4574,7 @@ } template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr) const { return ptr.get_checked(this); @@ -4700,10 +4611,18 @@ { basic_json& result = *this; // the valid JSON Patch operations - enum class patch_operations {add, remove, replace, move, copy, test, invalid}; - - const auto get_op = [](const std::string & op) + enum class patch_operations { + add, + remove, + replace, + move, + copy, + test, + invalid + }; + + const auto get_op = [](const std::string& op) { if (op == "add") { return patch_operations::add; @@ -4733,8 +4652,7 @@ }; // wrapper for "add" operation; add value at ptr - const auto operation_add = [&result](json_pointer & ptr, basic_json val) - { + const auto operation_add = [&result](json_pointer& ptr, basic_json val) { // adding to the root of the target document means replacing it if (ptr.empty()) { @@ -4788,21 +4706,20 @@ } // if there exists a parent it cannot be primitive - case value_t::string: // LCOV_EXCL_LINE - case value_t::boolean: // LCOV_EXCL_LINE - case value_t::number_integer: // LCOV_EXCL_LINE - case value_t::number_unsigned: // LCOV_EXCL_LINE - case value_t::number_float: // LCOV_EXCL_LINE - case value_t::binary: // LCOV_EXCL_LINE - case value_t::discarded: // LCOV_EXCL_LINE - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + case value_t::string: // LCOV_EXCL_LINE + case value_t::boolean: // LCOV_EXCL_LINE + case value_t::number_integer: // LCOV_EXCL_LINE + case value_t::number_unsigned: // LCOV_EXCL_LINE + case value_t::number_float: // LCOV_EXCL_LINE + case value_t::binary: // LCOV_EXCL_LINE + case value_t::discarded: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } }; // wrapper for "remove" operation; remove value at ptr - const auto operation_remove = [this, & result](json_pointer & ptr) - { + const auto operation_remove = [this, &result](json_pointer& ptr) { // get reference to parent of JSON pointer ptr const auto last_path = ptr.back(); ptr.pop_back(); @@ -4839,10 +4756,9 @@ for (const auto& val : json_patch) { // wrapper to get a value for an operation - const auto get_value = [&val](const std::string & op, - const std::string & member, - bool string_type) -> basic_json & - { + const auto get_value = [&val](const std::string& op, + const std::string& member, + bool string_type) -> basic_json& { // find value auto it = val.m_data.m_value.object->find(member); @@ -4940,7 +4856,7 @@ // the "path" location must exist - use at() success = (result.at(ptr) == get_value("test", "value", false)); } - JSON_INTERNAL_CATCH (out_of_range&) + JSON_INTERNAL_CATCH(out_of_range&) { // ignore out of range errors: success remains false } @@ -4977,8 +4893,7 @@ /// @brief creates a diff as a JSON patch /// @sa https://json.nlohmann.me/api/basic_json/diff/ JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json diff(const basic_json& source, const basic_json& target, - const std::string& path = "") + static basic_json diff(const basic_json& source, const basic_json& target, const std::string& path = "") { // the patch basic_json result(value_t::array); @@ -4993,9 +4908,7 @@ { // different types: replace value result.push_back( - { - {"op", "replace"}, {"path", path}, {"value", target} - }); + {{"op", "replace"}, {"path", path}, {"value", target}}); return result; } @@ -5022,11 +4935,7 @@ { // add operations in reverse order to avoid invalid // indices - result.insert(result.begin() + end_index, object( - { - {"op", "remove"}, - {"path", detail::concat(path, '/', std::to_string(i))} - })); + result.insert(result.begin() + end_index, object({{"op", "remove"}, {"path", detail::concat(path, '/', std::to_string(i))}})); ++i; } @@ -5034,11 +4943,9 @@ while (i < target.size()) { result.push_back( - { - {"op", "add"}, - {"path", detail::concat(path, "/-")}, - {"value", target[i]} - }); + {{"op", "add"}, + {"path", detail::concat(path, "/-")}, + {"value", target[i]}}); ++i; } @@ -5063,9 +4970,7 @@ { // found a key that is not in o -> remove it result.push_back(object( - { - {"op", "remove"}, {"path", path_key} - })); + {{"op", "remove"}, {"path", path_key}})); } } @@ -5077,10 +4982,7 @@ // found a key that is not in this -> add it const auto path_key = detail::concat(path, '/', detail::escape(it.key())); result.push_back( - { - {"op", "add"}, {"path", path_key}, - {"value", it.value()} - }); + {{"op", "add"}, {"path", path_key}, {"value", it.value()}}); } } @@ -5099,9 +5001,7 @@ { // both primitive type: replace value result.push_back( - { - {"op", "replace"}, {"path", path}, {"value", target} - }); + {{"op", "replace"}, {"path", path}, {"value", target}}); break; } } @@ -5156,18 +5056,16 @@ return j.dump(); } -inline namespace literals -{ -inline namespace json_literals -{ +inline namespace literals { +inline namespace json_literals { /// @brief user-defined string literal for JSON values /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/ JSON_HEDLEY_NON_NULL(1) -#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - inline nlohmann::json operator ""_json(const char* s, std::size_t n) +#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) +inline nlohmann::json operator""_json(const char* s, std::size_t n) #else - inline nlohmann::json operator "" _json(const char* s, std::size_t n) +inline nlohmann::json operator"" _json(const char* s, std::size_t n) #endif { return nlohmann::json::parse(s, s + n); @@ -5176,10 +5074,10 @@ /// @brief user-defined string literal for JSON pointer /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ JSON_HEDLEY_NON_NULL(1) -#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - inline nlohmann::json::json_pointer operator ""_json_pointer(const char* s, std::size_t n) +#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) +inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std::size_t n) #else - inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n) +inline nlohmann::json::json_pointer operator"" _json_pointer(const char* s, std::size_t n) #endif { return nlohmann::json::json_pointer(std::string(s, n)); @@ -5193,13 +5091,13 @@ // nonmember support // /////////////////////// -namespace std // NOLINT(cert-dcl58-cpp) +namespace std // NOLINT(cert-dcl58-cpp) { /// @brief hash value for JSON objects /// @sa https://json.nlohmann.me/api/basic_json/std_hash/ NLOHMANN_BASIC_JSON_TPL_DECLARATION -struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL> // NOLINT(cert-dcl58-cpp) +struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL> // NOLINT(cert-dcl58-cpp) { std::size_t operator()(const nlohmann::NLOHMANN_BASIC_JSON_TPL& j) const { @@ -5209,7 +5107,7 @@ // specialization for std::less<value_t> template<> -struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', see https://github.com/nlohmann/json/pull/679 +struct less<::nlohmann::detail::value_t> // do not remove the space after '<', see https://github.com/nlohmann/json/pull/679 { /*! @brief compare two value_t enum values @@ -5219,7 +5117,7 @@ ::nlohmann::detail::value_t rhs) const noexcept { #if JSON_HAS_THREE_WAY_COMPARISON - return std::is_lt(lhs <=> rhs); // *NOPAD* + return std::is_lt(lhs <= > rhs); // *NOPAD* #else return ::nlohmann::detail::operator<(lhs, rhs); #endif @@ -5233,7 +5131,7 @@ /// @sa https://json.nlohmann.me/api/basic_json/std_swap/ NLOHMANN_BASIC_JSON_TPL_DECLARATION inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) - is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value&& // NOLINT(misc-redundant-expression,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value && // NOLINT(misc-redundant-expression,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value) { j1.swap(j2); @@ -5244,12 +5142,12 @@ } // namespace std #if JSON_USE_GLOBAL_UDLS - #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - using nlohmann::literals::json_literals::operator ""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) - using nlohmann::literals::json_literals::operator ""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) + #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) +using nlohmann::literals::json_literals::operator""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) +using nlohmann::literals::json_literals::operator""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) #else - using nlohmann::literals::json_literals::operator "" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) - using nlohmann::literals::json_literals::operator "" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) +using nlohmann::literals::json_literals::operator"" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) +using nlohmann::literals::json_literals::operator"" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) #endif #endif
diff --git a/include/nlohmann/json_fwd.hpp b/include/nlohmann/json_fwd.hpp index 32bde59..4e57a91 100644 --- a/include/nlohmann/json_fwd.hpp +++ b/include/nlohmann/json_fwd.hpp
@@ -9,11 +9,11 @@ #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ -#include <cstdint> // int64_t, uint64_t -#include <map> // map -#include <memory> // allocator -#include <string> // string -#include <vector> // vector +#include <cstdint> // int64_t, uint64_t +#include <map> // map +#include <memory> // allocator +#include <string> // string +#include <vector> // vector #include <nlohmann/detail/abi_macros.hpp> @@ -37,16 +37,17 @@ /// a class to store JSON values /// @sa https://json.nlohmann.me/api/basic_json/ template<template<typename U, typename V, typename... Args> class ObjectType = - std::map, + std::map, template<typename U, typename... Args> class ArrayType = std::vector, - class StringType = std::string, class BooleanType = bool, + class StringType = std::string, + class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template<typename U> class AllocatorType = std::allocator, template<typename T, typename SFINAE = void> class JSONSerializer = - adl_serializer, - class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError + adl_serializer, + class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError class CustomBaseClass = void> class basic_json;
diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index 39e4a50..0f73460 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp
@@ -8,14 +8,14 @@ #pragma once -#include <functional> // equal_to, less -#include <initializer_list> // initializer_list -#include <iterator> // input_iterator_tag, iterator_traits -#include <memory> // allocator -#include <stdexcept> // for out_of_range -#include <type_traits> // enable_if, is_convertible -#include <utility> // pair -#include <vector> // vector +#include <functional> // equal_to, less +#include <initializer_list> // initializer_list +#include <iterator> // input_iterator_tag, iterator_traits +#include <memory> // allocator +#include <stdexcept> // for out_of_range +#include <type_traits> // enable_if, is_convertible +#include <utility> // pair +#include <vector> // vector #include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/meta/type_traits.hpp> @@ -24,9 +24,8 @@ /// ordered_map: a minimal map-like container that preserves insertion order /// for use within nlohmann::basic_json<ordered_map> -template <class Key, class T, class IgnoredLess = std::less<Key>, - class Allocator = std::allocator<std::pair<const Key, T>>> - struct ordered_map : std::vector<std::pair<const Key, T>, Allocator> +template<class Key, class T, class IgnoredLess = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>> +struct ordered_map : std::vector<std::pair<const Key, T>, Allocator> { using key_type = Key; using mapped_type = T; @@ -43,13 +42,19 @@ // Explicit constructors instead of `using Container::Container` // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) - ordered_map() noexcept(noexcept(Container())) : Container{} {} - explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {} - template <class It> + ordered_map() noexcept(noexcept(Container())) + : Container{} + {} + explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) + : Container{alloc} + {} + template<class It> ordered_map(It first, It last, const Allocator& alloc = Allocator()) - : Container{first, last, alloc} {} - ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator() ) - : Container{init, alloc} {} + : Container{first, last, alloc} + {} + ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator()) + : Container{init, alloc} + {} std::pair<iterator, bool> emplace(const key_type& key, T&& t) { @@ -64,9 +69,8 @@ return {std::prev(this->end()), true}; } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - std::pair<iterator, bool> emplace(KeyType && key, T && t) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + std::pair<iterator, bool> emplace(KeyType&& key, T&& t) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -84,9 +88,8 @@ return emplace(key, T{}).first->second; } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - T & operator[](KeyType && key) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + T& operator[](KeyType&& key) { return emplace(std::forward<KeyType>(key), T{}).first->second; } @@ -96,9 +99,8 @@ return at(key); } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - const T & operator[](KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + const T& operator[](KeyType&& key) const { return at(std::forward<KeyType>(key)); } @@ -116,9 +118,8 @@ JSON_THROW(std::out_of_range("key not found")); } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - T & at(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + T& at(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -144,9 +145,8 @@ JSON_THROW(std::out_of_range("key not found")); } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - const T & at(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + const T& at(KeyType&& key) const // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -168,7 +168,7 @@ // Since we cannot move const Keys, re-construct them in place for (auto next = it; ++next != this->end(); ++it) { - it->~value_type(); // Destroy but keep allocation + it->~value_type(); // Destroy but keep allocation new (&*it) value_type{std::move(*next)}; } Container::pop_back(); @@ -178,9 +178,8 @@ return 0; } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + size_type erase(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -189,7 +188,7 @@ // Since we cannot move const Keys, re-construct them in place for (auto next = it; ++next != this->end(); ++it) { - it->~value_type(); // Destroy but keep allocation + it->~value_type(); // Destroy but keep allocation new (&*it) value_type{std::move(*next)}; } Container::pop_back(); @@ -236,8 +235,8 @@ for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) { - it->~value_type(); // destroy but keep allocation - new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it + it->~value_type(); // destroy but keep allocation + new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it } // [ a, b, c, d, h, i, j, h, i, j ] @@ -269,9 +268,8 @@ return 0; } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - size_type count(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + size_type count(KeyType&& key) const // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -295,9 +293,8 @@ return Container::end(); } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - iterator find(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + iterator find(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -321,12 +318,12 @@ return Container::end(); } - std::pair<iterator, bool> insert( value_type&& value ) + std::pair<iterator, bool> insert(value_type&& value) { return emplace(value.first, std::move(value.second)); } - std::pair<iterator, bool> insert( const value_type& value ) + std::pair<iterator, bool> insert(const value_type& value) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -341,7 +338,7 @@ template<typename InputIt> using require_input_iter = typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category, - std::input_iterator_tag>::value>::type; + std::input_iterator_tag>::value>::type; template<typename InputIt, typename = require_input_iter<InputIt>> void insert(InputIt first, InputIt last) @@ -352,7 +349,7 @@ } } -private: + private: JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare(); };
diff --git a/include/nlohmann/thirdparty/hedley/hedley.hpp b/include/nlohmann/thirdparty/hedley/hedley.hpp index a1dc64f..3fa94ad 100644 --- a/include/nlohmann/thirdparty/hedley/hedley.hpp +++ b/include/nlohmann/thirdparty/hedley/hedley.hpp
@@ -14,2032 +14,1951 @@ */ #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15) -#if defined(JSON_HEDLEY_VERSION) - #undef JSON_HEDLEY_VERSION -#endif -#define JSON_HEDLEY_VERSION 15 - -#if defined(JSON_HEDLEY_STRINGIFY_EX) - #undef JSON_HEDLEY_STRINGIFY_EX -#endif -#define JSON_HEDLEY_STRINGIFY_EX(x) #x - -#if defined(JSON_HEDLEY_STRINGIFY) - #undef JSON_HEDLEY_STRINGIFY -#endif -#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x) - -#if defined(JSON_HEDLEY_CONCAT_EX) - #undef JSON_HEDLEY_CONCAT_EX -#endif -#define JSON_HEDLEY_CONCAT_EX(a,b) a##b - -#if defined(JSON_HEDLEY_CONCAT) - #undef JSON_HEDLEY_CONCAT -#endif -#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b) - -#if defined(JSON_HEDLEY_CONCAT3_EX) - #undef JSON_HEDLEY_CONCAT3_EX -#endif -#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c - -#if defined(JSON_HEDLEY_CONCAT3) - #undef JSON_HEDLEY_CONCAT3 -#endif -#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c) - -#if defined(JSON_HEDLEY_VERSION_ENCODE) - #undef JSON_HEDLEY_VERSION_ENCODE -#endif -#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision)) - -#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR) - #undef JSON_HEDLEY_VERSION_DECODE_MAJOR -#endif -#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000) - -#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR) - #undef JSON_HEDLEY_VERSION_DECODE_MINOR -#endif -#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000) - -#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION) - #undef JSON_HEDLEY_VERSION_DECODE_REVISION -#endif -#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000) - -#if defined(JSON_HEDLEY_GNUC_VERSION) - #undef JSON_HEDLEY_GNUC_VERSION -#endif -#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) - #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) -#elif defined(__GNUC__) - #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0) -#endif - -#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK) - #undef JSON_HEDLEY_GNUC_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_GNUC_VERSION) - #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_MSVC_VERSION) - #undef JSON_HEDLEY_MSVC_VERSION -#endif -#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL) - #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) -#elif defined(_MSC_FULL_VER) && !defined(__ICL) - #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) -#elif defined(_MSC_VER) && !defined(__ICL) - #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) -#endif - -#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) - #undef JSON_HEDLEY_MSVC_VERSION_CHECK -#endif -#if !defined(JSON_HEDLEY_MSVC_VERSION) - #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0) -#elif defined(_MSC_VER) && (_MSC_VER >= 1400) - #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) -#elif defined(_MSC_VER) && (_MSC_VER >= 1200) - #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) -#else - #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor))) -#endif - -#if defined(JSON_HEDLEY_INTEL_VERSION) - #undef JSON_HEDLEY_INTEL_VERSION -#endif -#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL) - #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) -#elif defined(__INTEL_COMPILER) && !defined(__ICL) - #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) -#endif - -#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK) - #undef JSON_HEDLEY_INTEL_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_INTEL_VERSION) - #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_INTEL_CL_VERSION) - #undef JSON_HEDLEY_INTEL_CL_VERSION -#endif -#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL) - #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0) -#endif - -#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK) - #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_INTEL_CL_VERSION) - #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_PGI_VERSION) - #undef JSON_HEDLEY_PGI_VERSION -#endif -#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) - #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) -#endif - -#if defined(JSON_HEDLEY_PGI_VERSION_CHECK) - #undef JSON_HEDLEY_PGI_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_PGI_VERSION) - #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_SUNPRO_VERSION) - #undef JSON_HEDLEY_SUNPRO_VERSION -#endif -#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) - #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10) -#elif defined(__SUNPRO_C) - #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf) -#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) - #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10) -#elif defined(__SUNPRO_CC) - #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf) -#endif - -#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK) - #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_SUNPRO_VERSION) - #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) - #undef JSON_HEDLEY_EMSCRIPTEN_VERSION -#endif -#if defined(__EMSCRIPTEN__) - #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__) -#endif - -#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK) - #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) - #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_ARM_VERSION) - #undef JSON_HEDLEY_ARM_VERSION -#endif -#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) - #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100) -#elif defined(__CC_ARM) && defined(__ARMCC_VERSION) - #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100) -#endif - -#if defined(JSON_HEDLEY_ARM_VERSION_CHECK) - #undef JSON_HEDLEY_ARM_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_ARM_VERSION) - #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_IBM_VERSION) - #undef JSON_HEDLEY_IBM_VERSION -#endif -#if defined(__ibmxl__) - #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__) -#elif defined(__xlC__) && defined(__xlC_ver__) - #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) -#elif defined(__xlC__) - #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0) -#endif - -#if defined(JSON_HEDLEY_IBM_VERSION_CHECK) - #undef JSON_HEDLEY_IBM_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_IBM_VERSION) - #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_VERSION) - #undef JSON_HEDLEY_TI_VERSION -#endif -#if \ - defined(__TI_COMPILER_VERSION__) && \ - ( \ - defined(__TMS470__) || defined(__TI_ARM__) || \ - defined(__MSP430__) || \ - defined(__TMS320C2000__) \ - ) -#if (__TI_COMPILER_VERSION__ >= 16000000) - #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif -#endif - -#if defined(JSON_HEDLEY_TI_VERSION_CHECK) - #undef JSON_HEDLEY_TI_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_VERSION) - #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_CL2000_VERSION) - #undef JSON_HEDLEY_TI_CL2000_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__) - #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK) - #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_CL2000_VERSION) - #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_CL430_VERSION) - #undef JSON_HEDLEY_TI_CL430_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__) - #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK) - #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_CL430_VERSION) - #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) - #undef JSON_HEDLEY_TI_ARMCL_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__)) - #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK) - #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) - #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_CL6X_VERSION) - #undef JSON_HEDLEY_TI_CL6X_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__) - #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK) - #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_CL6X_VERSION) - #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_CL7X_VERSION) - #undef JSON_HEDLEY_TI_CL7X_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__) - #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK) - #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_CL7X_VERSION) - #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) - #undef JSON_HEDLEY_TI_CLPRU_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__) - #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK) - #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) - #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_CRAY_VERSION) - #undef JSON_HEDLEY_CRAY_VERSION -#endif -#if defined(_CRAYC) - #if defined(_RELEASE_PATCHLEVEL) - #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL) - #else - #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0) + #if defined(JSON_HEDLEY_VERSION) + #undef JSON_HEDLEY_VERSION #endif -#endif + #define JSON_HEDLEY_VERSION 15 -#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK) - #undef JSON_HEDLEY_CRAY_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_CRAY_VERSION) - #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_IAR_VERSION) - #undef JSON_HEDLEY_IAR_VERSION -#endif -#if defined(__IAR_SYSTEMS_ICC__) - #if __VER__ > 1000 - #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) - #else - #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0) + #if defined(JSON_HEDLEY_STRINGIFY_EX) + #undef JSON_HEDLEY_STRINGIFY_EX #endif -#endif + #define JSON_HEDLEY_STRINGIFY_EX(x) #x -#if defined(JSON_HEDLEY_IAR_VERSION_CHECK) - #undef JSON_HEDLEY_IAR_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_IAR_VERSION) - #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_STRINGIFY) + #undef JSON_HEDLEY_STRINGIFY + #endif + #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x) -#if defined(JSON_HEDLEY_TINYC_VERSION) - #undef JSON_HEDLEY_TINYC_VERSION -#endif -#if defined(__TINYC__) - #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) -#endif + #if defined(JSON_HEDLEY_CONCAT_EX) + #undef JSON_HEDLEY_CONCAT_EX + #endif + #define JSON_HEDLEY_CONCAT_EX(a, b) a##b -#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK) - #undef JSON_HEDLEY_TINYC_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TINYC_VERSION) - #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_CONCAT) + #undef JSON_HEDLEY_CONCAT + #endif + #define JSON_HEDLEY_CONCAT(a, b) JSON_HEDLEY_CONCAT_EX(a, b) -#if defined(JSON_HEDLEY_DMC_VERSION) - #undef JSON_HEDLEY_DMC_VERSION -#endif -#if defined(__DMC__) - #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf) -#endif + #if defined(JSON_HEDLEY_CONCAT3_EX) + #undef JSON_HEDLEY_CONCAT3_EX + #endif + #define JSON_HEDLEY_CONCAT3_EX(a, b, c) a##b##c -#if defined(JSON_HEDLEY_DMC_VERSION_CHECK) - #undef JSON_HEDLEY_DMC_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_DMC_VERSION) - #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_CONCAT3) + #undef JSON_HEDLEY_CONCAT3 + #endif + #define JSON_HEDLEY_CONCAT3(a, b, c) JSON_HEDLEY_CONCAT3_EX(a, b, c) -#if defined(JSON_HEDLEY_COMPCERT_VERSION) - #undef JSON_HEDLEY_COMPCERT_VERSION -#endif -#if defined(__COMPCERT_VERSION__) - #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100) -#endif + #if defined(JSON_HEDLEY_VERSION_ENCODE) + #undef JSON_HEDLEY_VERSION_ENCODE + #endif + #define JSON_HEDLEY_VERSION_ENCODE(major, minor, revision) (((major) * 1000000) + ((minor) * 1000) + (revision)) -#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK) - #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_COMPCERT_VERSION) - #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR) + #undef JSON_HEDLEY_VERSION_DECODE_MAJOR + #endif + #define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000) -#if defined(JSON_HEDLEY_PELLES_VERSION) - #undef JSON_HEDLEY_PELLES_VERSION -#endif -#if defined(__POCC__) - #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0) -#endif + #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR) + #undef JSON_HEDLEY_VERSION_DECODE_MINOR + #endif + #define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000) -#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK) - #undef JSON_HEDLEY_PELLES_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_PELLES_VERSION) - #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_VERSION_DECODE_REVISION) + #undef JSON_HEDLEY_VERSION_DECODE_REVISION + #endif + #define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000) -#if defined(JSON_HEDLEY_MCST_LCC_VERSION) - #undef JSON_HEDLEY_MCST_LCC_VERSION -#endif -#if defined(__LCC__) && defined(__LCC_MINOR__) - #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__) -#endif + #if defined(JSON_HEDLEY_GNUC_VERSION) + #undef JSON_HEDLEY_GNUC_VERSION + #endif + #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) + #elif defined(__GNUC__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0) + #endif -#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK) - #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_MCST_LCC_VERSION) - #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_GNUC_VERSION_CHECK) + #undef JSON_HEDLEY_GNUC_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_GNUC_VERSION) + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GCC_VERSION) - #undef JSON_HEDLEY_GCC_VERSION -#endif -#if \ - defined(JSON_HEDLEY_GNUC_VERSION) && \ - !defined(__clang__) && \ - !defined(JSON_HEDLEY_INTEL_VERSION) && \ - !defined(JSON_HEDLEY_PGI_VERSION) && \ - !defined(JSON_HEDLEY_ARM_VERSION) && \ - !defined(JSON_HEDLEY_CRAY_VERSION) && \ - !defined(JSON_HEDLEY_TI_VERSION) && \ - !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \ - !defined(JSON_HEDLEY_TI_CL430_VERSION) && \ - !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \ - !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \ - !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \ - !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \ - !defined(__COMPCERT__) && \ - !defined(JSON_HEDLEY_MCST_LCC_VERSION) - #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION -#endif + #if defined(JSON_HEDLEY_MSVC_VERSION) + #undef JSON_HEDLEY_MSVC_VERSION + #endif + #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) + #elif defined(_MSC_FULL_VER) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) + #elif defined(_MSC_VER) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) + #endif -#if defined(JSON_HEDLEY_GCC_VERSION_CHECK) - #undef JSON_HEDLEY_GCC_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_GCC_VERSION) - #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) + #undef JSON_HEDLEY_MSVC_VERSION_CHECK + #endif + #if !defined(JSON_HEDLEY_MSVC_VERSION) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) (0) + #elif defined(_MSC_VER) && (_MSC_VER >= 1400) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) + #elif defined(_MSC_VER) && (_MSC_VER >= 1200) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) + #else + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) (_MSC_VER >= ((major * 100) + (minor))) + #endif -#if defined(JSON_HEDLEY_HAS_ATTRIBUTE) - #undef JSON_HEDLEY_HAS_ATTRIBUTE -#endif -#if \ - defined(__has_attribute) && \ - ( \ - (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \ - ) -# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) -#else -# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) -#endif + #if defined(JSON_HEDLEY_INTEL_VERSION) + #undef JSON_HEDLEY_INTEL_VERSION + #endif + #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) + #elif defined(__INTEL_COMPILER) && !defined(__ICL) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) - #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE -#endif -#if defined(__has_attribute) - #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) -#else - #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_INTEL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_INTEL_VERSION) + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE) - #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE -#endif -#if defined(__has_attribute) - #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) -#else - #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_INTEL_CL_VERSION) + #undef JSON_HEDLEY_INTEL_CL_VERSION + #endif + #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL) + #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0) + #endif -#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE) - #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE -#endif -#if \ - defined(__has_cpp_attribute) && \ - defined(__cplusplus) && \ - (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) - #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute) -#else - #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0) -#endif + #if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_INTEL_CL_VERSION) + #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS) - #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS -#endif -#if !defined(__cplusplus) || !defined(__has_cpp_attribute) - #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) -#elif \ - !defined(JSON_HEDLEY_PGI_VERSION) && \ - !defined(JSON_HEDLEY_IAR_VERSION) && \ - (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \ - (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0)) - #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute) -#else - #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) -#endif + #if defined(JSON_HEDLEY_PGI_VERSION) + #undef JSON_HEDLEY_PGI_VERSION + #endif + #if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) + #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE) - #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE -#endif -#if defined(__has_cpp_attribute) && defined(__cplusplus) - #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) -#else - #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_PGI_VERSION_CHECK) + #undef JSON_HEDLEY_PGI_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_PGI_VERSION) + #define JSON_HEDLEY_PGI_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_PGI_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE) - #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE -#endif -#if defined(__has_cpp_attribute) && defined(__cplusplus) - #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) -#else - #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_SUNPRO_VERSION) + #undef JSON_HEDLEY_SUNPRO_VERSION + #endif + #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10) + #elif defined(__SUNPRO_C) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf) + #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10) + #elif defined(__SUNPRO_CC) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf) + #endif -#if defined(JSON_HEDLEY_HAS_BUILTIN) - #undef JSON_HEDLEY_HAS_BUILTIN -#endif -#if defined(__has_builtin) - #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin) -#else - #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0) -#endif + #if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK) + #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_SUNPRO_VERSION) + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN) - #undef JSON_HEDLEY_GNUC_HAS_BUILTIN -#endif -#if defined(__has_builtin) - #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) -#else - #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION + #endif + #if defined(__EMSCRIPTEN__) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN) - #undef JSON_HEDLEY_GCC_HAS_BUILTIN -#endif -#if defined(__has_builtin) - #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) -#else - #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_HAS_FEATURE) - #undef JSON_HEDLEY_HAS_FEATURE -#endif -#if defined(__has_feature) - #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature) -#else - #define JSON_HEDLEY_HAS_FEATURE(feature) (0) -#endif + #if defined(JSON_HEDLEY_ARM_VERSION) + #undef JSON_HEDLEY_ARM_VERSION + #endif + #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100) + #elif defined(__CC_ARM) && defined(__ARMCC_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE) - #undef JSON_HEDLEY_GNUC_HAS_FEATURE -#endif -#if defined(__has_feature) - #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) -#else - #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_ARM_VERSION_CHECK) + #undef JSON_HEDLEY_ARM_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_ARM_VERSION) + #define JSON_HEDLEY_ARM_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_ARM_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_FEATURE) - #undef JSON_HEDLEY_GCC_HAS_FEATURE -#endif -#if defined(__has_feature) - #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) -#else - #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_IBM_VERSION) + #undef JSON_HEDLEY_IBM_VERSION + #endif + #if defined(__ibmxl__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__) + #elif defined(__xlC__) && defined(__xlC_ver__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) + #elif defined(__xlC__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0) + #endif -#if defined(JSON_HEDLEY_HAS_EXTENSION) - #undef JSON_HEDLEY_HAS_EXTENSION -#endif -#if defined(__has_extension) - #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension) -#else - #define JSON_HEDLEY_HAS_EXTENSION(extension) (0) -#endif + #if defined(JSON_HEDLEY_IBM_VERSION_CHECK) + #undef JSON_HEDLEY_IBM_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_IBM_VERSION) + #define JSON_HEDLEY_IBM_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_IBM_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION) - #undef JSON_HEDLEY_GNUC_HAS_EXTENSION -#endif -#if defined(__has_extension) - #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) -#else - #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_VERSION) + #undef JSON_HEDLEY_TI_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && \ + (defined(__TMS470__) || defined(__TI_ARM__) || \ + defined(__MSP430__) || \ + defined(__TMS320C2000__)) + #if (__TI_COMPILER_VERSION__ >= 16000000) + #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif + #endif -#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION) - #undef JSON_HEDLEY_GCC_HAS_EXTENSION -#endif -#if defined(__has_extension) - #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) -#else - #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_VERSION_CHECK) + #undef JSON_HEDLEY_TI_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_VERSION) + #define JSON_HEDLEY_TI_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE) - #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE -#endif -#if defined(__has_declspec_attribute) - #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute) -#else - #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0) -#endif + #if defined(JSON_HEDLEY_TI_CL2000_VERSION) + #undef JSON_HEDLEY_TI_CL2000_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__) + #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE) - #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE -#endif -#if defined(__has_declspec_attribute) - #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) -#else - #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_CL2000_VERSION) + #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE) - #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE -#endif -#if defined(__has_declspec_attribute) - #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) -#else - #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_CL430_VERSION) + #undef JSON_HEDLEY_TI_CL430_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__) + #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif -#if defined(JSON_HEDLEY_HAS_WARNING) - #undef JSON_HEDLEY_HAS_WARNING -#endif -#if defined(__has_warning) - #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning) -#else - #define JSON_HEDLEY_HAS_WARNING(warning) (0) -#endif + #if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_CL430_VERSION) + #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_WARNING) - #undef JSON_HEDLEY_GNUC_HAS_WARNING -#endif -#if defined(__has_warning) - #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) -#else - #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_ARMCL_VERSION) + #undef JSON_HEDLEY_TI_ARMCL_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__)) + #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_WARNING) - #undef JSON_HEDLEY_GCC_HAS_WARNING -#endif -#if defined(__has_warning) - #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) -#else - #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK) + #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_ARMCL_VERSION) + #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major, minor, patch) (0) + #endif -#if \ - (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ - defined(__clang__) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \ - JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \ - (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR)) - #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value) -#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) - #define JSON_HEDLEY_PRAGMA(value) __pragma(value) -#else - #define JSON_HEDLEY_PRAGMA(value) -#endif + #if defined(JSON_HEDLEY_TI_CL6X_VERSION) + #undef JSON_HEDLEY_TI_CL6X_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__) + #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif -#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH) - #undef JSON_HEDLEY_DIAGNOSTIC_PUSH -#endif -#if defined(JSON_HEDLEY_DIAGNOSTIC_POP) - #undef JSON_HEDLEY_DIAGNOSTIC_POP -#endif -#if defined(__clang__) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") -#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push)) - #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop)) -#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop") -#elif \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop") -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") -#else - #define JSON_HEDLEY_DIAGNOSTIC_PUSH - #define JSON_HEDLEY_DIAGNOSTIC_POP -#endif + #if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_CL6X_VERSION) + #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major, minor, patch) (0) + #endif -/* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for + #if defined(JSON_HEDLEY_TI_CL7X_VERSION) + #undef JSON_HEDLEY_TI_CL7X_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && defined(__C7000__) + #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif + + #if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_CL7X_VERSION) + #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_TI_CLPRU_VERSION) + #undef JSON_HEDLEY_TI_CLPRU_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && defined(__PRU__) + #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif + + #if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_CLPRU_VERSION) + #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_CRAY_VERSION) + #undef JSON_HEDLEY_CRAY_VERSION + #endif + #if defined(_CRAYC) + #if defined(_RELEASE_PATCHLEVEL) + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL) + #else + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0) + #endif + #endif + + #if defined(JSON_HEDLEY_CRAY_VERSION_CHECK) + #undef JSON_HEDLEY_CRAY_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_CRAY_VERSION) + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_IAR_VERSION) + #undef JSON_HEDLEY_IAR_VERSION + #endif + #if defined(__IAR_SYSTEMS_ICC__) + #if __VER__ > 1000 + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) + #else + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0) + #endif + #endif + + #if defined(JSON_HEDLEY_IAR_VERSION_CHECK) + #undef JSON_HEDLEY_IAR_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_IAR_VERSION) + #define JSON_HEDLEY_IAR_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_IAR_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_TINYC_VERSION) + #undef JSON_HEDLEY_TINYC_VERSION + #endif + #if defined(__TINYC__) + #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) + #endif + + #if defined(JSON_HEDLEY_TINYC_VERSION_CHECK) + #undef JSON_HEDLEY_TINYC_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_DMC_VERSION) + #undef JSON_HEDLEY_DMC_VERSION + #endif + #if defined(__DMC__) + #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf) + #endif + + #if defined(JSON_HEDLEY_DMC_VERSION_CHECK) + #undef JSON_HEDLEY_DMC_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_DMC_VERSION) + #define JSON_HEDLEY_DMC_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_DMC_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_COMPCERT_VERSION) + #undef JSON_HEDLEY_COMPCERT_VERSION + #endif + #if defined(__COMPCERT_VERSION__) + #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100) + #endif + + #if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK) + #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_COMPCERT_VERSION) + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_PELLES_VERSION) + #undef JSON_HEDLEY_PELLES_VERSION + #endif + #if defined(__POCC__) + #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0) + #endif + + #if defined(JSON_HEDLEY_PELLES_VERSION_CHECK) + #undef JSON_HEDLEY_PELLES_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_PELLES_VERSION) + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_MCST_LCC_VERSION) + #undef JSON_HEDLEY_MCST_LCC_VERSION + #endif + #if defined(__LCC__) && defined(__LCC_MINOR__) + #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__) + #endif + + #if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK) + #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_MCST_LCC_VERSION) + #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_GCC_VERSION) + #undef JSON_HEDLEY_GCC_VERSION + #endif + #if defined(JSON_HEDLEY_GNUC_VERSION) && \ + !defined(__clang__) && \ + !defined(JSON_HEDLEY_INTEL_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_ARM_VERSION) && \ + !defined(JSON_HEDLEY_CRAY_VERSION) && \ + !defined(JSON_HEDLEY_TI_VERSION) && \ + !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL430_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \ + !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \ + !defined(__COMPCERT__) && \ + !defined(JSON_HEDLEY_MCST_LCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION + #endif + + #if defined(JSON_HEDLEY_GCC_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_GCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_ATTRIBUTE + #endif + #if defined(__has_attribute) && \ + ((!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8, 5, 9))) + #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) + #else + #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE + #endif + #if defined(__has_attribute) + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) + #else + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE + #endif + #if defined(__has_attribute) + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) + #else + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE + #endif + #if defined(__has_cpp_attribute) && \ + defined(__cplusplus) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute) + #else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0) + #endif + + #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS + #endif + #if !defined(__cplusplus) || !defined(__has_cpp_attribute) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns, attribute) (0) + #elif !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_IAR_VERSION) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0)) && \ + (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19, 20, 0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns, attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute) + #else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns, attribute) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE + #endif + #if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) __has_cpp_attribute(attribute) + #else + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE + #endif + #if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) __has_cpp_attribute(attribute) + #else + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_BUILTIN) + #undef JSON_HEDLEY_HAS_BUILTIN + #endif + #if defined(__has_builtin) + #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin) + #else + #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN) + #undef JSON_HEDLEY_GNUC_HAS_BUILTIN + #endif + #if defined(__has_builtin) + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin, major, minor, patch) __has_builtin(builtin) + #else + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_BUILTIN) + #undef JSON_HEDLEY_GCC_HAS_BUILTIN + #endif + #if defined(__has_builtin) + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin, major, minor, patch) __has_builtin(builtin) + #else + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_FEATURE) + #undef JSON_HEDLEY_HAS_FEATURE + #endif + #if defined(__has_feature) + #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature) + #else + #define JSON_HEDLEY_HAS_FEATURE(feature) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_FEATURE) + #undef JSON_HEDLEY_GNUC_HAS_FEATURE + #endif + #if defined(__has_feature) + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature, major, minor, patch) __has_feature(feature) + #else + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_FEATURE) + #undef JSON_HEDLEY_GCC_HAS_FEATURE + #endif + #if defined(__has_feature) + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature, major, minor, patch) __has_feature(feature) + #else + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_EXTENSION) + #undef JSON_HEDLEY_HAS_EXTENSION + #endif + #if defined(__has_extension) + #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension) + #else + #define JSON_HEDLEY_HAS_EXTENSION(extension) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION) + #undef JSON_HEDLEY_GNUC_HAS_EXTENSION + #endif + #if defined(__has_extension) + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension, major, minor, patch) __has_extension(extension) + #else + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_EXTENSION) + #undef JSON_HEDLEY_GCC_HAS_EXTENSION + #endif + #if defined(__has_extension) + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension, major, minor, patch) __has_extension(extension) + #else + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE + #endif + #if defined(__has_declspec_attribute) + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute) + #else + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE + #endif + #if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) __has_declspec_attribute(attribute) + #else + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE + #endif + #if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) __has_declspec_attribute(attribute) + #else + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_WARNING) + #undef JSON_HEDLEY_HAS_WARNING + #endif + #if defined(__has_warning) + #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning) + #else + #define JSON_HEDLEY_HAS_WARNING(warning) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_WARNING) + #undef JSON_HEDLEY_GNUC_HAS_WARNING + #endif + #if defined(__has_warning) + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning, major, minor, patch) __has_warning(warning) + #else + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_WARNING) + #undef JSON_HEDLEY_GCC_HAS_WARNING + #endif + #if defined(__has_warning) + #define JSON_HEDLEY_GCC_HAS_WARNING(warning, major, minor, patch) __has_warning(warning) + #else + #define JSON_HEDLEY_GCC_HAS_WARNING(warning, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + defined(__clang__) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18, 4, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 7, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(2, 0, 1) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 1, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 0, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(5, 0, 0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 17) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(8, 0, 0) || \ + (JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) && defined(__C99_PRAGMA_OPERATOR)) + #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) + #define JSON_HEDLEY_PRAGMA(value) __pragma(value) + #else + #define JSON_HEDLEY_PRAGMA(value) + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH) + #undef JSON_HEDLEY_DIAGNOSTIC_PUSH + #endif + #if defined(JSON_HEDLEY_DIAGNOSTIC_POP) + #undef JSON_HEDLEY_DIAGNOSTIC_POP + #endif + #if defined(__clang__) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push)) + #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop)) + #elif JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop") + #elif JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 4, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 1, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop") + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2, 90, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") + #else + #define JSON_HEDLEY_DIAGNOSTIC_PUSH + #define JSON_HEDLEY_DIAGNOSTIC_POP + #endif + + /* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ -#endif -#if defined(__cplusplus) -# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") -# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions") -# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions") -# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ - _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ - _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \ - xpr \ - JSON_HEDLEY_DIAGNOSTIC_POP -# else -# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ - _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ - xpr \ - JSON_HEDLEY_DIAGNOSTIC_POP -# endif -# else -# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ - xpr \ - JSON_HEDLEY_DIAGNOSTIC_POP -# endif -# endif -#endif -#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x -#endif - -#if defined(JSON_HEDLEY_CONST_CAST) - #undef JSON_HEDLEY_CONST_CAST -#endif -#if defined(__cplusplus) -# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr)) -#elif \ - JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) -# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \ - ((T) (expr)); \ - JSON_HEDLEY_DIAGNOSTIC_POP \ - })) -#else -# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr)) -#endif - -#if defined(JSON_HEDLEY_REINTERPRET_CAST) - #undef JSON_HEDLEY_REINTERPRET_CAST -#endif -#if defined(__cplusplus) - #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr)) -#else - #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr)) -#endif - -#if defined(JSON_HEDLEY_STATIC_CAST) - #undef JSON_HEDLEY_STATIC_CAST -#endif -#if defined(__cplusplus) - #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr)) -#else - #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr)) -#endif - -#if defined(JSON_HEDLEY_CPP_CAST) - #undef JSON_HEDLEY_CPP_CAST -#endif -#if defined(__cplusplus) -# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast") -# define JSON_HEDLEY_CPP_CAST(T, expr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \ - ((T) (expr)) \ - JSON_HEDLEY_DIAGNOSTIC_POP -# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0) -# define JSON_HEDLEY_CPP_CAST(T, expr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("diag_suppress=Pe137") \ - JSON_HEDLEY_DIAGNOSTIC_POP -# else -# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr)) -# endif -#else -# define JSON_HEDLEY_CPP_CAST(T, expr) (expr) -#endif - -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations") - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") -#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") -#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786)) -#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445") -#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") -#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996)) -#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") -#elif \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718") -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)") -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)") -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215") -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)") -#else - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED -#endif - -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") -#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") -#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161)) -#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") -#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068)) -#elif \ - JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") -#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") -#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161") -#else - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS -#endif - -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes") - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") -#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") -#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292)) -#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030)) -#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098") -#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)") -#elif \ - JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097") -#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") -#else - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES -#endif - -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual") - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"") -#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") -#else - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL -#endif - -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wunused-function") - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"") -#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505)) -#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142") -#else - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION -#endif - -#if defined(JSON_HEDLEY_DEPRECATED) - #undef JSON_HEDLEY_DEPRECATED -#endif -#if defined(JSON_HEDLEY_DEPRECATED_FOR) - #undef JSON_HEDLEY_DEPRECATED_FOR -#endif -#if \ - JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since)) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) -#elif \ - (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) -#elif defined(__cplusplus) && (__cplusplus >= 201402L) - #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]]) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]]) -#elif \ - JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) - #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ - JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated") - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated") -#else - #define JSON_HEDLEY_DEPRECATED(since) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) -#endif - -#if defined(JSON_HEDLEY_UNAVAILABLE) - #undef JSON_HEDLEY_UNAVAILABLE -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) -#else - #define JSON_HEDLEY_UNAVAILABLE(available_since) -#endif - -#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT) - #undef JSON_HEDLEY_WARN_UNUSED_RESULT -#endif -#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG) - #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) - #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__)) -#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L) - #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) - #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]]) -#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) - #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) - #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) -#elif defined(_Check_return_) /* SAL */ - #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ - #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_ -#else - #define JSON_HEDLEY_WARN_UNUSED_RESULT - #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) -#endif - -#if defined(JSON_HEDLEY_SENTINEL) - #undef JSON_HEDLEY_SENTINEL -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) -#else - #define JSON_HEDLEY_SENTINEL(position) -#endif - -#if defined(JSON_HEDLEY_NO_RETURN) - #undef JSON_HEDLEY_NO_RETURN -#endif -#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_NO_RETURN __noreturn -#elif \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) -#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L - #define JSON_HEDLEY_NO_RETURN _Noreturn -#elif defined(__cplusplus) && (__cplusplus >= 201103L) - #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]]) -#elif \ - JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) - #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) - #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) -#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) - #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") -#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) - #define JSON_HEDLEY_NO_RETURN __attribute((noreturn)) -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) - #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) -#else - #define JSON_HEDLEY_NO_RETURN -#endif - -#if defined(JSON_HEDLEY_NO_ESCAPE) - #undef JSON_HEDLEY_NO_ESCAPE -#endif -#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape) - #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__)) -#else - #define JSON_HEDLEY_NO_ESCAPE -#endif - -#if defined(JSON_HEDLEY_UNREACHABLE) - #undef JSON_HEDLEY_UNREACHABLE -#endif -#if defined(JSON_HEDLEY_UNREACHABLE_RETURN) - #undef JSON_HEDLEY_UNREACHABLE_RETURN -#endif -#if defined(JSON_HEDLEY_ASSUME) - #undef JSON_HEDLEY_ASSUME -#endif -#if \ - JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_ASSUME(expr) __assume(expr) -#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) - #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) -#elif \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ + #endif #if defined(__cplusplus) - #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr) - #else - #define JSON_HEDLEY_ASSUME(expr) _nassert(expr) + #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") + #if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions") + #if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ + _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP + #endif + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP + #endif + #endif #endif -#endif -#if \ - (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \ - JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() -#elif defined(JSON_HEDLEY_ASSUME) - #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) -#endif -#if !defined(JSON_HEDLEY_ASSUME) + #if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x + #endif + + #if defined(JSON_HEDLEY_CONST_CAST) + #undef JSON_HEDLEY_CONST_CAST + #endif + #if defined(__cplusplus) + #define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr)) + #elif JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL((T)(expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) + #else + #define JSON_HEDLEY_CONST_CAST(T, expr) ((T)(expr)) + #endif + + #if defined(JSON_HEDLEY_REINTERPRET_CAST) + #undef JSON_HEDLEY_REINTERPRET_CAST + #endif + #if defined(__cplusplus) + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr)) + #else + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T)(expr)) + #endif + + #if defined(JSON_HEDLEY_STATIC_CAST) + #undef JSON_HEDLEY_STATIC_CAST + #endif + #if defined(__cplusplus) + #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr)) + #else + #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T)(expr)) + #endif + + #if defined(JSON_HEDLEY_CPP_CAST) + #undef JSON_HEDLEY_CPP_CAST + #endif + #if defined(__cplusplus) + #if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast") + #define JSON_HEDLEY_CPP_CAST(T, expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wold-style-cast\"")((T)(expr)) \ + JSON_HEDLEY_DIAGNOSTIC_POP + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 3, 0) + #define JSON_HEDLEY_CPP_CAST(T, expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("diag_suppress=Pe137") \ + JSON_HEDLEY_DIAGNOSTIC_POP + #else + #define JSON_HEDLEY_CPP_CAST(T, expr) ((T)(expr)) + #endif + #else + #define JSON_HEDLEY_CPP_CAST(T, expr) (expr) + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") + #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable : 1478 1786)) + #elif JSON_HEDLEY_PGI_VERSION_CHECK(20, 7, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445") + #elif JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 3, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable : 4996)) + #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") + #elif JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718") + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 13, 0) && !defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)") + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 13, 0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)") + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215") + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2, 90, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)") + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") + #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable : 161)) + #elif JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 3, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable : 4068)) + #elif JSON_HEDLEY_TI_VERSION_CHECK(16, 9, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 3, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") + #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") + #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161") + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(17, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") + #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable : 1292)) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(19, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable : 5030)) + #elif JSON_HEDLEY_PGI_VERSION_CHECK(20, 7, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098") + #elif JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)") + #elif JSON_HEDLEY_TI_VERSION_CHECK(18, 1, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 3, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097") + #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wcast-qual") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"") + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wunused-function") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(1, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable : 4505)) + #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142") + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION + #endif + + #if defined(JSON_HEDLEY_DEPRECATED) + #undef JSON_HEDLEY_DEPRECATED + #endif + #if defined(JSON_HEDLEY_DEPRECATED_FOR) + #undef JSON_HEDLEY_DEPRECATED_FOR + #endif + #if JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " #since)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) + #elif (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 13, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(18, 1, 0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18, 1, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 3, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 3, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) + #elif defined(__cplusplus) && (__cplusplus >= 201402L) + #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]]) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]]) + #elif JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \ + JSON_HEDLEY_PELLES_VERSION_CHECK(6, 50, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated") + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated") + #else + #define JSON_HEDLEY_DEPRECATED(since) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) + #endif + + #if defined(JSON_HEDLEY_UNAVAILABLE) + #undef JSON_HEDLEY_UNAVAILABLE + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 3, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) + #else + #define JSON_HEDLEY_UNAVAILABLE(available_since) + #endif + + #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT + #endif + #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0) && defined(__cplusplus)) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__)) + #elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]]) + #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #elif defined(_Check_return_) /* SAL */ + #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_ + #else + #define JSON_HEDLEY_WARN_UNUSED_RESULT + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) + #endif + + #if defined(JSON_HEDLEY_SENTINEL) + #undef JSON_HEDLEY_SENTINEL + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5, 4, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) + #else + #define JSON_HEDLEY_SENTINEL(position) + #endif + + #if defined(JSON_HEDLEY_NO_RETURN) + #undef JSON_HEDLEY_NO_RETURN + #endif + #if JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_NO_RETURN __noreturn + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) + #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + #define JSON_HEDLEY_NO_RETURN _Noreturn + #elif defined(__cplusplus) && (__cplusplus >= 201103L) + #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]]) + #elif JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 2, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0) + #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) + #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 0, 0) && defined(__cplusplus) + #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") + #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3, 2, 0) + #define JSON_HEDLEY_NO_RETURN __attribute((noreturn)) + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9, 0, 0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) + #else + #define JSON_HEDLEY_NO_RETURN + #endif + + #if defined(JSON_HEDLEY_NO_ESCAPE) + #undef JSON_HEDLEY_NO_ESCAPE + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(noescape) + #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__)) + #else + #define JSON_HEDLEY_NO_ESCAPE + #endif + #if defined(JSON_HEDLEY_UNREACHABLE) - #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1))) - #else - #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr) + #undef JSON_HEDLEY_UNREACHABLE #endif -#endif -#if defined(JSON_HEDLEY_UNREACHABLE) - #if \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) - #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value)) - #else - #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE() + #if defined(JSON_HEDLEY_UNREACHABLE_RETURN) + #undef JSON_HEDLEY_UNREACHABLE_RETURN #endif -#else - #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value) -#endif -#if !defined(JSON_HEDLEY_UNREACHABLE) - #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) -#endif + #if defined(JSON_HEDLEY_ASSUME) + #undef JSON_HEDLEY_ASSUME + #endif + #if JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_ASSUME(expr) __assume(expr) + #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) + #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) + #elif JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0) + #if defined(__cplusplus) + #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr) + #else + #define JSON_HEDLEY_ASSUME(expr) _nassert(expr) + #endif + #endif + #if (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18, 10, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 5) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(10, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() + #elif defined(JSON_HEDLEY_ASSUME) + #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) + #endif + #if !defined(JSON_HEDLEY_ASSUME) + #if defined(JSON_HEDLEY_UNREACHABLE) + #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1))) + #else + #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr) + #endif + #endif + #if defined(JSON_HEDLEY_UNREACHABLE) + #if JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0) + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value)) + #else + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE() + #endif + #else + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value) + #endif + #if !defined(JSON_HEDLEY_UNREACHABLE) + #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) + #endif JSON_HEDLEY_DIAGNOSTIC_PUSH -#if JSON_HEDLEY_HAS_WARNING("-Wpedantic") - #pragma clang diagnostic ignored "-Wpedantic" -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus) - #pragma clang diagnostic ignored "-Wc++98-compat-pedantic" -#endif -#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0) - #if defined(__clang__) - #pragma clang diagnostic ignored "-Wvariadic-macros" - #elif defined(JSON_HEDLEY_GCC_VERSION) - #pragma GCC diagnostic ignored "-Wvariadic-macros" + #if JSON_HEDLEY_HAS_WARNING("-Wpedantic") + #pragma clang diagnostic ignored "-Wpedantic" #endif -#endif -#if defined(JSON_HEDLEY_NON_NULL) - #undef JSON_HEDLEY_NON_NULL -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) - #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__))) -#else - #define JSON_HEDLEY_NON_NULL(...) -#endif + #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus) + #pragma clang diagnostic ignored "-Wc++98-compat-pedantic" + #endif + #if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros", 4, 0, 0) + #if defined(__clang__) + #pragma clang diagnostic ignored "-Wvariadic-macros" + #elif defined(JSON_HEDLEY_GCC_VERSION) + #pragma GCC diagnostic ignored "-Wvariadic-macros" + #endif + #endif + #if defined(JSON_HEDLEY_NON_NULL) + #undef JSON_HEDLEY_NON_NULL + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) + #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__))) + #else + #define JSON_HEDLEY_NON_NULL(...) + #endif JSON_HEDLEY_DIAGNOSTIC_POP -#if defined(JSON_HEDLEY_PRINTF_FORMAT) - #undef JSON_HEDLEY_PRINTF_FORMAT -#endif -#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO) - #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check))) -#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO) - #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check))) -#elif \ - JSON_HEDLEY_HAS_ATTRIBUTE(format) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0) - #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check)) -#else - #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) -#endif - -#if defined(JSON_HEDLEY_CONSTEXPR) - #undef JSON_HEDLEY_CONSTEXPR -#endif -#if defined(__cplusplus) - #if __cplusplus >= 201103L - #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr) + #if defined(JSON_HEDLEY_PRINTF_FORMAT) + #undef JSON_HEDLEY_PRINTF_FORMAT #endif -#endif -#if !defined(JSON_HEDLEY_CONSTEXPR) - #define JSON_HEDLEY_CONSTEXPR -#endif + #if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format, 4, 4, 0) && !defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check))) + #elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format, 4, 4, 0) && defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check))) + #elif JSON_HEDLEY_HAS_ATTRIBUTE(format) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6, 0, 0) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) __declspec(vaformat(printf, string_idx, first_to_check)) + #else + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) + #endif -#if defined(JSON_HEDLEY_PREDICT) - #undef JSON_HEDLEY_PREDICT -#endif -#if defined(JSON_HEDLEY_LIKELY) - #undef JSON_HEDLEY_LIKELY -#endif -#if defined(JSON_HEDLEY_UNLIKELY) - #undef JSON_HEDLEY_UNLIKELY -#endif -#if defined(JSON_HEDLEY_UNPREDICTABLE) - #undef JSON_HEDLEY_UNPREDICTABLE -#endif -#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable) - #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr)) -#endif -#if \ - (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) -# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability)) -# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability)) -# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability)) -# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 ) -# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 ) -#elif \ - (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \ - JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) -# define JSON_HEDLEY_PREDICT(expr, expected, probability) \ - (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))) -# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ - (__extension__ ({ \ - double hedley_probability_ = (probability); \ - ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \ - })) -# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \ - (__extension__ ({ \ - double hedley_probability_ = (probability); \ - ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \ - })) -# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) -# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) -#else -# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)) -# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr)) -# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr)) -# define JSON_HEDLEY_LIKELY(expr) (!!(expr)) -# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr)) -#endif -#if !defined(JSON_HEDLEY_UNPREDICTABLE) - #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5) -#endif + #if defined(JSON_HEDLEY_CONSTEXPR) + #undef JSON_HEDLEY_CONSTEXPR + #endif + #if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr) + #endif + #endif + #if !defined(JSON_HEDLEY_CONSTEXPR) + #define JSON_HEDLEY_CONSTEXPR + #endif -#if defined(JSON_HEDLEY_MALLOC) - #undef JSON_HEDLEY_MALLOC -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) - #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_MALLOC __declspec(restrict) -#else - #define JSON_HEDLEY_MALLOC -#endif + #if defined(JSON_HEDLEY_PREDICT) + #undef JSON_HEDLEY_PREDICT + #endif + #if defined(JSON_HEDLEY_LIKELY) + #undef JSON_HEDLEY_LIKELY + #endif + #if defined(JSON_HEDLEY_UNLIKELY) + #undef JSON_HEDLEY_UNLIKELY + #endif + #if defined(JSON_HEDLEY_UNPREDICTABLE) + #undef JSON_HEDLEY_UNPREDICTABLE + #endif + #if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable) + #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr)) + #endif + #if (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(9, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability((expr), (value), (probability)) + #define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1, (probability)) + #define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0, (probability)) + #define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) + #define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) + #elif (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0) && defined(__cplusplus)) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 7, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 1, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 1, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 27) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_PREDICT(expr, expected, probability) \ + (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))) + #define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ + (__extension__({ \ + double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \ + })) + #define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \ + (__extension__({ \ + double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \ + })) + #define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) + #define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) + #else + #define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)) + #define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr)) + #define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr)) + #define JSON_HEDLEY_LIKELY(expr) (!!(expr)) + #define JSON_HEDLEY_UNLIKELY(expr) (!!(expr)) + #endif + #if !defined(JSON_HEDLEY_UNPREDICTABLE) + #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5) + #endif -#if defined(JSON_HEDLEY_PURE) - #undef JSON_HEDLEY_PURE -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) -# define JSON_HEDLEY_PURE __attribute__((__pure__)) -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) -# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") -#elif defined(__cplusplus) && \ - ( \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \ - ) -# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;") -#else -# define JSON_HEDLEY_PURE -#endif + #if defined(JSON_HEDLEY_MALLOC) + #undef JSON_HEDLEY_MALLOC + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0) + #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_MALLOC __declspec(restrict) + #else + #define JSON_HEDLEY_MALLOC + #endif -#if defined(JSON_HEDLEY_CONST) - #undef JSON_HEDLEY_CONST -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(const) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_CONST __attribute__((__const__)) -#elif \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) - #define JSON_HEDLEY_CONST _Pragma("no_side_effect") -#else - #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE -#endif + #if defined(JSON_HEDLEY_PURE) + #undef JSON_HEDLEY_PURE + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2, 96, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_PURE __attribute__((__pure__)) + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0) + #define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") + #elif defined(__cplusplus) && \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(2, 0, 1) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0)) + #define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;") + #else + #define JSON_HEDLEY_PURE + #endif -#if defined(JSON_HEDLEY_RESTRICT) - #undef JSON_HEDLEY_RESTRICT -#endif -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus) - #define JSON_HEDLEY_RESTRICT restrict -#elif \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ - defined(__clang__) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_RESTRICT __restrict -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus) - #define JSON_HEDLEY_RESTRICT _Restrict -#else - #define JSON_HEDLEY_RESTRICT -#endif + #if defined(JSON_HEDLEY_CONST) + #undef JSON_HEDLEY_CONST + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(const) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2, 5, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_CONST __attribute__((__const__)) + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0) + #define JSON_HEDLEY_CONST _Pragma("no_side_effect") + #else + #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE + #endif -#if defined(JSON_HEDLEY_INLINE) - #undef JSON_HEDLEY_INLINE -#endif -#if \ - (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ - (defined(__cplusplus) && (__cplusplus >= 199711L)) - #define JSON_HEDLEY_INLINE inline -#elif \ - defined(JSON_HEDLEY_GCC_VERSION) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0) - #define JSON_HEDLEY_INLINE __inline__ -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_INLINE __inline -#else - #define JSON_HEDLEY_INLINE -#endif + #if defined(JSON_HEDLEY_RESTRICT) + #undef JSON_HEDLEY_RESTRICT + #endif + #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT restrict + #elif JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 4) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 1, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus)) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) || \ + defined(__clang__) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_RESTRICT __restrict + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 3, 0) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT _Restrict + #else + #define JSON_HEDLEY_RESTRICT + #endif -#if defined(JSON_HEDLEY_ALWAYS_INLINE) - #undef JSON_HEDLEY_ALWAYS_INLINE -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) -# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) -# define JSON_HEDLEY_ALWAYS_INLINE __forceinline -#elif defined(__cplusplus) && \ - ( \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \ - ) -# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;") -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) -# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced") -#else -# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE -#endif + #if defined(JSON_HEDLEY_INLINE) + #undef JSON_HEDLEY_INLINE + #endif + #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + (defined(__cplusplus) && (__cplusplus >= 199711L)) + #define JSON_HEDLEY_INLINE inline + #elif defined(JSON_HEDLEY_GCC_VERSION) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(6, 2, 0) + #define JSON_HEDLEY_INLINE __inline__ + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(12, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 1, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_INLINE __inline + #else + #define JSON_HEDLEY_INLINE + #endif -#if defined(JSON_HEDLEY_NEVER_INLINE) - #undef JSON_HEDLEY_NEVER_INLINE -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) - #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) -#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0) - #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") -#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) - #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;") -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never") -#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) - #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline)) -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) - #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) -#else - #define JSON_HEDLEY_NEVER_INLINE -#endif + #if defined(JSON_HEDLEY_ALWAYS_INLINE) + #undef JSON_HEDLEY_ALWAYS_INLINE + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0) + #define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(12, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_ALWAYS_INLINE __forceinline + #elif defined(__cplusplus) && \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 1, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0)) + #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;") + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced") + #else + #define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE + #endif -#if defined(JSON_HEDLEY_PRIVATE) - #undef JSON_HEDLEY_PRIVATE -#endif -#if defined(JSON_HEDLEY_PUBLIC) - #undef JSON_HEDLEY_PUBLIC -#endif -#if defined(JSON_HEDLEY_IMPORT) - #undef JSON_HEDLEY_IMPORT -#endif -#if defined(_WIN32) || defined(__CYGWIN__) -# define JSON_HEDLEY_PRIVATE -# define JSON_HEDLEY_PUBLIC __declspec(dllexport) -# define JSON_HEDLEY_IMPORT __declspec(dllimport) -#else -# if \ - JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ - ( \ - defined(__TI_EABI__) && \ - ( \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \ - ) \ - ) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) -# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) -# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) -# else -# define JSON_HEDLEY_PRIVATE -# define JSON_HEDLEY_PUBLIC -# endif -# define JSON_HEDLEY_IMPORT extern -#endif + #if defined(JSON_HEDLEY_NEVER_INLINE) + #undef JSON_HEDLEY_NEVER_INLINE + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0) + #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) + #elif JSON_HEDLEY_PGI_VERSION_CHECK(10, 2, 0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") + #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 0, 0) && defined(__cplusplus) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;") + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never") + #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3, 2, 0) + #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline)) + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9, 0, 0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) + #else + #define JSON_HEDLEY_NEVER_INLINE + #endif -#if defined(JSON_HEDLEY_NO_THROW) - #undef JSON_HEDLEY_NO_THROW -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) - #define JSON_HEDLEY_NO_THROW __declspec(nothrow) -#else - #define JSON_HEDLEY_NO_THROW -#endif + #if defined(JSON_HEDLEY_PRIVATE) + #undef JSON_HEDLEY_PRIVATE + #endif + #if defined(JSON_HEDLEY_PUBLIC) + #undef JSON_HEDLEY_PUBLIC + #endif + #if defined(JSON_HEDLEY_IMPORT) + #undef JSON_HEDLEY_IMPORT + #endif + #if defined(_WIN32) || defined(__CYGWIN__) + #define JSON_HEDLEY_PRIVATE + #define JSON_HEDLEY_PUBLIC __declspec(dllexport) + #define JSON_HEDLEY_IMPORT __declspec(dllimport) + #else + #if JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \ + (defined(__TI_EABI__) && \ + ((JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0))) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) + #define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) + #else + #define JSON_HEDLEY_PRIVATE + #define JSON_HEDLEY_PUBLIC + #endif + #define JSON_HEDLEY_IMPORT extern + #endif -#if defined(JSON_HEDLEY_FALL_THROUGH) - #undef JSON_HEDLEY_FALL_THROUGH -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) -#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough) - #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) -#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough) - #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]]) -#elif defined(__fallthrough) /* SAL */ - #define JSON_HEDLEY_FALL_THROUGH __fallthrough -#else - #define JSON_HEDLEY_FALL_THROUGH -#endif + #if defined(JSON_HEDLEY_NO_THROW) + #undef JSON_HEDLEY_NO_THROW + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 1, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) + #define JSON_HEDLEY_NO_THROW __declspec(nothrow) + #else + #define JSON_HEDLEY_NO_THROW + #endif -#if defined(JSON_HEDLEY_RETURNS_NON_NULL) - #undef JSON_HEDLEY_RETURNS_NON_NULL -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) -#elif defined(_Ret_notnull_) /* SAL */ - #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ -#else - #define JSON_HEDLEY_RETURNS_NON_NULL -#endif + #if defined(JSON_HEDLEY_FALL_THROUGH) + #undef JSON_HEDLEY_FALL_THROUGH + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(7, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) + #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang, fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) + #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]]) + #elif defined(__fallthrough) /* SAL */ + #define JSON_HEDLEY_FALL_THROUGH __fallthrough + #else + #define JSON_HEDLEY_FALL_THROUGH + #endif -#if defined(JSON_HEDLEY_ARRAY_PARAM) - #undef JSON_HEDLEY_ARRAY_PARAM -#endif -#if \ - defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ - !defined(__STDC_NO_VLA__) && \ - !defined(__cplusplus) && \ - !defined(JSON_HEDLEY_PGI_VERSION) && \ - !defined(JSON_HEDLEY_TINYC_VERSION) - #define JSON_HEDLEY_ARRAY_PARAM(name) (name) -#else - #define JSON_HEDLEY_ARRAY_PARAM(name) -#endif + #if defined(JSON_HEDLEY_RETURNS_NON_NULL) + #undef JSON_HEDLEY_RETURNS_NON_NULL + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) + #elif defined(_Ret_notnull_) /* SAL */ + #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ + #else + #define JSON_HEDLEY_RETURNS_NON_NULL + #endif -#if defined(JSON_HEDLEY_IS_CONSTANT) - #undef JSON_HEDLEY_IS_CONSTANT -#endif -#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR) - #undef JSON_HEDLEY_REQUIRE_CONSTEXPR -#endif -/* JSON_HEDLEY_IS_CONSTEXPR_ is for + #if defined(JSON_HEDLEY_ARRAY_PARAM) + #undef JSON_HEDLEY_ARRAY_PARAM + #endif + #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ + !defined(__STDC_NO_VLA__) && \ + !defined(__cplusplus) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_ARRAY_PARAM(name) (name) + #else + #define JSON_HEDLEY_ARRAY_PARAM(name) + #endif + + #if defined(JSON_HEDLEY_IS_CONSTANT) + #undef JSON_HEDLEY_IS_CONSTANT + #endif + #if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR) + #undef JSON_HEDLEY_REQUIRE_CONSTEXPR + #endif + /* JSON_HEDLEY_IS_CONSTEXPR_ is for HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ -#if defined(JSON_HEDLEY_IS_CONSTEXPR_) - #undef JSON_HEDLEY_IS_CONSTEXPR_ -#endif -#if \ - JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ - (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \ - JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) -#endif -#if !defined(__cplusplus) -# if \ - JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ - JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ - JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24) -#if defined(__INTPTR_TYPE__) - #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*) -#else - #include <stdint.h> - #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*) -#endif -# elif \ - ( \ - defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ - !defined(JSON_HEDLEY_SUNPRO_VERSION) && \ - !defined(JSON_HEDLEY_PGI_VERSION) && \ - !defined(JSON_HEDLEY_IAR_VERSION)) || \ - (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0) -#if defined(__INTPTR_TYPE__) - #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0) -#else - #include <stdint.h> - #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0) -#endif -# elif \ - defined(JSON_HEDLEY_GCC_VERSION) || \ - defined(JSON_HEDLEY_INTEL_VERSION) || \ - defined(JSON_HEDLEY_TINYC_VERSION) || \ - defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \ - defined(JSON_HEDLEY_TI_CL2000_VERSION) || \ - defined(JSON_HEDLEY_TI_CL6X_VERSION) || \ - defined(JSON_HEDLEY_TI_CL7X_VERSION) || \ - defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \ - defined(__clang__) -# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \ - sizeof(void) != \ - sizeof(*( \ - 1 ? \ - ((void*) ((expr) * 0L) ) : \ -((struct { char v[sizeof(void) * 2]; } *) 1) \ - ) \ - ) \ - ) -# endif -#endif -#if defined(JSON_HEDLEY_IS_CONSTEXPR_) - #if !defined(JSON_HEDLEY_IS_CONSTANT) - #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr) + #if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #undef JSON_HEDLEY_IS_CONSTEXPR_ #endif - #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1)) -#else - #if !defined(JSON_HEDLEY_IS_CONSTANT) - #define JSON_HEDLEY_IS_CONSTANT(expr) (0) + #if JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 19) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 1, 0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0) && !defined(__cplusplus)) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) #endif - #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr) -#endif + #if !defined(__cplusplus) + #if JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5, 4, 0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 24) + #if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*)((__INTPTR_TYPE__)((expr) * 0)) : (int*)0)), int*) + #else + #include <stdint.h> + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*)((intptr_t)((expr) * 0)) : (int*)0)), int*) + #endif + #elif ( \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ + !defined(JSON_HEDLEY_SUNPRO_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_IAR_VERSION)) || \ + (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(17, 0, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5, 3, 0) + #if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*)((__INTPTR_TYPE__)((expr) * 0)) : (int*)0), int*: 1, void*: 0) + #else + #include <stdint.h> + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*)((intptr_t) * 0) : (int*)0), int*: 1, void*: 0) + #endif + #elif defined(JSON_HEDLEY_GCC_VERSION) || \ + defined(JSON_HEDLEY_INTEL_VERSION) || \ + defined(JSON_HEDLEY_TINYC_VERSION) || \ + defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(18, 12, 0) || \ + defined(JSON_HEDLEY_TI_CL2000_VERSION) || \ + defined(JSON_HEDLEY_TI_CL6X_VERSION) || \ + defined(JSON_HEDLEY_TI_CL7X_VERSION) || \ + defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \ + defined(__clang__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \ + sizeof(void) != \ + sizeof(*( \ + 1 ? ((void*)((expr) * 0L)) : ((struct { char v[sizeof(void) * 2]; }*)1)))) + #endif + #endif + #if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1)) + #else + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) (0) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr) + #endif -#if defined(JSON_HEDLEY_BEGIN_C_DECLS) - #undef JSON_HEDLEY_BEGIN_C_DECLS -#endif -#if defined(JSON_HEDLEY_END_C_DECLS) - #undef JSON_HEDLEY_END_C_DECLS -#endif -#if defined(JSON_HEDLEY_C_DECL) - #undef JSON_HEDLEY_C_DECL -#endif -#if defined(__cplusplus) - #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" { - #define JSON_HEDLEY_END_C_DECLS } - #define JSON_HEDLEY_C_DECL extern "C" -#else - #define JSON_HEDLEY_BEGIN_C_DECLS - #define JSON_HEDLEY_END_C_DECLS - #define JSON_HEDLEY_C_DECL -#endif + #if defined(JSON_HEDLEY_BEGIN_C_DECLS) + #undef JSON_HEDLEY_BEGIN_C_DECLS + #endif + #if defined(JSON_HEDLEY_END_C_DECLS) + #undef JSON_HEDLEY_END_C_DECLS + #endif + #if defined(JSON_HEDLEY_C_DECL) + #undef JSON_HEDLEY_C_DECL + #endif + #if defined(__cplusplus) + #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" { + #define JSON_HEDLEY_END_C_DECLS } + #define JSON_HEDLEY_C_DECL extern "C" + #else + #define JSON_HEDLEY_BEGIN_C_DECLS + #define JSON_HEDLEY_END_C_DECLS + #define JSON_HEDLEY_C_DECL + #endif -#if defined(JSON_HEDLEY_STATIC_ASSERT) - #undef JSON_HEDLEY_STATIC_ASSERT -#endif -#if \ - !defined(__cplusplus) && ( \ - (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ - (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - defined(_Static_assert) \ - ) -# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) -#elif \ - (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ - JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) -# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) -#else -# define JSON_HEDLEY_STATIC_ASSERT(expr, message) -#endif + #if defined(JSON_HEDLEY_STATIC_ASSERT) + #undef JSON_HEDLEY_STATIC_ASSERT + #endif + #if !defined(__cplusplus) && ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ + (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(6, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + defined(_Static_assert)) + #define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) + #elif (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(16, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) + #else + #define JSON_HEDLEY_STATIC_ASSERT(expr, message) + #endif -#if defined(JSON_HEDLEY_NULL) - #undef JSON_HEDLEY_NULL -#endif -#if defined(__cplusplus) - #if __cplusplus >= 201103L - #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr) + #if defined(JSON_HEDLEY_NULL) + #undef JSON_HEDLEY_NULL + #endif + #if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr) + #elif defined(NULL) + #define JSON_HEDLEY_NULL NULL + #else + #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0) + #endif #elif defined(NULL) #define JSON_HEDLEY_NULL NULL #else - #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0) + #define JSON_HEDLEY_NULL ((void*)0) #endif -#elif defined(NULL) - #define JSON_HEDLEY_NULL NULL -#else - #define JSON_HEDLEY_NULL ((void*) 0) -#endif -#if defined(JSON_HEDLEY_MESSAGE) - #undef JSON_HEDLEY_MESSAGE -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") -# define JSON_HEDLEY_MESSAGE(msg) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ - JSON_HEDLEY_PRAGMA(message msg) \ - JSON_HEDLEY_DIAGNOSTIC_POP -#elif \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) -# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg) -#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) -# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg) -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) -# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0) -# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) -#else -# define JSON_HEDLEY_MESSAGE(msg) -#endif + #if defined(JSON_HEDLEY_MESSAGE) + #undef JSON_HEDLEY_MESSAGE + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") + #define JSON_HEDLEY_MESSAGE(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(message msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 4, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg) + #elif JSON_HEDLEY_CRAY_VERSION_CHECK(5, 0, 0) + #define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg) + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2, 0, 0) + #define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) + #else + #define JSON_HEDLEY_MESSAGE(msg) + #endif -#if defined(JSON_HEDLEY_WARNING) - #undef JSON_HEDLEY_WARNING -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") -# define JSON_HEDLEY_WARNING(msg) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ - JSON_HEDLEY_PRAGMA(clang warning msg) \ - JSON_HEDLEY_DIAGNOSTIC_POP -#elif \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) -# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) -# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) -#else -# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) -#endif + #if defined(JSON_HEDLEY_WARNING) + #undef JSON_HEDLEY_WARNING + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") + #define JSON_HEDLEY_WARNING(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(clang warning msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 8, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18, 4, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) + #else + #define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) + #endif -#if defined(JSON_HEDLEY_REQUIRE) - #undef JSON_HEDLEY_REQUIRE -#endif -#if defined(JSON_HEDLEY_REQUIRE_MSG) - #undef JSON_HEDLEY_REQUIRE_MSG -#endif -#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if) -# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat") -# define JSON_HEDLEY_REQUIRE(expr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ - __attribute__((diagnose_if(!(expr), #expr, "error"))) \ - JSON_HEDLEY_DIAGNOSTIC_POP -# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ - __attribute__((diagnose_if(!(expr), msg, "error"))) \ - JSON_HEDLEY_DIAGNOSTIC_POP -# else -# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error"))) -# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error"))) -# endif -#else -# define JSON_HEDLEY_REQUIRE(expr) -# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) -#endif + #if defined(JSON_HEDLEY_REQUIRE) + #undef JSON_HEDLEY_REQUIRE + #endif + #if defined(JSON_HEDLEY_REQUIRE_MSG) + #undef JSON_HEDLEY_REQUIRE_MSG + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if) + #if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat") + #define JSON_HEDLEY_REQUIRE(expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), #expr, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP + #define JSON_HEDLEY_REQUIRE_MSG(expr, msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), msg, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP + #else + #define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error"))) + #define JSON_HEDLEY_REQUIRE_MSG(expr, msg) __attribute__((diagnose_if(!(expr), msg, "error"))) + #endif + #else + #define JSON_HEDLEY_REQUIRE(expr) + #define JSON_HEDLEY_REQUIRE_MSG(expr, msg) + #endif -#if defined(JSON_HEDLEY_FLAGS) - #undef JSON_HEDLEY_FLAGS -#endif -#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion")) - #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) -#else - #define JSON_HEDLEY_FLAGS -#endif + #if defined(JSON_HEDLEY_FLAGS) + #undef JSON_HEDLEY_FLAGS + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion")) + #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) + #else + #define JSON_HEDLEY_FLAGS + #endif -#if defined(JSON_HEDLEY_FLAGS_CAST) - #undef JSON_HEDLEY_FLAGS_CAST -#endif -#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0) -# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("warning(disable:188)") \ - ((T) (expr)); \ - JSON_HEDLEY_DIAGNOSTIC_POP \ - })) -#else -# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr) -#endif + #if defined(JSON_HEDLEY_FLAGS_CAST) + #undef JSON_HEDLEY_FLAGS_CAST + #endif + #if JSON_HEDLEY_INTEL_VERSION_CHECK(19, 0, 0) + #define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("warning(disable:188)")((T)(expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) + #else + #define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr) + #endif -#if defined(JSON_HEDLEY_EMPTY_BASES) - #undef JSON_HEDLEY_EMPTY_BASES -#endif -#if \ - (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) -#else - #define JSON_HEDLEY_EMPTY_BASES -#endif + #if defined(JSON_HEDLEY_EMPTY_BASES) + #undef JSON_HEDLEY_EMPTY_BASES + #endif + #if (JSON_HEDLEY_MSVC_VERSION_CHECK(19, 0, 23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20, 0, 0)) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) + #else + #define JSON_HEDLEY_EMPTY_BASES + #endif /* Remaining macros are deprecated. */ -#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK) - #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK -#endif -#if defined(__clang__) - #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0) -#else - #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK + #endif + #if defined(__clang__) + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major, minor, patch) (0) + #else + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif -#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE) - #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE -#endif -#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) + #if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE + #endif + #define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) -#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE) - #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE -#endif -#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) + #if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE + #endif + #define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) -#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN) - #undef JSON_HEDLEY_CLANG_HAS_BUILTIN -#endif -#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin) + #if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN) + #undef JSON_HEDLEY_CLANG_HAS_BUILTIN + #endif + #define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin) -#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE) - #undef JSON_HEDLEY_CLANG_HAS_FEATURE -#endif -#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature) + #if defined(JSON_HEDLEY_CLANG_HAS_FEATURE) + #undef JSON_HEDLEY_CLANG_HAS_FEATURE + #endif + #define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature) -#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION) - #undef JSON_HEDLEY_CLANG_HAS_EXTENSION -#endif -#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension) + #if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION) + #undef JSON_HEDLEY_CLANG_HAS_EXTENSION + #endif + #define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension) -#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE) - #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE -#endif -#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) + #if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE + #endif + #define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) -#if defined(JSON_HEDLEY_CLANG_HAS_WARNING) - #undef JSON_HEDLEY_CLANG_HAS_WARNING -#endif -#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning) + #if defined(JSON_HEDLEY_CLANG_HAS_WARNING) + #undef JSON_HEDLEY_CLANG_HAS_WARNING + #endif + #define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning) #endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8b72ea6..5719c72 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp
@@ -18,18 +18,18 @@ #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ -#include <algorithm> // all_of, find, for_each -#include <cstddef> // nullptr_t, ptrdiff_t, size_t -#include <functional> // hash, less -#include <initializer_list> // initializer_list +#include <algorithm> // all_of, find, for_each +#include <cstddef> // nullptr_t, ptrdiff_t, size_t +#include <functional> // hash, less +#include <initializer_list> // initializer_list #ifndef JSON_NO_IO - #include <iosfwd> // istream, ostream -#endif // JSON_NO_IO -#include <iterator> // random_access_iterator_tag -#include <memory> // unique_ptr -#include <string> // string, stoi, to_string -#include <utility> // declval, forward, move, pair, swap -#include <vector> // vector + #include <iosfwd> // istream, ostream +#endif // JSON_NO_IO +#include <iterator> // random_access_iterator_tag +#include <memory> // unique_ptr +#include <string> // string, stoi, to_string +#include <utility> // declval, forward, move, pair, swap +#include <vector> // vector // #include <nlohmann/adl_serializer.hpp> // __ _____ _____ _____ @@ -40,8 +40,6 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - #include <utility> // #include <nlohmann/detail/abi_macros.hpp> @@ -53,8 +51,6 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK @@ -94,56 +90,54 @@ #endif // Construct the namespace ABI tags component -#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b +#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi##a##b #define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) -#define NLOHMANN_JSON_ABI_TAGS \ - NLOHMANN_JSON_ABI_TAGS_CONCAT( \ - NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ - NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) +#define NLOHMANN_JSON_ABI_TAGS \ + NLOHMANN_JSON_ABI_TAGS_CONCAT( \ + NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ + NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) // Construct the namespace version component #define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ - _v ## major ## _ ## minor ## _ ## patch + _v##major##_##minor##_##patch #define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) #if NLOHMANN_JSON_NAMESPACE_NO_VERSION -#define NLOHMANN_JSON_NAMESPACE_VERSION + #define NLOHMANN_JSON_NAMESPACE_VERSION #else -#define NLOHMANN_JSON_NAMESPACE_VERSION \ - NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ - NLOHMANN_JSON_VERSION_MINOR, \ - NLOHMANN_JSON_VERSION_PATCH) + #define NLOHMANN_JSON_NAMESPACE_VERSION \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH) #endif // Combine namespace components -#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b +#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a##b #define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) #ifndef NLOHMANN_JSON_NAMESPACE -#define NLOHMANN_JSON_NAMESPACE \ - nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ - NLOHMANN_JSON_ABI_TAGS, \ + #define NLOHMANN_JSON_NAMESPACE \ + nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ NLOHMANN_JSON_NAMESPACE_VERSION) #endif #ifndef NLOHMANN_JSON_NAMESPACE_BEGIN -#define NLOHMANN_JSON_NAMESPACE_BEGIN \ - namespace nlohmann \ - { \ - inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ - NLOHMANN_JSON_ABI_TAGS, \ - NLOHMANN_JSON_NAMESPACE_VERSION) \ - { + #define NLOHMANN_JSON_NAMESPACE_BEGIN \ + namespace nlohmann { \ + inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) { #endif #ifndef NLOHMANN_JSON_NAMESPACE_END -#define NLOHMANN_JSON_NAMESPACE_END \ - } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ - } // namespace nlohmann + #define NLOHMANN_JSON_NAMESPACE_END \ + } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ + } // namespace nlohmann #endif // #include <nlohmann/detail/conversions/from_json.hpp> @@ -155,19 +149,17 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <algorithm> // transform -#include <array> // array -#include <forward_list> // forward_list -#include <iterator> // inserter, front_inserter, end -#include <map> // map -#include <string> // string -#include <tuple> // tuple, make_tuple -#include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible -#include <unordered_map> // unordered_map -#include <utility> // pair, declval -#include <valarray> // valarray +#include <algorithm> // transform +#include <array> // array +#include <forward_list> // forward_list +#include <iterator> // inserter, front_inserter, end +#include <map> // map +#include <string> // string +#include <tuple> // tuple, make_tuple +#include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible +#include <unordered_map> // unordered_map +#include <utility> // pair, declval +#include <valarray> // valarray // #include <nlohmann/detail/exceptions.hpp> // __ _____ _____ _____ @@ -178,18 +170,16 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <cstddef> // nullptr_t -#include <exception> // exception +#include <cstddef> // nullptr_t +#include <exception> // exception #if JSON_DIAGNOSTICS - #include <numeric> // accumulate + #include <numeric> // accumulate #endif -#include <stdexcept> // runtime_error -#include <string> // to_string -#include <vector> // vector +#include <stdexcept> // runtime_error +#include <string> // to_string +#include <vector> // vector -// #include <nlohmann/detail/value_t.hpp> +// #include <nlohmann/detail/input/position_t.hpp> // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.3 @@ -198,12 +188,32 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT +#include <cstddef> // size_t +// #include <nlohmann/detail/abi_macros.hpp> -#include <array> // array -#include <cstddef> // size_t -#include <cstdint> // uint8_t -#include <string> // string +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail { + +/// struct to capture the start position of the current token +struct position_t +{ + /// the total number of characters read + std::size_t chars_read_total = 0; + /// the number of characters read in the current line + std::size_t chars_read_current_line = 0; + /// the number of lines read + std::size_t lines_read = 0; + + /// conversion to size_t to preserve SAX interface + constexpr operator size_t() const + { + return chars_read_total; + } +}; + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END // #include <nlohmann/detail/macro_scope.hpp> // __ _____ _____ _____ @@ -214,9 +224,6 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <utility> // declval, pair // #include <nlohmann/detail/meta/detected.hpp> // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ @@ -226,8 +233,6 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - #include <type_traits> // #include <nlohmann/detail/meta/void_t.hpp> @@ -239,28 +244,24 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - // #include <nlohmann/detail/abi_macros.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { -template<typename ...Ts> struct make_void +template<typename... Ts> +struct make_void { using type = void; }; -template<typename ...Ts> using void_t = typename make_void<Ts...>::type; +template<typename... Ts> +using void_t = typename make_void<Ts...>::type; } // namespace detail NLOHMANN_JSON_NAMESPACE_END - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { // https://en.cppreference.com/w/cpp/experimental/is_detected struct nonesuch @@ -275,7 +276,8 @@ template<class Default, class AlwaysVoid, - template<class...> class Op, + template<class...> + class Op, class... Args> struct detector { @@ -294,7 +296,8 @@ using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t; template<template<class...> class Op, class... Args> -struct is_detected_lazy : is_detected<Op, Args...> { }; +struct is_detected_lazy : is_detected<Op, Args...> +{}; template<template<class...> class Op, class... Args> using detected_t = typename detector<nonesuch, void, Op, Args...>::type; @@ -317,7 +320,6 @@ // #include <nlohmann/thirdparty/hedley/hedley.hpp> - // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.3 @@ -332,2043 +334,1962 @@ */ #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15) -#if defined(JSON_HEDLEY_VERSION) - #undef JSON_HEDLEY_VERSION -#endif -#define JSON_HEDLEY_VERSION 15 - -#if defined(JSON_HEDLEY_STRINGIFY_EX) - #undef JSON_HEDLEY_STRINGIFY_EX -#endif -#define JSON_HEDLEY_STRINGIFY_EX(x) #x - -#if defined(JSON_HEDLEY_STRINGIFY) - #undef JSON_HEDLEY_STRINGIFY -#endif -#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x) - -#if defined(JSON_HEDLEY_CONCAT_EX) - #undef JSON_HEDLEY_CONCAT_EX -#endif -#define JSON_HEDLEY_CONCAT_EX(a,b) a##b - -#if defined(JSON_HEDLEY_CONCAT) - #undef JSON_HEDLEY_CONCAT -#endif -#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b) - -#if defined(JSON_HEDLEY_CONCAT3_EX) - #undef JSON_HEDLEY_CONCAT3_EX -#endif -#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c - -#if defined(JSON_HEDLEY_CONCAT3) - #undef JSON_HEDLEY_CONCAT3 -#endif -#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c) - -#if defined(JSON_HEDLEY_VERSION_ENCODE) - #undef JSON_HEDLEY_VERSION_ENCODE -#endif -#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision)) - -#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR) - #undef JSON_HEDLEY_VERSION_DECODE_MAJOR -#endif -#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000) - -#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR) - #undef JSON_HEDLEY_VERSION_DECODE_MINOR -#endif -#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000) - -#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION) - #undef JSON_HEDLEY_VERSION_DECODE_REVISION -#endif -#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000) - -#if defined(JSON_HEDLEY_GNUC_VERSION) - #undef JSON_HEDLEY_GNUC_VERSION -#endif -#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) - #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) -#elif defined(__GNUC__) - #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0) -#endif - -#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK) - #undef JSON_HEDLEY_GNUC_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_GNUC_VERSION) - #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_MSVC_VERSION) - #undef JSON_HEDLEY_MSVC_VERSION -#endif -#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL) - #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) -#elif defined(_MSC_FULL_VER) && !defined(__ICL) - #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) -#elif defined(_MSC_VER) && !defined(__ICL) - #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) -#endif - -#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) - #undef JSON_HEDLEY_MSVC_VERSION_CHECK -#endif -#if !defined(JSON_HEDLEY_MSVC_VERSION) - #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0) -#elif defined(_MSC_VER) && (_MSC_VER >= 1400) - #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) -#elif defined(_MSC_VER) && (_MSC_VER >= 1200) - #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) -#else - #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor))) -#endif - -#if defined(JSON_HEDLEY_INTEL_VERSION) - #undef JSON_HEDLEY_INTEL_VERSION -#endif -#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL) - #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) -#elif defined(__INTEL_COMPILER) && !defined(__ICL) - #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) -#endif - -#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK) - #undef JSON_HEDLEY_INTEL_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_INTEL_VERSION) - #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_INTEL_CL_VERSION) - #undef JSON_HEDLEY_INTEL_CL_VERSION -#endif -#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL) - #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0) -#endif - -#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK) - #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_INTEL_CL_VERSION) - #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_PGI_VERSION) - #undef JSON_HEDLEY_PGI_VERSION -#endif -#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) - #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) -#endif - -#if defined(JSON_HEDLEY_PGI_VERSION_CHECK) - #undef JSON_HEDLEY_PGI_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_PGI_VERSION) - #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_SUNPRO_VERSION) - #undef JSON_HEDLEY_SUNPRO_VERSION -#endif -#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) - #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10) -#elif defined(__SUNPRO_C) - #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf) -#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) - #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10) -#elif defined(__SUNPRO_CC) - #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf) -#endif - -#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK) - #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_SUNPRO_VERSION) - #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) - #undef JSON_HEDLEY_EMSCRIPTEN_VERSION -#endif -#if defined(__EMSCRIPTEN__) - #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__) -#endif - -#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK) - #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) - #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_ARM_VERSION) - #undef JSON_HEDLEY_ARM_VERSION -#endif -#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) - #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100) -#elif defined(__CC_ARM) && defined(__ARMCC_VERSION) - #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100) -#endif - -#if defined(JSON_HEDLEY_ARM_VERSION_CHECK) - #undef JSON_HEDLEY_ARM_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_ARM_VERSION) - #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_IBM_VERSION) - #undef JSON_HEDLEY_IBM_VERSION -#endif -#if defined(__ibmxl__) - #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__) -#elif defined(__xlC__) && defined(__xlC_ver__) - #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) -#elif defined(__xlC__) - #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0) -#endif - -#if defined(JSON_HEDLEY_IBM_VERSION_CHECK) - #undef JSON_HEDLEY_IBM_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_IBM_VERSION) - #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_VERSION) - #undef JSON_HEDLEY_TI_VERSION -#endif -#if \ - defined(__TI_COMPILER_VERSION__) && \ - ( \ - defined(__TMS470__) || defined(__TI_ARM__) || \ - defined(__MSP430__) || \ - defined(__TMS320C2000__) \ - ) -#if (__TI_COMPILER_VERSION__ >= 16000000) - #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif -#endif - -#if defined(JSON_HEDLEY_TI_VERSION_CHECK) - #undef JSON_HEDLEY_TI_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_VERSION) - #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_CL2000_VERSION) - #undef JSON_HEDLEY_TI_CL2000_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__) - #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK) - #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_CL2000_VERSION) - #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_CL430_VERSION) - #undef JSON_HEDLEY_TI_CL430_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__) - #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK) - #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_CL430_VERSION) - #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) - #undef JSON_HEDLEY_TI_ARMCL_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__)) - #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK) - #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) - #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_CL6X_VERSION) - #undef JSON_HEDLEY_TI_CL6X_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__) - #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK) - #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_CL6X_VERSION) - #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_CL7X_VERSION) - #undef JSON_HEDLEY_TI_CL7X_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__) - #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK) - #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_CL7X_VERSION) - #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) - #undef JSON_HEDLEY_TI_CLPRU_VERSION -#endif -#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__) - #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) -#endif - -#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK) - #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) - #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_CRAY_VERSION) - #undef JSON_HEDLEY_CRAY_VERSION -#endif -#if defined(_CRAYC) - #if defined(_RELEASE_PATCHLEVEL) - #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL) - #else - #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0) + #if defined(JSON_HEDLEY_VERSION) + #undef JSON_HEDLEY_VERSION #endif -#endif + #define JSON_HEDLEY_VERSION 15 -#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK) - #undef JSON_HEDLEY_CRAY_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_CRAY_VERSION) - #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0) -#endif - -#if defined(JSON_HEDLEY_IAR_VERSION) - #undef JSON_HEDLEY_IAR_VERSION -#endif -#if defined(__IAR_SYSTEMS_ICC__) - #if __VER__ > 1000 - #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) - #else - #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0) + #if defined(JSON_HEDLEY_STRINGIFY_EX) + #undef JSON_HEDLEY_STRINGIFY_EX #endif -#endif + #define JSON_HEDLEY_STRINGIFY_EX(x) #x -#if defined(JSON_HEDLEY_IAR_VERSION_CHECK) - #undef JSON_HEDLEY_IAR_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_IAR_VERSION) - #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_STRINGIFY) + #undef JSON_HEDLEY_STRINGIFY + #endif + #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x) -#if defined(JSON_HEDLEY_TINYC_VERSION) - #undef JSON_HEDLEY_TINYC_VERSION -#endif -#if defined(__TINYC__) - #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) -#endif + #if defined(JSON_HEDLEY_CONCAT_EX) + #undef JSON_HEDLEY_CONCAT_EX + #endif + #define JSON_HEDLEY_CONCAT_EX(a, b) a##b -#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK) - #undef JSON_HEDLEY_TINYC_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_TINYC_VERSION) - #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_CONCAT) + #undef JSON_HEDLEY_CONCAT + #endif + #define JSON_HEDLEY_CONCAT(a, b) JSON_HEDLEY_CONCAT_EX(a, b) -#if defined(JSON_HEDLEY_DMC_VERSION) - #undef JSON_HEDLEY_DMC_VERSION -#endif -#if defined(__DMC__) - #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf) -#endif + #if defined(JSON_HEDLEY_CONCAT3_EX) + #undef JSON_HEDLEY_CONCAT3_EX + #endif + #define JSON_HEDLEY_CONCAT3_EX(a, b, c) a##b##c -#if defined(JSON_HEDLEY_DMC_VERSION_CHECK) - #undef JSON_HEDLEY_DMC_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_DMC_VERSION) - #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_CONCAT3) + #undef JSON_HEDLEY_CONCAT3 + #endif + #define JSON_HEDLEY_CONCAT3(a, b, c) JSON_HEDLEY_CONCAT3_EX(a, b, c) -#if defined(JSON_HEDLEY_COMPCERT_VERSION) - #undef JSON_HEDLEY_COMPCERT_VERSION -#endif -#if defined(__COMPCERT_VERSION__) - #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100) -#endif + #if defined(JSON_HEDLEY_VERSION_ENCODE) + #undef JSON_HEDLEY_VERSION_ENCODE + #endif + #define JSON_HEDLEY_VERSION_ENCODE(major, minor, revision) (((major) * 1000000) + ((minor) * 1000) + (revision)) -#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK) - #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_COMPCERT_VERSION) - #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR) + #undef JSON_HEDLEY_VERSION_DECODE_MAJOR + #endif + #define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000) -#if defined(JSON_HEDLEY_PELLES_VERSION) - #undef JSON_HEDLEY_PELLES_VERSION -#endif -#if defined(__POCC__) - #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0) -#endif + #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR) + #undef JSON_HEDLEY_VERSION_DECODE_MINOR + #endif + #define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000) -#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK) - #undef JSON_HEDLEY_PELLES_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_PELLES_VERSION) - #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_VERSION_DECODE_REVISION) + #undef JSON_HEDLEY_VERSION_DECODE_REVISION + #endif + #define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000) -#if defined(JSON_HEDLEY_MCST_LCC_VERSION) - #undef JSON_HEDLEY_MCST_LCC_VERSION -#endif -#if defined(__LCC__) && defined(__LCC_MINOR__) - #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__) -#endif + #if defined(JSON_HEDLEY_GNUC_VERSION) + #undef JSON_HEDLEY_GNUC_VERSION + #endif + #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) + #elif defined(__GNUC__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0) + #endif -#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK) - #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_MCST_LCC_VERSION) - #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_GNUC_VERSION_CHECK) + #undef JSON_HEDLEY_GNUC_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_GNUC_VERSION) + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GCC_VERSION) - #undef JSON_HEDLEY_GCC_VERSION -#endif -#if \ - defined(JSON_HEDLEY_GNUC_VERSION) && \ - !defined(__clang__) && \ - !defined(JSON_HEDLEY_INTEL_VERSION) && \ - !defined(JSON_HEDLEY_PGI_VERSION) && \ - !defined(JSON_HEDLEY_ARM_VERSION) && \ - !defined(JSON_HEDLEY_CRAY_VERSION) && \ - !defined(JSON_HEDLEY_TI_VERSION) && \ - !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \ - !defined(JSON_HEDLEY_TI_CL430_VERSION) && \ - !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \ - !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \ - !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \ - !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \ - !defined(__COMPCERT__) && \ - !defined(JSON_HEDLEY_MCST_LCC_VERSION) - #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION -#endif + #if defined(JSON_HEDLEY_MSVC_VERSION) + #undef JSON_HEDLEY_MSVC_VERSION + #endif + #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) + #elif defined(_MSC_FULL_VER) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) + #elif defined(_MSC_VER) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) + #endif -#if defined(JSON_HEDLEY_GCC_VERSION_CHECK) - #undef JSON_HEDLEY_GCC_VERSION_CHECK -#endif -#if defined(JSON_HEDLEY_GCC_VERSION) - #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) -#else - #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0) -#endif + #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) + #undef JSON_HEDLEY_MSVC_VERSION_CHECK + #endif + #if !defined(JSON_HEDLEY_MSVC_VERSION) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) (0) + #elif defined(_MSC_VER) && (_MSC_VER >= 1400) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) + #elif defined(_MSC_VER) && (_MSC_VER >= 1200) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) + #else + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) (_MSC_VER >= ((major * 100) + (minor))) + #endif -#if defined(JSON_HEDLEY_HAS_ATTRIBUTE) - #undef JSON_HEDLEY_HAS_ATTRIBUTE -#endif -#if \ - defined(__has_attribute) && \ - ( \ - (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \ - ) -# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) -#else -# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) -#endif + #if defined(JSON_HEDLEY_INTEL_VERSION) + #undef JSON_HEDLEY_INTEL_VERSION + #endif + #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) + #elif defined(__INTEL_COMPILER) && !defined(__ICL) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) - #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE -#endif -#if defined(__has_attribute) - #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) -#else - #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_INTEL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_INTEL_VERSION) + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE) - #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE -#endif -#if defined(__has_attribute) - #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) -#else - #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_INTEL_CL_VERSION) + #undef JSON_HEDLEY_INTEL_CL_VERSION + #endif + #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL) + #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0) + #endif -#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE) - #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE -#endif -#if \ - defined(__has_cpp_attribute) && \ - defined(__cplusplus) && \ - (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) - #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute) -#else - #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0) -#endif + #if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_INTEL_CL_VERSION) + #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS) - #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS -#endif -#if !defined(__cplusplus) || !defined(__has_cpp_attribute) - #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) -#elif \ - !defined(JSON_HEDLEY_PGI_VERSION) && \ - !defined(JSON_HEDLEY_IAR_VERSION) && \ - (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \ - (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0)) - #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute) -#else - #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) -#endif + #if defined(JSON_HEDLEY_PGI_VERSION) + #undef JSON_HEDLEY_PGI_VERSION + #endif + #if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) + #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE) - #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE -#endif -#if defined(__has_cpp_attribute) && defined(__cplusplus) - #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) -#else - #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_PGI_VERSION_CHECK) + #undef JSON_HEDLEY_PGI_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_PGI_VERSION) + #define JSON_HEDLEY_PGI_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_PGI_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE) - #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE -#endif -#if defined(__has_cpp_attribute) && defined(__cplusplus) - #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) -#else - #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_SUNPRO_VERSION) + #undef JSON_HEDLEY_SUNPRO_VERSION + #endif + #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10) + #elif defined(__SUNPRO_C) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf) + #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10) + #elif defined(__SUNPRO_CC) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf) + #endif -#if defined(JSON_HEDLEY_HAS_BUILTIN) - #undef JSON_HEDLEY_HAS_BUILTIN -#endif -#if defined(__has_builtin) - #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin) -#else - #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0) -#endif + #if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK) + #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_SUNPRO_VERSION) + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN) - #undef JSON_HEDLEY_GNUC_HAS_BUILTIN -#endif -#if defined(__has_builtin) - #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) -#else - #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION + #endif + #if defined(__EMSCRIPTEN__) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN) - #undef JSON_HEDLEY_GCC_HAS_BUILTIN -#endif -#if defined(__has_builtin) - #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) -#else - #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_HAS_FEATURE) - #undef JSON_HEDLEY_HAS_FEATURE -#endif -#if defined(__has_feature) - #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature) -#else - #define JSON_HEDLEY_HAS_FEATURE(feature) (0) -#endif + #if defined(JSON_HEDLEY_ARM_VERSION) + #undef JSON_HEDLEY_ARM_VERSION + #endif + #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100) + #elif defined(__CC_ARM) && defined(__ARMCC_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE) - #undef JSON_HEDLEY_GNUC_HAS_FEATURE -#endif -#if defined(__has_feature) - #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) -#else - #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_ARM_VERSION_CHECK) + #undef JSON_HEDLEY_ARM_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_ARM_VERSION) + #define JSON_HEDLEY_ARM_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_ARM_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_FEATURE) - #undef JSON_HEDLEY_GCC_HAS_FEATURE -#endif -#if defined(__has_feature) - #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) -#else - #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_IBM_VERSION) + #undef JSON_HEDLEY_IBM_VERSION + #endif + #if defined(__ibmxl__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__) + #elif defined(__xlC__) && defined(__xlC_ver__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) + #elif defined(__xlC__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0) + #endif -#if defined(JSON_HEDLEY_HAS_EXTENSION) - #undef JSON_HEDLEY_HAS_EXTENSION -#endif -#if defined(__has_extension) - #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension) -#else - #define JSON_HEDLEY_HAS_EXTENSION(extension) (0) -#endif + #if defined(JSON_HEDLEY_IBM_VERSION_CHECK) + #undef JSON_HEDLEY_IBM_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_IBM_VERSION) + #define JSON_HEDLEY_IBM_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_IBM_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION) - #undef JSON_HEDLEY_GNUC_HAS_EXTENSION -#endif -#if defined(__has_extension) - #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) -#else - #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_VERSION) + #undef JSON_HEDLEY_TI_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && \ + (defined(__TMS470__) || defined(__TI_ARM__) || \ + defined(__MSP430__) || \ + defined(__TMS320C2000__)) + #if (__TI_COMPILER_VERSION__ >= 16000000) + #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif + #endif -#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION) - #undef JSON_HEDLEY_GCC_HAS_EXTENSION -#endif -#if defined(__has_extension) - #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) -#else - #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_VERSION_CHECK) + #undef JSON_HEDLEY_TI_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_VERSION) + #define JSON_HEDLEY_TI_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE) - #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE -#endif -#if defined(__has_declspec_attribute) - #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute) -#else - #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0) -#endif + #if defined(JSON_HEDLEY_TI_CL2000_VERSION) + #undef JSON_HEDLEY_TI_CL2000_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__) + #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE) - #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE -#endif -#if defined(__has_declspec_attribute) - #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) -#else - #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_CL2000_VERSION) + #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE) - #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE -#endif -#if defined(__has_declspec_attribute) - #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) -#else - #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_CL430_VERSION) + #undef JSON_HEDLEY_TI_CL430_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__) + #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif -#if defined(JSON_HEDLEY_HAS_WARNING) - #undef JSON_HEDLEY_HAS_WARNING -#endif -#if defined(__has_warning) - #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning) -#else - #define JSON_HEDLEY_HAS_WARNING(warning) (0) -#endif + #if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_CL430_VERSION) + #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major, minor, patch) (0) + #endif -#if defined(JSON_HEDLEY_GNUC_HAS_WARNING) - #undef JSON_HEDLEY_GNUC_HAS_WARNING -#endif -#if defined(__has_warning) - #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) -#else - #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_ARMCL_VERSION) + #undef JSON_HEDLEY_TI_ARMCL_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__)) + #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif -#if defined(JSON_HEDLEY_GCC_HAS_WARNING) - #undef JSON_HEDLEY_GCC_HAS_WARNING -#endif -#if defined(__has_warning) - #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) -#else - #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK) + #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_ARMCL_VERSION) + #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major, minor, patch) (0) + #endif -#if \ - (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ - defined(__clang__) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \ - JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \ - (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR)) - #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value) -#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) - #define JSON_HEDLEY_PRAGMA(value) __pragma(value) -#else - #define JSON_HEDLEY_PRAGMA(value) -#endif + #if defined(JSON_HEDLEY_TI_CL6X_VERSION) + #undef JSON_HEDLEY_TI_CL6X_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__) + #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif -#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH) - #undef JSON_HEDLEY_DIAGNOSTIC_PUSH -#endif -#if defined(JSON_HEDLEY_DIAGNOSTIC_POP) - #undef JSON_HEDLEY_DIAGNOSTIC_POP -#endif -#if defined(__clang__) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") -#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push)) - #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop)) -#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop") -#elif \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop") -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) - #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") - #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") -#else - #define JSON_HEDLEY_DIAGNOSTIC_PUSH - #define JSON_HEDLEY_DIAGNOSTIC_POP -#endif + #if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_CL6X_VERSION) + #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major, minor, patch) (0) + #endif -/* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for + #if defined(JSON_HEDLEY_TI_CL7X_VERSION) + #undef JSON_HEDLEY_TI_CL7X_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && defined(__C7000__) + #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif + + #if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_CL7X_VERSION) + #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_TI_CLPRU_VERSION) + #undef JSON_HEDLEY_TI_CLPRU_VERSION + #endif + #if defined(__TI_COMPILER_VERSION__) && defined(__PRU__) + #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) + #endif + + #if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TI_CLPRU_VERSION) + #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_CRAY_VERSION) + #undef JSON_HEDLEY_CRAY_VERSION + #endif + #if defined(_CRAYC) + #if defined(_RELEASE_PATCHLEVEL) + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL) + #else + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0) + #endif + #endif + + #if defined(JSON_HEDLEY_CRAY_VERSION_CHECK) + #undef JSON_HEDLEY_CRAY_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_CRAY_VERSION) + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_IAR_VERSION) + #undef JSON_HEDLEY_IAR_VERSION + #endif + #if defined(__IAR_SYSTEMS_ICC__) + #if __VER__ > 1000 + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) + #else + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0) + #endif + #endif + + #if defined(JSON_HEDLEY_IAR_VERSION_CHECK) + #undef JSON_HEDLEY_IAR_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_IAR_VERSION) + #define JSON_HEDLEY_IAR_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_IAR_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_TINYC_VERSION) + #undef JSON_HEDLEY_TINYC_VERSION + #endif + #if defined(__TINYC__) + #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) + #endif + + #if defined(JSON_HEDLEY_TINYC_VERSION_CHECK) + #undef JSON_HEDLEY_TINYC_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_DMC_VERSION) + #undef JSON_HEDLEY_DMC_VERSION + #endif + #if defined(__DMC__) + #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf) + #endif + + #if defined(JSON_HEDLEY_DMC_VERSION_CHECK) + #undef JSON_HEDLEY_DMC_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_DMC_VERSION) + #define JSON_HEDLEY_DMC_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_DMC_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_COMPCERT_VERSION) + #undef JSON_HEDLEY_COMPCERT_VERSION + #endif + #if defined(__COMPCERT_VERSION__) + #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100) + #endif + + #if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK) + #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_COMPCERT_VERSION) + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_PELLES_VERSION) + #undef JSON_HEDLEY_PELLES_VERSION + #endif + #if defined(__POCC__) + #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0) + #endif + + #if defined(JSON_HEDLEY_PELLES_VERSION_CHECK) + #undef JSON_HEDLEY_PELLES_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_PELLES_VERSION) + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_MCST_LCC_VERSION) + #undef JSON_HEDLEY_MCST_LCC_VERSION + #endif + #if defined(__LCC__) && defined(__LCC_MINOR__) + #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__) + #endif + + #if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK) + #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_MCST_LCC_VERSION) + #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_GCC_VERSION) + #undef JSON_HEDLEY_GCC_VERSION + #endif + #if defined(JSON_HEDLEY_GNUC_VERSION) && \ + !defined(__clang__) && \ + !defined(JSON_HEDLEY_INTEL_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_ARM_VERSION) && \ + !defined(JSON_HEDLEY_CRAY_VERSION) && \ + !defined(JSON_HEDLEY_TI_VERSION) && \ + !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL430_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \ + !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \ + !defined(__COMPCERT__) && \ + !defined(JSON_HEDLEY_MCST_LCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION + #endif + + #if defined(JSON_HEDLEY_GCC_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_VERSION_CHECK + #endif + #if defined(JSON_HEDLEY_GCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) + #else + #define JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) (0) + #endif + + #if defined(JSON_HEDLEY_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_ATTRIBUTE + #endif + #if defined(__has_attribute) && \ + ((!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8, 5, 9))) + #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) + #else + #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE + #endif + #if defined(__has_attribute) + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) + #else + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE + #endif + #if defined(__has_attribute) + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) + #else + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE + #endif + #if defined(__has_cpp_attribute) && \ + defined(__cplusplus) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute) + #else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0) + #endif + + #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS + #endif + #if !defined(__cplusplus) || !defined(__has_cpp_attribute) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns, attribute) (0) + #elif !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_IAR_VERSION) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0)) && \ + (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19, 20, 0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns, attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute) + #else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns, attribute) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE + #endif + #if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) __has_cpp_attribute(attribute) + #else + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE + #endif + #if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) __has_cpp_attribute(attribute) + #else + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_BUILTIN) + #undef JSON_HEDLEY_HAS_BUILTIN + #endif + #if defined(__has_builtin) + #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin) + #else + #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN) + #undef JSON_HEDLEY_GNUC_HAS_BUILTIN + #endif + #if defined(__has_builtin) + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin, major, minor, patch) __has_builtin(builtin) + #else + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_BUILTIN) + #undef JSON_HEDLEY_GCC_HAS_BUILTIN + #endif + #if defined(__has_builtin) + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin, major, minor, patch) __has_builtin(builtin) + #else + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_FEATURE) + #undef JSON_HEDLEY_HAS_FEATURE + #endif + #if defined(__has_feature) + #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature) + #else + #define JSON_HEDLEY_HAS_FEATURE(feature) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_FEATURE) + #undef JSON_HEDLEY_GNUC_HAS_FEATURE + #endif + #if defined(__has_feature) + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature, major, minor, patch) __has_feature(feature) + #else + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_FEATURE) + #undef JSON_HEDLEY_GCC_HAS_FEATURE + #endif + #if defined(__has_feature) + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature, major, minor, patch) __has_feature(feature) + #else + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_EXTENSION) + #undef JSON_HEDLEY_HAS_EXTENSION + #endif + #if defined(__has_extension) + #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension) + #else + #define JSON_HEDLEY_HAS_EXTENSION(extension) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION) + #undef JSON_HEDLEY_GNUC_HAS_EXTENSION + #endif + #if defined(__has_extension) + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension, major, minor, patch) __has_extension(extension) + #else + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_EXTENSION) + #undef JSON_HEDLEY_GCC_HAS_EXTENSION + #endif + #if defined(__has_extension) + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension, major, minor, patch) __has_extension(extension) + #else + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE + #endif + #if defined(__has_declspec_attribute) + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute) + #else + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE + #endif + #if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) __has_declspec_attribute(attribute) + #else + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE + #endif + #if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) __has_declspec_attribute(attribute) + #else + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_HAS_WARNING) + #undef JSON_HEDLEY_HAS_WARNING + #endif + #if defined(__has_warning) + #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning) + #else + #define JSON_HEDLEY_HAS_WARNING(warning) (0) + #endif + + #if defined(JSON_HEDLEY_GNUC_HAS_WARNING) + #undef JSON_HEDLEY_GNUC_HAS_WARNING + #endif + #if defined(__has_warning) + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning, major, minor, patch) __has_warning(warning) + #else + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning, major, minor, patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) + #endif + + #if defined(JSON_HEDLEY_GCC_HAS_WARNING) + #undef JSON_HEDLEY_GCC_HAS_WARNING + #endif + #if defined(__has_warning) + #define JSON_HEDLEY_GCC_HAS_WARNING(warning, major, minor, patch) __has_warning(warning) + #else + #define JSON_HEDLEY_GCC_HAS_WARNING(warning, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif + + #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + defined(__clang__) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18, 4, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 7, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(2, 0, 1) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 1, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 0, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(5, 0, 0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 17) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(8, 0, 0) || \ + (JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) && defined(__C99_PRAGMA_OPERATOR)) + #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) + #define JSON_HEDLEY_PRAGMA(value) __pragma(value) + #else + #define JSON_HEDLEY_PRAGMA(value) + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH) + #undef JSON_HEDLEY_DIAGNOSTIC_PUSH + #endif + #if defined(JSON_HEDLEY_DIAGNOSTIC_POP) + #undef JSON_HEDLEY_DIAGNOSTIC_POP + #endif + #if defined(__clang__) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push)) + #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop)) + #elif JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop") + #elif JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 4, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 1, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop") + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2, 90, 0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") + #else + #define JSON_HEDLEY_DIAGNOSTIC_PUSH + #define JSON_HEDLEY_DIAGNOSTIC_POP + #endif + + /* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ -#endif -#if defined(__cplusplus) -# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") -# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions") -# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions") -# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ - _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ - _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \ - xpr \ - JSON_HEDLEY_DIAGNOSTIC_POP -# else -# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ - _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ - xpr \ - JSON_HEDLEY_DIAGNOSTIC_POP -# endif -# else -# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ - xpr \ - JSON_HEDLEY_DIAGNOSTIC_POP -# endif -# endif -#endif -#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x -#endif - -#if defined(JSON_HEDLEY_CONST_CAST) - #undef JSON_HEDLEY_CONST_CAST -#endif -#if defined(__cplusplus) -# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr)) -#elif \ - JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) -# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \ - ((T) (expr)); \ - JSON_HEDLEY_DIAGNOSTIC_POP \ - })) -#else -# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr)) -#endif - -#if defined(JSON_HEDLEY_REINTERPRET_CAST) - #undef JSON_HEDLEY_REINTERPRET_CAST -#endif -#if defined(__cplusplus) - #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr)) -#else - #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr)) -#endif - -#if defined(JSON_HEDLEY_STATIC_CAST) - #undef JSON_HEDLEY_STATIC_CAST -#endif -#if defined(__cplusplus) - #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr)) -#else - #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr)) -#endif - -#if defined(JSON_HEDLEY_CPP_CAST) - #undef JSON_HEDLEY_CPP_CAST -#endif -#if defined(__cplusplus) -# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast") -# define JSON_HEDLEY_CPP_CAST(T, expr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \ - ((T) (expr)) \ - JSON_HEDLEY_DIAGNOSTIC_POP -# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0) -# define JSON_HEDLEY_CPP_CAST(T, expr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("diag_suppress=Pe137") \ - JSON_HEDLEY_DIAGNOSTIC_POP -# else -# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr)) -# endif -#else -# define JSON_HEDLEY_CPP_CAST(T, expr) (expr) -#endif - -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations") - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") -#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") -#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786)) -#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445") -#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") -#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996)) -#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") -#elif \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718") -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)") -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)") -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215") -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)") -#else - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED -#endif - -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") -#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") -#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161)) -#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") -#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068)) -#elif \ - JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") -#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") -#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161") -#else - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS -#endif - -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes") - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") -#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") -#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292)) -#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030)) -#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098") -#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)") -#elif \ - JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097") -#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") -#else - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES -#endif - -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual") - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"") -#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") -#else - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL -#endif - -#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION) - #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wunused-function") - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"") -#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"") -#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505)) -#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142") -#else - #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION -#endif - -#if defined(JSON_HEDLEY_DEPRECATED) - #undef JSON_HEDLEY_DEPRECATED -#endif -#if defined(JSON_HEDLEY_DEPRECATED_FOR) - #undef JSON_HEDLEY_DEPRECATED_FOR -#endif -#if \ - JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since)) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) -#elif \ - (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) -#elif defined(__cplusplus) && (__cplusplus >= 201402L) - #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]]) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]]) -#elif \ - JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) - #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ - JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated") - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated") -#else - #define JSON_HEDLEY_DEPRECATED(since) - #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) -#endif - -#if defined(JSON_HEDLEY_UNAVAILABLE) - #undef JSON_HEDLEY_UNAVAILABLE -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) -#else - #define JSON_HEDLEY_UNAVAILABLE(available_since) -#endif - -#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT) - #undef JSON_HEDLEY_WARN_UNUSED_RESULT -#endif -#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG) - #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) - #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__)) -#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L) - #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) - #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]]) -#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) - #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) - #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) -#elif defined(_Check_return_) /* SAL */ - #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ - #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_ -#else - #define JSON_HEDLEY_WARN_UNUSED_RESULT - #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) -#endif - -#if defined(JSON_HEDLEY_SENTINEL) - #undef JSON_HEDLEY_SENTINEL -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) -#else - #define JSON_HEDLEY_SENTINEL(position) -#endif - -#if defined(JSON_HEDLEY_NO_RETURN) - #undef JSON_HEDLEY_NO_RETURN -#endif -#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_NO_RETURN __noreturn -#elif \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) -#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L - #define JSON_HEDLEY_NO_RETURN _Noreturn -#elif defined(__cplusplus) && (__cplusplus >= 201103L) - #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]]) -#elif \ - JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) - #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) - #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) -#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) - #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") -#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) - #define JSON_HEDLEY_NO_RETURN __attribute((noreturn)) -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) - #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) -#else - #define JSON_HEDLEY_NO_RETURN -#endif - -#if defined(JSON_HEDLEY_NO_ESCAPE) - #undef JSON_HEDLEY_NO_ESCAPE -#endif -#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape) - #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__)) -#else - #define JSON_HEDLEY_NO_ESCAPE -#endif - -#if defined(JSON_HEDLEY_UNREACHABLE) - #undef JSON_HEDLEY_UNREACHABLE -#endif -#if defined(JSON_HEDLEY_UNREACHABLE_RETURN) - #undef JSON_HEDLEY_UNREACHABLE_RETURN -#endif -#if defined(JSON_HEDLEY_ASSUME) - #undef JSON_HEDLEY_ASSUME -#endif -#if \ - JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_ASSUME(expr) __assume(expr) -#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) - #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) -#elif \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ + #endif #if defined(__cplusplus) - #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr) - #else - #define JSON_HEDLEY_ASSUME(expr) _nassert(expr) + #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") + #if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions") + #if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ + _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP + #endif + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP + #endif + #endif #endif -#endif -#if \ - (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \ - JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() -#elif defined(JSON_HEDLEY_ASSUME) - #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) -#endif -#if !defined(JSON_HEDLEY_ASSUME) + #if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x + #endif + + #if defined(JSON_HEDLEY_CONST_CAST) + #undef JSON_HEDLEY_CONST_CAST + #endif + #if defined(__cplusplus) + #define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr)) + #elif JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL((T)(expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) + #else + #define JSON_HEDLEY_CONST_CAST(T, expr) ((T)(expr)) + #endif + + #if defined(JSON_HEDLEY_REINTERPRET_CAST) + #undef JSON_HEDLEY_REINTERPRET_CAST + #endif + #if defined(__cplusplus) + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr)) + #else + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T)(expr)) + #endif + + #if defined(JSON_HEDLEY_STATIC_CAST) + #undef JSON_HEDLEY_STATIC_CAST + #endif + #if defined(__cplusplus) + #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr)) + #else + #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T)(expr)) + #endif + + #if defined(JSON_HEDLEY_CPP_CAST) + #undef JSON_HEDLEY_CPP_CAST + #endif + #if defined(__cplusplus) + #if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast") + #define JSON_HEDLEY_CPP_CAST(T, expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wold-style-cast\"")((T)(expr)) \ + JSON_HEDLEY_DIAGNOSTIC_POP + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 3, 0) + #define JSON_HEDLEY_CPP_CAST(T, expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("diag_suppress=Pe137") \ + JSON_HEDLEY_DIAGNOSTIC_POP + #else + #define JSON_HEDLEY_CPP_CAST(T, expr) ((T)(expr)) + #endif + #else + #define JSON_HEDLEY_CPP_CAST(T, expr) (expr) + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") + #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable : 1478 1786)) + #elif JSON_HEDLEY_PGI_VERSION_CHECK(20, 7, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445") + #elif JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 3, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable : 4996)) + #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") + #elif JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718") + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 13, 0) && !defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)") + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 13, 0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)") + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215") + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2, 90, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)") + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") + #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable : 161)) + #elif JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 3, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable : 4068)) + #elif JSON_HEDLEY_TI_VERSION_CHECK(16, 9, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 3, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") + #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") + #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161") + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(17, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") + #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable : 1292)) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(19, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable : 5030)) + #elif JSON_HEDLEY_PGI_VERSION_CHECK(20, 7, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098") + #elif JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)") + #elif JSON_HEDLEY_TI_VERSION_CHECK(18, 1, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 3, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097") + #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wcast-qual") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"") + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL + #endif + + #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wunused-function") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"") + #elif JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(1, 0, 0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable : 4505)) + #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142") + #else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION + #endif + + #if defined(JSON_HEDLEY_DEPRECATED) + #undef JSON_HEDLEY_DEPRECATED + #endif + #if defined(JSON_HEDLEY_DEPRECATED_FOR) + #undef JSON_HEDLEY_DEPRECATED_FOR + #endif + #if JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " #since)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) + #elif (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 13, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(18, 1, 0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18, 1, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 3, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 3, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) + #elif defined(__cplusplus) && (__cplusplus >= 201402L) + #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]]) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]]) + #elif JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \ + JSON_HEDLEY_PELLES_VERSION_CHECK(6, 50, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated") + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated") + #else + #define JSON_HEDLEY_DEPRECATED(since) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) + #endif + + #if defined(JSON_HEDLEY_UNAVAILABLE) + #undef JSON_HEDLEY_UNAVAILABLE + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 3, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) + #else + #define JSON_HEDLEY_UNAVAILABLE(available_since) + #endif + + #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT + #endif + #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0) && defined(__cplusplus)) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__)) + #elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]]) + #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #elif defined(_Check_return_) /* SAL */ + #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_ + #else + #define JSON_HEDLEY_WARN_UNUSED_RESULT + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) + #endif + + #if defined(JSON_HEDLEY_SENTINEL) + #undef JSON_HEDLEY_SENTINEL + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5, 4, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) + #else + #define JSON_HEDLEY_SENTINEL(position) + #endif + + #if defined(JSON_HEDLEY_NO_RETURN) + #undef JSON_HEDLEY_NO_RETURN + #endif + #if JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_NO_RETURN __noreturn + #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) + #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + #define JSON_HEDLEY_NO_RETURN _Noreturn + #elif defined(__cplusplus) && (__cplusplus >= 201103L) + #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]]) + #elif JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 2, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0) + #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) + #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 0, 0) && defined(__cplusplus) + #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") + #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3, 2, 0) + #define JSON_HEDLEY_NO_RETURN __attribute((noreturn)) + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9, 0, 0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) + #else + #define JSON_HEDLEY_NO_RETURN + #endif + + #if defined(JSON_HEDLEY_NO_ESCAPE) + #undef JSON_HEDLEY_NO_ESCAPE + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(noescape) + #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__)) + #else + #define JSON_HEDLEY_NO_ESCAPE + #endif + #if defined(JSON_HEDLEY_UNREACHABLE) - #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1))) - #else - #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr) + #undef JSON_HEDLEY_UNREACHABLE #endif -#endif -#if defined(JSON_HEDLEY_UNREACHABLE) - #if \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) - #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value)) - #else - #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE() + #if defined(JSON_HEDLEY_UNREACHABLE_RETURN) + #undef JSON_HEDLEY_UNREACHABLE_RETURN #endif -#else - #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value) -#endif -#if !defined(JSON_HEDLEY_UNREACHABLE) - #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) -#endif + #if defined(JSON_HEDLEY_ASSUME) + #undef JSON_HEDLEY_ASSUME + #endif + #if JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_ASSUME(expr) __assume(expr) + #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) + #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) + #elif JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0) + #if defined(__cplusplus) + #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr) + #else + #define JSON_HEDLEY_ASSUME(expr) _nassert(expr) + #endif + #endif + #if (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18, 10, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 5) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(10, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() + #elif defined(JSON_HEDLEY_ASSUME) + #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) + #endif + #if !defined(JSON_HEDLEY_ASSUME) + #if defined(JSON_HEDLEY_UNREACHABLE) + #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1))) + #else + #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr) + #endif + #endif + #if defined(JSON_HEDLEY_UNREACHABLE) + #if JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0) + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value)) + #else + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE() + #endif + #else + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value) + #endif + #if !defined(JSON_HEDLEY_UNREACHABLE) + #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) + #endif JSON_HEDLEY_DIAGNOSTIC_PUSH -#if JSON_HEDLEY_HAS_WARNING("-Wpedantic") - #pragma clang diagnostic ignored "-Wpedantic" -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus) - #pragma clang diagnostic ignored "-Wc++98-compat-pedantic" -#endif -#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0) - #if defined(__clang__) - #pragma clang diagnostic ignored "-Wvariadic-macros" - #elif defined(JSON_HEDLEY_GCC_VERSION) - #pragma GCC diagnostic ignored "-Wvariadic-macros" + #if JSON_HEDLEY_HAS_WARNING("-Wpedantic") + #pragma clang diagnostic ignored "-Wpedantic" #endif -#endif -#if defined(JSON_HEDLEY_NON_NULL) - #undef JSON_HEDLEY_NON_NULL -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) - #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__))) -#else - #define JSON_HEDLEY_NON_NULL(...) -#endif + #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus) + #pragma clang diagnostic ignored "-Wc++98-compat-pedantic" + #endif + #if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros", 4, 0, 0) + #if defined(__clang__) + #pragma clang diagnostic ignored "-Wvariadic-macros" + #elif defined(JSON_HEDLEY_GCC_VERSION) + #pragma GCC diagnostic ignored "-Wvariadic-macros" + #endif + #endif + #if defined(JSON_HEDLEY_NON_NULL) + #undef JSON_HEDLEY_NON_NULL + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) + #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__))) + #else + #define JSON_HEDLEY_NON_NULL(...) + #endif JSON_HEDLEY_DIAGNOSTIC_POP -#if defined(JSON_HEDLEY_PRINTF_FORMAT) - #undef JSON_HEDLEY_PRINTF_FORMAT -#endif -#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO) - #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check))) -#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO) - #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check))) -#elif \ - JSON_HEDLEY_HAS_ATTRIBUTE(format) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0) - #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check)) -#else - #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) -#endif - -#if defined(JSON_HEDLEY_CONSTEXPR) - #undef JSON_HEDLEY_CONSTEXPR -#endif -#if defined(__cplusplus) - #if __cplusplus >= 201103L - #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr) + #if defined(JSON_HEDLEY_PRINTF_FORMAT) + #undef JSON_HEDLEY_PRINTF_FORMAT #endif -#endif -#if !defined(JSON_HEDLEY_CONSTEXPR) - #define JSON_HEDLEY_CONSTEXPR -#endif + #if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format, 4, 4, 0) && !defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check))) + #elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format, 4, 4, 0) && defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check))) + #elif JSON_HEDLEY_HAS_ATTRIBUTE(format) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6, 0, 0) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) __declspec(vaformat(printf, string_idx, first_to_check)) + #else + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) + #endif -#if defined(JSON_HEDLEY_PREDICT) - #undef JSON_HEDLEY_PREDICT -#endif -#if defined(JSON_HEDLEY_LIKELY) - #undef JSON_HEDLEY_LIKELY -#endif -#if defined(JSON_HEDLEY_UNLIKELY) - #undef JSON_HEDLEY_UNLIKELY -#endif -#if defined(JSON_HEDLEY_UNPREDICTABLE) - #undef JSON_HEDLEY_UNPREDICTABLE -#endif -#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable) - #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr)) -#endif -#if \ - (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) -# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability)) -# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability)) -# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability)) -# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 ) -# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 ) -#elif \ - (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \ - JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) -# define JSON_HEDLEY_PREDICT(expr, expected, probability) \ - (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))) -# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ - (__extension__ ({ \ - double hedley_probability_ = (probability); \ - ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \ - })) -# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \ - (__extension__ ({ \ - double hedley_probability_ = (probability); \ - ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \ - })) -# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) -# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) -#else -# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)) -# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr)) -# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr)) -# define JSON_HEDLEY_LIKELY(expr) (!!(expr)) -# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr)) -#endif -#if !defined(JSON_HEDLEY_UNPREDICTABLE) - #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5) -#endif + #if defined(JSON_HEDLEY_CONSTEXPR) + #undef JSON_HEDLEY_CONSTEXPR + #endif + #if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr) + #endif + #endif + #if !defined(JSON_HEDLEY_CONSTEXPR) + #define JSON_HEDLEY_CONSTEXPR + #endif -#if defined(JSON_HEDLEY_MALLOC) - #undef JSON_HEDLEY_MALLOC -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) - #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_MALLOC __declspec(restrict) -#else - #define JSON_HEDLEY_MALLOC -#endif + #if defined(JSON_HEDLEY_PREDICT) + #undef JSON_HEDLEY_PREDICT + #endif + #if defined(JSON_HEDLEY_LIKELY) + #undef JSON_HEDLEY_LIKELY + #endif + #if defined(JSON_HEDLEY_UNLIKELY) + #undef JSON_HEDLEY_UNLIKELY + #endif + #if defined(JSON_HEDLEY_UNPREDICTABLE) + #undef JSON_HEDLEY_UNPREDICTABLE + #endif + #if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable) + #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr)) + #endif + #if (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(9, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability((expr), (value), (probability)) + #define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1, (probability)) + #define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0, (probability)) + #define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) + #define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) + #elif (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0) && defined(__cplusplus)) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 7, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 1, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 1, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 27) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_PREDICT(expr, expected, probability) \ + (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))) + #define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ + (__extension__({ \ + double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \ + })) + #define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \ + (__extension__({ \ + double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \ + })) + #define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) + #define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) + #else + #define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)) + #define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr)) + #define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr)) + #define JSON_HEDLEY_LIKELY(expr) (!!(expr)) + #define JSON_HEDLEY_UNLIKELY(expr) (!!(expr)) + #endif + #if !defined(JSON_HEDLEY_UNPREDICTABLE) + #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5) + #endif -#if defined(JSON_HEDLEY_PURE) - #undef JSON_HEDLEY_PURE -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) -# define JSON_HEDLEY_PURE __attribute__((__pure__)) -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) -# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") -#elif defined(__cplusplus) && \ - ( \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \ - ) -# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;") -#else -# define JSON_HEDLEY_PURE -#endif + #if defined(JSON_HEDLEY_MALLOC) + #undef JSON_HEDLEY_MALLOC + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0) + #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_MALLOC __declspec(restrict) + #else + #define JSON_HEDLEY_MALLOC + #endif -#if defined(JSON_HEDLEY_CONST) - #undef JSON_HEDLEY_CONST -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(const) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_CONST __attribute__((__const__)) -#elif \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) - #define JSON_HEDLEY_CONST _Pragma("no_side_effect") -#else - #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE -#endif + #if defined(JSON_HEDLEY_PURE) + #undef JSON_HEDLEY_PURE + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2, 96, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_PURE __attribute__((__pure__)) + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0) + #define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") + #elif defined(__cplusplus) && \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(2, 0, 1) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0)) + #define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;") + #else + #define JSON_HEDLEY_PURE + #endif -#if defined(JSON_HEDLEY_RESTRICT) - #undef JSON_HEDLEY_RESTRICT -#endif -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus) - #define JSON_HEDLEY_RESTRICT restrict -#elif \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ - defined(__clang__) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_RESTRICT __restrict -#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus) - #define JSON_HEDLEY_RESTRICT _Restrict -#else - #define JSON_HEDLEY_RESTRICT -#endif + #if defined(JSON_HEDLEY_CONST) + #undef JSON_HEDLEY_CONST + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(const) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2, 5, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_CONST __attribute__((__const__)) + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0) + #define JSON_HEDLEY_CONST _Pragma("no_side_effect") + #else + #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE + #endif -#if defined(JSON_HEDLEY_INLINE) - #undef JSON_HEDLEY_INLINE -#endif -#if \ - (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ - (defined(__cplusplus) && (__cplusplus >= 199711L)) - #define JSON_HEDLEY_INLINE inline -#elif \ - defined(JSON_HEDLEY_GCC_VERSION) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0) - #define JSON_HEDLEY_INLINE __inline__ -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_INLINE __inline -#else - #define JSON_HEDLEY_INLINE -#endif + #if defined(JSON_HEDLEY_RESTRICT) + #undef JSON_HEDLEY_RESTRICT + #endif + #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT restrict + #elif JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 4) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 1, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus)) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) || \ + defined(__clang__) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_RESTRICT __restrict + #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 3, 0) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT _Restrict + #else + #define JSON_HEDLEY_RESTRICT + #endif -#if defined(JSON_HEDLEY_ALWAYS_INLINE) - #undef JSON_HEDLEY_ALWAYS_INLINE -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) -# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) -# define JSON_HEDLEY_ALWAYS_INLINE __forceinline -#elif defined(__cplusplus) && \ - ( \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \ - ) -# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;") -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) -# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced") -#else -# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE -#endif + #if defined(JSON_HEDLEY_INLINE) + #undef JSON_HEDLEY_INLINE + #endif + #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + (defined(__cplusplus) && (__cplusplus >= 199711L)) + #define JSON_HEDLEY_INLINE inline + #elif defined(JSON_HEDLEY_GCC_VERSION) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(6, 2, 0) + #define JSON_HEDLEY_INLINE __inline__ + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(12, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 1, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(3, 1, 0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_INLINE __inline + #else + #define JSON_HEDLEY_INLINE + #endif -#if defined(JSON_HEDLEY_NEVER_INLINE) - #undef JSON_HEDLEY_NEVER_INLINE -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ - JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ - (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ - (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ - (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ - JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ - JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ - JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) - #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) -#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0) - #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") -#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) - #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;") -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) - #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never") -#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) - #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline)) -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) - #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) -#else - #define JSON_HEDLEY_NEVER_INLINE -#endif + #if defined(JSON_HEDLEY_ALWAYS_INLINE) + #undef JSON_HEDLEY_ALWAYS_INLINE + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0) + #define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(12, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_ALWAYS_INLINE __forceinline + #elif defined(__cplusplus) && \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 1, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0)) + #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;") + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced") + #else + #define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE + #endif -#if defined(JSON_HEDLEY_PRIVATE) - #undef JSON_HEDLEY_PRIVATE -#endif -#if defined(JSON_HEDLEY_PUBLIC) - #undef JSON_HEDLEY_PUBLIC -#endif -#if defined(JSON_HEDLEY_IMPORT) - #undef JSON_HEDLEY_IMPORT -#endif -#if defined(_WIN32) || defined(__CYGWIN__) -# define JSON_HEDLEY_PRIVATE -# define JSON_HEDLEY_PUBLIC __declspec(dllexport) -# define JSON_HEDLEY_IMPORT __declspec(dllimport) -#else -# if \ - JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ - JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ - ( \ - defined(__TI_EABI__) && \ - ( \ - (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \ - ) \ - ) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) -# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) -# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) -# else -# define JSON_HEDLEY_PRIVATE -# define JSON_HEDLEY_PUBLIC -# endif -# define JSON_HEDLEY_IMPORT extern -#endif + #if defined(JSON_HEDLEY_NEVER_INLINE) + #undef JSON_HEDLEY_NEVER_INLINE + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0) + #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) + #elif JSON_HEDLEY_PGI_VERSION_CHECK(10, 2, 0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") + #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 0, 0) && defined(__cplusplus) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;") + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never") + #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3, 2, 0) + #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline)) + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9, 0, 0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) + #else + #define JSON_HEDLEY_NEVER_INLINE + #endif -#if defined(JSON_HEDLEY_NO_THROW) - #undef JSON_HEDLEY_NO_THROW -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) - #define JSON_HEDLEY_NO_THROW __declspec(nothrow) -#else - #define JSON_HEDLEY_NO_THROW -#endif + #if defined(JSON_HEDLEY_PRIVATE) + #undef JSON_HEDLEY_PRIVATE + #endif + #if defined(JSON_HEDLEY_PUBLIC) + #undef JSON_HEDLEY_PUBLIC + #endif + #if defined(JSON_HEDLEY_IMPORT) + #undef JSON_HEDLEY_IMPORT + #endif + #if defined(_WIN32) || defined(__CYGWIN__) + #define JSON_HEDLEY_PRIVATE + #define JSON_HEDLEY_PUBLIC __declspec(dllexport) + #define JSON_HEDLEY_IMPORT __declspec(dllimport) + #else + #if JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \ + (defined(__TI_EABI__) && \ + ((JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0))) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) + #define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) + #else + #define JSON_HEDLEY_PRIVATE + #define JSON_HEDLEY_PUBLIC + #endif + #define JSON_HEDLEY_IMPORT extern + #endif -#if defined(JSON_HEDLEY_FALL_THROUGH) - #undef JSON_HEDLEY_FALL_THROUGH -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) -#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough) - #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) -#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough) - #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]]) -#elif defined(__fallthrough) /* SAL */ - #define JSON_HEDLEY_FALL_THROUGH __fallthrough -#else - #define JSON_HEDLEY_FALL_THROUGH -#endif + #if defined(JSON_HEDLEY_NO_THROW) + #undef JSON_HEDLEY_NO_THROW + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 1, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) + #define JSON_HEDLEY_NO_THROW __declspec(nothrow) + #else + #define JSON_HEDLEY_NO_THROW + #endif -#if defined(JSON_HEDLEY_RETURNS_NON_NULL) - #undef JSON_HEDLEY_RETURNS_NON_NULL -#endif -#if \ - JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) -#elif defined(_Ret_notnull_) /* SAL */ - #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ -#else - #define JSON_HEDLEY_RETURNS_NON_NULL -#endif + #if defined(JSON_HEDLEY_FALL_THROUGH) + #undef JSON_HEDLEY_FALL_THROUGH + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(7, 0, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) + #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang, fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) + #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]]) + #elif defined(__fallthrough) /* SAL */ + #define JSON_HEDLEY_FALL_THROUGH __fallthrough + #else + #define JSON_HEDLEY_FALL_THROUGH + #endif -#if defined(JSON_HEDLEY_ARRAY_PARAM) - #undef JSON_HEDLEY_ARRAY_PARAM -#endif -#if \ - defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ - !defined(__STDC_NO_VLA__) && \ - !defined(__cplusplus) && \ - !defined(JSON_HEDLEY_PGI_VERSION) && \ - !defined(JSON_HEDLEY_TINYC_VERSION) - #define JSON_HEDLEY_ARRAY_PARAM(name) (name) -#else - #define JSON_HEDLEY_ARRAY_PARAM(name) -#endif + #if defined(JSON_HEDLEY_RETURNS_NON_NULL) + #undef JSON_HEDLEY_RETURNS_NON_NULL + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) + #elif defined(_Ret_notnull_) /* SAL */ + #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ + #else + #define JSON_HEDLEY_RETURNS_NON_NULL + #endif -#if defined(JSON_HEDLEY_IS_CONSTANT) - #undef JSON_HEDLEY_IS_CONSTANT -#endif -#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR) - #undef JSON_HEDLEY_REQUIRE_CONSTEXPR -#endif -/* JSON_HEDLEY_IS_CONSTEXPR_ is for + #if defined(JSON_HEDLEY_ARRAY_PARAM) + #undef JSON_HEDLEY_ARRAY_PARAM + #endif + #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ + !defined(__STDC_NO_VLA__) && \ + !defined(__cplusplus) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_ARRAY_PARAM(name) (name) + #else + #define JSON_HEDLEY_ARRAY_PARAM(name) + #endif + + #if defined(JSON_HEDLEY_IS_CONSTANT) + #undef JSON_HEDLEY_IS_CONSTANT + #endif + #if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR) + #undef JSON_HEDLEY_REQUIRE_CONSTEXPR + #endif + /* JSON_HEDLEY_IS_CONSTEXPR_ is for HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ -#if defined(JSON_HEDLEY_IS_CONSTEXPR_) - #undef JSON_HEDLEY_IS_CONSTEXPR_ -#endif -#if \ - JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ - JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ - (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \ - JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ - JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) - #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) -#endif -#if !defined(__cplusplus) -# if \ - JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ - JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ - JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24) -#if defined(__INTPTR_TYPE__) - #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*) -#else - #include <stdint.h> - #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*) -#endif -# elif \ - ( \ - defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ - !defined(JSON_HEDLEY_SUNPRO_VERSION) && \ - !defined(JSON_HEDLEY_PGI_VERSION) && \ - !defined(JSON_HEDLEY_IAR_VERSION)) || \ - (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ - JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0) -#if defined(__INTPTR_TYPE__) - #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0) -#else - #include <stdint.h> - #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0) -#endif -# elif \ - defined(JSON_HEDLEY_GCC_VERSION) || \ - defined(JSON_HEDLEY_INTEL_VERSION) || \ - defined(JSON_HEDLEY_TINYC_VERSION) || \ - defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \ - JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \ - defined(JSON_HEDLEY_TI_CL2000_VERSION) || \ - defined(JSON_HEDLEY_TI_CL6X_VERSION) || \ - defined(JSON_HEDLEY_TI_CL7X_VERSION) || \ - defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \ - defined(__clang__) -# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \ - sizeof(void) != \ - sizeof(*( \ - 1 ? \ - ((void*) ((expr) * 0L) ) : \ -((struct { char v[sizeof(void) * 2]; } *) 1) \ - ) \ - ) \ - ) -# endif -#endif -#if defined(JSON_HEDLEY_IS_CONSTEXPR_) - #if !defined(JSON_HEDLEY_IS_CONSTANT) - #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr) + #if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #undef JSON_HEDLEY_IS_CONSTEXPR_ #endif - #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1)) -#else - #if !defined(JSON_HEDLEY_IS_CONSTANT) - #define JSON_HEDLEY_IS_CONSTANT(expr) (0) + #if JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 19) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 1, 0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0) && !defined(__cplusplus)) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8, 1, 0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) + #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) #endif - #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr) -#endif + #if !defined(__cplusplus) + #if JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5, 4, 0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 24) + #if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*)((__INTPTR_TYPE__)((expr) * 0)) : (int*)0)), int*) + #else + #include <stdint.h> + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*)((intptr_t)((expr) * 0)) : (int*)0)), int*) + #endif + #elif ( \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ + !defined(JSON_HEDLEY_SUNPRO_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_IAR_VERSION)) || \ + (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(17, 0, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12, 1, 0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5, 3, 0) + #if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*)((__INTPTR_TYPE__)((expr) * 0)) : (int*)0), int*: 1, void*: 0) + #else + #include <stdint.h> + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*)((intptr_t) * 0) : (int*)0), int*: 1, void*: 0) + #endif + #elif defined(JSON_HEDLEY_GCC_VERSION) || \ + defined(JSON_HEDLEY_INTEL_VERSION) || \ + defined(JSON_HEDLEY_TINYC_VERSION) || \ + defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(18, 12, 0) || \ + defined(JSON_HEDLEY_TI_CL2000_VERSION) || \ + defined(JSON_HEDLEY_TI_CL6X_VERSION) || \ + defined(JSON_HEDLEY_TI_CL7X_VERSION) || \ + defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \ + defined(__clang__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \ + sizeof(void) != \ + sizeof(*( \ + 1 ? ((void*)((expr) * 0L)) : ((struct { char v[sizeof(void) * 2]; }*)1)))) + #endif + #endif + #if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1)) + #else + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) (0) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr) + #endif -#if defined(JSON_HEDLEY_BEGIN_C_DECLS) - #undef JSON_HEDLEY_BEGIN_C_DECLS -#endif -#if defined(JSON_HEDLEY_END_C_DECLS) - #undef JSON_HEDLEY_END_C_DECLS -#endif -#if defined(JSON_HEDLEY_C_DECL) - #undef JSON_HEDLEY_C_DECL -#endif -#if defined(__cplusplus) - #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" { - #define JSON_HEDLEY_END_C_DECLS } - #define JSON_HEDLEY_C_DECL extern "C" -#else - #define JSON_HEDLEY_BEGIN_C_DECLS - #define JSON_HEDLEY_END_C_DECLS - #define JSON_HEDLEY_C_DECL -#endif + #if defined(JSON_HEDLEY_BEGIN_C_DECLS) + #undef JSON_HEDLEY_BEGIN_C_DECLS + #endif + #if defined(JSON_HEDLEY_END_C_DECLS) + #undef JSON_HEDLEY_END_C_DECLS + #endif + #if defined(JSON_HEDLEY_C_DECL) + #undef JSON_HEDLEY_C_DECL + #endif + #if defined(__cplusplus) + #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" { + #define JSON_HEDLEY_END_C_DECLS } + #define JSON_HEDLEY_C_DECL extern "C" + #else + #define JSON_HEDLEY_BEGIN_C_DECLS + #define JSON_HEDLEY_END_C_DECLS + #define JSON_HEDLEY_C_DECL + #endif -#if defined(JSON_HEDLEY_STATIC_ASSERT) - #undef JSON_HEDLEY_STATIC_ASSERT -#endif -#if \ - !defined(__cplusplus) && ( \ - (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ - (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ - defined(_Static_assert) \ - ) -# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) -#elif \ - (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ - JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) -# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) -#else -# define JSON_HEDLEY_STATIC_ASSERT(expr, message) -#endif + #if defined(JSON_HEDLEY_STATIC_ASSERT) + #undef JSON_HEDLEY_STATIC_ASSERT + #endif + #if !defined(__cplusplus) && ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ + (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(6, 0, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ + defined(_Static_assert)) + #define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) + #elif (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(16, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) + #else + #define JSON_HEDLEY_STATIC_ASSERT(expr, message) + #endif -#if defined(JSON_HEDLEY_NULL) - #undef JSON_HEDLEY_NULL -#endif -#if defined(__cplusplus) - #if __cplusplus >= 201103L - #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr) + #if defined(JSON_HEDLEY_NULL) + #undef JSON_HEDLEY_NULL + #endif + #if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr) + #elif defined(NULL) + #define JSON_HEDLEY_NULL NULL + #else + #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0) + #endif #elif defined(NULL) #define JSON_HEDLEY_NULL NULL #else - #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0) + #define JSON_HEDLEY_NULL ((void*)0) #endif -#elif defined(NULL) - #define JSON_HEDLEY_NULL NULL -#else - #define JSON_HEDLEY_NULL ((void*) 0) -#endif -#if defined(JSON_HEDLEY_MESSAGE) - #undef JSON_HEDLEY_MESSAGE -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") -# define JSON_HEDLEY_MESSAGE(msg) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ - JSON_HEDLEY_PRAGMA(message msg) \ - JSON_HEDLEY_DIAGNOSTIC_POP -#elif \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) -# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg) -#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) -# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg) -#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) -# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) -#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0) -# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) -#else -# define JSON_HEDLEY_MESSAGE(msg) -#endif + #if defined(JSON_HEDLEY_MESSAGE) + #undef JSON_HEDLEY_MESSAGE + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") + #define JSON_HEDLEY_MESSAGE(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(message msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 4, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg) + #elif JSON_HEDLEY_CRAY_VERSION_CHECK(5, 0, 0) + #define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg) + #elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) + #define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) + #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2, 0, 0) + #define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) + #else + #define JSON_HEDLEY_MESSAGE(msg) + #endif -#if defined(JSON_HEDLEY_WARNING) - #undef JSON_HEDLEY_WARNING -#endif -#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") -# define JSON_HEDLEY_WARNING(msg) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ - JSON_HEDLEY_PRAGMA(clang warning msg) \ - JSON_HEDLEY_DIAGNOSTIC_POP -#elif \ - JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \ - JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) -# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) -#elif \ - JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) -# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) -#else -# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) -#endif + #if defined(JSON_HEDLEY_WARNING) + #undef JSON_HEDLEY_WARNING + #endif + #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") + #define JSON_HEDLEY_WARNING(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(clang warning msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP + #elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 8, 0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18, 4, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) + #define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) + #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) + #else + #define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) + #endif -#if defined(JSON_HEDLEY_REQUIRE) - #undef JSON_HEDLEY_REQUIRE -#endif -#if defined(JSON_HEDLEY_REQUIRE_MSG) - #undef JSON_HEDLEY_REQUIRE_MSG -#endif -#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if) -# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat") -# define JSON_HEDLEY_REQUIRE(expr) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ - __attribute__((diagnose_if(!(expr), #expr, "error"))) \ - JSON_HEDLEY_DIAGNOSTIC_POP -# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ - __attribute__((diagnose_if(!(expr), msg, "error"))) \ - JSON_HEDLEY_DIAGNOSTIC_POP -# else -# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error"))) -# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error"))) -# endif -#else -# define JSON_HEDLEY_REQUIRE(expr) -# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) -#endif + #if defined(JSON_HEDLEY_REQUIRE) + #undef JSON_HEDLEY_REQUIRE + #endif + #if defined(JSON_HEDLEY_REQUIRE_MSG) + #undef JSON_HEDLEY_REQUIRE_MSG + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if) + #if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat") + #define JSON_HEDLEY_REQUIRE(expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), #expr, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP + #define JSON_HEDLEY_REQUIRE_MSG(expr, msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), msg, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP + #else + #define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error"))) + #define JSON_HEDLEY_REQUIRE_MSG(expr, msg) __attribute__((diagnose_if(!(expr), msg, "error"))) + #endif + #else + #define JSON_HEDLEY_REQUIRE(expr) + #define JSON_HEDLEY_REQUIRE_MSG(expr, msg) + #endif -#if defined(JSON_HEDLEY_FLAGS) - #undef JSON_HEDLEY_FLAGS -#endif -#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion")) - #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) -#else - #define JSON_HEDLEY_FLAGS -#endif + #if defined(JSON_HEDLEY_FLAGS) + #undef JSON_HEDLEY_FLAGS + #endif + #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion")) + #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) + #else + #define JSON_HEDLEY_FLAGS + #endif -#if defined(JSON_HEDLEY_FLAGS_CAST) - #undef JSON_HEDLEY_FLAGS_CAST -#endif -#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0) -# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \ - JSON_HEDLEY_DIAGNOSTIC_PUSH \ - _Pragma("warning(disable:188)") \ - ((T) (expr)); \ - JSON_HEDLEY_DIAGNOSTIC_POP \ - })) -#else -# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr) -#endif + #if defined(JSON_HEDLEY_FLAGS_CAST) + #undef JSON_HEDLEY_FLAGS_CAST + #endif + #if JSON_HEDLEY_INTEL_VERSION_CHECK(19, 0, 0) + #define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("warning(disable:188)")((T)(expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) + #else + #define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr) + #endif -#if defined(JSON_HEDLEY_EMPTY_BASES) - #undef JSON_HEDLEY_EMPTY_BASES -#endif -#if \ - (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \ - JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) - #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) -#else - #define JSON_HEDLEY_EMPTY_BASES -#endif + #if defined(JSON_HEDLEY_EMPTY_BASES) + #undef JSON_HEDLEY_EMPTY_BASES + #endif + #if (JSON_HEDLEY_MSVC_VERSION_CHECK(19, 0, 23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20, 0, 0)) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) + #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) + #else + #define JSON_HEDLEY_EMPTY_BASES + #endif -/* Remaining macros are deprecated. */ + /* Remaining macros are deprecated. */ -#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK) - #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK -#endif -#if defined(__clang__) - #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0) -#else - #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) -#endif + #if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK + #endif + #if defined(__clang__) + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major, minor, patch) (0) + #else + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) + #endif -#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE) - #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE -#endif -#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) + #if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE + #endif + #define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) -#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE) - #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE -#endif -#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) + #if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE + #endif + #define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) -#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN) - #undef JSON_HEDLEY_CLANG_HAS_BUILTIN -#endif -#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin) + #if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN) + #undef JSON_HEDLEY_CLANG_HAS_BUILTIN + #endif + #define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin) -#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE) - #undef JSON_HEDLEY_CLANG_HAS_FEATURE -#endif -#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature) + #if defined(JSON_HEDLEY_CLANG_HAS_FEATURE) + #undef JSON_HEDLEY_CLANG_HAS_FEATURE + #endif + #define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature) -#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION) - #undef JSON_HEDLEY_CLANG_HAS_EXTENSION -#endif -#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension) + #if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION) + #undef JSON_HEDLEY_CLANG_HAS_EXTENSION + #endif + #define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension) -#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE) - #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE -#endif -#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) + #if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE + #endif + #define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) -#if defined(JSON_HEDLEY_CLANG_HAS_WARNING) - #undef JSON_HEDLEY_CLANG_HAS_WARNING -#endif -#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning) + #if defined(JSON_HEDLEY_CLANG_HAS_WARNING) + #undef JSON_HEDLEY_CLANG_HAS_WARNING + #endif + #define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning) #endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */ +#include <utility> // declval, pair // This file contains all internal macro definitions (except those affecting ABI) // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them // #include <nlohmann/detail/abi_macros.hpp> - // exclude unsupported compilers #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) #if defined(__clang__) @@ -2389,7 +2310,7 @@ #define JSON_HAS_CPP_20 #define JSON_HAS_CPP_17 #define JSON_HAS_CPP_14 - #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 #define JSON_HAS_CPP_17 #define JSON_HAS_CPP_14 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) @@ -2466,8 +2387,7 @@ #endif #ifndef JSON_HAS_THREE_WAY_COMPARISON - #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \ - && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L + #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L #define JSON_HAS_THREE_WAY_COMPARISON 1 #else #define JSON_HAS_THREE_WAY_COMPARISON 0 @@ -2516,14 +2436,14 @@ #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) #define JSON_THROW(exception) throw exception #define JSON_TRY try - #define JSON_CATCH(exception) catch(exception) - #define JSON_INTERNAL_CATCH(exception) catch(exception) + #define JSON_CATCH(exception) catch (exception) + #define JSON_INTERNAL_CATCH(exception) catch (exception) #else #include <cstdlib> #define JSON_THROW(exception) std::abort() - #define JSON_TRY if(true) - #define JSON_CATCH(exception) if(false) - #define JSON_INTERNAL_CATCH(exception) if(false) + #define JSON_TRY if (true) + #define JSON_CATCH(exception) if (false) + #define JSON_INTERNAL_CATCH(exception) if (false) #endif // override exception macros @@ -2548,7 +2468,7 @@ // allow overriding assert #if !defined(JSON_ASSERT) - #include <cassert> // assert + #include <cassert> // assert #define JSON_ASSERT(x) assert(x) #endif @@ -2564,119 +2484,119 @@ @def NLOHMANN_JSON_SERIALIZE_ENUM @since version 3.4.0 */ -#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ - template<typename BasicJsonType> \ - inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ - { \ - static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ - static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ - auto it = std::find_if(std::begin(m), std::end(m), \ - [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \ - { \ - return ej_pair.first == e; \ - }); \ - j = ((it != std::end(m)) ? it : std::begin(m))->second; \ - } \ - template<typename BasicJsonType> \ - inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ - { \ - static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ - static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ - auto it = std::find_if(std::begin(m), std::end(m), \ - [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \ - { \ - return ej_pair.second == j; \ - }); \ - e = ((it != std::end(m)) ? it : std::begin(m))->first; \ +#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ + template<typename BasicJsonType> \ + inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool { \ + return ej_pair.first == e; \ + }); \ + j = ((it != std::end(m)) ? it : std::begin(m))->second; \ + } \ + template<typename BasicJsonType> \ + inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool { \ + return ej_pair.second == j; \ + }); \ + e = ((it != std::end(m)) ? it : std::begin(m))->first; \ } // Ugly macros to avoid uglier copy-paste when specializing basic_json. They // may be removed in the future once the class is split. -#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ - template<template<typename, typename, typename...> class ObjectType, \ - template<typename, typename...> class ArrayType, \ - class StringType, class BooleanType, class NumberIntegerType, \ - class NumberUnsignedType, class NumberFloatType, \ - template<typename> class AllocatorType, \ - template<typename, typename = void> class JSONSerializer, \ - class BinaryType, \ +#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ + template<template<typename, typename, typename...> class ObjectType, \ + template<typename, typename...> \ + class ArrayType, \ + class StringType, \ + class BooleanType, \ + class NumberIntegerType, \ + class NumberUnsignedType, \ + class NumberFloatType, \ + template<typename> \ + class AllocatorType, \ + template<typename, typename = void> \ + class JSONSerializer, \ + class BinaryType, \ class CustomBaseClass> -#define NLOHMANN_BASIC_JSON_TPL \ - basic_json<ObjectType, ArrayType, StringType, BooleanType, \ - NumberIntegerType, NumberUnsignedType, NumberFloatType, \ - AllocatorType, JSONSerializer, BinaryType, CustomBaseClass> +#define NLOHMANN_BASIC_JSON_TPL \ + basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass> // Macros to simplify conversion from/to types -#define NLOHMANN_JSON_EXPAND( x ) x -#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME -#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \ - NLOHMANN_JSON_PASTE64, \ - NLOHMANN_JSON_PASTE63, \ - NLOHMANN_JSON_PASTE62, \ - NLOHMANN_JSON_PASTE61, \ - NLOHMANN_JSON_PASTE60, \ - NLOHMANN_JSON_PASTE59, \ - NLOHMANN_JSON_PASTE58, \ - NLOHMANN_JSON_PASTE57, \ - NLOHMANN_JSON_PASTE56, \ - NLOHMANN_JSON_PASTE55, \ - NLOHMANN_JSON_PASTE54, \ - NLOHMANN_JSON_PASTE53, \ - NLOHMANN_JSON_PASTE52, \ - NLOHMANN_JSON_PASTE51, \ - NLOHMANN_JSON_PASTE50, \ - NLOHMANN_JSON_PASTE49, \ - NLOHMANN_JSON_PASTE48, \ - NLOHMANN_JSON_PASTE47, \ - NLOHMANN_JSON_PASTE46, \ - NLOHMANN_JSON_PASTE45, \ - NLOHMANN_JSON_PASTE44, \ - NLOHMANN_JSON_PASTE43, \ - NLOHMANN_JSON_PASTE42, \ - NLOHMANN_JSON_PASTE41, \ - NLOHMANN_JSON_PASTE40, \ - NLOHMANN_JSON_PASTE39, \ - NLOHMANN_JSON_PASTE38, \ - NLOHMANN_JSON_PASTE37, \ - NLOHMANN_JSON_PASTE36, \ - NLOHMANN_JSON_PASTE35, \ - NLOHMANN_JSON_PASTE34, \ - NLOHMANN_JSON_PASTE33, \ - NLOHMANN_JSON_PASTE32, \ - NLOHMANN_JSON_PASTE31, \ - NLOHMANN_JSON_PASTE30, \ - NLOHMANN_JSON_PASTE29, \ - NLOHMANN_JSON_PASTE28, \ - NLOHMANN_JSON_PASTE27, \ - NLOHMANN_JSON_PASTE26, \ - NLOHMANN_JSON_PASTE25, \ - NLOHMANN_JSON_PASTE24, \ - NLOHMANN_JSON_PASTE23, \ - NLOHMANN_JSON_PASTE22, \ - NLOHMANN_JSON_PASTE21, \ - NLOHMANN_JSON_PASTE20, \ - NLOHMANN_JSON_PASTE19, \ - NLOHMANN_JSON_PASTE18, \ - NLOHMANN_JSON_PASTE17, \ - NLOHMANN_JSON_PASTE16, \ - NLOHMANN_JSON_PASTE15, \ - NLOHMANN_JSON_PASTE14, \ - NLOHMANN_JSON_PASTE13, \ - NLOHMANN_JSON_PASTE12, \ - NLOHMANN_JSON_PASTE11, \ - NLOHMANN_JSON_PASTE10, \ - NLOHMANN_JSON_PASTE9, \ - NLOHMANN_JSON_PASTE8, \ - NLOHMANN_JSON_PASTE7, \ - NLOHMANN_JSON_PASTE6, \ - NLOHMANN_JSON_PASTE5, \ - NLOHMANN_JSON_PASTE4, \ - NLOHMANN_JSON_PASTE3, \ - NLOHMANN_JSON_PASTE2, \ - NLOHMANN_JSON_PASTE1)(__VA_ARGS__)) +#define NLOHMANN_JSON_EXPAND(x) x +#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME, ...) NAME +#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \ + NLOHMANN_JSON_PASTE64, \ + NLOHMANN_JSON_PASTE63, \ + NLOHMANN_JSON_PASTE62, \ + NLOHMANN_JSON_PASTE61, \ + NLOHMANN_JSON_PASTE60, \ + NLOHMANN_JSON_PASTE59, \ + NLOHMANN_JSON_PASTE58, \ + NLOHMANN_JSON_PASTE57, \ + NLOHMANN_JSON_PASTE56, \ + NLOHMANN_JSON_PASTE55, \ + NLOHMANN_JSON_PASTE54, \ + NLOHMANN_JSON_PASTE53, \ + NLOHMANN_JSON_PASTE52, \ + NLOHMANN_JSON_PASTE51, \ + NLOHMANN_JSON_PASTE50, \ + NLOHMANN_JSON_PASTE49, \ + NLOHMANN_JSON_PASTE48, \ + NLOHMANN_JSON_PASTE47, \ + NLOHMANN_JSON_PASTE46, \ + NLOHMANN_JSON_PASTE45, \ + NLOHMANN_JSON_PASTE44, \ + NLOHMANN_JSON_PASTE43, \ + NLOHMANN_JSON_PASTE42, \ + NLOHMANN_JSON_PASTE41, \ + NLOHMANN_JSON_PASTE40, \ + NLOHMANN_JSON_PASTE39, \ + NLOHMANN_JSON_PASTE38, \ + NLOHMANN_JSON_PASTE37, \ + NLOHMANN_JSON_PASTE36, \ + NLOHMANN_JSON_PASTE35, \ + NLOHMANN_JSON_PASTE34, \ + NLOHMANN_JSON_PASTE33, \ + NLOHMANN_JSON_PASTE32, \ + NLOHMANN_JSON_PASTE31, \ + NLOHMANN_JSON_PASTE30, \ + NLOHMANN_JSON_PASTE29, \ + NLOHMANN_JSON_PASTE28, \ + NLOHMANN_JSON_PASTE27, \ + NLOHMANN_JSON_PASTE26, \ + NLOHMANN_JSON_PASTE25, \ + NLOHMANN_JSON_PASTE24, \ + NLOHMANN_JSON_PASTE23, \ + NLOHMANN_JSON_PASTE22, \ + NLOHMANN_JSON_PASTE21, \ + NLOHMANN_JSON_PASTE20, \ + NLOHMANN_JSON_PASTE19, \ + NLOHMANN_JSON_PASTE18, \ + NLOHMANN_JSON_PASTE17, \ + NLOHMANN_JSON_PASTE16, \ + NLOHMANN_JSON_PASTE15, \ + NLOHMANN_JSON_PASTE14, \ + NLOHMANN_JSON_PASTE13, \ + NLOHMANN_JSON_PASTE12, \ + NLOHMANN_JSON_PASTE11, \ + NLOHMANN_JSON_PASTE10, \ + NLOHMANN_JSON_PASTE9, \ + NLOHMANN_JSON_PASTE8, \ + NLOHMANN_JSON_PASTE7, \ + NLOHMANN_JSON_PASTE6, \ + NLOHMANN_JSON_PASTE5, \ + NLOHMANN_JSON_PASTE4, \ + NLOHMANN_JSON_PASTE3, \ + NLOHMANN_JSON_PASTE2, \ + NLOHMANN_JSON_PASTE1)(__VA_ARGS__)) #define NLOHMANN_JSON_PASTE2(func, v1) func(v1) #define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2) #define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3) @@ -2750,32 +2670,64 @@ @def NLOHMANN_DEFINE_TYPE_INTRUSIVE @since version 3.9.0 */ -#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \ - friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } \ + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) \ + } -#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ - friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } \ + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) \ + { \ + const Type nlohmann_json_default_obj{}; \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) \ + } -#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ - friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } /*! @brief macro @def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE @since version 3.9.0 */ -#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \ - inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } \ + inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) \ + } -#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ - inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } -#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ - inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } \ + inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) \ + { \ + const Type nlohmann_json_default_obj{}; \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) \ + } // inspired from https://stackoverflow.com/a/26745591 // allows to call any std function as if (e.g. with begin): @@ -2786,30 +2738,30 @@ #define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \ namespace detail { \ using std::std_name; \ - \ + \ template<typename... T> \ using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \ } \ - \ + \ namespace detail2 { \ struct std_name##_tag \ { \ }; \ - \ + \ template<typename... T> \ std_name##_tag std_name(T&&...); \ - \ + \ template<typename... T> \ using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \ - \ + \ template<typename... T> \ struct would_call_std_##std_name \ { \ static constexpr auto const value = ::nlohmann::detail:: \ - is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \ + is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \ }; \ - } /* namespace detail2 */ \ - \ + } /* namespace detail2 */ \ + \ template<typename... T> \ struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \ { \ @@ -2833,226 +2785,6 @@ #define JSON_USE_GLOBAL_UDLS 1 #endif -#if JSON_HAS_THREE_WAY_COMPARISON - #include <compare> // partial_ordering -#endif - -NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ - -/////////////////////////// -// JSON type enumeration // -/////////////////////////// - -/*! -@brief the JSON type enumeration - -This enumeration collects the different JSON types. It is internally used to -distinguish the stored values, and the functions @ref basic_json::is_null(), -@ref basic_json::is_object(), @ref basic_json::is_array(), -@ref basic_json::is_string(), @ref basic_json::is_boolean(), -@ref basic_json::is_number() (with @ref basic_json::is_number_integer(), -@ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()), -@ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and -@ref basic_json::is_structured() rely on it. - -@note There are three enumeration entries (number_integer, number_unsigned, and -number_float), because the library distinguishes these three types for numbers: -@ref basic_json::number_unsigned_t is used for unsigned integers, -@ref basic_json::number_integer_t is used for signed integers, and -@ref basic_json::number_float_t is used for floating-point numbers or to -approximate integers which do not fit in the limits of their respective type. - -@sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON -value with the default value for a given type - -@since version 1.0.0 -*/ -enum class value_t : std::uint8_t -{ - null, ///< null value - object, ///< object (unordered set of name/value pairs) - array, ///< array (ordered collection of values) - string, ///< string value - boolean, ///< boolean value - number_integer, ///< number value (signed integer) - number_unsigned, ///< number value (unsigned integer) - number_float, ///< number value (floating-point) - binary, ///< binary array (ordered collection of bytes) - discarded ///< discarded by the parser callback function -}; - -/*! -@brief comparison operator for JSON types - -Returns an ordering that is similar to Python: -- order: null < boolean < number < object < array < string < binary -- furthermore, each type is not smaller than itself -- discarded values are not comparable -- binary is represented as a b"" string in python and directly comparable to a - string; however, making a binary array directly comparable with a string would - be surprising behavior in a JSON file. - -@since version 1.0.0 -*/ -#if JSON_HAS_THREE_WAY_COMPARISON - inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) noexcept // *NOPAD* -#else - inline bool operator<(const value_t lhs, const value_t rhs) noexcept -#endif -{ - static constexpr std::array<std::uint8_t, 9> order = {{ - 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, - 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, - 6 /* binary */ - } - }; - - const auto l_index = static_cast<std::size_t>(lhs); - const auto r_index = static_cast<std::size_t>(rhs); -#if JSON_HAS_THREE_WAY_COMPARISON - if (l_index < order.size() && r_index < order.size()) - { - return order[l_index] <=> order[r_index]; // *NOPAD* - } - return std::partial_ordering::unordered; -#else - return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; -#endif -} - -// GCC selects the built-in operator< over an operator rewritten from -// a user-defined spaceship operator -// Clang, MSVC, and ICC select the rewritten candidate -// (see GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105200) -#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__) -inline bool operator<(const value_t lhs, const value_t rhs) noexcept -{ - return std::is_lt(lhs <=> rhs); // *NOPAD* -} -#endif - -} // namespace detail -NLOHMANN_JSON_NAMESPACE_END - -// #include <nlohmann/detail/string_escape.hpp> -// __ _____ _____ _____ -// __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.3 -// |_____|_____|_____|_|___| https://github.com/nlohmann/json -// -// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> -// SPDX-License-Identifier: MIT - - - -// #include <nlohmann/detail/abi_macros.hpp> - - -NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ - -/*! -@brief replace all occurrences of a substring by another string - -@param[in,out] s the string to manipulate; changed so that all - occurrences of @a f are replaced with @a t -@param[in] f the substring to replace with @a t -@param[in] t the string to replace @a f - -@pre The search string @a f must not be empty. **This precondition is -enforced with an assertion.** - -@since version 2.0.0 -*/ -template<typename StringType> -inline void replace_substring(StringType& s, const StringType& f, - const StringType& t) -{ - JSON_ASSERT(!f.empty()); - for (auto pos = s.find(f); // find first occurrence of f - pos != StringType::npos; // make sure f was found - s.replace(pos, f.size(), t), // replace with t, and - pos = s.find(f, pos + t.size())) // find next occurrence of f - {} -} - -/*! - * @brief string escaping as described in RFC 6901 (Sect. 4) - * @param[in] s string to escape - * @return escaped string - * - * Note the order of escaping "~" to "~0" and "/" to "~1" is important. - */ -template<typename StringType> -inline StringType escape(StringType s) -{ - replace_substring(s, StringType{"~"}, StringType{"~0"}); - replace_substring(s, StringType{"/"}, StringType{"~1"}); - return s; -} - -/*! - * @brief string unescaping as described in RFC 6901 (Sect. 4) - * @param[in] s string to unescape - * @return unescaped string - * - * Note the order of escaping "~1" to "/" and "~0" to "~" is important. - */ -template<typename StringType> -static void unescape(StringType& s) -{ - replace_substring(s, StringType{"~1"}, StringType{"/"}); - replace_substring(s, StringType{"~0"}, StringType{"~"}); -} - -} // namespace detail -NLOHMANN_JSON_NAMESPACE_END - -// #include <nlohmann/detail/input/position_t.hpp> -// __ _____ _____ _____ -// __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.3 -// |_____|_____|_____|_|___| https://github.com/nlohmann/json -// -// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> -// SPDX-License-Identifier: MIT - - - -#include <cstddef> // size_t - -// #include <nlohmann/detail/abi_macros.hpp> - - -NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ - -/// struct to capture the start position of the current token -struct position_t -{ - /// the total number of characters read - std::size_t chars_read_total = 0; - /// the number of characters read in the current line - std::size_t chars_read_current_line = 0; - /// the number of lines read - std::size_t lines_read = 0; - - /// conversion to size_t to preserve SAX interface - constexpr operator size_t() const - { - return chars_read_total; - } -}; - -} // namespace detail -NLOHMANN_JSON_NAMESPACE_END - -// #include <nlohmann/detail/macro_scope.hpp> - // #include <nlohmann/detail/meta/cpp_future.hpp> // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ @@ -3063,19 +2795,15 @@ // SPDX-FileCopyrightText: 2018 The Abseil Authors // SPDX-License-Identifier: MIT - - -#include <array> // array -#include <cstddef> // size_t -#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type -#include <utility> // index_sequence, make_index_sequence, index_sequence_for +#include <array> // array +#include <cstddef> // size_t +#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type +#include <utility> // index_sequence, make_index_sequence, index_sequence_for // #include <nlohmann/detail/macro_scope.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename T> using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type; @@ -3085,8 +2813,8 @@ // the following utilities are natively available in C++14 using std::enable_if_t; using std::index_sequence; -using std::make_index_sequence; using std::index_sequence_for; +using std::make_index_sequence; #else @@ -3118,7 +2846,7 @@ // // will be deduced to `0, 1, 2, 3, 4`. // user_function(make_integer_sequence<int, 5>()); // } -template <typename T, T... Ints> +template<typename T, T... Ints> struct integer_sequence { using value_type = T; @@ -3133,38 +2861,37 @@ // A helper template for an `integer_sequence` of `size_t`, // `absl::index_sequence` is designed to be a drop-in replacement for C++14's // `std::index_sequence`. -template <size_t... Ints> +template<size_t... Ints> using index_sequence = integer_sequence<size_t, Ints...>; -namespace utility_internal -{ +namespace utility_internal { -template <typename Seq, size_t SeqSize, size_t Rem> +template<typename Seq, size_t SeqSize, size_t Rem> struct Extend; // Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency. -template <typename T, T... Ints, size_t SeqSize> +template<typename T, T... Ints, size_t SeqSize> struct Extend<integer_sequence<T, Ints...>, SeqSize, 0> { - using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >; + using type = integer_sequence<T, Ints..., (Ints + SeqSize)...>; }; -template <typename T, T... Ints, size_t SeqSize> +template<typename T, T... Ints, size_t SeqSize> struct Extend<integer_sequence<T, Ints...>, SeqSize, 1> { - using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >; + using type = integer_sequence<T, Ints..., (Ints + SeqSize)..., 2 * SeqSize>; }; // Recursion helper for 'make_integer_sequence<T, N>'. // 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'. -template <typename T, size_t N> +template<typename T, size_t N> struct Gen { using type = - typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type; + typename Extend<typename Gen<T, N / 2>::type, N / 2, N % 2>::type; }; -template <typename T> +template<typename T> struct Gen<T, 0> { using type = integer_sequence<T>; @@ -3179,7 +2906,7 @@ // This template alias is equivalent to // `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in // replacement for C++14's `std::make_integer_sequence`. -template <typename T, T N> +template<typename T, T N> using make_integer_sequence = typename utility_internal::Gen<T, N>::type; // make_index_sequence @@ -3187,7 +2914,7 @@ // This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`, // and is designed to be a drop-in replacement for C++14's // `std::make_index_sequence`. -template <size_t N> +template<size_t N> using make_index_sequence = make_integer_sequence<size_t, N>; // index_sequence_for @@ -3195,16 +2922,20 @@ // Converts a typename pack into an index sequence of the same length, and // is designed to be a drop-in replacement for C++14's // `std::index_sequence_for()` -template <typename... Ts> +template<typename... Ts> using index_sequence_for = make_index_sequence<sizeof...(Ts)>; -//// END OF CODE FROM GOOGLE ABSEIL + //// END OF CODE FROM GOOGLE ABSEIL #endif // dispatch utility (taken from ranges-v3) -template<unsigned N> struct priority_tag : priority_tag < N - 1 > {}; -template<> struct priority_tag<0> {}; +template<unsigned N> +struct priority_tag : priority_tag<N - 1> +{}; +template<> +struct priority_tag<0> +{}; // taken from ranges-v3 template<typename T> @@ -3214,14 +2945,14 @@ }; #ifndef JSON_HAS_CPP_17 - template<typename T> - constexpr T static_const<T>::value; +template<typename T> +constexpr T static_const<T>::value; #endif template<typename T, typename... Args> -inline constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args) +inline constexpr std::array<T, sizeof...(Args)> make_array(Args&&... args) { - return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}}; + return std::array<T, sizeof...(Args)>{{static_cast<T>(std::forward<Args>(args))...}}; } } // namespace detail @@ -3236,13 +2967,11 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <limits> // numeric_limits -#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type -#include <utility> // declval -#include <tuple> // tuple -#include <string> // char_traits +#include <limits> // numeric_limits +#include <string> // char_traits +#include <tuple> // tuple +#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type +#include <utility> // declval // #include <nlohmann/detail/iterators/iterator_traits.hpp> // __ _____ _____ _____ @@ -3253,29 +2982,25 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <iterator> // random_access_iterator_tag +#include <iterator> // random_access_iterator_tag // #include <nlohmann/detail/abi_macros.hpp> -// #include <nlohmann/detail/meta/void_t.hpp> - // #include <nlohmann/detail/meta/cpp_future.hpp> +// #include <nlohmann/detail/meta/void_t.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename It, typename = void> -struct iterator_types {}; +struct iterator_types +{}; template<typename It> -struct iterator_types < +struct iterator_types< It, - void_t<typename It::difference_type, typename It::value_type, typename It::pointer, - typename It::reference, typename It::iterator_category >> + void_t<typename It::difference_type, typename It::value_type, typename It::pointer, typename It::reference, typename It::iterator_category>> { using difference_type = typename It::difference_type; using value_type = typename It::value_type; @@ -3292,8 +3017,8 @@ }; template<typename T> -struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >> - : iterator_types<T> +struct iterator_traits<T, enable_if_t<!std::is_pointer<T>::value>> + : iterator_types<T> { }; @@ -3321,11 +3046,8 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - // #include <nlohmann/detail/macro_scope.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); @@ -3341,11 +3063,8 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - // #include <nlohmann/detail/macro_scope.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); @@ -3368,73 +3087,72 @@ #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ - #include <cstdint> // int64_t, uint64_t - #include <map> // map - #include <memory> // allocator - #include <string> // string - #include <vector> // vector + #include <cstdint> // int64_t, uint64_t + #include <map> // map + #include <memory> // allocator + #include <string> // string + #include <vector> // vector - // #include <nlohmann/detail/abi_macros.hpp> +// #include <nlohmann/detail/abi_macros.hpp> +/*! +@brief namespace for Niels Lohmann +@see https://github.com/nlohmann +@since version 1.0.0 +*/ +NLOHMANN_JSON_NAMESPACE_BEGIN - /*! - @brief namespace for Niels Lohmann - @see https://github.com/nlohmann - @since version 1.0.0 - */ - NLOHMANN_JSON_NAMESPACE_BEGIN +/*! +@brief default JSONSerializer template argument - /*! - @brief default JSONSerializer template argument +This serializer ignores the template arguments and uses ADL +([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) +for serialization. +*/ +template<typename T = void, typename SFINAE = void> +struct adl_serializer; - This serializer ignores the template arguments and uses ADL - ([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) - for serialization. - */ - template<typename T = void, typename SFINAE = void> - struct adl_serializer; +/// a class to store JSON values +/// @sa https://json.nlohmann.me/api/basic_json/ +template<template<typename U, typename V, typename... Args> class ObjectType = + std::map, + template<typename U, typename... Args> class ArrayType = std::vector, + class StringType = std::string, + class BooleanType = bool, + class NumberIntegerType = std::int64_t, + class NumberUnsignedType = std::uint64_t, + class NumberFloatType = double, + template<typename U> class AllocatorType = std::allocator, + template<typename T, typename SFINAE = void> class JSONSerializer = + adl_serializer, + class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError + class CustomBaseClass = void> +class basic_json; - /// a class to store JSON values - /// @sa https://json.nlohmann.me/api/basic_json/ - template<template<typename U, typename V, typename... Args> class ObjectType = - std::map, - template<typename U, typename... Args> class ArrayType = std::vector, - class StringType = std::string, class BooleanType = bool, - class NumberIntegerType = std::int64_t, - class NumberUnsignedType = std::uint64_t, - class NumberFloatType = double, - template<typename U> class AllocatorType = std::allocator, - template<typename T, typename SFINAE = void> class JSONSerializer = - adl_serializer, - class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError - class CustomBaseClass = void> - class basic_json; +/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document +/// @sa https://json.nlohmann.me/api/json_pointer/ +template<typename RefStringType> +class json_pointer; - /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document - /// @sa https://json.nlohmann.me/api/json_pointer/ - template<typename RefStringType> - class json_pointer; +/*! +@brief default specialization +@sa https://json.nlohmann.me/api/json/ +*/ +using json = basic_json<>; - /*! - @brief default specialization - @sa https://json.nlohmann.me/api/json/ - */ - using json = basic_json<>; +/// @brief a minimal map-like container that preserves insertion order +/// @sa https://json.nlohmann.me/api/ordered_map/ +template<class Key, class T, class IgnoredLess, class Allocator> +struct ordered_map; - /// @brief a minimal map-like container that preserves insertion order - /// @sa https://json.nlohmann.me/api/ordered_map/ - template<class Key, class T, class IgnoredLess, class Allocator> - struct ordered_map; +/// @brief specialization that maintains the insertion order of object keys +/// @sa https://json.nlohmann.me/api/ordered_json/ +using ordered_json = basic_json<nlohmann::ordered_map>; - /// @brief specialization that maintains the insertion order of object keys - /// @sa https://json.nlohmann.me/api/ordered_json/ - using ordered_json = basic_json<nlohmann::ordered_map>; - - NLOHMANN_JSON_NAMESPACE_END +NLOHMANN_JSON_NAMESPACE_END #endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_ - NLOHMANN_JSON_NAMESPACE_BEGIN /*! @brief detail namespace with internal helper functions @@ -3444,8 +3162,7 @@ @since version 2.1.0 */ -namespace detail -{ +namespace detail { ///////////// // helpers // @@ -3460,19 +3177,20 @@ // In this case, T has to be properly CV-qualified to constraint the function arguments // (e.g. to_json(BasicJsonType&, const T&)) -template<typename> struct is_basic_json : std::false_type {}; +template<typename> +struct is_basic_json : std::false_type +{}; NLOHMANN_BASIC_JSON_TPL_DECLARATION -struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {}; +struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type +{}; // used by exceptions create() member functions // true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t // false_type otherwise template<typename BasicJsonContext> -struct is_basic_json_context : - std::integral_constant < bool, - is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value - || std::is_same<BasicJsonContext, std::nullptr_t>::value > +struct is_basic_json_context : std::integral_constant<bool, + is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value || std::is_same<BasicJsonContext, std::nullptr_t>::value> {}; ////////////////////// @@ -3483,10 +3201,12 @@ class json_ref; template<typename> -struct is_json_ref : std::false_type {}; +struct is_json_ref : std::false_type +{}; template<typename T> -struct is_json_ref<json_ref<T>> : std::true_type {}; +struct is_json_ref<json_ref<T>> : std::true_type +{}; ////////////////////////// // aliases for detected // @@ -3524,63 +3244,64 @@ // trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists template<typename BasicJsonType, typename T, typename = void> -struct has_from_json : std::false_type {}; +struct has_from_json : std::false_type +{}; // trait checking if j.get<T> is valid // use this trait instead of std::is_constructible or std::is_convertible, // both rely on, or make use of implicit conversions, and thus fail when T // has several constructors/operator= (see https://github.com/nlohmann/json/issues/958) -template <typename BasicJsonType, typename T> +template<typename BasicJsonType, typename T> struct is_getable { static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value; }; template<typename BasicJsonType, typename T> -struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >> +struct has_from_json<BasicJsonType, T, enable_if_t<!is_basic_json<T>::value>> { using serializer = typename BasicJsonType::template json_serializer<T, void>; static constexpr bool value = - is_detected_exact<void, from_json_function, serializer, - const BasicJsonType&, T&>::value; + is_detected_exact<void, from_json_function, serializer, const BasicJsonType&, T&>::value; }; // This trait checks if JSONSerializer<T>::from_json(json const&) exists // this overload is used for non-default-constructible user-defined-types template<typename BasicJsonType, typename T, typename = void> -struct has_non_default_from_json : std::false_type {}; +struct has_non_default_from_json : std::false_type +{}; template<typename BasicJsonType, typename T> -struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >> +struct has_non_default_from_json<BasicJsonType, T, enable_if_t<!is_basic_json<T>::value>> { using serializer = typename BasicJsonType::template json_serializer<T, void>; static constexpr bool value = - is_detected_exact<T, from_json_function, serializer, - const BasicJsonType&>::value; + is_detected_exact<T, from_json_function, serializer, const BasicJsonType&>::value; }; // This trait checks if BasicJsonType::json_serializer<T>::to_json exists // Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion. template<typename BasicJsonType, typename T, typename = void> -struct has_to_json : std::false_type {}; +struct has_to_json : std::false_type +{}; template<typename BasicJsonType, typename T> -struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >> +struct has_to_json<BasicJsonType, T, enable_if_t<!is_basic_json<T>::value>> { using serializer = typename BasicJsonType::template json_serializer<T, void>; static constexpr bool value = - is_detected_exact<void, to_json_function, serializer, BasicJsonType&, - T>::value; + is_detected_exact<void, to_json_function, serializer, BasicJsonType&, T>::value; }; template<typename T> using detect_key_compare = typename T::key_compare; template<typename T> -struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {}; +struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> +{}; // obtains the actual object key comparator template<typename BasicJsonType> @@ -3588,8 +3309,9 @@ { using object_t = typename BasicJsonType::object_t; using object_comparator_t = typename BasicJsonType::default_object_comparator_t; - using type = typename std::conditional < has_key_compare<object_t>::value, - typename object_t::key_compare, object_comparator_t>::type; + using type = typename std::conditional<has_key_compare<object_t>::value, + typename object_t::key_compare, + object_comparator_t>::type; }; template<typename BasicJsonType> @@ -3657,54 +3379,72 @@ /////////////////// // https://en.cppreference.com/w/cpp/types/conjunction -template<class...> struct conjunction : std::true_type { }; -template<class B> struct conjunction<B> : B { }; +template<class...> +struct conjunction : std::true_type +{}; +template<class B> +struct conjunction<B> : B +{}; template<class B, class... Bn> struct conjunction<B, Bn...> -: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {}; + : std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type +{}; // https://en.cppreference.com/w/cpp/types/negation -template<class B> struct negation : std::integral_constant < bool, !B::value > { }; +template<class B> +struct negation : std::integral_constant<bool, !B::value> +{}; // Reimplementation of is_constructible and is_default_constructible, due to them being broken for // std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367). // This causes compile errors in e.g. clang 3.5 or gcc 4.9. -template <typename T> -struct is_default_constructible : std::is_default_constructible<T> {}; +template<typename T> +struct is_default_constructible : std::is_default_constructible<T> +{}; -template <typename T1, typename T2> +template<typename T1, typename T2> struct is_default_constructible<std::pair<T1, T2>> - : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {}; + : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> +{}; -template <typename T1, typename T2> +template<typename T1, typename T2> struct is_default_constructible<const std::pair<T1, T2>> - : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {}; + : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> +{}; -template <typename... Ts> +template<typename... Ts> struct is_default_constructible<std::tuple<Ts...>> - : conjunction<is_default_constructible<Ts>...> {}; + : conjunction<is_default_constructible<Ts>...> +{}; -template <typename... Ts> +template<typename... Ts> struct is_default_constructible<const std::tuple<Ts...>> - : conjunction<is_default_constructible<Ts>...> {}; + : conjunction<is_default_constructible<Ts>...> +{}; -template <typename T, typename... Args> -struct is_constructible : std::is_constructible<T, Args...> {}; +template<typename T, typename... Args> +struct is_constructible : std::is_constructible<T, Args...> +{}; -template <typename T1, typename T2> -struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {}; +template<typename T1, typename T2> +struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> +{}; -template <typename T1, typename T2> -struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {}; +template<typename T1, typename T2> +struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> +{}; -template <typename... Ts> -struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {}; +template<typename... Ts> +struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> +{}; -template <typename... Ts> -struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {}; +template<typename... Ts> +struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> +{}; template<typename T, typename = void> -struct is_iterator_traits : std::false_type {}; +struct is_iterator_traits : std::false_type +{}; template<typename T> struct is_iterator_traits<iterator_traits<T>> @@ -3751,44 +3491,49 @@ // and is written by Xiang Fan who agreed to using it in this library. template<typename T, typename = void> -struct is_complete_type : std::false_type {}; +struct is_complete_type : std::false_type +{}; template<typename T> -struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {}; +struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type +{}; -template<typename BasicJsonType, typename CompatibleObjectType, - typename = void> -struct is_compatible_object_type_impl : std::false_type {}; +template<typename BasicJsonType, typename CompatibleObjectType, typename = void> +struct is_compatible_object_type_impl : std::false_type +{}; template<typename BasicJsonType, typename CompatibleObjectType> -struct is_compatible_object_type_impl < - BasicJsonType, CompatibleObjectType, - enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&& - is_detected<key_type_t, CompatibleObjectType>::value >> +struct is_compatible_object_type_impl< + BasicJsonType, + CompatibleObjectType, + enable_if_t<is_detected<mapped_type_t, CompatibleObjectType>::value && + is_detected<key_type_t, CompatibleObjectType>::value>> { using object_t = typename BasicJsonType::object_t; // macOS's is_constructible does not play well with nonesuch... static constexpr bool value = is_constructible<typename object_t::key_type, - typename CompatibleObjectType::key_type>::value && + typename CompatibleObjectType::key_type>::value && is_constructible<typename object_t::mapped_type, - typename CompatibleObjectType::mapped_type>::value; + typename CompatibleObjectType::mapped_type>::value; }; template<typename BasicJsonType, typename CompatibleObjectType> struct is_compatible_object_type - : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {}; + : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> +{}; -template<typename BasicJsonType, typename ConstructibleObjectType, - typename = void> -struct is_constructible_object_type_impl : std::false_type {}; +template<typename BasicJsonType, typename ConstructibleObjectType, typename = void> +struct is_constructible_object_type_impl : std::false_type +{}; template<typename BasicJsonType, typename ConstructibleObjectType> -struct is_constructible_object_type_impl < - BasicJsonType, ConstructibleObjectType, - enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&& - is_detected<key_type_t, ConstructibleObjectType>::value >> +struct is_constructible_object_type_impl< + BasicJsonType, + ConstructibleObjectType, + enable_if_t<is_detected<mapped_type_t, ConstructibleObjectType>::value && + is_detected<key_type_t, ConstructibleObjectType>::value>> { using object_t = typename BasicJsonType::object_t; @@ -3797,21 +3542,22 @@ (std::is_move_assignable<ConstructibleObjectType>::value || std::is_copy_assignable<ConstructibleObjectType>::value) && (is_constructible<typename ConstructibleObjectType::key_type, - typename object_t::key_type>::value && - std::is_same < - typename object_t::mapped_type, - typename ConstructibleObjectType::mapped_type >::value)) || + typename object_t::key_type>::value && + std::is_same< + typename object_t::mapped_type, + typename ConstructibleObjectType::mapped_type>::value)) || (has_from_json<BasicJsonType, - typename ConstructibleObjectType::mapped_type>::value || - has_non_default_from_json < - BasicJsonType, - typename ConstructibleObjectType::mapped_type >::value); + typename ConstructibleObjectType::mapped_type>::value || + has_non_default_from_json< + BasicJsonType, + typename ConstructibleObjectType::mapped_type>::value); }; template<typename BasicJsonType, typename ConstructibleObjectType> struct is_constructible_object_type - : is_constructible_object_type_impl<BasicJsonType, - ConstructibleObjectType> {}; + : is_constructible_object_type_impl<BasicJsonType, + ConstructibleObjectType> +{}; template<typename BasicJsonType, typename CompatibleStringType> struct is_compatible_string_type @@ -3831,88 +3577,98 @@ #endif static constexpr auto value = - conjunction < - is_constructible<laundered_type, typename BasicJsonType::string_t>, - is_detected_exact<typename BasicJsonType::string_t::value_type, - value_type_t, laundered_type >>::value; + conjunction< + is_constructible<laundered_type, typename BasicJsonType::string_t>, + is_detected_exact<typename BasicJsonType::string_t::value_type, + value_type_t, + laundered_type>>::value; }; template<typename BasicJsonType, typename CompatibleArrayType, typename = void> -struct is_compatible_array_type_impl : std::false_type {}; +struct is_compatible_array_type_impl : std::false_type +{}; template<typename BasicJsonType, typename CompatibleArrayType> -struct is_compatible_array_type_impl < - BasicJsonType, CompatibleArrayType, - enable_if_t < - is_detected<iterator_t, CompatibleArrayType>::value&& - is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&& -// special case for types like std::filesystem::path whose iterator's value_type are themselves -// c.f. https://github.com/nlohmann/json/pull/3073 - !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >> +struct is_compatible_array_type_impl< + BasicJsonType, + CompatibleArrayType, + enable_if_t< + is_detected<iterator_t, CompatibleArrayType>::value && + is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value && + // special case for types like std::filesystem::path whose iterator's value_type are themselves + // c.f. https://github.com/nlohmann/json/pull/3073 + !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value>> { static constexpr bool value = is_constructible<BasicJsonType, - range_value_t<CompatibleArrayType>>::value; + range_value_t<CompatibleArrayType>>::value; }; template<typename BasicJsonType, typename CompatibleArrayType> struct is_compatible_array_type - : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {}; + : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> +{}; template<typename BasicJsonType, typename ConstructibleArrayType, typename = void> -struct is_constructible_array_type_impl : std::false_type {}; +struct is_constructible_array_type_impl : std::false_type +{}; template<typename BasicJsonType, typename ConstructibleArrayType> -struct is_constructible_array_type_impl < - BasicJsonType, ConstructibleArrayType, +struct is_constructible_array_type_impl< + BasicJsonType, + ConstructibleArrayType, enable_if_t<std::is_same<ConstructibleArrayType, - typename BasicJsonType::value_type>::value >> - : std::true_type {}; + typename BasicJsonType::value_type>::value>> + : std::true_type +{}; template<typename BasicJsonType, typename ConstructibleArrayType> -struct is_constructible_array_type_impl < - BasicJsonType, ConstructibleArrayType, - enable_if_t < !std::is_same<ConstructibleArrayType, - typename BasicJsonType::value_type>::value&& - !is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value&& - is_default_constructible<ConstructibleArrayType>::value&& -(std::is_move_assignable<ConstructibleArrayType>::value || - std::is_copy_assignable<ConstructibleArrayType>::value)&& -is_detected<iterator_t, ConstructibleArrayType>::value&& -is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&& -is_detected<range_value_t, ConstructibleArrayType>::value&& -// special case for types like std::filesystem::path whose iterator's value_type are themselves -// c.f. https://github.com/nlohmann/json/pull/3073 -!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&& - is_complete_type < - detected_t<range_value_t, ConstructibleArrayType >>::value >> +struct is_constructible_array_type_impl< + BasicJsonType, + ConstructibleArrayType, + enable_if_t<!std::is_same<ConstructibleArrayType, + typename BasicJsonType::value_type>::value && + !is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value && + is_default_constructible<ConstructibleArrayType>::value && + (std::is_move_assignable<ConstructibleArrayType>::value || + std::is_copy_assignable<ConstructibleArrayType>::value) && + is_detected<iterator_t, ConstructibleArrayType>::value && + is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value && + is_detected<range_value_t, ConstructibleArrayType>::value && + // special case for types like std::filesystem::path whose iterator's value_type are themselves + // c.f. https://github.com/nlohmann/json/pull/3073 + !std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value && + is_complete_type< + detected_t<range_value_t, ConstructibleArrayType>>::value>> { using value_type = range_value_t<ConstructibleArrayType>; static constexpr bool value = std::is_same<value_type, - typename BasicJsonType::array_t::value_type>::value || + typename BasicJsonType::array_t::value_type>::value || has_from_json<BasicJsonType, - value_type>::value || - has_non_default_from_json < - BasicJsonType, - value_type >::value; + value_type>::value || + has_non_default_from_json< + BasicJsonType, + value_type>::value; }; template<typename BasicJsonType, typename ConstructibleArrayType> struct is_constructible_array_type - : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {}; + : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> +{}; -template<typename RealIntegerType, typename CompatibleNumberIntegerType, - typename = void> -struct is_compatible_integer_type_impl : std::false_type {}; +template<typename RealIntegerType, typename CompatibleNumberIntegerType, typename = void> +struct is_compatible_integer_type_impl : std::false_type +{}; template<typename RealIntegerType, typename CompatibleNumberIntegerType> -struct is_compatible_integer_type_impl < - RealIntegerType, CompatibleNumberIntegerType, - enable_if_t < std::is_integral<RealIntegerType>::value&& - std::is_integral<CompatibleNumberIntegerType>::value&& - !std::is_same<bool, CompatibleNumberIntegerType>::value >> +struct is_compatible_integer_type_impl< + RealIntegerType, + CompatibleNumberIntegerType, + enable_if_t<std::is_integral<RealIntegerType>::value && + std::is_integral<CompatibleNumberIntegerType>::value && + !std::is_same<bool, CompatibleNumberIntegerType>::value>> { // is there an assert somewhere on overflows? using RealLimits = std::numeric_limits<RealIntegerType>; @@ -3920,23 +3676,26 @@ static constexpr auto value = is_constructible<RealIntegerType, - CompatibleNumberIntegerType>::value && + CompatibleNumberIntegerType>::value && CompatibleLimits::is_integer && RealLimits::is_signed == CompatibleLimits::is_signed; }; template<typename RealIntegerType, typename CompatibleNumberIntegerType> struct is_compatible_integer_type - : is_compatible_integer_type_impl<RealIntegerType, - CompatibleNumberIntegerType> {}; + : is_compatible_integer_type_impl<RealIntegerType, + CompatibleNumberIntegerType> +{}; template<typename BasicJsonType, typename CompatibleType, typename = void> -struct is_compatible_type_impl: std::false_type {}; +struct is_compatible_type_impl : std::false_type +{}; template<typename BasicJsonType, typename CompatibleType> -struct is_compatible_type_impl < - BasicJsonType, CompatibleType, - enable_if_t<is_complete_type<CompatibleType>::value >> +struct is_compatible_type_impl< + BasicJsonType, + CompatibleType, + enable_if_t<is_complete_type<CompatibleType>::value>> { static constexpr bool value = has_to_json<BasicJsonType, CompatibleType>::value; @@ -3944,60 +3703,60 @@ template<typename BasicJsonType, typename CompatibleType> struct is_compatible_type - : is_compatible_type_impl<BasicJsonType, CompatibleType> {}; + : is_compatible_type_impl<BasicJsonType, CompatibleType> +{}; template<typename T1, typename T2> -struct is_constructible_tuple : std::false_type {}; +struct is_constructible_tuple : std::false_type +{}; template<typename T1, typename... Args> -struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {}; +struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> +{}; template<typename BasicJsonType, typename T> -struct is_json_iterator_of : std::false_type {}; +struct is_json_iterator_of : std::false_type +{}; template<typename BasicJsonType> -struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::iterator> : std::true_type {}; +struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::iterator> : std::true_type +{}; template<typename BasicJsonType> struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type {}; // checks if a given type T is a template specialization of Primary -template<template <typename...> class Primary, typename T> -struct is_specialization_of : std::false_type {}; +template<template<typename...> class Primary, typename T> +struct is_specialization_of : std::false_type +{}; -template<template <typename...> class Primary, typename... Args> -struct is_specialization_of<Primary, Primary<Args...>> : std::true_type {}; +template<template<typename...> class Primary, typename... Args> +struct is_specialization_of<Primary, Primary<Args...>> : std::true_type +{}; template<typename T> using is_json_pointer = is_specialization_of<::nlohmann::json_pointer, uncvref_t<T>>; // checks if A and B are comparable using Compare functor template<typename Compare, typename A, typename B, typename = void> -struct is_comparable : std::false_type {}; +struct is_comparable : std::false_type +{}; template<typename Compare, typename A, typename B> -struct is_comparable<Compare, A, B, void_t< -decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())), -decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>())) ->> : std::true_type {}; +struct is_comparable<Compare, A, B, void_t<decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())), decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))>> : std::true_type +{}; template<typename T> using detect_is_transparent = typename T::is_transparent; // type trait to check if KeyType can be used as object key (without a BasicJsonType) // see is_usable_as_basic_json_key_type below -template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, - bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>> -using is_usable_as_key_type = typename std::conditional < - is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value - && !(ExcludeObjectKeyType && std::is_same<KeyType, - ObjectKeyType>::value) - && (!RequireTransparentComparator - || is_detected <detect_is_transparent, Comparator>::value) - && !is_json_pointer<KeyType>::value, - std::true_type, - std::false_type >::type; +template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>> +using is_usable_as_key_type = typename std::conditional< + is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value && !(ExcludeObjectKeyType && std::is_same<KeyType, ObjectKeyType>::value) && (!RequireTransparentComparator || is_detected<detect_is_transparent, Comparator>::value) && !is_json_pointer<KeyType>::value, + std::true_type, + std::false_type>::type; // type trait to check if KeyType can be used as object key // true if: @@ -4005,48 +3764,55 @@ // - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type // - the comparator is transparent or RequireTransparentComparator is false // - KeyType is not a JSON iterator or json_pointer -template<typename BasicJsonType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, - bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>> -using is_usable_as_basic_json_key_type = typename std::conditional < - is_usable_as_key_type<typename BasicJsonType::object_comparator_t, - typename BasicJsonType::object_t::key_type, KeyTypeCVRef, - RequireTransparentComparator, ExcludeObjectKeyType>::value - && !is_json_iterator_of<BasicJsonType, KeyType>::value, - std::true_type, - std::false_type >::type; +template<typename BasicJsonType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>> +using is_usable_as_basic_json_key_type = typename std::conditional< + is_usable_as_key_type<typename BasicJsonType::object_comparator_t, + typename BasicJsonType::object_t::key_type, + KeyTypeCVRef, + RequireTransparentComparator, + ExcludeObjectKeyType>::value && + !is_json_iterator_of<BasicJsonType, KeyType>::value, + std::true_type, + std::false_type>::type; template<typename ObjectType, typename KeyType> using detect_erase_with_key_type = decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>())); // type trait to check if object_t has an erase() member functions accepting KeyType template<typename BasicJsonType, typename KeyType> -using has_erase_with_key_type = typename std::conditional < - is_detected < - detect_erase_with_key_type, - typename BasicJsonType::object_t, KeyType >::value, - std::true_type, - std::false_type >::type; +using has_erase_with_key_type = typename std::conditional< + is_detected< + detect_erase_with_key_type, + typename BasicJsonType::object_t, + KeyType>::value, + std::true_type, + std::false_type>::type; // a naive helper to check if a type is an ordered_map (exploits the fact that // ordered_map inherits capacity() from std::vector) -template <typename T> +template<typename T> struct is_ordered_map { using one = char; struct two { - char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) }; - template <typename C> static one test( decltype(&C::capacity) ) ; - template <typename C> static two test(...); + template<typename C> + static one test(decltype(&C::capacity)); + template<typename C> + static two test(...); - enum { value = sizeof(test<T>(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + enum + { + value = sizeof(test<T>(nullptr)) == sizeof(char) + }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) }; // to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) -template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 > +template<typename T, typename U, enable_if_t<!std::is_same<T, U>::value, int> = 0> T conditional_static_cast(U value) { return static_cast<T>(value); @@ -4069,17 +3835,14 @@ // there's a disjunction trait in another PR; replace when merged template<typename... Types> -using same_sign = std::integral_constant < bool, - all_signed<Types...>::value || all_unsigned<Types...>::value >; +using same_sign = std::integral_constant<bool, + all_signed<Types...>::value || all_unsigned<Types...>::value>; template<typename OfType, typename T> -using never_out_of_range = std::integral_constant < bool, - (std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType))) - || (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T)) >; +using never_out_of_range = std::integral_constant<bool, + (std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType))) || (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T))>; -template<typename OfType, typename T, - bool OfTypeSigned = std::is_signed<OfType>::value, - bool TSigned = std::is_signed<T>::value> +template<typename OfType, typename T, bool OfTypeSigned = std::is_signed<OfType>::value, bool TSigned = std::is_signed<T>::value> struct value_in_range_of_impl2; template<typename OfType, typename T> @@ -4118,14 +3881,11 @@ static constexpr bool test(T val) { using CommonType = typename std::common_type<OfType, T>::type; - return static_cast<CommonType>(val) >= static_cast<CommonType>((std::numeric_limits<OfType>::min)()) - && static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)()); + return static_cast<CommonType>(val) >= static_cast<CommonType>((std::numeric_limits<OfType>::min)()) && static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)()); } }; -template<typename OfType, typename T, - bool NeverOutOfRange = never_out_of_range<OfType, T>::value, - typename = detail::enable_if_t<all_integral<OfType, T>::value>> +template<typename OfType, typename T, bool NeverOutOfRange = never_out_of_range<OfType, T>::value, typename = detail::enable_if_t<all_integral<OfType, T>::value>> struct value_in_range_of_impl1; template<typename OfType, typename T> @@ -4159,8 +3919,7 @@ // is_c_string /////////////////////////////////////////////////////////////////////////////// -namespace impl -{ +namespace impl { template<typename T> inline constexpr bool is_c_string() @@ -4169,16 +3928,15 @@ using TUnCVExt = typename std::remove_cv<TUnExt>::type; using TUnPtr = typename std::remove_pointer<T>::type; using TUnCVPtr = typename std::remove_cv<TUnPtr>::type; - return - (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value) - || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value); + return (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value) || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value); } } // namespace impl // checks whether T is a [cv] char */[cv] char[] C string template<typename T> -struct is_c_string : bool_constant<impl::is_c_string<T>()> {}; +struct is_c_string : bool_constant<impl::is_c_string<T>()> +{}; template<typename T> using is_c_string_uncvref = is_c_string<uncvref_t<T>>; @@ -4187,8 +3945,7 @@ // is_transparent /////////////////////////////////////////////////////////////////////////////// -namespace impl -{ +namespace impl { template<typename T> inline constexpr bool is_transparent() @@ -4200,7 +3957,8 @@ // checks whether T has a member named is_transparent template<typename T> -struct is_transparent : bool_constant<impl::is_transparent<T>()> {}; +struct is_transparent : bool_constant<impl::is_transparent<T>()> +{}; /////////////////////////////////////////////////////////////////////////////// @@ -4216,20 +3974,16 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <cstring> // strlen -#include <string> // string -#include <utility> // forward +#include <cstring> // strlen +#include <string> // string +#include <utility> // forward // #include <nlohmann/detail/meta/cpp_future.hpp> // #include <nlohmann/detail/meta/detected.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { inline std::size_t concat_length() { @@ -4237,26 +3991,26 @@ } template<typename... Args> -inline std::size_t concat_length(const char* cstr, const Args& ... rest); +inline std::size_t concat_length(const char* cstr, const Args&... rest); template<typename StringType, typename... Args> -inline std::size_t concat_length(const StringType& str, const Args& ... rest); +inline std::size_t concat_length(const StringType& str, const Args&... rest); template<typename... Args> -inline std::size_t concat_length(const char /*c*/, const Args& ... rest) +inline std::size_t concat_length(const char /*c*/, const Args&... rest) { return 1 + concat_length(rest...); } template<typename... Args> -inline std::size_t concat_length(const char* cstr, const Args& ... rest) +inline std::size_t concat_length(const char* cstr, const Args&... rest) { // cppcheck-suppress ignoredReturnValue return ::strlen(cstr) + concat_length(rest...); } template<typename StringType, typename... Args> -inline std::size_t concat_length(const StringType& str, const Args& ... rest) +inline std::size_t concat_length(const StringType& str, const Args&... rest) { return str.size() + concat_length(rest...); } @@ -4266,13 +4020,13 @@ {} template<typename StringType, typename Arg> -using string_can_append = decltype(std::declval<StringType&>().append(std::declval < Arg && > ())); +using string_can_append = decltype(std::declval<StringType&>().append(std::declval<Arg&&>())); template<typename StringType, typename Arg> using detect_string_can_append = is_detected<string_can_append, StringType, Arg>; template<typename StringType, typename Arg> -using string_can_append_op = decltype(std::declval<StringType&>() += std::declval < Arg && > ()); +using string_can_append_op = decltype(std::declval<StringType&>() += std::declval<Arg&&>()); template<typename StringType, typename Arg> using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>; @@ -4289,64 +4043,45 @@ template<typename StringType, typename Arg> using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>; -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && detect_string_can_append_op<OutStringType, Arg>::value, int > = 0 > -inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest); +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && detect_string_can_append_op<OutStringType, Arg>::value, int> = 0> +inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest); -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && !detect_string_can_append_op<OutStringType, Arg>::value - && detect_string_can_append_iter<OutStringType, Arg>::value, int > = 0 > -inline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest); +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && detect_string_can_append_iter<OutStringType, Arg>::value, int> = 0> +inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest); -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && !detect_string_can_append_op<OutStringType, Arg>::value - && !detect_string_can_append_iter<OutStringType, Arg>::value - && detect_string_can_append_data<OutStringType, Arg>::value, int > = 0 > -inline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest); +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && !detect_string_can_append_iter<OutStringType, Arg>::value && detect_string_can_append_data<OutStringType, Arg>::value, int> = 0> +inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest); -template<typename OutStringType, typename Arg, typename... Args, - enable_if_t<detect_string_can_append<OutStringType, Arg>::value, int> = 0> -inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest) +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<detect_string_can_append<OutStringType, Arg>::value, int> = 0> +inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest) { out.append(std::forward<Arg>(arg)); concat_into(out, std::forward<Args>(rest)...); } -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && detect_string_can_append_op<OutStringType, Arg>::value, int > > -inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest) +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && detect_string_can_append_op<OutStringType, Arg>::value, int>> +inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest) { out += std::forward<Arg>(arg); concat_into(out, std::forward<Args>(rest)...); } -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && !detect_string_can_append_op<OutStringType, Arg>::value - && detect_string_can_append_iter<OutStringType, Arg>::value, int > > -inline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest) +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && detect_string_can_append_iter<OutStringType, Arg>::value, int>> +inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest) { out.append(arg.begin(), arg.end()); concat_into(out, std::forward<Args>(rest)...); } -template < typename OutStringType, typename Arg, typename... Args, - enable_if_t < !detect_string_can_append<OutStringType, Arg>::value - && !detect_string_can_append_op<OutStringType, Arg>::value - && !detect_string_can_append_iter<OutStringType, Arg>::value - && detect_string_can_append_data<OutStringType, Arg>::value, int > > -inline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest) +template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && !detect_string_can_append_iter<OutStringType, Arg>::value && detect_string_can_append_data<OutStringType, Arg>::value, int>> +inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest) { out.append(arg.data(), arg.size()); concat_into(out, std::forward<Args>(rest)...); } template<typename OutStringType = std::string, typename... Args> -inline OutStringType concat(Args && ... args) +inline OutStringType concat(Args&&... args) { OutStringType str; str.reserve(concat_length(args...)); @@ -4357,10 +4092,201 @@ } // namespace detail NLOHMANN_JSON_NAMESPACE_END +// #include <nlohmann/detail/string_escape.hpp> +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> +// SPDX-License-Identifier: MIT + +// #include <nlohmann/detail/abi_macros.hpp> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail +namespace detail { + +/*! +@brief replace all occurrences of a substring by another string + +@param[in,out] s the string to manipulate; changed so that all + occurrences of @a f are replaced with @a t +@param[in] f the substring to replace with @a t +@param[in] t the string to replace @a f + +@pre The search string @a f must not be empty. **This precondition is +enforced with an assertion.** + +@since version 2.0.0 +*/ +template<typename StringType> +inline void replace_substring(StringType& s, const StringType& f, const StringType& t) { + JSON_ASSERT(!f.empty()); + for (auto pos = s.find(f); // find first occurrence of f + pos != StringType::npos; // make sure f was found + s.replace(pos, f.size(), t), // replace with t, and + pos = s.find(f, pos + t.size())) // find next occurrence of f + {} +} + +/*! + * @brief string escaping as described in RFC 6901 (Sect. 4) + * @param[in] s string to escape + * @return escaped string + * + * Note the order of escaping "~" to "~0" and "/" to "~1" is important. + */ +template<typename StringType> +inline StringType escape(StringType s) +{ + replace_substring(s, StringType{"~"}, StringType{"~0"}); + replace_substring(s, StringType{"/"}, StringType{"~1"}); + return s; +} + +/*! + * @brief string unescaping as described in RFC 6901 (Sect. 4) + * @param[in] s string to unescape + * @return unescaped string + * + * Note the order of escaping "~1" to "/" and "~0" to "~" is important. + */ +template<typename StringType> +static void unescape(StringType& s) +{ + replace_substring(s, StringType{"~1"}, StringType{"/"}); + replace_substring(s, StringType{"~0"}, StringType{"~"}); +} + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include <nlohmann/detail/value_t.hpp> +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> +// SPDX-License-Identifier: MIT + +#include <array> // array +#include <cstddef> // size_t +#include <cstdint> // uint8_t +#include <string> // string + +// #include <nlohmann/detail/macro_scope.hpp> + +#if JSON_HAS_THREE_WAY_COMPARISON + #include <compare> // partial_ordering +#endif + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail { + +/////////////////////////// +// JSON type enumeration // +/////////////////////////// + +/*! +@brief the JSON type enumeration + +This enumeration collects the different JSON types. It is internally used to +distinguish the stored values, and the functions @ref basic_json::is_null(), +@ref basic_json::is_object(), @ref basic_json::is_array(), +@ref basic_json::is_string(), @ref basic_json::is_boolean(), +@ref basic_json::is_number() (with @ref basic_json::is_number_integer(), +@ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()), +@ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and +@ref basic_json::is_structured() rely on it. + +@note There are three enumeration entries (number_integer, number_unsigned, and +number_float), because the library distinguishes these three types for numbers: +@ref basic_json::number_unsigned_t is used for unsigned integers, +@ref basic_json::number_integer_t is used for signed integers, and +@ref basic_json::number_float_t is used for floating-point numbers or to +approximate integers which do not fit in the limits of their respective type. + +@sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON +value with the default value for a given type + +@since version 1.0.0 +*/ +enum class value_t : std::uint8_t +{ + null, ///< null value + object, ///< object (unordered set of name/value pairs) + array, ///< array (ordered collection of values) + string, ///< string value + boolean, ///< boolean value + number_integer, ///< number value (signed integer) + number_unsigned, ///< number value (unsigned integer) + number_float, ///< number value (floating-point) + binary, ///< binary array (ordered collection of bytes) + discarded ///< discarded by the parser callback function +}; + +/*! +@brief comparison operator for JSON types + +Returns an ordering that is similar to Python: +- order: null < boolean < number < object < array < string < binary +- furthermore, each type is not smaller than itself +- discarded values are not comparable +- binary is represented as a b"" string in python and directly comparable to a + string; however, making a binary array directly comparable with a string would + be surprising behavior in a JSON file. + +@since version 1.0.0 +*/ +#if JSON_HAS_THREE_WAY_COMPARISON +inline std::partial_ordering operator<= > (const value_t lhs, const value_t rhs) noexcept // *NOPAD* +#else +inline bool operator<(const value_t lhs, const value_t rhs) noexcept +#endif +{ + static constexpr std::array<std::uint8_t, 9> order = {{ + 0 /* null */, + 3 /* object */, + 4 /* array */, + 5 /* string */, + 1 /* boolean */, + 2 /* integer */, + 2 /* unsigned */, + 2 /* float */, + 6 /* binary */ + }}; + + const auto l_index = static_cast<std::size_t>(lhs); + const auto r_index = static_cast<std::size_t>(rhs); +#if JSON_HAS_THREE_WAY_COMPARISON + if (l_index < order.size() && r_index < order.size()) + { + return order[l_index] <= > order[r_index]; // *NOPAD* + } + return std::partial_ordering::unordered; +#else + return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; +#endif +} + +// GCC selects the built-in operator< over an operator rewritten from +// a user-defined spaceship operator +// Clang, MSVC, and ICC select the rewritten candidate +// (see GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105200) +#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__) +inline bool operator<(const value_t lhs, const value_t rhs) noexcept +{ + return std::is_lt(lhs <= > rhs); // *NOPAD* +} +#endif + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail { //////////////// // exceptions // @@ -4378,11 +4304,14 @@ } /// the id of the exception - const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) + const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) protected: JSON_HEDLEY_NON_NULL(3) - exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} // NOLINT(bugprone-throw-keyword-missing) + exception(int id_, const char* what_arg) + : id(id_) + , m(what_arg) + {} // NOLINT(bugprone-throw-keyword-missing) static std::string name(const std::string& ename, int id_) { @@ -4429,16 +4358,16 @@ break; } - case value_t::null: // LCOV_EXCL_LINE - case value_t::string: // LCOV_EXCL_LINE - case value_t::boolean: // LCOV_EXCL_LINE - case value_t::number_integer: // LCOV_EXCL_LINE - case value_t::number_unsigned: // LCOV_EXCL_LINE - case value_t::number_float: // LCOV_EXCL_LINE - case value_t::binary: // LCOV_EXCL_LINE - case value_t::discarded: // LCOV_EXCL_LINE - default: // LCOV_EXCL_LINE - break; // LCOV_EXCL_LINE + case value_t::null: // LCOV_EXCL_LINE + case value_t::string: // LCOV_EXCL_LINE + case value_t::boolean: // LCOV_EXCL_LINE + case value_t::number_integer: // LCOV_EXCL_LINE + case value_t::number_unsigned: // LCOV_EXCL_LINE + case value_t::number_float: // LCOV_EXCL_LINE + case value_t::binary: // LCOV_EXCL_LINE + case value_t::discarded: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + break; // LCOV_EXCL_LINE } } @@ -4447,9 +4376,7 @@ return ""; } - auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, - [](const std::string & a, const std::string & b) - { + auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, [](const std::string& a, const std::string& b) { return concat(a, '/', detail::escape(b)); }); return concat('(', str, ") "); @@ -4481,17 +4408,14 @@ template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0> static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context) { - const std::string w = concat(exception::name("parse_error", id_), "parse error", - position_string(pos), ": ", exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("parse_error", id_), "parse error", position_string(pos), ": ", exception::diagnostics(context), what_arg); return {id_, pos.chars_read_total, w.c_str()}; } template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0> static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, BasicJsonContext context) { - const std::string w = concat(exception::name("parse_error", id_), "parse error", - (byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""), - ": ", exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("parse_error", id_), "parse error", (byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""), ": ", exception::diagnostics(context), what_arg); return {id_, byte_, w.c_str()}; } @@ -4508,12 +4432,13 @@ private: parse_error(int id_, std::size_t byte_, const char* what_arg) - : exception(id_, what_arg), byte(byte_) {} + : exception(id_, what_arg) + , byte(byte_) + {} static std::string position_string(const position_t& pos) { - return concat(" at line ", std::to_string(pos.lines_read + 1), - ", column ", std::to_string(pos.chars_read_current_line)); + return concat(" at line ", std::to_string(pos.lines_read + 1), ", column ", std::to_string(pos.chars_read_current_line)); } }; @@ -4532,7 +4457,8 @@ private: JSON_HEDLEY_NON_NULL(3) invalid_iterator(int id_, const char* what_arg) - : exception(id_, what_arg) {} + : exception(id_, what_arg) + {} }; /// @brief exception indicating executing a member function with a wrong type @@ -4549,7 +4475,9 @@ private: JSON_HEDLEY_NON_NULL(3) - type_error(int id_, const char* what_arg) : exception(id_, what_arg) {} + type_error(int id_, const char* what_arg) + : exception(id_, what_arg) + {} }; /// @brief exception indicating access out of the defined range @@ -4566,7 +4494,9 @@ private: JSON_HEDLEY_NON_NULL(3) - out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {} + out_of_range(int id_, const char* what_arg) + : exception(id_, what_arg) + {} }; /// @brief exception indicating other library errors @@ -4583,7 +4513,9 @@ private: JSON_HEDLEY_NON_NULL(3) - other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} + other_error(int id_, const char* what_arg) + : exception(id_, what_arg) + {} }; } // namespace detail @@ -4602,17 +4534,15 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - // #include <nlohmann/detail/abi_macros.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { // dispatching helper struct -template <class T> struct identity_tag {}; +template<class T> +struct identity_tag +{}; } // namespace detail NLOHMANN_JSON_NAMESPACE_END @@ -4626,24 +4556,19 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - // #include <nlohmann/detail/macro_scope.hpp> - #if JSON_HAS_EXPERIMENTAL_FILESYSTEM -#include <experimental/filesystem> + #include <experimental/filesystem> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { namespace std_fs = std::experimental::filesystem; } // namespace detail NLOHMANN_JSON_NAMESPACE_END #elif JSON_HAS_FILESYSTEM -#include <filesystem> + #include <filesystem> NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { namespace std_fs = std::filesystem; } // namespace detail NLOHMANN_JSON_NAMESPACE_END @@ -4655,10 +4580,8 @@ // #include <nlohmann/detail/value_t.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename BasicJsonType> inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n) @@ -4671,10 +4594,7 @@ } // overloads for basic_json template parameters -template < typename BasicJsonType, typename ArithmeticType, - enable_if_t < std::is_arithmetic<ArithmeticType>::value&& - !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, - int > = 0 > +template<typename BasicJsonType, typename ArithmeticType, enable_if_t<std::is_arithmetic<ArithmeticType>::value && !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, int> = 0> void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) { switch (static_cast<value_t>(j)) @@ -4727,13 +4647,12 @@ s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); } -template < - typename BasicJsonType, typename StringType, - enable_if_t < - std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value - && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value - && !std::is_same<typename BasicJsonType::string_t, StringType>::value - && !is_json_ref<StringType>::value, int > = 0 > +template< + typename BasicJsonType, + typename StringType, + enable_if_t< + std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value && !std::is_same<typename BasicJsonType::string_t, StringType>::value && !is_json_ref<StringType>::value, + int> = 0> inline void from_json(const BasicJsonType& j, StringType& s) { if (JSON_HEDLEY_UNLIKELY(!j.is_string())) @@ -4763,8 +4682,7 @@ } #if !JSON_DISABLE_ENUM_SERIALIZATION -template<typename BasicJsonType, typename EnumType, - enable_if_t<std::is_enum<EnumType>::value, int> = 0> +template<typename BasicJsonType, typename EnumType, enable_if_t<std::is_enum<EnumType>::value, int> = 0> inline void from_json(const BasicJsonType& j, EnumType& e) { typename std::underlying_type<EnumType>::type val; @@ -4774,8 +4692,7 @@ #endif // JSON_DISABLE_ENUM_SERIALIZATION // forward_list doesn't have an insert method -template<typename BasicJsonType, typename T, typename Allocator, - enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> +template<typename BasicJsonType, typename T, typename Allocator, enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> inline void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) @@ -4783,16 +4700,13 @@ JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); } l.clear(); - std::transform(j.rbegin(), j.rend(), - std::front_inserter(l), [](const BasicJsonType & i) - { + std::transform(j.rbegin(), j.rend(), std::front_inserter(l), [](const BasicJsonType& i) { return i.template get<T>(); }); } // valarray doesn't have an insert method -template<typename BasicJsonType, typename T, - enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> +template<typename BasicJsonType, typename T, enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> inline void from_json(const BasicJsonType& j, std::valarray<T>& l) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) @@ -4800,16 +4714,14 @@ JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); } l.resize(j.size()); - std::transform(j.begin(), j.end(), std::begin(l), - [](const BasicJsonType & elem) - { + std::transform(j.begin(), j.end(), std::begin(l), [](const BasicJsonType& elem) { return elem.template get<T>(); }); } template<typename BasicJsonType, typename T, std::size_t N> auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) --> decltype(j.template get<T>(), void()) + -> decltype(j.template get<T>(), void()) { for (std::size_t i = 0; i < N; ++i) { @@ -4824,9 +4736,8 @@ } template<typename BasicJsonType, typename T, std::size_t N> -auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, - priority_tag<2> /*unused*/) --> decltype(j.template get<T>(), void()) +auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, priority_tag<2> /*unused*/) + -> decltype(j.template get<T>(), void()) { for (std::size_t i = 0; i < N; ++i) { @@ -4834,23 +4745,17 @@ } } -template<typename BasicJsonType, typename ConstructibleArrayType, - enable_if_t< - std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, - int> = 0> +template<typename BasicJsonType, typename ConstructibleArrayType, enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, int> = 0> auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/) --> decltype( - arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()), - j.template get<typename ConstructibleArrayType::value_type>(), - void()) + -> decltype(arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()), + j.template get<typename ConstructibleArrayType::value_type>(), + void()) { using std::end; ConstructibleArrayType ret; ret.reserve(j.size()); - std::transform(j.begin(), j.end(), - std::inserter(ret, end(ret)), [](const BasicJsonType & i) - { + std::transform(j.begin(), j.end(), std::inserter(ret, end(ret)), [](const BasicJsonType& i) { // get<BasicJsonType>() returns *this, this won't call a from_json // method when value_type is BasicJsonType return i.template get<typename ConstructibleArrayType::value_type>(); @@ -4858,65 +4763,56 @@ arr = std::move(ret); } -template<typename BasicJsonType, typename ConstructibleArrayType, - enable_if_t< - std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, - int> = 0> -inline void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, - priority_tag<0> /*unused*/) +template<typename BasicJsonType, typename ConstructibleArrayType, enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, int> = 0> +inline void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<0> /*unused*/) { using std::end; ConstructibleArrayType ret; std::transform( - j.begin(), j.end(), std::inserter(ret, end(ret)), - [](const BasicJsonType & i) - { - // get<BasicJsonType>() returns *this, this won't call a from_json - // method when value_type is BasicJsonType - return i.template get<typename ConstructibleArrayType::value_type>(); - }); + j.begin(), + j.end(), + std::inserter(ret, end(ret)), + [](const BasicJsonType& i) { + // get<BasicJsonType>() returns *this, this won't call a from_json + // method when value_type is BasicJsonType + return i.template get<typename ConstructibleArrayType::value_type>(); + }); arr = std::move(ret); } -template < typename BasicJsonType, typename ConstructibleArrayType, - enable_if_t < - is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&& - !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&& - !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&& - !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&& - !is_basic_json<ConstructibleArrayType>::value, - int > = 0 > +template<typename BasicJsonType, typename ConstructibleArrayType, enable_if_t<is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value && !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value && !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value && !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value && !is_basic_json<ConstructibleArrayType>::value, int> = 0> auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr) --> decltype(from_json_array_impl(j, arr, priority_tag<3> {}), -j.template get<typename ConstructibleArrayType::value_type>(), -void()) + -> decltype(from_json_array_impl(j, arr, priority_tag<3>{}), + j.template get<typename ConstructibleArrayType::value_type>(), + void()) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); } - from_json_array_impl(j, arr, priority_tag<3> {}); + from_json_array_impl(j, arr, priority_tag<3>{}); } -template < typename BasicJsonType, typename T, std::size_t... Idx > +template<typename BasicJsonType, typename T, std::size_t... Idx> std::array<T, sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j, - identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/) + identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, + index_sequence<Idx...> /*unused*/) { - return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } }; + return {{std::forward<BasicJsonType>(j).at(Idx).template get<T>()...}}; } -template < typename BasicJsonType, typename T, std::size_t N > +template<typename BasicJsonType, typename T, std::size_t N> auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag) --> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {})) + -> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N>{})) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); } - return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}); + return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N>{}); } template<typename BasicJsonType> @@ -4930,8 +4826,7 @@ bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>(); } -template<typename BasicJsonType, typename ConstructibleObjectType, - enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0> +template<typename BasicJsonType, typename ConstructibleObjectType, enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0> inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) { if (JSON_HEDLEY_UNLIKELY(!j.is_object())) @@ -4943,12 +4838,12 @@ const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>(); using value_type = typename ConstructibleObjectType::value_type; std::transform( - inner_object->begin(), inner_object->end(), + inner_object->begin(), + inner_object->end(), std::inserter(ret, ret.begin()), - [](typename BasicJsonType::object_t::value_type const & p) - { - return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>()); - }); + [](typename BasicJsonType::object_t::value_type const& p) { + return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>()); + }); obj = std::move(ret); } @@ -4956,14 +4851,7 @@ // (BooleanType, etc..); note: Is it really necessary to provide explicit // overloads for boolean_t etc. in case of a custom BooleanType which is not // an arithmetic type? -template < typename BasicJsonType, typename ArithmeticType, - enable_if_t < - std::is_arithmetic<ArithmeticType>::value&& - !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&& - !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&& - !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&& - !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, - int > = 0 > +template<typename BasicJsonType, typename ArithmeticType, enable_if_t<std::is_arithmetic<ArithmeticType>::value && !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value && !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value && !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value && !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, int> = 0> inline void from_json(const BasicJsonType& j, ArithmeticType& val) { switch (static_cast<value_t>(j)) @@ -5006,7 +4894,7 @@ return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).template get<Args>()...); } -template < typename BasicJsonType, class A1, class A2 > +template<typename BasicJsonType, class A1, class A2> std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/) { return {std::forward<BasicJsonType>(j).at(0).template get<A1>(), @@ -5016,36 +4904,34 @@ template<typename BasicJsonType, typename A1, typename A2> inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> /*unused*/) { - p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {}); + p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>>{}, priority_tag<0>{}); } template<typename BasicJsonType, typename... Args> std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> /*unused*/, priority_tag<2> /*unused*/) { - return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {}); + return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...>{}); } template<typename BasicJsonType, typename... Args> inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> /*unused*/) { - t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {}); + t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...>{}); } template<typename BasicJsonType, typename TupleRelated> auto from_json(BasicJsonType&& j, TupleRelated&& t) --> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {})) + -> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3>{})) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); } - return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}); + return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3>{}); } -template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator, - typename = enable_if_t < !std::is_constructible < - typename BasicJsonType::string_t, Key >::value >> +template<typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator, typename = enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, Key>::value>> inline void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) @@ -5063,9 +4949,7 @@ } } -template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator, - typename = enable_if_t < !std::is_constructible < - typename BasicJsonType::string_t, Key >::value >> +template<typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator, typename = enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, Key>::value>> inline void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m) { if (JSON_HEDLEY_UNLIKELY(!j.is_array())) @@ -5099,8 +4983,8 @@ { template<typename BasicJsonType, typename T> auto operator()(const BasicJsonType& j, T&& val) const - noexcept(noexcept(from_json(j, std::forward<T>(val)))) - -> decltype(from_json(j, std::forward<T>(val))) + noexcept(noexcept(from_json(j, std::forward<T>(val)))) + -> decltype(from_json(j, std::forward<T>(val))) { return from_json(j, std::forward<T>(val)); } @@ -5112,10 +4996,10 @@ /// namespace to hold default `from_json` function /// to see why this is required: /// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html -namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) +namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) { #endif -JSON_INLINE_VARIABLE constexpr const auto& from_json = // NOLINT(misc-definitions-in-headers) +JSON_INLINE_VARIABLE constexpr const auto& from_json = // NOLINT(misc-definitions-in-headers) detail::static_const<detail::from_json_fn>::value; #ifndef JSON_HAS_CPP_17 } // namespace @@ -5132,16 +5016,14 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <algorithm> // copy -#include <iterator> // begin, end -#include <string> // string -#include <tuple> // tuple, get -#include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type -#include <utility> // move, forward, declval, pair -#include <valarray> // valarray -#include <vector> // vector +#include <algorithm> // copy +#include <iterator> // begin, end +#include <string> // string +#include <tuple> // tuple, get +#include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type +#include <utility> // move, forward, declval, pair +#include <valarray> // valarray +#include <vector> // vector // #include <nlohmann/detail/iterators/iteration_proxy.hpp> // __ _____ _____ _____ @@ -5152,16 +5034,14 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <cstddef> // size_t -#include <iterator> // input_iterator_tag -#include <string> // string, to_string -#include <tuple> // tuple_size, get, tuple_element -#include <utility> // move +#include <cstddef> // size_t +#include <iterator> // input_iterator_tag +#include <string> // string, to_string +#include <tuple> // tuple_size, get, tuple_element +#include <utility> // move #if JSON_HAS_RANGES - #include <ranges> // enable_borrowed_range + #include <ranges> // enable_borrowed_range #endif // #include <nlohmann/detail/abi_macros.hpp> @@ -5170,27 +5050,26 @@ // #include <nlohmann/detail/value_t.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename string_type> -void int_to_string( string_type& target, std::size_t value ) +void int_to_string(string_type& target, std::size_t value) { // For ADL using std::to_string; target = to_string(value); } -template<typename IteratorType> class iteration_proxy_value +template<typename IteratorType> +class iteration_proxy_value { public: using difference_type = std::ptrdiff_t; using value_type = iteration_proxy_value; - using pointer = value_type *; - using reference = value_type &; + using pointer = value_type*; + using reference = value_type&; using iterator_category = std::input_iterator_tag; - using string_type = typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type; + using string_type = typename std::remove_cv<typename std::remove_reference<decltype(std::declval<IteratorType>().key())>::type>::type; private: /// the iterator @@ -5206,22 +5085,16 @@ public: explicit iteration_proxy_value() = default; - explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0) - noexcept(std::is_nothrow_move_constructible<IteratorType>::value - && std::is_nothrow_default_constructible<string_type>::value) - : anchor(std::move(it)) - , array_index(array_index_) + explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0) noexcept(std::is_nothrow_move_constructible<IteratorType>::value && std::is_nothrow_default_constructible<string_type>::value) + : anchor(std::move(it)) + , array_index(array_index_) {} iteration_proxy_value(iteration_proxy_value const&) = default; iteration_proxy_value& operator=(iteration_proxy_value const&) = default; // older GCCs are a bit fussy and require explicit noexcept specifiers on defaulted functions - iteration_proxy_value(iteration_proxy_value&&) - noexcept(std::is_nothrow_move_constructible<IteratorType>::value - && std::is_nothrow_move_constructible<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations) - iteration_proxy_value& operator=(iteration_proxy_value&&) - noexcept(std::is_nothrow_move_assignable<IteratorType>::value - && std::is_nothrow_move_assignable<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations) + iteration_proxy_value(iteration_proxy_value&&) noexcept(std::is_nothrow_move_constructible<IteratorType>::value && std::is_nothrow_move_constructible<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations) + iteration_proxy_value& operator=(iteration_proxy_value&&) noexcept(std::is_nothrow_move_assignable<IteratorType>::value && std::is_nothrow_move_assignable<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations) ~iteration_proxy_value() = default; /// dereference operator (needed for range-based for) @@ -5239,7 +5112,7 @@ return *this; } - iteration_proxy_value operator++(int)& // NOLINT(cert-dcl21-cpp) + iteration_proxy_value operator++(int) & // NOLINT(cert-dcl21-cpp) { auto tmp = iteration_proxy_value(anchor, array_index); ++anchor; @@ -5271,7 +5144,7 @@ { if (array_index != array_index_last) { - int_to_string( array_index_str, array_index ); + int_to_string(array_index_str, array_index); array_index_last = array_index; } return array_index_str; @@ -5303,7 +5176,8 @@ }; /// proxy class for the items() function -template<typename IteratorType> class iteration_proxy +template<typename IteratorType> +class iteration_proxy { private: /// the container to iterate @@ -5314,7 +5188,8 @@ /// construct iteration proxy from a container explicit iteration_proxy(typename IteratorType::reference cont) noexcept - : container(&cont) {} + : container(&cont) + {} iteration_proxy(iteration_proxy const&) = default; iteration_proxy& operator=(iteration_proxy const&) = default; @@ -5359,8 +5234,7 @@ // Structured Bindings Support to the iteration_proxy_value class // For further reference see https://blog.tartanllama.xyz/structured-bindings/ // And see https://github.com/nlohmann/json/pull/1391 -namespace std -{ +namespace std { #if defined(__clang__) // Fix: https://github.com/nlohmann/json/issues/1401 @@ -5368,16 +5242,16 @@ #pragma clang diagnostic ignored "-Wmismatched-tags" #endif template<typename IteratorType> -class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp) - : public std::integral_constant<std::size_t, 2> {}; +class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp) + : public std::integral_constant<std::size_t, 2> +{}; template<std::size_t N, typename IteratorType> -class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp) +class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp) { public: - using type = decltype( - get<N>(std::declval < - ::nlohmann::detail::iteration_proxy_value<IteratorType >> ())); + using type = decltype(get<N>(std::declval< + ::nlohmann::detail::iteration_proxy_value<IteratorType>>())); }; #if defined(__clang__) #pragma clang diagnostic pop @@ -5386,8 +5260,8 @@ } // namespace std #if JSON_HAS_RANGES - template <typename IteratorType> - inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> = true; +template<typename IteratorType> +inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> = true; #endif // #include <nlohmann/detail/macro_scope.hpp> @@ -5400,10 +5274,8 @@ // #include <nlohmann/detail/value_t.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { ////////////////// // constructors // @@ -5416,7 +5288,8 @@ * https://github.com/nlohmann/json/issues/2865 for more information. */ -template<value_t> struct external_constructor; +template<value_t> +struct external_constructor; template<> struct external_constructor<value_t::boolean> @@ -5452,9 +5325,7 @@ j.assert_invariant(); } - template < typename BasicJsonType, typename CompatibleStringType, - enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value, - int > = 0 > + template<typename BasicJsonType, typename CompatibleStringType, enable_if_t<!std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value, int> = 0> static void construct(BasicJsonType& j, const CompatibleStringType& str) { j.m_data.m_value.destroy(j.m_data.m_type); @@ -5548,9 +5419,7 @@ j.assert_invariant(); } - template < typename BasicJsonType, typename CompatibleArrayType, - enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value, - int > = 0 > + template<typename BasicJsonType, typename CompatibleArrayType, enable_if_t<!std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value, int> = 0> static void construct(BasicJsonType& j, const CompatibleArrayType& arr) { using std::begin; @@ -5578,8 +5447,7 @@ j.assert_invariant(); } - template<typename BasicJsonType, typename T, - enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> + template<typename BasicJsonType, typename T, enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> static void construct(BasicJsonType& j, const std::valarray<T>& arr) { j.m_data.m_value.destroy(j.m_data.m_type); @@ -5618,8 +5486,7 @@ j.assert_invariant(); } - template < typename BasicJsonType, typename CompatibleObjectType, - enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int > = 0 > + template<typename BasicJsonType, typename CompatibleObjectType, enable_if_t<!std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int> = 0> static void construct(BasicJsonType& j, const CompatibleObjectType& obj) { using std::begin; @@ -5637,28 +5504,19 @@ // to_json // ///////////// -template<typename BasicJsonType, typename T, - enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0> +template<typename BasicJsonType, typename T, enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0> inline void to_json(BasicJsonType& j, T b) noexcept { external_constructor<value_t::boolean>::construct(j, b); } -template < typename BasicJsonType, typename BoolRef, - enable_if_t < - ((std::is_same<std::vector<bool>::reference, BoolRef>::value - && !std::is_same <std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value) - || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value - && !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>, - typename BasicJsonType::boolean_t >::value)) - && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value, int > = 0 > +template<typename BasicJsonType, typename BoolRef, enable_if_t<((std::is_same<std::vector<bool>::reference, BoolRef>::value && !std::is_same<std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value) || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value && !std::is_same<detail::uncvref_t<std::vector<bool>::const_reference>, typename BasicJsonType::boolean_t>::value)) && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value, int> = 0> inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept { external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b)); } -template<typename BasicJsonType, typename CompatibleString, - enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0> +template<typename BasicJsonType, typename CompatibleString, enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0> inline void to_json(BasicJsonType& j, const CompatibleString& s) { external_constructor<value_t::string>::construct(j, s); @@ -5670,30 +5528,26 @@ external_constructor<value_t::string>::construct(j, std::move(s)); } -template<typename BasicJsonType, typename FloatType, - enable_if_t<std::is_floating_point<FloatType>::value, int> = 0> +template<typename BasicJsonType, typename FloatType, enable_if_t<std::is_floating_point<FloatType>::value, int> = 0> inline void to_json(BasicJsonType& j, FloatType val) noexcept { external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val)); } -template<typename BasicJsonType, typename CompatibleNumberUnsignedType, - enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0> +template<typename BasicJsonType, typename CompatibleNumberUnsignedType, enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0> inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept { external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val)); } -template<typename BasicJsonType, typename CompatibleNumberIntegerType, - enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0> +template<typename BasicJsonType, typename CompatibleNumberIntegerType, enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0> inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept { external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val)); } #if !JSON_DISABLE_ENUM_SERIALIZATION -template<typename BasicJsonType, typename EnumType, - enable_if_t<std::is_enum<EnumType>::value, int> = 0> +template<typename BasicJsonType, typename EnumType, enable_if_t<std::is_enum<EnumType>::value, int> = 0> inline void to_json(BasicJsonType& j, EnumType e) noexcept { using underlying_type = typename std::underlying_type<EnumType>::type; @@ -5707,14 +5561,7 @@ external_constructor<value_t::array>::construct(j, e); } -template < typename BasicJsonType, typename CompatibleArrayType, - enable_if_t < is_compatible_array_type<BasicJsonType, - CompatibleArrayType>::value&& - !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&& - !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&& - !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&& - !is_basic_json<CompatibleArrayType>::value, - int > = 0 > +template<typename BasicJsonType, typename CompatibleArrayType, enable_if_t<is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value && !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value && !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value && !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value && !is_basic_json<CompatibleArrayType>::value, int> = 0> inline void to_json(BasicJsonType& j, const CompatibleArrayType& arr) { external_constructor<value_t::array>::construct(j, arr); @@ -5726,8 +5573,7 @@ external_constructor<value_t::binary>::construct(j, bin); } -template<typename BasicJsonType, typename T, - enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> +template<typename BasicJsonType, typename T, enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> inline void to_json(BasicJsonType& j, const std::valarray<T>& arr) { external_constructor<value_t::array>::construct(j, std::move(arr)); @@ -5739,8 +5585,7 @@ external_constructor<value_t::array>::construct(j, std::move(arr)); } -template < typename BasicJsonType, typename CompatibleObjectType, - enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value, int > = 0 > +template<typename BasicJsonType, typename CompatibleObjectType, enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value && !is_basic_json<CompatibleObjectType>::value, int> = 0> inline void to_json(BasicJsonType& j, const CompatibleObjectType& obj) { external_constructor<value_t::object>::construct(j, obj); @@ -5752,40 +5597,41 @@ external_constructor<value_t::object>::construct(j, std::move(obj)); } -template < - typename BasicJsonType, typename T, std::size_t N, - enable_if_t < !std::is_constructible<typename BasicJsonType::string_t, - const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - int > = 0 > -inline void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) +template< + typename BasicJsonType, + typename T, + std::size_t N, + enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, + const T (&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + int> = 0> +inline void to_json(BasicJsonType& j, const T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) { external_constructor<value_t::array>::construct(j, arr); } -template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value, int > = 0 > +template<typename BasicJsonType, typename T1, typename T2, enable_if_t<std::is_constructible<BasicJsonType, T1>::value && std::is_constructible<BasicJsonType, T2>::value, int> = 0> inline void to_json(BasicJsonType& j, const std::pair<T1, T2>& p) { - j = { p.first, p.second }; + j = {p.first, p.second}; } // for https://github.com/nlohmann/json/pull/1134 -template<typename BasicJsonType, typename T, - enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0> +template<typename BasicJsonType, typename T, enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0> inline void to_json(BasicJsonType& j, const T& b) { - j = { {b.key(), b.value()} }; + j = {{b.key(), b.value()}}; } template<typename BasicJsonType, typename Tuple, std::size_t... Idx> inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/) { - j = { std::get<Idx>(t)... }; + j = {std::get<Idx>(t)...}; } -template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int > = 0> +template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int> = 0> inline void to_json(BasicJsonType& j, const T& t) { - to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {}); + to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value>{}); } #if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM @@ -5800,7 +5646,7 @@ { template<typename BasicJsonType, typename T> auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j, std::forward<T>(val)))) - -> decltype(to_json(j, std::forward<T>(val)), void()) + -> decltype(to_json(j, std::forward<T>(val)), void()) { return to_json(j, std::forward<T>(val)); } @@ -5811,10 +5657,10 @@ /// namespace to hold default `to_json` function /// to see why this is required: /// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html -namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) +namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) { #endif -JSON_INLINE_VARIABLE constexpr const auto& to_json = // NOLINT(misc-definitions-in-headers) +JSON_INLINE_VARIABLE constexpr const auto& to_json = // NOLINT(misc-definitions-in-headers) detail::static_const<detail::to_json_fn>::value; #ifndef JSON_HAS_CPP_17 } // namespace @@ -5824,7 +5670,6 @@ // #include <nlohmann/detail/meta/identity_tag.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN /// @sa https://json.nlohmann.me/api/adl_serializer/ @@ -5834,9 +5679,9 @@ /// @brief convert a JSON value to any value type /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/ template<typename BasicJsonType, typename TargetType = ValueType> - static auto from_json(BasicJsonType && j, TargetType& val) noexcept( + static auto from_json(BasicJsonType&& j, TargetType& val) noexcept( noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val))) - -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void()) + -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void()) { ::nlohmann::from_json(std::forward<BasicJsonType>(j), val); } @@ -5844,19 +5689,19 @@ /// @brief convert a JSON value to any value type /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/ template<typename BasicJsonType, typename TargetType = ValueType> - static auto from_json(BasicJsonType && j) noexcept( - noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))) - -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})) + static auto from_json(BasicJsonType&& j) noexcept( + noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType>{}))) + -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType>{})) { - return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}); + return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType>{}); } /// @brief convert any value type to a JSON value /// @sa https://json.nlohmann.me/api/adl_serializer/to_json/ template<typename BasicJsonType, typename TargetType = ValueType> - static auto to_json(BasicJsonType& j, TargetType && val) noexcept( + static auto to_json(BasicJsonType& j, TargetType&& val) noexcept( noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val)))) - -> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void()) + -> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void()) { ::nlohmann::to_json(j, std::forward<TargetType>(val)); } @@ -5873,15 +5718,12 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <cstdint> // uint8_t, uint64_t -#include <tuple> // tie -#include <utility> // move +#include <cstdint> // uint8_t, uint64_t +#include <tuple> // tie +#include <utility> // move // #include <nlohmann/detail/abi_macros.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN /// @brief an internal type for a backed binary type @@ -5895,31 +5737,31 @@ /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype() noexcept(noexcept(container_type())) - : container_type() + : container_type() {} /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b))) - : container_type(b) + : container_type(b) {} /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b)))) - : container_type(std::move(b)) + : container_type(std::move(b)) {} /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b))) - : container_type(b) - , m_subtype(subtype_) - , m_has_subtype(true) + : container_type(b) + , m_subtype(subtype_) + , m_has_subtype(true) {} /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b)))) - : container_type(std::move(b)) - , m_subtype(subtype_) - , m_has_subtype(true) + : container_type(std::move(b)) + , m_subtype(subtype_) + , m_has_subtype(true) {} bool operator==(const byte_container_with_subtype& rhs) const @@ -5985,20 +5827,16 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <cstdint> // uint8_t -#include <cstddef> // size_t -#include <functional> // hash +#include <cstddef> // size_t +#include <cstdint> // uint8_t +#include <functional> // hash // #include <nlohmann/detail/abi_macros.hpp> // #include <nlohmann/detail/value_t.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { // boost::hash_combine inline std::size_t combine(std::size_t seed, std::size_t h) noexcept @@ -6040,7 +5878,7 @@ auto seed = combine(type, j.size()); for (const auto& element : j.items()) { - const auto h = std::hash<string_t> {}(element.key()); + const auto h = std::hash<string_t>{}(element.key()); seed = combine(seed, h); seed = combine(seed, hash(element.value())); } @@ -6059,50 +5897,50 @@ case BasicJsonType::value_t::string: { - const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>()); + const auto h = std::hash<string_t>{}(j.template get_ref<const string_t&>()); return combine(type, h); } case BasicJsonType::value_t::boolean: { - const auto h = std::hash<bool> {}(j.template get<bool>()); + const auto h = std::hash<bool>{}(j.template get<bool>()); return combine(type, h); } case BasicJsonType::value_t::number_integer: { - const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>()); + const auto h = std::hash<number_integer_t>{}(j.template get<number_integer_t>()); return combine(type, h); } case BasicJsonType::value_t::number_unsigned: { - const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>()); + const auto h = std::hash<number_unsigned_t>{}(j.template get<number_unsigned_t>()); return combine(type, h); } case BasicJsonType::value_t::number_float: { - const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>()); + const auto h = std::hash<number_float_t>{}(j.template get<number_float_t>()); return combine(type, h); } case BasicJsonType::value_t::binary: { auto seed = combine(type, j.get_binary().size()); - const auto h = std::hash<bool> {}(j.get_binary().has_subtype()); + const auto h = std::hash<bool>{}(j.get_binary().has_subtype()); seed = combine(seed, h); seed = combine(seed, static_cast<std::size_t>(j.get_binary().subtype())); for (const auto byte : j.get_binary()) { - seed = combine(seed, std::hash<std::uint8_t> {}(byte)); + seed = combine(seed, std::hash<std::uint8_t>{}(byte)); } return seed; } - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE - return 0; // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + return 0; // LCOV_EXCL_LINE } } @@ -6118,20 +5956,18 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <algorithm> // generate_n -#include <array> // array -#include <cmath> // ldexp -#include <cstddef> // size_t -#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t -#include <cstdio> // snprintf -#include <cstring> // memcpy -#include <iterator> // back_inserter -#include <limits> // numeric_limits -#include <string> // char_traits, string -#include <utility> // make_pair, move -#include <vector> // vector +#include <algorithm> // generate_n +#include <array> // array +#include <cmath> // ldexp +#include <cstddef> // size_t +#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t +#include <cstdio> // snprintf +#include <cstring> // memcpy +#include <iterator> // back_inserter +#include <limits> // numeric_limits +#include <string> // char_traits, string +#include <utility> // make_pair, move +#include <vector> // vector // #include <nlohmann/detail/exceptions.hpp> @@ -6144,17 +5980,15 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <array> // array -#include <cstddef> // size_t -#include <cstring> // strlen -#include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next -#include <memory> // shared_ptr, make_shared, addressof -#include <numeric> // accumulate -#include <string> // string, char_traits -#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer -#include <utility> // pair, declval +#include <array> // array +#include <cstddef> // size_t +#include <cstring> // strlen +#include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next +#include <memory> // shared_ptr, make_shared, addressof +#include <numeric> // accumulate +#include <string> // string, char_traits +#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer +#include <utility> // pair, declval #ifndef JSON_NO_IO #include <cstdio> // FILE * @@ -6167,13 +6001,19 @@ // #include <nlohmann/detail/meta/type_traits.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /// the supported input formats -enum class input_format_t { json, cbor, msgpack, ubjson, bson, bjdata }; +enum class input_format_t +{ + json, + cbor, + msgpack, + ubjson, + bson, + bjdata +}; //////////////////// // input adapters // @@ -6191,7 +6031,7 @@ JSON_HEDLEY_NON_NULL(2) explicit file_input_adapter(std::FILE* f) noexcept - : m_file(f) + : m_file(f) { JSON_ASSERT(m_file != nullptr); } @@ -6238,7 +6078,8 @@ } explicit input_stream_adapter(std::istream& i) - : is(&i), sb(i.rdbuf()) + : is(&i) + , sb(i.rdbuf()) {} // delete because of pointer members @@ -6247,7 +6088,8 @@ input_stream_adapter& operator=(input_stream_adapter&&) = delete; input_stream_adapter(input_stream_adapter&& rhs) noexcept - : is(rhs.is), sb(rhs.sb) + : is(rhs.is) + , sb(rhs.sb) { rhs.is = nullptr; rhs.sb = nullptr; @@ -6283,7 +6125,8 @@ using char_type = typename std::iterator_traits<IteratorType>::value_type; iterator_input_adapter(IteratorType first, IteratorType last) - : current(std::move(first)), end(std::move(last)) + : current(std::move(first)) + , end(std::move(last)) {} typename char_traits<char_type>::int_type get_character() @@ -6442,7 +6285,8 @@ using char_type = char; wide_string_input_adapter(BaseInputAdapter base) - : base_adapter(base) {} + : base_adapter(base) + {} typename std::char_traits<char>::int_type get_character() noexcept { @@ -6528,26 +6372,26 @@ // Enables ADL on begin(container) and end(container) // Encloses the using declarations in namespace for not to leak them to outside scope -namespace container_input_adapter_factory_impl -{ +namespace container_input_adapter_factory_impl { using std::begin; using std::end; template<typename ContainerType, typename Enable = void> -struct container_input_adapter_factory {}; +struct container_input_adapter_factory +{}; template<typename ContainerType> -struct container_input_adapter_factory< ContainerType, - void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>> - { - using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))); - - static adapter_type create(const ContainerType& container) +struct container_input_adapter_factory<ContainerType, + void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>> { - return input_adapter(begin(container), end(container)); -} - }; + using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))); + + static adapter_type create(const ContainerType& container) + { + return input_adapter(begin(container), end(container)); + } +}; } // namespace container_input_adapter_factory_impl @@ -6578,13 +6422,13 @@ using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>())); // Null-delimited strings, and the like. -template < typename CharT, - typename std::enable_if < - std::is_pointer<CharT>::value&& - !std::is_array<CharT>::value&& - std::is_integral<typename std::remove_pointer<CharT>::type>::value&& - sizeof(typename std::remove_pointer<CharT>::type) == 1, - int >::type = 0 > +template<typename CharT, + typename std::enable_if< + std::is_pointer<CharT>::value && + !std::is_array<CharT>::value && + std::is_integral<typename std::remove_pointer<CharT>::type>::value && + sizeof(typename std::remove_pointer<CharT>::type) == 1, + int>::type = 0> contiguous_bytes_input_adapter input_adapter(CharT b) { auto length = std::strlen(reinterpret_cast<const char*>(b)); @@ -6593,7 +6437,7 @@ } template<typename T, std::size_t N> -auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) +auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) { return input_adapter(array, array + N); } @@ -6604,25 +6448,27 @@ class span_input_adapter { public: - template < typename CharT, - typename std::enable_if < - std::is_pointer<CharT>::value&& - std::is_integral<typename std::remove_pointer<CharT>::type>::value&& - sizeof(typename std::remove_pointer<CharT>::type) == 1, - int >::type = 0 > + template<typename CharT, + typename std::enable_if< + std::is_pointer<CharT>::value && + std::is_integral<typename std::remove_pointer<CharT>::type>::value && + sizeof(typename std::remove_pointer<CharT>::type) == 1, + int>::type = 0> span_input_adapter(CharT b, std::size_t l) - : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {} + : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) + {} template<class IteratorType, typename std::enable_if< std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value, int>::type = 0> span_input_adapter(IteratorType first, IteratorType last) - : ia(input_adapter(first, last)) {} + : ia(input_adapter(first, last)) + {} contiguous_bytes_input_adapter&& get() { - return std::move(ia); // NOLINT(hicpp-move-const-arg,performance-move-const-arg) + return std::move(ia); // NOLINT(hicpp-move-const-arg,performance-move-const-arg) } private: @@ -6641,12 +6487,10 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - #include <cstddef> -#include <string> // string -#include <utility> // move -#include <vector> // vector +#include <string> // string +#include <utility> // move +#include <vector> // vector // #include <nlohmann/detail/exceptions.hpp> @@ -6654,7 +6498,6 @@ // #include <nlohmann/detail/string_concat.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN /*! @@ -6780,8 +6623,7 @@ virtual ~json_sax() = default; }; -namespace detail -{ +namespace detail { /*! @brief SAX implementation to create a JSON value from SAX events @@ -6811,14 +6653,15 @@ @param[in] allow_exceptions_ whether parse errors yield exceptions */ explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true) - : root(r), allow_exceptions(allow_exceptions_) + : root(r) + , allow_exceptions(allow_exceptions_) {} // make class move-only json_sax_dom_parser(const json_sax_dom_parser&) = delete; - json_sax_dom_parser(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + json_sax_dom_parser(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete; - json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) ~json_sax_dom_parser() = default; bool null() @@ -6918,8 +6761,7 @@ } template<class Exception> - bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, - const Exception& ex) + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex) { errored = true; static_cast<void>(ex); @@ -6944,7 +6786,8 @@ */ template<typename Value> JSON_HEDLEY_RETURNS_NON_NULL - BasicJsonType* handle_value(Value&& v) + BasicJsonType* + handle_value(Value&& v) { if (ref_stack.empty()) { @@ -6969,7 +6812,7 @@ /// the parsed JSON value BasicJsonType& root; /// stack to model hierarchy of values - std::vector<BasicJsonType*> ref_stack {}; + std::vector<BasicJsonType*> ref_stack{}; /// helper to hold the reference for the next object element BasicJsonType* object_element = nullptr; /// whether a syntax error occurred @@ -6993,16 +6836,18 @@ json_sax_dom_callback_parser(BasicJsonType& r, const parser_callback_t cb, const bool allow_exceptions_ = true) - : root(r), callback(cb), allow_exceptions(allow_exceptions_) + : root(r) + , callback(cb) + , allow_exceptions(allow_exceptions_) { keep_stack.push_back(true); } // make class move-only json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete; - json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete; - json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) ~json_sax_dom_callback_parser() = default; bool null() @@ -7168,8 +7013,7 @@ } template<class Exception> - bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, - const Exception& ex) + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex) { errored = true; static_cast<void>(ex); @@ -7228,7 +7072,7 @@ if (ref_stack.empty()) { root = std::move(value); - return {true, & root}; + return {true, &root}; } // skip this value if we already decided to skip the parent @@ -7245,7 +7089,7 @@ if (ref_stack.back()->is_array()) { ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value)); - return {true, & (ref_stack.back()->m_data.m_value.array->back())}; + return {true, &(ref_stack.back()->m_data.m_value.array->back())}; } // object @@ -7268,11 +7112,11 @@ /// the parsed JSON value BasicJsonType& root; /// stack to model hierarchy of values - std::vector<BasicJsonType*> ref_stack {}; + std::vector<BasicJsonType*> ref_stack{}; /// stack to manage which values to keep - std::vector<bool> keep_stack {}; + std::vector<bool> keep_stack{}; /// stack to manage which object keys to keep - std::vector<bool> key_keep_stack {}; + std::vector<bool> key_keep_stack{}; /// helper to hold the reference for the next object element BasicJsonType* object_element = nullptr; /// whether a syntax error occurred @@ -7373,17 +7217,15 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <array> // array -#include <clocale> // localeconv -#include <cstddef> // size_t -#include <cstdio> // snprintf -#include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull -#include <initializer_list> // initializer_list -#include <string> // char_traits, string -#include <utility> // move -#include <vector> // vector +#include <array> // array +#include <clocale> // localeconv +#include <cstddef> // size_t +#include <cstdio> // snprintf +#include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull +#include <initializer_list> // initializer_list +#include <string> // char_traits, string +#include <utility> // move +#include <vector> // vector // #include <nlohmann/detail/input/input_adapters.hpp> @@ -7393,10 +7235,8 @@ // #include <nlohmann/detail/meta/type_traits.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /////////// // lexer // @@ -7468,7 +7308,7 @@ case token_type::literal_or_value: return "'[', '{', or a literal"; // LCOV_EXCL_START - default: // catch non-enum values + default: // catch non-enum values return "unknown token"; // LCOV_EXCL_STOP } @@ -7493,16 +7333,16 @@ using token_type = typename lexer_base<BasicJsonType>::token_type; explicit lexer(InputAdapterType&& adapter, bool ignore_comments_ = false) noexcept - : ia(std::move(adapter)) - , ignore_comments(ignore_comments_) - , decimal_point_char(static_cast<char_int_type>(get_decimal_point())) + : ia(std::move(adapter)) + , ignore_comments(ignore_comments_) + , decimal_point_char(static_cast<char_int_type>(get_decimal_point())) {} // delete because of pointer members lexer(const lexer&) = delete; - lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) lexer& operator=(lexer&) = delete; - lexer& operator=(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + lexer& operator=(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) ~lexer() = default; private: @@ -7544,7 +7384,7 @@ JSON_ASSERT(current == 'u'); int codepoint = 0; - const auto factors = { 12u, 8u, 4u, 0u }; + const auto factors = {12u, 8u, 4u, 0u}; for (const auto factor : factors) { get(); @@ -7594,7 +7434,7 @@ for (auto range = ranges.begin(); range != ranges.end(); ++range) { get(); - if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range))) // NOLINT(bugprone-inc-dec-in-conditions) + if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range))) // NOLINT(bugprone-inc-dec-in-conditions) { add(current); } @@ -7691,7 +7531,7 @@ case 'u': { const int codepoint1 = get_codepoint(); - int codepoint = codepoint1; // start with codepoint1 + int codepoint = codepoint1; // start with codepoint1 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1)) { @@ -7718,14 +7558,14 @@ { // overwrite codepoint codepoint = static_cast<int>( - // high surrogate occupies the most significant 22 bits - (static_cast<unsigned int>(codepoint1) << 10u) - // low surrogate occupies the least significant 15 bits - + static_cast<unsigned int>(codepoint2) - // there is still the 0xD800, 0xDC00 and 0x10000 noise - // in the result, so we have to subtract with: - // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 - - 0x35FDC00u); + // high surrogate occupies the most significant 22 bits + (static_cast<unsigned int>(codepoint1) << 10u) + // low surrogate occupies the least significant 15 bits + + static_cast<unsigned int>(codepoint2) + // there is still the 0xD800, 0xDC00 and 0x10000 noise + // in the result, so we have to subtract with: + // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 + - 0x35FDC00u); } else { @@ -8377,8 +8217,8 @@ } // all other characters are rejected outside scan_number() - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } scan_number_minus: @@ -8616,7 +8456,7 @@ // we are done scanning a number) unget(); - char* endptr = nullptr; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + char* endptr = nullptr; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) errno = 0; // try to parse integers first and fall back to floats @@ -8669,8 +8509,7 @@ @param[in] return_type the token type to return on success */ JSON_HEDLEY_NON_NULL(2) - token_type scan_literal(const char_type* literal_text, const std::size_t length, - token_type return_type) + token_type scan_literal(const char_type* literal_text, const std::size_t length, token_type return_type) { JSON_ASSERT(char_traits<char_type>::to_char_type(current) == literal_text[0]); for (std::size_t i = 1; i < length; ++i) @@ -8827,7 +8666,7 @@ { // escape control characters std::array<char, 9> cs{{}}; - static_cast<void>((std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + static_cast<void>((std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) result += cs.data(); } else @@ -8874,8 +8713,7 @@ do { get(); - } - while (current == ' ' || current == '\t' || current == '\n' || current == '\r'); + } while (current == ' ' || current == '\t' || current == '\n' || current == '\r'); } token_type scan() @@ -8980,13 +8818,13 @@ bool next_unget = false; /// the start position of the current token - position_t position {}; + position_t position{}; /// raw input token string (for error messages) - std::vector<char_type> token_string {}; + std::vector<char_type> token_string{}; /// buffer for variable-length tokens (numbers, strings) - string_t token_buffer {}; + string_t token_buffer{}; /// a description of occurred lexer errors const char* error_message = ""; @@ -9014,11 +8852,9 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <cstdint> // size_t -#include <utility> // declval -#include <string> // string +#include <cstdint> // size_t +#include <string> // string +#include <utility> // declval // #include <nlohmann/detail/abi_macros.hpp> @@ -9026,10 +8862,8 @@ // #include <nlohmann/detail/meta/type_traits.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename T> using null_function_t = decltype(std::declval<T&>().null()); @@ -9048,7 +8882,8 @@ template<typename T, typename Float, typename String> using number_float_function_t = decltype(std::declval<T&>().number_float( - std::declval<Float>(), std::declval<const String&>())); + std::declval<Float>(), + std::declval<const String&>())); template<typename T, typename String> using string_function_t = @@ -9078,8 +8913,9 @@ template<typename T, typename Exception> using parse_error_function_t = decltype(std::declval<T&>().parse_error( - std::declval<std::size_t>(), std::declval<const std::string&>(), - std::declval<const Exception&>())); + std::declval<std::size_t>(), + std::declval<const std::string&>(), + std::declval<const Exception&>())); template<typename SAX, typename BasicJsonType> struct is_sax @@ -9134,15 +8970,12 @@ static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, "Missing/invalid function: bool boolean(bool)"); static_assert( - is_detected_exact<bool, number_integer_function_t, SAX, - number_integer_t>::value, + is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value, "Missing/invalid function: bool number_integer(number_integer_t)"); static_assert( - is_detected_exact<bool, number_unsigned_function_t, SAX, - number_unsigned_t>::value, + is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value, "Missing/invalid function: bool number_unsigned(number_unsigned_t)"); - static_assert(is_detected_exact<bool, number_float_function_t, SAX, - number_float_t, string_t>::value, + static_assert(is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value, "Missing/invalid function: bool number_float(number_float_t, const string_t&)"); static_assert( is_detected_exact<bool, string_function_t, SAX, string_t>::value, @@ -9175,10 +9008,8 @@ // #include <nlohmann/detail/value_t.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /// how to treat CBOR tags enum class cbor_tag_handler_t @@ -9225,16 +9056,18 @@ @param[in] adapter input adapter to read from */ - explicit binary_reader(InputAdapterType&& adapter, const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format) + explicit binary_reader(InputAdapterType&& adapter, const input_format_t format = input_format_t::json) noexcept + : ia(std::move(adapter)) + , input_format(format) { - (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {}; + (void)detail::is_sax_static_asserts<SAX, BasicJsonType>{}; } // make class move-only binary_reader(const binary_reader&) = delete; - binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) binary_reader& operator=(const binary_reader&) = delete; - binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) ~binary_reader() = default; /*! @@ -9273,9 +9106,9 @@ result = parse_ubjson_internal(); break; - case input_format_t::json: // LCOV_EXCL_LINE - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + case input_format_t::json: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } // strict mode: next byte must be EOF @@ -9292,8 +9125,7 @@ if (JSON_HEDLEY_UNLIKELY(current != char_traits<char_type>::eof())) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read, - exception_message(input_format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read, exception_message(input_format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr)); } } @@ -9319,7 +9151,7 @@ return false; } - if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/false))) + if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/ false))) { return false; } @@ -9369,8 +9201,7 @@ if (JSON_HEDLEY_UNLIKELY(len < 1)) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format_t::bson, concat("string length must be at least 1, is ", std::to_string(len)), "string"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, concat("string length must be at least 1, is ", std::to_string(len)), "string"), nullptr)); } return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != char_traits<char_type>::eof(); @@ -9391,8 +9222,7 @@ if (JSON_HEDLEY_UNLIKELY(len < 0)) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format_t::bson, concat("byte array length cannot be negative, is ", std::to_string(len)), "binary"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, concat("byte array length cannot be negative, is ", std::to_string(len)), "binary"), nullptr)); } // All BSON binary values have a subtype @@ -9418,65 +9248,64 @@ { switch (element_type) { - case 0x01: // double + case 0x01: // double { double number{}; return get_number<double, true>(input_format_t::bson, number) && sax->number_float(static_cast<number_float_t>(number), ""); } - case 0x02: // string + case 0x02: // string { std::int32_t len{}; string_t value; return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value); } - case 0x03: // object + case 0x03: // object { return parse_bson_internal(); } - case 0x04: // array + case 0x04: // array { return parse_bson_array(); } - case 0x05: // binary + case 0x05: // binary { std::int32_t len{}; binary_t value; return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value); } - case 0x08: // boolean + case 0x08: // boolean { return sax->boolean(get() != 0); } - case 0x0A: // null + case 0x0A: // null { return sax->null(); } - case 0x10: // int32 + case 0x10: // int32 { std::int32_t value{}; return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value); } - case 0x12: // int64 + case 0x12: // int64 { std::int64_t value{}; return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value); } - default: // anything else not supported (yet) + default: // anything else not supported (yet) { std::array<char, 3> cr{{}}; - static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) const std::string cr_str{cr.data()}; - return sax->parse_error(element_type_parse_position, cr_str, - parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr)); + return sax->parse_error(element_type_parse_position, cr_str, parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr)); } } } @@ -9541,7 +9370,7 @@ return false; } - if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/true))) + if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/ true))) { return false; } @@ -9597,25 +9426,25 @@ case 0x17: return sax->number_unsigned(static_cast<number_unsigned_t>(current)); - case 0x18: // Unsigned integer (one-byte uint8_t follows) + case 0x18: // Unsigned integer (one-byte uint8_t follows) { std::uint8_t number{}; return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); } - case 0x19: // Unsigned integer (two-byte uint16_t follows) + case 0x19: // Unsigned integer (two-byte uint16_t follows) { std::uint16_t number{}; return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); } - case 0x1A: // Unsigned integer (four-byte uint32_t follows) + case 0x1A: // Unsigned integer (four-byte uint32_t follows) { std::uint32_t number{}; return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); } - case 0x1B: // Unsigned integer (eight-byte uint64_t follows) + case 0x1B: // Unsigned integer (eight-byte uint64_t follows) { std::uint64_t number{}; return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); @@ -9648,29 +9477,28 @@ case 0x37: return sax->number_integer(static_cast<std::int8_t>(0x20 - 1 - current)); - case 0x38: // Negative integer (one-byte uint8_t follows) + case 0x38: // Negative integer (one-byte uint8_t follows) { std::uint8_t number{}; return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number); } - case 0x39: // Negative integer -1-n (two-byte uint16_t follows) + case 0x39: // Negative integer -1-n (two-byte uint16_t follows) { std::uint16_t number{}; return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number); } - case 0x3A: // Negative integer -1-n (four-byte uint32_t follows) + case 0x3A: // Negative integer -1-n (four-byte uint32_t follows) { std::uint32_t number{}; return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number); } - case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows) + case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows) { std::uint64_t number{}; - return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - - static_cast<number_integer_t>(number)); + return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - static_cast<number_integer_t>(number)); } // Binary data (0x00..0x17 bytes follow) @@ -9698,11 +9526,11 @@ case 0x55: case 0x56: case 0x57: - case 0x58: // Binary data (one-byte uint8_t for n follows) - case 0x59: // Binary data (two-byte uint16_t for n follow) - case 0x5A: // Binary data (four-byte uint32_t for n follow) - case 0x5B: // Binary data (eight-byte uint64_t for n follow) - case 0x5F: // Binary data (indefinite length) + case 0x58: // Binary data (one-byte uint8_t for n follows) + case 0x59: // Binary data (two-byte uint16_t for n follow) + case 0x5A: // Binary data (four-byte uint32_t for n follow) + case 0x5B: // Binary data (eight-byte uint64_t for n follow) + case 0x5F: // Binary data (indefinite length) { binary_t b; return get_cbor_binary(b) && sax->binary(b); @@ -9733,11 +9561,11 @@ case 0x75: case 0x76: case 0x77: - case 0x78: // UTF-8 string (one-byte uint8_t for n follows) - case 0x79: // UTF-8 string (two-byte uint16_t for n follow) - case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) - case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) - case 0x7F: // UTF-8 string (indefinite length) + case 0x78: // UTF-8 string (one-byte uint8_t for n follows) + case 0x79: // UTF-8 string (two-byte uint16_t for n follow) + case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) + case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) + case 0x7F: // UTF-8 string (indefinite length) { string_t s; return get_cbor_string(s) && sax->string(s); @@ -9769,33 +9597,34 @@ case 0x96: case 0x97: return get_cbor_array( - conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler); + conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), + tag_handler); - case 0x98: // array (one-byte uint8_t for n follows) + case 0x98: // array (one-byte uint8_t for n follows) { std::uint8_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler); } - case 0x99: // array (two-byte uint16_t for n follow) + case 0x99: // array (two-byte uint16_t for n follow) { std::uint16_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler); } - case 0x9A: // array (four-byte uint32_t for n follow) + case 0x9A: // array (four-byte uint32_t for n follow) { std::uint32_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler); } - case 0x9B: // array (eight-byte uint64_t for n follow) + case 0x9B: // array (eight-byte uint64_t for n follow) { std::uint64_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler); } - case 0x9F: // array (indefinite length) + case 0x9F: // array (indefinite length) return get_cbor_array(static_cast<std::size_t>(-1), tag_handler); // map (0x00..0x17 pairs of data items follow) @@ -9825,34 +9654,34 @@ case 0xB7: return get_cbor_object(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler); - case 0xB8: // map (one-byte uint8_t for n follows) + case 0xB8: // map (one-byte uint8_t for n follows) { std::uint8_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler); } - case 0xB9: // map (two-byte uint16_t for n follow) + case 0xB9: // map (two-byte uint16_t for n follow) { std::uint16_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler); } - case 0xBA: // map (four-byte uint32_t for n follow) + case 0xBA: // map (four-byte uint32_t for n follow) { std::uint32_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler); } - case 0xBB: // map (eight-byte uint64_t for n follow) + case 0xBB: // map (eight-byte uint64_t for n follow) { std::uint64_t len{}; return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler); } - case 0xBF: // map (indefinite length) + case 0xBF: // map (indefinite length) return get_cbor_object(static_cast<std::size_t>(-1), tag_handler); - case 0xC6: // tagged item + case 0xC6: // tagged item case 0xC7: case 0xC8: case 0xC9: @@ -9867,18 +9696,17 @@ case 0xD2: case 0xD3: case 0xD4: - case 0xD8: // tagged item (1 bytes follow) - case 0xD9: // tagged item (2 bytes follow) - case 0xDA: // tagged item (4 bytes follow) - case 0xDB: // tagged item (8 bytes follow) + case 0xD8: // tagged item (1 bytes follow) + case 0xD9: // tagged item (2 bytes follow) + case 0xDA: // tagged item (4 bytes follow) + case 0xDB: // tagged item (8 bytes follow) { switch (tag_handler) { case cbor_tag_handler_t::error: { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr)); } case cbor_tag_handler_t::ignore: @@ -9958,21 +9786,21 @@ } default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE return false; // LCOV_EXCL_LINE } } - case 0xF4: // false + case 0xF4: // false return sax->boolean(false); - case 0xF5: // true + case 0xF5: // true return sax->boolean(true); - case 0xF6: // null + case 0xF6: // null return sax->null(); - case 0xF9: // Half-Precision Float (two-byte IEEE 754) + case 0xF9: // Half-Precision Float (two-byte IEEE 754) { const auto byte1_raw = get(); if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number"))) @@ -9997,11 +9825,10 @@ // half-precision floating-point numbers in the C language // is shown in Fig. 3. const auto half = static_cast<unsigned int>((byte1 << 8u) + byte2); - const double val = [&half] - { + const double val = [&half] { const int exp = (half >> 10u) & 0x1Fu; const unsigned int mant = half & 0x3FFu; - JSON_ASSERT(0 <= exp&& exp <= 32); + JSON_ASSERT(0 <= exp && exp <= 32); JSON_ASSERT(mant <= 1024); switch (exp) { @@ -10009,34 +9836,34 @@ return std::ldexp(mant, -24); case 31: return (mant == 0) - ? std::numeric_limits<double>::infinity() - : std::numeric_limits<double>::quiet_NaN(); + ? std::numeric_limits<double>::infinity() + : std::numeric_limits<double>::quiet_NaN(); default: return std::ldexp(mant + 1024, exp - 25); } }(); return sax->number_float((half & 0x8000u) != 0 - ? static_cast<number_float_t>(-val) - : static_cast<number_float_t>(val), ""); + ? static_cast<number_float_t>(-val) + : static_cast<number_float_t>(val), + ""); } - case 0xFA: // Single-Precision Float (four-byte IEEE 754) + case 0xFA: // Single-Precision Float (four-byte IEEE 754) { float number{}; return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), ""); } - case 0xFB: // Double-Precision Float (eight-byte IEEE 754) + case 0xFB: // Double-Precision Float (eight-byte IEEE 754) { double number{}; return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), ""); } - default: // anything else (0xFF is handled inside the other types) + default: // anything else (0xFF is handled inside the other types) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr)); } } } @@ -10090,31 +9917,31 @@ return get_string(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result); } - case 0x78: // UTF-8 string (one-byte uint8_t for n follows) + case 0x78: // UTF-8 string (one-byte uint8_t for n follows) { std::uint8_t len{}; return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); } - case 0x79: // UTF-8 string (two-byte uint16_t for n follow) + case 0x79: // UTF-8 string (two-byte uint16_t for n follow) { std::uint16_t len{}; return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); } - case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) + case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) { std::uint32_t len{}; return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); } - case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) + case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) { std::uint64_t len{}; return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); } - case 0x7F: // UTF-8 string (indefinite length) + case 0x7F: // UTF-8 string (indefinite length) { while (get() != 0xFF) { @@ -10131,8 +9958,7 @@ default: { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, - exception_message(input_format_t::cbor, concat("expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token), "string"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, concat("expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token), "string"), nullptr)); } } } @@ -10186,35 +10012,35 @@ return get_binary(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result); } - case 0x58: // Binary data (one-byte uint8_t for n follows) + case 0x58: // Binary data (one-byte uint8_t for n follows) { std::uint8_t len{}; return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result); } - case 0x59: // Binary data (two-byte uint16_t for n follow) + case 0x59: // Binary data (two-byte uint16_t for n follow) { std::uint16_t len{}; return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result); } - case 0x5A: // Binary data (four-byte uint32_t for n follow) + case 0x5A: // Binary data (four-byte uint32_t for n follow) { std::uint32_t len{}; return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result); } - case 0x5B: // Binary data (eight-byte uint64_t for n follow) + case 0x5B: // Binary data (eight-byte uint64_t for n follow) { std::uint64_t len{}; return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result); } - case 0x5F: // Binary data (indefinite length) + case 0x5F: // Binary data (indefinite length) { while (get() != 0xFF) { @@ -10231,8 +10057,7 @@ default: { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, - exception_message(input_format_t::cbor, concat("expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x", last_token), "binary"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, concat("expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x", last_token), "binary"), nullptr)); } } } @@ -10547,118 +10372,118 @@ case 0xBD: case 0xBE: case 0xBF: - case 0xD9: // str 8 - case 0xDA: // str 16 - case 0xDB: // str 32 + case 0xD9: // str 8 + case 0xDA: // str 16 + case 0xDB: // str 32 { string_t s; return get_msgpack_string(s) && sax->string(s); } - case 0xC0: // nil + case 0xC0: // nil return sax->null(); - case 0xC2: // false + case 0xC2: // false return sax->boolean(false); - case 0xC3: // true + case 0xC3: // true return sax->boolean(true); - case 0xC4: // bin 8 - case 0xC5: // bin 16 - case 0xC6: // bin 32 - case 0xC7: // ext 8 - case 0xC8: // ext 16 - case 0xC9: // ext 32 - case 0xD4: // fixext 1 - case 0xD5: // fixext 2 - case 0xD6: // fixext 4 - case 0xD7: // fixext 8 - case 0xD8: // fixext 16 + case 0xC4: // bin 8 + case 0xC5: // bin 16 + case 0xC6: // bin 32 + case 0xC7: // ext 8 + case 0xC8: // ext 16 + case 0xC9: // ext 32 + case 0xD4: // fixext 1 + case 0xD5: // fixext 2 + case 0xD6: // fixext 4 + case 0xD7: // fixext 8 + case 0xD8: // fixext 16 { binary_t b; return get_msgpack_binary(b) && sax->binary(b); } - case 0xCA: // float 32 + case 0xCA: // float 32 { float number{}; return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), ""); } - case 0xCB: // float 64 + case 0xCB: // float 64 { double number{}; return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), ""); } - case 0xCC: // uint 8 + case 0xCC: // uint 8 { std::uint8_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); } - case 0xCD: // uint 16 + case 0xCD: // uint 16 { std::uint16_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); } - case 0xCE: // uint 32 + case 0xCE: // uint 32 { std::uint32_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); } - case 0xCF: // uint 64 + case 0xCF: // uint 64 { std::uint64_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); } - case 0xD0: // int 8 + case 0xD0: // int 8 { std::int8_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_integer(number); } - case 0xD1: // int 16 + case 0xD1: // int 16 { std::int16_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_integer(number); } - case 0xD2: // int 32 + case 0xD2: // int 32 { std::int32_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_integer(number); } - case 0xD3: // int 64 + case 0xD3: // int 64 { std::int64_t number{}; return get_number(input_format_t::msgpack, number) && sax->number_integer(number); } - case 0xDC: // array 16 + case 0xDC: // array 16 { std::uint16_t len{}; return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast<std::size_t>(len)); } - case 0xDD: // array 32 + case 0xDD: // array 32 { std::uint32_t len{}; return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len)); } - case 0xDE: // map 16 + case 0xDE: // map 16 { std::uint16_t len{}; return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast<std::size_t>(len)); } - case 0xDF: // map 32 + case 0xDF: // map 32 { std::uint32_t len{}; return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len)); @@ -10699,11 +10524,10 @@ case 0xFF: return sax->number_integer(static_cast<std::int8_t>(current)); - default: // anything else + default: // anything else { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format_t::msgpack, concat("invalid byte: 0x", last_token), "value"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::msgpack, concat("invalid byte: 0x", last_token), "value"), nullptr)); } } } @@ -10764,19 +10588,19 @@ return get_string(input_format_t::msgpack, static_cast<unsigned int>(current) & 0x1Fu, result); } - case 0xD9: // str 8 + case 0xD9: // str 8 { std::uint8_t len{}; return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); } - case 0xDA: // str 16 + case 0xDA: // str 16 { std::uint16_t len{}; return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); } - case 0xDB: // str 32 + case 0xDB: // str 32 { std::uint32_t len{}; return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); @@ -10785,8 +10609,7 @@ default: { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, - exception_message(input_format_t::msgpack, concat("expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token), "string"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::msgpack, concat("expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token), "string"), nullptr)); } } } @@ -10804,36 +10627,35 @@ bool get_msgpack_binary(binary_t& result) { // helper function to set the subtype - auto assign_and_return_true = [&result](std::int8_t subtype) - { + auto assign_and_return_true = [&result](std::int8_t subtype) { result.set_subtype(static_cast<std::uint8_t>(subtype)); return true; }; switch (current) { - case 0xC4: // bin 8 + case 0xC4: // bin 8 { std::uint8_t len{}; return get_number(input_format_t::msgpack, len) && get_binary(input_format_t::msgpack, len, result); } - case 0xC5: // bin 16 + case 0xC5: // bin 16 { std::uint16_t len{}; return get_number(input_format_t::msgpack, len) && get_binary(input_format_t::msgpack, len, result); } - case 0xC6: // bin 32 + case 0xC6: // bin 32 { std::uint32_t len{}; return get_number(input_format_t::msgpack, len) && get_binary(input_format_t::msgpack, len, result); } - case 0xC7: // ext 8 + case 0xC7: // ext 8 { std::uint8_t len{}; std::int8_t subtype{}; @@ -10843,7 +10665,7 @@ assign_and_return_true(subtype); } - case 0xC8: // ext 16 + case 0xC8: // ext 16 { std::uint16_t len{}; std::int8_t subtype{}; @@ -10853,7 +10675,7 @@ assign_and_return_true(subtype); } - case 0xC9: // ext 32 + case 0xC9: // ext 32 { std::uint32_t len{}; std::int8_t subtype{}; @@ -10863,7 +10685,7 @@ assign_and_return_true(subtype); } - case 0xD4: // fixext 1 + case 0xD4: // fixext 1 { std::int8_t subtype{}; return get_number(input_format_t::msgpack, subtype) && @@ -10871,7 +10693,7 @@ assign_and_return_true(subtype); } - case 0xD5: // fixext 2 + case 0xD5: // fixext 2 { std::int8_t subtype{}; return get_number(input_format_t::msgpack, subtype) && @@ -10879,7 +10701,7 @@ assign_and_return_true(subtype); } - case 0xD6: // fixext 4 + case 0xD6: // fixext 4 { std::int8_t subtype{}; return get_number(input_format_t::msgpack, subtype) && @@ -10887,7 +10709,7 @@ assign_and_return_true(subtype); } - case 0xD7: // fixext 8 + case 0xD7: // fixext 8 { std::int8_t subtype{}; return get_number(input_format_t::msgpack, subtype) && @@ -10895,7 +10717,7 @@ assign_and_return_true(subtype); } - case 0xD8: // fixext 16 + case 0xD8: // fixext 16 { std::int8_t subtype{}; return get_number(input_format_t::msgpack, subtype) && @@ -11179,10 +11001,9 @@ } if (number < 0) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, - exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); } - result = static_cast<std::size_t>(number); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): number is not a char + result = static_cast<std::size_t>(number); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): number is not a char return true; } @@ -11195,8 +11016,7 @@ } if (number < 0) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, - exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); } result = static_cast<std::size_t>(number); return true; @@ -11211,8 +11031,7 @@ } if (number < 0) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, - exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); } result = static_cast<std::size_t>(number); return true; @@ -11227,13 +11046,11 @@ } if (number < 0) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, - exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); } if (!value_in_range_of<std::size_t>(number)) { - return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, - exception_message(input_format, "integer value overflow", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "integer value overflow", "size"), nullptr)); } result = static_cast<std::size_t>(number); return true; @@ -11282,8 +11099,7 @@ } if (!value_in_range_of<std::size_t>(number)) { - return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, - exception_message(input_format, "integer value overflow", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "integer value overflow", "size"), nullptr)); } result = detail::conditional_static_cast<std::size_t>(number); return true; @@ -11295,7 +11111,7 @@ { break; } - if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array + if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array { return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimensional vector is not allowed", "size"), nullptr)); } @@ -11304,16 +11120,16 @@ { return false; } - if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1)) // return normal array size if 1D row vector + if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1)) // return normal array size if 1D row vector { result = dim.at(dim.size() - 1); return true; } if (!dim.empty()) // if ndarray, convert to an object in JData annotated array format { - for (auto i : dim) // test if any dimension in an ndarray is 0, if so, return a 1D empty container + for (auto i : dim) // test if any dimension in an ndarray is 0, if so, return a 1D empty container { - if ( i == 0 ) + if (i == 0) { result = 0; return true; @@ -11329,7 +11145,7 @@ for (auto i : dim) { result *= i; - if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type() + if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type() { return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr)); } @@ -11375,8 +11191,8 @@ */ bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result, bool inside_ndarray = false) { - result.first = npos; // size - result.second = 0; // type + result.first = npos; // size + result.second = 0; // type bool is_ndarray = false; get_ignore_noop(); @@ -11384,12 +11200,10 @@ if (current == '$') { result.second = get(); // must not ignore 'N', because 'N' maybe the type - if (input_format == input_format_t::bjdata - && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second))) + if (input_format == input_format_t::bjdata && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second))) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format, concat("marker 0x", last_token, " is not a permitted optimized array type"), "type"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, concat("marker 0x", last_token, " is not a permitted optimized array type"), "type"), nullptr)); } if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "type"))) @@ -11405,8 +11219,7 @@ return false; } auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr)); } const bool is_error = get_ubjson_size_value(result.first, is_ndarray); @@ -11414,10 +11227,9 @@ { if (inside_ndarray) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, - exception_message(input_format, "ndarray can not be recursive", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, exception_message(input_format, "ndarray can not be recursive", "size"), nullptr)); } - result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters + result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters } return is_error; } @@ -11427,8 +11239,7 @@ const bool is_error = get_ubjson_size_value(result.first, is_ndarray); if (input_format == input_format_t::bjdata && is_ndarray) { - return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, - exception_message(input_format, "ndarray requires both type and size", "size"), nullptr)); + return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, exception_message(input_format, "ndarray requires both type and size", "size"), nullptr)); } return is_error; } @@ -11544,11 +11355,10 @@ // half-precision floating-point numbers in the C language // is shown in Fig. 3. const auto half = static_cast<unsigned int>((byte2 << 8u) + byte1); - const double val = [&half] - { + const double val = [&half] { const int exp = (half >> 10u) & 0x1Fu; const unsigned int mant = half & 0x3FFu; - JSON_ASSERT(0 <= exp&& exp <= 32); + JSON_ASSERT(0 <= exp && exp <= 32); JSON_ASSERT(mant <= 1024); switch (exp) { @@ -11556,15 +11366,16 @@ return std::ldexp(mant, -24); case 31: return (mant == 0) - ? std::numeric_limits<double>::infinity() - : std::numeric_limits<double>::quiet_NaN(); + ? std::numeric_limits<double>::infinity() + : std::numeric_limits<double>::quiet_NaN(); default: return std::ldexp(mant + 1024, exp - 25); } }(); return sax->number_float((half & 0x8000u) != 0 - ? static_cast<number_float_t>(-val) - : static_cast<number_float_t>(val), ""); + ? static_cast<number_float_t>(-val) + : static_cast<number_float_t>(val), + ""); } case 'd': @@ -11594,8 +11405,7 @@ if (JSON_HEDLEY_UNLIKELY(current > 127)) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, - exception_message(input_format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"), nullptr)); } string_t s(1, static_cast<typename string_t::value_type>(current)); return sax->string(s); @@ -11613,7 +11423,7 @@ case '{': // object return get_ubjson_object(); - default: // anything else + default: // anything else break; } auto last_token = get_token_string(); @@ -11637,19 +11447,17 @@ if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) { size_and_type.second &= ~(static_cast<char_int_type>(1) << 8); // use bit 8 to indicate ndarray, here we remove the bit to restore the type marker - auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](const bjd_type & p, char_int_type t) - { + auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](const bjd_type& p, char_int_type t) { return p.first < t; }); string_t key = "_ArrayType_"; if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second)) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr)); } - string_t type = it->second; // sax->string() takes a reference + string_t type = it->second; // sax->string() takes a reference if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type))) { return false; @@ -11661,7 +11469,7 @@ } key = "_ArrayData_"; - if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) )) + if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first))) { return false; } @@ -11743,8 +11551,7 @@ if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) { auto last_token = get_token_string(); - return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, - exception_message(input_format, "BJData object does not support ND-array size in optimized format", "object"), nullptr)); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, "BJData object does not support ND-array size in optimized format", "object"), nullptr)); } string_t key; @@ -11848,8 +11655,7 @@ if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input)) { - return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, - exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); + return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); } switch (result_number) @@ -11875,8 +11681,7 @@ case token_type::end_of_input: case token_type::literal_or_value: default: - return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, - exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); + return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); } } @@ -11907,8 +11712,7 @@ do { get(); - } - while (current == 'N'); + } while (current == 'N'); return current; } @@ -11948,7 +11752,7 @@ } else { - vec[i] = static_cast<std::uint8_t>(current); // LCOV_EXCL_LINE + vec[i] = static_cast<std::uint8_t>(current); // LCOV_EXCL_LINE } } @@ -12033,8 +11837,7 @@ { if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof())) { - return sax->parse_error(chars_read, "<end of file>", - parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr)); + return sax->parse_error(chars_read, "<end of file>", parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr)); } return true; } @@ -12045,7 +11848,7 @@ std::string get_token_string() const { std::array<char, 3> cr{{}}; - static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) return std::string{cr.data()}; } @@ -12083,9 +11886,9 @@ error_msg += "BJData"; break; - case input_format_t::json: // LCOV_EXCL_LINE - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + case input_format_t::json: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } return concat(error_msg, ' ', context, ": ", detail); @@ -12118,23 +11921,23 @@ #define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \ make_array<bjd_type>( \ - bjd_type{'C', "char"}, \ - bjd_type{'D', "double"}, \ - bjd_type{'I', "int16"}, \ - bjd_type{'L', "int64"}, \ - bjd_type{'M', "uint64"}, \ - bjd_type{'U', "uint8"}, \ - bjd_type{'d', "single"}, \ - bjd_type{'i', "int8"}, \ - bjd_type{'l', "int32"}, \ - bjd_type{'m', "uint32"}, \ - bjd_type{'u', "uint16"}) + bjd_type{'C', "char"}, \ + bjd_type{'D', "double"}, \ + bjd_type{'I', "int16"}, \ + bjd_type{'L', "int64"}, \ + bjd_type{'M', "uint64"}, \ + bjd_type{'U', "uint8"}, \ + bjd_type{'d', "single"}, \ + bjd_type{'i', "int8"}, \ + bjd_type{'l', "int32"}, \ + bjd_type{'m', "uint32"}, \ + bjd_type{'u', "uint16"}) - JSON_PRIVATE_UNLESS_TESTED: - // lookup tables - // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) - const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = - JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_; + JSON_PRIVATE_UNLESS_TESTED : + // lookup tables + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = + JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_; using bjd_type = std::pair<char_int_type, string_t>; // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) @@ -12146,8 +11949,8 @@ }; #ifndef JSON_HAS_CPP_17 - template<typename BasicJsonType, typename InputAdapterType, typename SAX> - constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos; +template<typename BasicJsonType, typename InputAdapterType, typename SAX> +constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos; #endif } // namespace detail @@ -12166,14 +11969,12 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <cmath> // isfinite -#include <cstdint> // uint8_t -#include <functional> // function -#include <string> // string -#include <utility> // move -#include <vector> // vector +#include <cmath> // isfinite +#include <cstdint> // uint8_t +#include <functional> // function +#include <string> // string +#include <utility> // move +#include <vector> // vector // #include <nlohmann/detail/exceptions.hpp> @@ -12191,10 +11992,8 @@ // #include <nlohmann/detail/value_t.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { //////////// // parser // //////////// @@ -12240,9 +12039,9 @@ const parser_callback_t<BasicJsonType> cb = nullptr, const bool allow_exceptions_ = true, const bool skip_comments = false) - : callback(cb) - , m_lexer(std::move(adapter), skip_comments) - , allow_exceptions(allow_exceptions_) + : callback(cb) + , m_lexer(std::move(adapter), skip_comments) + , allow_exceptions(allow_exceptions_) { // read first token get_token(); @@ -12270,8 +12069,7 @@ { sdp.parse_error(m_lexer.get_position(), m_lexer.get_token_string(), - parse_error::create(101, m_lexer.get_position(), - exception_message(token_type::end_of_input, "value"), nullptr)); + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr)); } // in case of an error, return discarded value @@ -12328,7 +12126,7 @@ JSON_HEDLEY_NON_NULL(2) bool sax_parse(SAX* sax, const bool strict = true) { - (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {}; + (void)detail::is_sax_static_asserts<SAX, BasicJsonType>{}; const bool result = sax_parse_internal(sax); // strict mode: next byte must be EOF @@ -12515,8 +12313,7 @@ { return sax->parse_error(m_lexer.get_position(), m_lexer.get_token_string(), - parse_error::create(101, m_lexer.get_position(), - "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr)); + parse_error::create(101, m_lexer.get_position(), "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr)); } return sax->parse_error(m_lexer.get_position(), @@ -12529,7 +12326,7 @@ case token_type::name_separator: case token_type::value_separator: case token_type::literal_or_value: - default: // the last token was unexpected + default: // the last token was unexpected { return sax->parse_error(m_lexer.get_position(), m_lexer.get_token_string(), @@ -12656,8 +12453,7 @@ if (last_token == token_type::parse_error) { - error_msg += concat(m_lexer.get_error_message(), "; last read: '", - m_lexer.get_token_string(), '\''); + error_msg += concat(m_lexer.get_error_message(), "; last read: '", m_lexer.get_token_string(), '\''); } else { @@ -12695,8 +12491,6 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - // #include <nlohmann/detail/abi_macros.hpp> // #include <nlohmann/detail/iterators/primitive_iterator.hpp> @@ -12708,17 +12502,13 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <cstddef> // ptrdiff_t -#include <limits> // numeric_limits +#include <cstddef> // ptrdiff_t +#include <limits> // numeric_limits // #include <nlohmann/detail/macro_scope.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /* @brief an iterator for primitive JSON types @@ -12736,9 +12526,9 @@ static constexpr difference_type begin_value = 0; static constexpr difference_type end_value = begin_value + 1; - JSON_PRIVATE_UNLESS_TESTED: - /// iterator as signed integer type - difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)(); + JSON_PRIVATE_UNLESS_TESTED : + /// iterator as signed integer type + difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)(); public: constexpr difference_type get_value() const noexcept @@ -12798,7 +12588,7 @@ return *this; } - primitive_iterator_t operator++(int)& noexcept // NOLINT(cert-dcl21-cpp) + primitive_iterator_t operator++(int) & noexcept // NOLINT(cert-dcl21-cpp) { auto result = *this; ++m_it; @@ -12811,7 +12601,7 @@ return *this; } - primitive_iterator_t operator--(int)& noexcept // NOLINT(cert-dcl21-cpp) + primitive_iterator_t operator--(int) & noexcept // NOLINT(cert-dcl21-cpp) { auto result = *this; --m_it; @@ -12834,10 +12624,8 @@ } // namespace detail NLOHMANN_JSON_NAMESPACE_END - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /*! @brief an iterator value @@ -12845,14 +12633,15 @@ @note This structure could easily be a union, but MSVC currently does not allow unions members with complex constructors, see https://github.com/nlohmann/json/pull/105. */ -template<typename BasicJsonType> struct internal_iterator +template<typename BasicJsonType> +struct internal_iterator { /// iterator for JSON objects - typename BasicJsonType::object_t::iterator object_iterator {}; + typename BasicJsonType::object_t::iterator object_iterator{}; /// iterator for JSON arrays - typename BasicJsonType::array_t::iterator array_iterator {}; + typename BasicJsonType::array_t::iterator array_iterator{}; /// generic iterator for all other types - primitive_iterator_t primitive_iterator {}; + primitive_iterator_t primitive_iterator{}; }; } // namespace detail @@ -12867,10 +12656,8 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next -#include <type_traits> // conditional, is_const, remove_const +#include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next +#include <type_traits> // conditional, is_const, remove_const // #include <nlohmann/detail/exceptions.hpp> @@ -12886,14 +12673,14 @@ // #include <nlohmann/detail/value_t.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { // forward declare, to be able to friend it later on -template<typename IteratorType> class iteration_proxy; -template<typename IteratorType> class iteration_proxy_value; +template<typename IteratorType> +class iteration_proxy; +template<typename IteratorType> +class iteration_proxy_value; /*! @brief a template for a bidirectional iterator for the @ref basic_json class @@ -12912,7 +12699,7 @@ iterators in version 3.0.0 (see https://github.com/nlohmann/json/issues/593) */ template<typename BasicJsonType> -class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) +class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) { /// the iterator with BasicJsonType of different const-ness using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>; @@ -12928,8 +12715,7 @@ static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value, "iter_impl only accepts (const) basic_json"); // superficial check for the LegacyBidirectionalIterator named requirement - static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value - && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value, + static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value, "basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement."); public: @@ -12946,13 +12732,13 @@ using difference_type = typename BasicJsonType::difference_type; /// defines a pointer to the type iterated over (value_type) using pointer = typename std::conditional<std::is_const<BasicJsonType>::value, - typename BasicJsonType::const_pointer, - typename BasicJsonType::pointer>::type; + typename BasicJsonType::const_pointer, + typename BasicJsonType::pointer>::type; /// defines a reference to the type iterated over (value_type) using reference = typename std::conditional<std::is_const<BasicJsonType>::value, - typename BasicJsonType::const_reference, - typename BasicJsonType::reference>::type; + typename BasicJsonType::const_reference, + typename BasicJsonType::reference>::type; iter_impl() = default; ~iter_impl() = default; @@ -12965,7 +12751,8 @@ @pre object != nullptr @post The iterator is initialized; i.e. `m_object != nullptr`. */ - explicit iter_impl(pointer object) noexcept : m_object(object) + explicit iter_impl(pointer object) noexcept + : m_object(object) { JSON_ASSERT(m_object != nullptr); @@ -13016,7 +12803,8 @@ information refer to: https://github.com/nlohmann/json/issues/1608 */ iter_impl(const iter_impl<const BasicJsonType>& other) noexcept - : m_object(other.m_object), m_it(other.m_it) + : m_object(other.m_object) + , m_it(other.m_it) {} /*! @@ -13041,7 +12829,8 @@ @note It is not checked whether @a other is initialized. */ iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept - : m_object(other.m_object), m_it(other.m_it) + : m_object(other.m_object) + , m_it(other.m_it) {} /*! @@ -13050,19 +12839,20 @@ @return const/non-const iterator @note It is not checked whether @a other is initialized. */ - iter_impl& operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept // NOLINT(cert-oop54-cpp) + iter_impl& operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept // NOLINT(cert-oop54-cpp) { m_object = other.m_object; m_it = other.m_it; return *this; } - JSON_PRIVATE_UNLESS_TESTED: - /*! + JSON_PRIVATE_UNLESS_TESTED : + /*! @brief set the iterator to the first value @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - void set_begin() noexcept + void + set_begin() noexcept { JSON_ASSERT(m_object != nullptr); @@ -13231,7 +13021,7 @@ @brief post-increment (it++) @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - iter_impl operator++(int)& // NOLINT(cert-dcl21-cpp) + iter_impl operator++(int) & // NOLINT(cert-dcl21-cpp) { auto result = *this; ++(*this); @@ -13282,7 +13072,7 @@ @brief post-decrement (it--) @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - iter_impl operator--(int)& // NOLINT(cert-dcl21-cpp) + iter_impl operator--(int) & // NOLINT(cert-dcl21-cpp) { auto result = *this; --(*this); @@ -13333,7 +13123,7 @@ @brief comparison: equal @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr > + template<typename IterImpl, detail::enable_if_t<(std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t> = nullptr> bool operator==(const IterImpl& other) const { // if objects are not the same, the comparison is undefined @@ -13369,7 +13159,7 @@ @brief comparison: not equal @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr > + template<typename IterImpl, detail::enable_if_t<(std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t> = nullptr> bool operator!=(const IterImpl& other) const { return !operator==(other); @@ -13416,7 +13206,7 @@ */ bool operator<=(const iter_impl& other) const { - return !other.operator < (*this); + return !other.operator<(*this); } /*! @@ -13608,11 +13398,11 @@ return operator*(); } - JSON_PRIVATE_UNLESS_TESTED: - /// associated JSON instance - pointer m_object = nullptr; + JSON_PRIVATE_UNLESS_TESTED : + /// associated JSON instance + pointer m_object = nullptr; /// the actual iterator of the associated instance - internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {}; + internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it{}; }; } // namespace detail @@ -13629,18 +13419,14 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <cstddef> // ptrdiff_t -#include <iterator> // reverse_iterator -#include <utility> // declval +#include <cstddef> // ptrdiff_t +#include <iterator> // reverse_iterator +#include <utility> // declval // #include <nlohmann/detail/abi_macros.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { ////////////////////// // reverse_iterator // @@ -13676,13 +13462,16 @@ /// create reverse iterator from iterator explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept - : base_iterator(it) {} + : base_iterator(it) + {} /// create reverse iterator from base class - explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {} + explicit json_reverse_iterator(const base_iterator& it) noexcept + : base_iterator(it) + {} /// post-increment (it++) - json_reverse_iterator operator++(int)& // NOLINT(cert-dcl21-cpp) + json_reverse_iterator operator++(int) & // NOLINT(cert-dcl21-cpp) { return static_cast<json_reverse_iterator>(base_iterator::operator++(1)); } @@ -13694,7 +13483,7 @@ } /// post-decrement (it--) - json_reverse_iterator operator--(int)& // NOLINT(cert-dcl21-cpp) + json_reverse_iterator operator--(int) & // NOLINT(cert-dcl21-cpp) { return static_cast<json_reverse_iterator>(base_iterator::operator--(1)); } @@ -13746,7 +13535,7 @@ reference value() const { auto it = --this->base(); - return it.operator * (); + return it.operator*(); } }; @@ -13764,16 +13553,12 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <type_traits> // conditional, is_same +#include <type_traits> // conditional, is_same // #include <nlohmann/detail/abi_macros.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /*! @brief Default base class of the @ref basic_json class. @@ -13785,14 +13570,14 @@ By default, this class is used because it is empty and thus has no effect on the behavior of @ref basic_json. */ -struct json_default_base {}; +struct json_default_base +{}; template<class T> -using json_base_class = typename std::conditional < - std::is_same<T, void>::value, - json_default_base, - T - >::type; +using json_base_class = typename std::conditional< + std::is_same<T, void>::value, + json_default_base, + T>::type; } // namespace detail NLOHMANN_JSON_NAMESPACE_END @@ -13806,20 +13591,18 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <algorithm> // all_of -#include <cctype> // isdigit -#include <cerrno> // errno, ERANGE -#include <cstdlib> // strtoull +#include <algorithm> // all_of +#include <cctype> // isdigit +#include <cerrno> // errno, ERANGE +#include <cstdlib> // strtoull #ifndef JSON_NO_IO - #include <iosfwd> // ostream -#endif // JSON_NO_IO -#include <limits> // max -#include <numeric> // accumulate -#include <string> // string -#include <utility> // move -#include <vector> // vector + #include <iosfwd> // ostream +#endif // JSON_NO_IO +#include <limits> // max +#include <numeric> // accumulate +#include <string> // string +#include <utility> // move +#include <vector> // vector // #include <nlohmann/detail/exceptions.hpp> @@ -13831,7 +13614,6 @@ // #include <nlohmann/detail/value_t.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document @@ -13865,17 +13647,14 @@ /// @brief create JSON pointer /// @sa https://json.nlohmann.me/api/json_pointer/json_pointer/ explicit json_pointer(const string_t& s = "") - : reference_tokens(split(s)) + : reference_tokens(split(s)) {} /// @brief return a string representation of the JSON pointer /// @sa https://json.nlohmann.me/api/json_pointer/to_string/ string_t to_string() const { - return std::accumulate(reference_tokens.begin(), reference_tokens.end(), - string_t{}, - [](const string_t& a, const string_t& b) - { + return std::accumulate(reference_tokens.begin(), reference_tokens.end(), string_t{}, [](const string_t& a, const string_t& b) { return detail::concat(a, '/', detail::escape(b)); }); } @@ -13933,7 +13712,7 @@ /// @brief create a new JSON pointer by appending the unescaped token at the end of the JSON pointer /// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/ - friend json_pointer operator/(const json_pointer& lhs, string_t token) // NOLINT(performance-unnecessary-value-param) + friend json_pointer operator/(const json_pointer& lhs, string_t token) // NOLINT(performance-unnecessary-value-param) { return json_pointer(lhs) /= std::move(token); } @@ -14034,11 +13813,11 @@ const char* p = s.c_str(); char* p_end = nullptr; - errno = 0; // strtoull doesn't reset errno - const unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) - if (p == p_end // invalid input or empty string - || errno == ERANGE // out of range - || JSON_HEDLEY_UNLIKELY(static_cast<std::size_t>(p_end - p) != s.size())) // incomplete read + errno = 0; // strtoull doesn't reset errno + const unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) + if (p == p_end // invalid input or empty string + || errno == ERANGE // out of range + || JSON_HEDLEY_UNLIKELY(static_cast<std::size_t>(p_end - p) != s.size())) // incomplete read { JSON_THROW(detail::out_of_range::create(404, detail::concat("unresolved reference token '", s, "'"), nullptr)); } @@ -14047,14 +13826,13 @@ // https://github.com/nlohmann/json/pull/2203 if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)())) // NOLINT(runtime/int) { - JSON_THROW(detail::out_of_range::create(410, detail::concat("array index ", s, " exceeds size_type"), nullptr)); // LCOV_EXCL_LINE + JSON_THROW(detail::out_of_range::create(410, detail::concat("array index ", s, " exceeds size_type"), nullptr)); // LCOV_EXCL_LINE } return static_cast<size_type>(res); } - JSON_PRIVATE_UNLESS_TESTED: - json_pointer top() const + JSON_PRIVATE_UNLESS_TESTED : json_pointer top() const { if (JSON_HEDLEY_UNLIKELY(empty())) { @@ -14165,16 +13943,14 @@ { // check if reference token is a number const bool nums = - std::all_of(reference_token.begin(), reference_token.end(), - [](const unsigned char x) - { - return std::isdigit(x); - }); + std::all_of(reference_token.begin(), reference_token.end(), [](const unsigned char x) { + return std::isdigit(x); + }); // change value to array for numbers or "-" or to object otherwise *ptr = (nums || reference_token == "-") - ? detail::value_t::array - : detail::value_t::object; + ? detail::value_t::array + : detail::value_t::object; } switch (ptr->type()) @@ -14242,9 +14018,7 @@ if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) { // "-" always fails the range check - JSON_THROW(detail::out_of_range::create(402, detail::concat( - "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), - ") is out of range"), ptr)); + JSON_THROW(detail::out_of_range::create(402, detail::concat("array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), ") is out of range"), ptr)); } // note: at performs range check @@ -14349,9 +14123,7 @@ if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) { // "-" always fails the range check - JSON_THROW(detail::out_of_range::create(402, detail::concat( - "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), - ") is out of range"), ptr)); + JSON_THROW(detail::out_of_range::create(402, detail::concat("array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), ") is out of range"), ptr)); } // note: at performs range check @@ -14490,14 +14262,14 @@ for ( // search for the first slash after the first character std::size_t slash = reference_string.find_first_of('/', 1), - // set the beginning of the first reference token + // set the beginning of the first reference token start = 1; // we can stop if start == 0 (if slash == string_t::npos) start != 0; // set the beginning of the next reference token // (will eventually be 0 if slash == string_t::npos) start = (slash == string_t::npos) ? 0 : slash + 1, - // find next slash + // find next slash slash = reference_string.find_first_of('/', start)) { // use the text between the beginning of the reference token @@ -14506,8 +14278,8 @@ // check reference tokens are properly escaped for (std::size_t pos = reference_token.find_first_of('~'); - pos != string_t::npos; - pos = reference_token.find_first_of('~', pos + 1)) + pos != string_t::npos; + pos = reference_token.find_first_of('~', pos + 1)) { JSON_ASSERT(reference_token[pos] == '~'); @@ -14556,7 +14328,8 @@ for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i) { flatten(detail::concat(reference_string, '/', std::to_string(i)), - value.m_data.m_value.array->operator[](i), result); + value.m_data.m_value.array->operator[](i), + result); } } break; @@ -14644,7 +14417,7 @@ return result; } - json_pointer<string_t> convert()&& + json_pointer<string_t> convert() && { json_pointer<string_t> result; result.reference_tokens = std::move(reference_tokens); @@ -14671,9 +14444,9 @@ /// @brief 3-way compares two JSON pointers template<typename RefStringTypeRhs> - std::strong_ordering operator<=>(const json_pointer<RefStringTypeRhs>& rhs) const noexcept // *NOPAD* + std::strong_ordering operator<= > (const json_pointer<RefStringTypeRhs>& rhs) const noexcept // *NOPAD* { - return reference_tokens <=> rhs.reference_tokens; // *NOPAD* + return reference_tokens <= > rhs.reference_tokens; // *NOPAD* } #else /// @brief compares two JSON pointers for equality @@ -14801,8 +14574,6 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - #include <initializer_list> #include <utility> @@ -14810,10 +14581,8 @@ // #include <nlohmann/detail/meta/type_traits.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { template<typename BasicJsonType> class json_ref @@ -14822,22 +14591,22 @@ using value_type = BasicJsonType; json_ref(value_type&& value) - : owned_value(std::move(value)) + : owned_value(std::move(value)) {} json_ref(const value_type& value) - : value_ref(&value) + : value_ref(&value) {} json_ref(std::initializer_list<json_ref> init) - : owned_value(init) + : owned_value(init) {} - template < + template< class... Args, - enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 > - json_ref(Args && ... args) - : owned_value(std::forward<Args>(args)...) + enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0> + json_ref(Args&&... args) + : owned_value(std::forward<Args>(args)...) {} // class should be movable only @@ -14863,7 +14632,7 @@ value_type const* operator->() const { - return &** this; + return &**this; } private: @@ -14876,10 +14645,6 @@ // #include <nlohmann/detail/macro_scope.hpp> -// #include <nlohmann/detail/string_concat.hpp> - -// #include <nlohmann/detail/string_escape.hpp> - // #include <nlohmann/detail/meta/cpp_future.hpp> // #include <nlohmann/detail/meta/type_traits.hpp> @@ -14893,18 +14658,16 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <algorithm> // reverse -#include <array> // array -#include <map> // map -#include <cmath> // isnan, isinf -#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t -#include <cstring> // memcpy -#include <limits> // numeric_limits -#include <string> // string -#include <utility> // move -#include <vector> // vector +#include <algorithm> // reverse +#include <array> // array +#include <cmath> // isnan, isinf +#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t +#include <cstring> // memcpy +#include <limits> // numeric_limits +#include <map> // map +#include <string> // string +#include <utility> // move +#include <vector> // vector // #include <nlohmann/detail/input/binary_reader.hpp> @@ -14919,29 +14682,26 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <algorithm> // copy -#include <cstddef> // size_t -#include <iterator> // back_inserter -#include <memory> // shared_ptr, make_shared -#include <string> // basic_string -#include <vector> // vector +#include <algorithm> // copy +#include <cstddef> // size_t +#include <iterator> // back_inserter +#include <memory> // shared_ptr, make_shared +#include <string> // basic_string +#include <vector> // vector #ifndef JSON_NO_IO #include <ios> // streamsize #include <ostream> // basic_ostream -#endif // JSON_NO_IO +#endif // JSON_NO_IO // #include <nlohmann/detail/macro_scope.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /// abstract output adapter interface -template<typename CharType> struct output_adapter_protocol +template<typename CharType> +struct output_adapter_protocol { virtual void write_character(CharType c) = 0; virtual void write_characters(const CharType* s, std::size_t length) = 0; @@ -14964,7 +14724,7 @@ { public: explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept - : v(vec) + : v(vec) {} void write_character(CharType c) override @@ -14989,7 +14749,7 @@ { public: explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept - : stream(s) + : stream(s) {} void write_character(CharType c) override @@ -15014,7 +14774,7 @@ { public: explicit output_string_adapter(StringType& s) noexcept - : str(s) + : str(s) {} void write_character(CharType c) override @@ -15038,15 +14798,18 @@ public: template<typename AllocatorType = std::allocator<CharType>> output_adapter(std::vector<CharType, AllocatorType>& vec) - : oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {} + : oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) + {} #ifndef JSON_NO_IO output_adapter(std::basic_ostream<CharType>& s) - : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {} + : oa(std::make_shared<output_stream_adapter<CharType>>(s)) + {} #endif // JSON_NO_IO output_adapter(StringType& s) - : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {} + : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) + {} operator output_adapter_t<CharType>() { @@ -15062,10 +14825,8 @@ // #include <nlohmann/detail/string_concat.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /////////////////// // binary writer // @@ -15087,7 +14848,8 @@ @param[in] adapter output adapter to write to */ - explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter)) + explicit binary_writer(output_adapter_t<CharType> adapter) + : oa(std::move(adapter)) { JSON_ASSERT(oa); } @@ -15138,8 +14900,8 @@ case value_t::boolean: { oa->write_character(j.m_data.m_value.boolean - ? to_char_type(0xF5) - : to_char_type(0xF4)); + ? to_char_type(0xF5) + : to_char_type(0xF4)); break; } @@ -15453,17 +15215,17 @@ { switch (j.type()) { - case value_t::null: // nil + case value_t::null: // nil { oa->write_character(to_char_type(0xC0)); break; } - case value_t::boolean: // true and false + case value_t::boolean: // true and false { oa->write_character(j.m_data.m_value.boolean - ? to_char_type(0xC3) - : to_char_type(0xC2)); + ? to_char_type(0xC3) + : to_char_type(0xC2)); break; } @@ -15665,30 +15427,29 @@ switch (N) { case 1: - output_type = 0xD4; // fixext 1 + output_type = 0xD4; // fixext 1 break; case 2: - output_type = 0xD5; // fixext 2 + output_type = 0xD5; // fixext 2 break; case 4: - output_type = 0xD6; // fixext 4 + output_type = 0xD6; // fixext 4 break; case 8: - output_type = 0xD7; // fixext 8 + output_type = 0xD7; // fixext 8 break; case 16: - output_type = 0xD8; // fixext 16 + output_type = 0xD8; // fixext 16 break; default: - output_type = 0xC7; // ext 8 + output_type = 0xC7; // ext 8 fixed = false; break; } - } else { - output_type = 0xC4; // bin 8 + output_type = 0xC4; // bin 8 fixed = false; } @@ -15701,8 +15462,8 @@ else if (N <= (std::numeric_limits<std::uint16_t>::max)()) { const std::uint8_t output_type = use_ext - ? 0xC8 // ext 16 - : 0xC5; // bin 16 + ? 0xC8 // ext 16 + : 0xC5; // bin 16 oa->write_character(to_char_type(output_type)); write_number(static_cast<std::uint16_t>(N)); @@ -15710,8 +15471,8 @@ else if (N <= (std::numeric_limits<std::uint32_t>::max)()) { const std::uint8_t output_type = use_ext - ? 0xC9 // ext 32 - : 0xC6; // bin 32 + ? 0xC9 // ext 32 + : 0xC6; // bin 32 oa->write_character(to_char_type(output_type)); write_number(static_cast<std::uint32_t>(N)); @@ -15775,9 +15536,7 @@ @param[in] add_prefix whether prefixes need to be used for this value @param[in] use_bjdata whether write in BJData format, default is false */ - void write_ubjson(const BasicJsonType& j, const bool use_count, - const bool use_type, const bool add_prefix = true, - const bool use_bjdata = false) + void write_ubjson(const BasicJsonType& j, const bool use_count, const bool use_type, const bool add_prefix = true, const bool use_bjdata = false) { switch (j.type()) { @@ -15795,8 +15554,8 @@ if (add_prefix) { oa->write_character(j.m_data.m_value.boolean - ? to_char_type('T') - : to_char_type('F')); + ? to_char_type('T') + : to_char_type('F')); } break; } @@ -15844,13 +15603,11 @@ { JSON_ASSERT(use_count); const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata); - const bool same_prefix = std::all_of(j.begin() + 1, j.end(), - [this, first_prefix, use_bjdata](const BasicJsonType & v) - { + const bool same_prefix = std::all_of(j.begin() + 1, j.end(), [this, first_prefix, use_bjdata](const BasicJsonType& v) { return ubjson_prefix(v, use_bjdata) == first_prefix; }); - std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type + std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end())) { @@ -15942,13 +15699,11 @@ { JSON_ASSERT(use_count); const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata); - const bool same_prefix = std::all_of(j.begin(), j.end(), - [this, first_prefix, use_bjdata](const BasicJsonType & v) - { + const bool same_prefix = std::all_of(j.begin(), j.end(), [this, first_prefix, use_bjdata](const BasicJsonType& v) { return ubjson_prefix(v, use_bjdata) == first_prefix; }); - std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type + std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end())) { @@ -16005,7 +15760,7 @@ static_cast<void>(j); } - return /*id*/ 1ul + name.size() + /*zero-terminator*/1u; + return /*id*/ 1ul + name.size() + /*zero-terminator*/ 1u; } /*! @@ -16014,7 +15769,7 @@ void write_bson_entry_header(const string_t& name, const std::uint8_t element_type) { - oa->write_character(to_char_type(element_type)); // boolean + oa->write_character(to_char_type(element_type)); // boolean oa->write_characters( reinterpret_cast<const CharType*>(name.c_str()), name.size() + 1u); @@ -16076,8 +15831,8 @@ static std::size_t calc_bson_integer_size(const std::int64_t value) { return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)() - ? sizeof(std::int32_t) - : sizeof(std::int64_t); + ? sizeof(std::int32_t) + : sizeof(std::int64_t); } /*! @@ -16088,12 +15843,12 @@ { if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()) { - write_bson_entry_header(name, 0x10); // int32 + write_bson_entry_header(name, 0x10); // int32 write_number<std::int32_t>(static_cast<std::int32_t>(value), true); } else { - write_bson_entry_header(name, 0x12); // int64 + write_bson_entry_header(name, 0x12); // int64 write_number<std::int64_t>(static_cast<std::int64_t>(value), true); } } @@ -16104,8 +15859,8 @@ static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept { return (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) - ? sizeof(std::int32_t) - : sizeof(std::int64_t); + ? sizeof(std::int32_t) + : sizeof(std::int64_t); } /*! @@ -16136,7 +15891,7 @@ void write_bson_object_entry(const string_t& name, const typename BasicJsonType::object_t& value) { - write_bson_entry_header(name, 0x03); // object + write_bson_entry_header(name, 0x03); // object write_bson_object(value); } @@ -16147,8 +15902,7 @@ { std::size_t array_index = 0ul; - const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast<std::size_t>(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el) - { + const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast<std::size_t>(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type& el) { return result + calc_bson_element_size(std::to_string(array_index++), el); }); @@ -16169,7 +15923,7 @@ void write_bson_array(const string_t& name, const typename BasicJsonType::array_t& value) { - write_bson_entry_header(name, 0x04); // array + write_bson_entry_header(name, 0x04); // array write_number<std::int32_t>(static_cast<std::int32_t>(calc_bson_array_size(value)), true); std::size_t array_index = 0ul; @@ -16201,7 +15955,7 @@ @return The calculated size for the BSON document entry for @a j with the given @a name. */ static std::size_t calc_bson_element_size(const string_t& name, - const BasicJsonType& j) + const BasicJsonType& j) { const auto header_size = calc_bson_entry_header_size(name, j); switch (j.type()) @@ -16236,7 +15990,7 @@ // LCOV_EXCL_START case value_t::discarded: default: - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) return 0ul; // LCOV_EXCL_STOP } @@ -16283,7 +16037,7 @@ // LCOV_EXCL_START case value_t::discarded: default: - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) return; // LCOV_EXCL_STOP } @@ -16297,9 +16051,7 @@ */ static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value) { - const std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast<std::size_t>(0), - [](size_t result, const typename BasicJsonType::object_t::value_type & el) - { + const std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast<std::size_t>(0), [](size_t result, const typename BasicJsonType::object_t::value_type& el) { return result += calc_bson_element_size(el.first, el.second); }); @@ -16355,8 +16107,7 @@ //////////// // UBJSON: write number (floating point) - template<typename NumberType, typename std::enable_if< - std::is_floating_point<NumberType>::value, int>::type = 0> + template<typename NumberType, typename std::enable_if<std::is_floating_point<NumberType>::value, int>::type = 0> void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix, const bool use_bjdata) @@ -16369,8 +16120,7 @@ } // UBJSON: write number (unsigned integer) - template<typename NumberType, typename std::enable_if< - std::is_unsigned<NumberType>::value, int>::type = 0> + template<typename NumberType, typename std::enable_if<std::is_unsigned<NumberType>::value, int>::type = 0> void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix, const bool use_bjdata) @@ -16456,9 +16206,7 @@ } // UBJSON: write number (signed integer) - template < typename NumberType, typename std::enable_if < - std::is_signed<NumberType>::value&& - !std::is_floating_point<NumberType>::value, int >::type = 0 > + template<typename NumberType, typename std::enable_if<std::is_signed<NumberType>::value && !std::is_floating_point<NumberType>::value, int>::type = 0> void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix, const bool use_bjdata) @@ -16581,7 +16329,7 @@ return 'L'; } // anything else is treated as high-precision number - return 'H'; // LCOV_EXCL_LINE + return 'H'; // LCOV_EXCL_LINE } case value_t::number_unsigned: @@ -16619,7 +16367,7 @@ return 'M'; } // anything else is treated as high-precision number - return 'H'; // LCOV_EXCL_LINE + return 'H'; // LCOV_EXCL_LINE } case value_t::number_float: @@ -16628,7 +16376,7 @@ case value_t::string: return 'S'; - case value_t::array: // fallthrough + case value_t::array: // fallthrough case value_t::binary: return '['; @@ -16656,9 +16404,7 @@ */ bool write_bjdata_ndarray(const typename BasicJsonType::object_t& value, const bool use_count, const bool use_type) { - std::map<string_t, CharType> bjdtype = {{"uint8", 'U'}, {"int8", 'i'}, {"uint16", 'u'}, {"int16", 'I'}, - {"uint32", 'm'}, {"int32", 'l'}, {"uint64", 'M'}, {"int64", 'L'}, {"single", 'd'}, {"double", 'D'}, {"char", 'C'} - }; + std::map<string_t, CharType> bjdtype = {{"uint8", 'U'}, {"int8", 'i'}, {"uint16", 'u'}, {"int16", 'I'}, {"uint32", 'm'}, {"int32", 'l'}, {"uint64", 'M'}, {"int64", 'L'}, {"single", 'd'}, {"double", 'D'}, {"char", 'C'}}; string_t key = "_ArrayType_"; auto it = bjdtype.find(static_cast<string_t>(value.at(key))); @@ -16687,7 +16433,7 @@ oa->write_character('#'); key = "_ArraySize_"; - write_ubjson(value.at(key), use_count, use_type, true, true); + write_ubjson(value.at(key), use_count, use_type, true, true); key = "_ArrayData_"; if (dtype == 'U' || dtype == 'C') @@ -16800,27 +16546,27 @@ void write_compact_float(const number_float_t n, detail::input_format_t format) { #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" #endif if (static_cast<double>(n) >= static_cast<double>(std::numeric_limits<float>::lowest()) && - static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) && - static_cast<double>(static_cast<float>(n)) == static_cast<double>(n)) + static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) && + static_cast<double>(static_cast<float>(n)) == static_cast<double>(n)) { oa->write_character(format == detail::input_format_t::cbor - ? get_cbor_float_prefix(static_cast<float>(n)) - : get_msgpack_float_prefix(static_cast<float>(n))); + ? get_cbor_float_prefix(static_cast<float>(n)) + : get_msgpack_float_prefix(static_cast<float>(n))); write_number(static_cast<float>(n)); } else { oa->write_character(format == detail::input_format_t::cbor - ? get_cbor_float_prefix(n) - : get_msgpack_float_prefix(n)); + ? get_cbor_float_prefix(n) + : get_msgpack_float_prefix(n)); write_number(n); } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif } @@ -16829,15 +16575,15 @@ // between uint8_t and CharType. In case CharType is not unsigned, // such a conversion is required to allow values greater than 128. // See <https://github.com/nlohmann/json/issues/1286> for a discussion. - template < typename C = CharType, - enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * = nullptr > + template<typename C = CharType, + enable_if_t<std::is_signed<C>::value && std::is_signed<char>::value>* = nullptr> static constexpr CharType to_char_type(std::uint8_t x) noexcept { return *reinterpret_cast<char*>(&x); } - template < typename C = CharType, - enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * = nullptr > + template<typename C = CharType, + enable_if_t<std::is_signed<C>::value && std::is_unsigned<char>::value>* = nullptr> static CharType to_char_type(std::uint8_t x) noexcept { static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t"); @@ -16854,12 +16600,7 @@ return x; } - template < typename InputCharType, typename C = CharType, - enable_if_t < - std::is_signed<C>::value && - std::is_signed<char>::value && - std::is_same<char, typename std::remove_cv<InputCharType>::type>::value - > * = nullptr > + template<typename InputCharType, typename C = CharType, enable_if_t<std::is_signed<C>::value && std::is_signed<char>::value && std::is_same<char, typename std::remove_cv<InputCharType>::type>::value>* = nullptr> static constexpr CharType to_char_type(InputCharType x) noexcept { return x; @@ -16888,20 +16629,18 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <algorithm> // reverse, remove, fill, find, none_of -#include <array> // array -#include <clocale> // localeconv, lconv -#include <cmath> // labs, isfinite, isnan, signbit -#include <cstddef> // size_t, ptrdiff_t -#include <cstdint> // uint8_t -#include <cstdio> // snprintf -#include <limits> // numeric_limits -#include <string> // string, char_traits -#include <iomanip> // setfill, setw -#include <type_traits> // is_same -#include <utility> // move +#include <algorithm> // reverse, remove, fill, find, none_of +#include <array> // array +#include <clocale> // localeconv, lconv +#include <cmath> // labs, isfinite, isnan, signbit +#include <cstddef> // size_t, ptrdiff_t +#include <cstdint> // uint8_t +#include <cstdio> // snprintf +#include <iomanip> // setfill, setw +#include <limits> // numeric_limits +#include <string> // string, char_traits +#include <type_traits> // is_same +#include <utility> // move // #include <nlohmann/detail/conversions/to_chars.hpp> // __ _____ _____ _____ @@ -16913,21 +16652,17 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <array> // array -#include <cmath> // signbit, isfinite -#include <cstdint> // intN_t, uintN_t -#include <cstring> // memcpy, memmove -#include <limits> // numeric_limits -#include <type_traits> // conditional +#include <array> // array +#include <cmath> // signbit, isfinite +#include <cstdint> // intN_t, uintN_t +#include <cstring> // memcpy, memmove +#include <limits> // numeric_limits +#include <type_traits> // conditional // #include <nlohmann/detail/macro_scope.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /*! @brief implements the Grisu2 algorithm for binary to decimal floating-point @@ -16948,8 +16683,7 @@ Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language Design and Implementation, PLDI 1996 */ -namespace dtoa_impl -{ +namespace dtoa_impl { template<typename Target, typename Source> Target reinterpret_bits(const Source source) @@ -16961,14 +16695,17 @@ return target; } -struct diyfp // f * 2^e +struct diyfp // f * 2^e { - static constexpr int kPrecision = 64; // = q + static constexpr int kPrecision = 64; // = q std::uint64_t f = 0; int e = 0; - constexpr diyfp(std::uint64_t f_, int e_) noexcept : f(f_), e(e_) {} + constexpr diyfp(std::uint64_t f_, int e_) noexcept + : f(f_) + , e(e_) + {} /*! @brief returns x - y @@ -17040,7 +16777,7 @@ // Effectively we only need to add the highest bit in p_lo to p_hi (and // Q_hi + 1 does not overflow). - Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up + Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u); @@ -17108,12 +16845,12 @@ static_assert(std::numeric_limits<FloatType>::is_iec559, "internal error: dtoa_short requires an IEEE-754 floating-point implementation"); - constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit) - constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1); - constexpr int kMinExp = 1 - kBias; - constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1); // = 2^(p-1) + constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit) + constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1); + constexpr int kMinExp = 1 - kBias; + constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1); // = 2^(p-1) - using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type; + using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t>::type; const auto bits = static_cast<std::uint64_t>(reinterpret_bits<bits_type>(value)); const std::uint64_t E = bits >> (kPrecision - 1); @@ -17121,8 +16858,8 @@ const bool is_denormal = E == 0; const diyfp v = is_denormal - ? diyfp(F, kMinExp) - : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias); + ? diyfp(F, kMinExp) + : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias); // Compute the boundaries m- and m+ of the floating-point value // v = f * 2^e. @@ -17148,8 +16885,8 @@ const bool lower_boundary_is_closer = F == 0 && E > 1; const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1); const diyfp m_minus = lower_boundary_is_closer - ? diyfp(4 * v.f - 1, v.e - 2) // (B) - : diyfp(2 * v.f - 1, v.e - 1); // (A) + ? diyfp(4 * v.f - 1, v.e - 2) // (B) + : diyfp(2 * v.f - 1, v.e - 1); // (A) // Determine the normalized w+ = m+. const diyfp w_plus = diyfp::normalize(m_plus); @@ -17218,7 +16955,7 @@ constexpr int kAlpha = -60; constexpr int kGamma = -32; -struct cached_power // c = f * 2^e ~= 10^k +struct cached_power // c = f * 2^e ~= 10^k { std::uint64_t f; int e; @@ -17288,96 +17025,95 @@ constexpr int kCachedPowersDecStep = 8; static constexpr std::array<cached_power, 79> kCachedPowers = - { { - { 0xAB70FE17C79AC6CA, -1060, -300 }, - { 0xFF77B1FCBEBCDC4F, -1034, -292 }, - { 0xBE5691EF416BD60C, -1007, -284 }, - { 0x8DD01FAD907FFC3C, -980, -276 }, - { 0xD3515C2831559A83, -954, -268 }, - { 0x9D71AC8FADA6C9B5, -927, -260 }, - { 0xEA9C227723EE8BCB, -901, -252 }, - { 0xAECC49914078536D, -874, -244 }, - { 0x823C12795DB6CE57, -847, -236 }, - { 0xC21094364DFB5637, -821, -228 }, - { 0x9096EA6F3848984F, -794, -220 }, - { 0xD77485CB25823AC7, -768, -212 }, - { 0xA086CFCD97BF97F4, -741, -204 }, - { 0xEF340A98172AACE5, -715, -196 }, - { 0xB23867FB2A35B28E, -688, -188 }, - { 0x84C8D4DFD2C63F3B, -661, -180 }, - { 0xC5DD44271AD3CDBA, -635, -172 }, - { 0x936B9FCEBB25C996, -608, -164 }, - { 0xDBAC6C247D62A584, -582, -156 }, - { 0xA3AB66580D5FDAF6, -555, -148 }, - { 0xF3E2F893DEC3F126, -529, -140 }, - { 0xB5B5ADA8AAFF80B8, -502, -132 }, - { 0x87625F056C7C4A8B, -475, -124 }, - { 0xC9BCFF6034C13053, -449, -116 }, - { 0x964E858C91BA2655, -422, -108 }, - { 0xDFF9772470297EBD, -396, -100 }, - { 0xA6DFBD9FB8E5B88F, -369, -92 }, - { 0xF8A95FCF88747D94, -343, -84 }, - { 0xB94470938FA89BCF, -316, -76 }, - { 0x8A08F0F8BF0F156B, -289, -68 }, - { 0xCDB02555653131B6, -263, -60 }, - { 0x993FE2C6D07B7FAC, -236, -52 }, - { 0xE45C10C42A2B3B06, -210, -44 }, - { 0xAA242499697392D3, -183, -36 }, - { 0xFD87B5F28300CA0E, -157, -28 }, - { 0xBCE5086492111AEB, -130, -20 }, - { 0x8CBCCC096F5088CC, -103, -12 }, - { 0xD1B71758E219652C, -77, -4 }, - { 0x9C40000000000000, -50, 4 }, - { 0xE8D4A51000000000, -24, 12 }, - { 0xAD78EBC5AC620000, 3, 20 }, - { 0x813F3978F8940984, 30, 28 }, - { 0xC097CE7BC90715B3, 56, 36 }, - { 0x8F7E32CE7BEA5C70, 83, 44 }, - { 0xD5D238A4ABE98068, 109, 52 }, - { 0x9F4F2726179A2245, 136, 60 }, - { 0xED63A231D4C4FB27, 162, 68 }, - { 0xB0DE65388CC8ADA8, 189, 76 }, - { 0x83C7088E1AAB65DB, 216, 84 }, - { 0xC45D1DF942711D9A, 242, 92 }, - { 0x924D692CA61BE758, 269, 100 }, - { 0xDA01EE641A708DEA, 295, 108 }, - { 0xA26DA3999AEF774A, 322, 116 }, - { 0xF209787BB47D6B85, 348, 124 }, - { 0xB454E4A179DD1877, 375, 132 }, - { 0x865B86925B9BC5C2, 402, 140 }, - { 0xC83553C5C8965D3D, 428, 148 }, - { 0x952AB45CFA97A0B3, 455, 156 }, - { 0xDE469FBD99A05FE3, 481, 164 }, - { 0xA59BC234DB398C25, 508, 172 }, - { 0xF6C69A72A3989F5C, 534, 180 }, - { 0xB7DCBF5354E9BECE, 561, 188 }, - { 0x88FCF317F22241E2, 588, 196 }, - { 0xCC20CE9BD35C78A5, 614, 204 }, - { 0x98165AF37B2153DF, 641, 212 }, - { 0xE2A0B5DC971F303A, 667, 220 }, - { 0xA8D9D1535CE3B396, 694, 228 }, - { 0xFB9B7CD9A4A7443C, 720, 236 }, - { 0xBB764C4CA7A44410, 747, 244 }, - { 0x8BAB8EEFB6409C1A, 774, 252 }, - { 0xD01FEF10A657842C, 800, 260 }, - { 0x9B10A4E5E9913129, 827, 268 }, - { 0xE7109BFBA19C0C9D, 853, 276 }, - { 0xAC2820D9623BF429, 880, 284 }, - { 0x80444B5E7AA7CF85, 907, 292 }, - { 0xBF21E44003ACDD2D, 933, 300 }, - { 0x8E679C2F5E44FF8F, 960, 308 }, - { 0xD433179D9C8CB841, 986, 316 }, - { 0x9E19DB92B4E31BA9, 1013, 324 }, - } - }; + { + {0xAB70FE17C79AC6CA, -1060, -300}, + {0xFF77B1FCBEBCDC4F, -1034, -292}, + {0xBE5691EF416BD60C, -1007, -284}, + {0x8DD01FAD907FFC3C, -980, -276}, + {0xD3515C2831559A83, -954, -268}, + {0x9D71AC8FADA6C9B5, -927, -260}, + {0xEA9C227723EE8BCB, -901, -252}, + {0xAECC49914078536D, -874, -244}, + {0x823C12795DB6CE57, -847, -236}, + {0xC21094364DFB5637, -821, -228}, + {0x9096EA6F3848984F, -794, -220}, + {0xD77485CB25823AC7, -768, -212}, + {0xA086CFCD97BF97F4, -741, -204}, + {0xEF340A98172AACE5, -715, -196}, + {0xB23867FB2A35B28E, -688, -188}, + {0x84C8D4DFD2C63F3B, -661, -180}, + {0xC5DD44271AD3CDBA, -635, -172}, + {0x936B9FCEBB25C996, -608, -164}, + {0xDBAC6C247D62A584, -582, -156}, + {0xA3AB66580D5FDAF6, -555, -148}, + {0xF3E2F893DEC3F126, -529, -140}, + {0xB5B5ADA8AAFF80B8, -502, -132}, + {0x87625F056C7C4A8B, -475, -124}, + {0xC9BCFF6034C13053, -449, -116}, + {0x964E858C91BA2655, -422, -108}, + {0xDFF9772470297EBD, -396, -100}, + {0xA6DFBD9FB8E5B88F, -369, -92}, + {0xF8A95FCF88747D94, -343, -84}, + {0xB94470938FA89BCF, -316, -76}, + {0x8A08F0F8BF0F156B, -289, -68}, + {0xCDB02555653131B6, -263, -60}, + {0x993FE2C6D07B7FAC, -236, -52}, + {0xE45C10C42A2B3B06, -210, -44}, + {0xAA242499697392D3, -183, -36}, + {0xFD87B5F28300CA0E, -157, -28}, + {0xBCE5086492111AEB, -130, -20}, + {0x8CBCCC096F5088CC, -103, -12}, + {0xD1B71758E219652C, -77, -4}, + {0x9C40000000000000, -50, 4}, + {0xE8D4A51000000000, -24, 12}, + {0xAD78EBC5AC620000, 3, 20}, + {0x813F3978F8940984, 30, 28}, + {0xC097CE7BC90715B3, 56, 36}, + {0x8F7E32CE7BEA5C70, 83, 44}, + {0xD5D238A4ABE98068, 109, 52}, + {0x9F4F2726179A2245, 136, 60}, + {0xED63A231D4C4FB27, 162, 68}, + {0xB0DE65388CC8ADA8, 189, 76}, + {0x83C7088E1AAB65DB, 216, 84}, + {0xC45D1DF942711D9A, 242, 92}, + {0x924D692CA61BE758, 269, 100}, + {0xDA01EE641A708DEA, 295, 108}, + {0xA26DA3999AEF774A, 322, 116}, + {0xF209787BB47D6B85, 348, 124}, + {0xB454E4A179DD1877, 375, 132}, + {0x865B86925B9BC5C2, 402, 140}, + {0xC83553C5C8965D3D, 428, 148}, + {0x952AB45CFA97A0B3, 455, 156}, + {0xDE469FBD99A05FE3, 481, 164}, + {0xA59BC234DB398C25, 508, 172}, + {0xF6C69A72A3989F5C, 534, 180}, + {0xB7DCBF5354E9BECE, 561, 188}, + {0x88FCF317F22241E2, 588, 196}, + {0xCC20CE9BD35C78A5, 614, 204}, + {0x98165AF37B2153DF, 641, 212}, + {0xE2A0B5DC971F303A, 667, 220}, + {0xA8D9D1535CE3B396, 694, 228}, + {0xFB9B7CD9A4A7443C, 720, 236}, + {0xBB764C4CA7A44410, 747, 244}, + {0x8BAB8EEFB6409C1A, 774, 252}, + {0xD01FEF10A657842C, 800, 260}, + {0x9B10A4E5E9913129, 827, 268}, + {0xE7109BFBA19C0C9D, 853, 276}, + {0xAC2820D9623BF429, 880, 284}, + {0x80444B5E7AA7CF85, 907, 292}, + {0xBF21E44003ACDD2D, 933, 300}, + {0x8E679C2F5E44FF8F, 960, 308}, + {0xD433179D9C8CB841, 986, 316}, + {0x9E19DB92B4E31BA9, 1013, 324}, + }}; // This computation gives exactly the same results for k as // k = ceil((kAlpha - e - 1) * 0.30102999566398114) // for |e| <= 1500, but doesn't require floating-point operations. // NB: log_10(2) ~= 78913 / 2^18 JSON_ASSERT(e >= -1500); - JSON_ASSERT(e <= 1500); + JSON_ASSERT(e <= 1500); const int f = kAlpha - e - 1; const int k = (f * 78913) / (1 << 18) + static_cast<int>(f > 0); @@ -17408,50 +17144,49 @@ if (n >= 100000000) { pow10 = 100000000; - return 9; + return 9; } if (n >= 10000000) { pow10 = 10000000; - return 8; + return 8; } if (n >= 1000000) { pow10 = 1000000; - return 7; + return 7; } if (n >= 100000) { pow10 = 100000; - return 6; + return 6; } if (n >= 10000) { pow10 = 10000; - return 5; + return 5; } if (n >= 1000) { pow10 = 1000; - return 4; + return 4; } if (n >= 100) { pow10 = 100; - return 3; + return 3; } if (n >= 10) { pow10 = 10; - return 2; + return 2; } pow10 = 1; return 1; } -inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta, - std::uint64_t rest, std::uint64_t ten_k) +inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta, std::uint64_t rest, std::uint64_t ten_k) { JSON_ASSERT(len >= 1); JSON_ASSERT(dist <= delta); @@ -17477,9 +17212,7 @@ // The tests are written in this order to avoid overflow in unsigned // integer arithmetic. - while (rest < dist - && delta - rest >= ten_k - && (rest + ten_k < dist || dist - rest > rest + ten_k - dist)) + while (rest < dist && delta - rest >= ten_k && (rest + ten_k < dist || dist - rest > rest + ten_k - dist)) { JSON_ASSERT(buf[len - 1] != '0'); buf[len - 1]--; @@ -17491,8 +17224,7 @@ Generates V = buffer * 10^decimal_exponent, such that M- <= V <= M+. M- and M+ must be normalized and share the same exponent -60 <= e <= -32. */ -inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, - diyfp M_minus, diyfp w, diyfp M_plus) +inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus) { static_assert(kAlpha >= -60, "internal error"); static_assert(kGamma <= -32, "internal error"); @@ -17512,8 +17244,8 @@ JSON_ASSERT(M_plus.e >= kAlpha); JSON_ASSERT(M_plus.e <= kGamma); - std::uint64_t delta = diyfp::sub(M_plus, M_minus).f; // (significand of (M+ - M-), implicit exponent is e) - std::uint64_t dist = diyfp::sub(M_plus, w ).f; // (significand of (M+ - w ), implicit exponent is e) + std::uint64_t delta = diyfp::sub(M_plus, M_minus).f; // (significand of (M+ - M-), implicit exponent is e) + std::uint64_t dist = diyfp::sub(M_plus, w).f; // (significand of (M+ - w ), implicit exponent is e) // Split M+ = f * 2^e into two parts p1 and p2 (note: e < 0): // @@ -17524,8 +17256,8 @@ const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e); - auto p1 = static_cast<std::uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.) - std::uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e + auto p1 = static_cast<std::uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.) + std::uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e // 1) // @@ -17568,7 +17300,7 @@ // = (buffer * 10 + d) * 10^(n-1) + (r + p2 * 2^e) // JSON_ASSERT(d <= 9); - buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d + buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d // // M+ = buffer * 10^(n-1) + (r + p2 * 2^e) // @@ -17667,15 +17399,15 @@ // JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10); p2 *= 10; - const std::uint64_t d = p2 >> -one.e; // d = (10 * p2) div 2^-e - const std::uint64_t r = p2 & (one.f - 1); // r = (10 * p2) mod 2^-e + const std::uint64_t d = p2 >> -one.e; // d = (10 * p2) div 2^-e + const std::uint64_t r = p2 & (one.f - 1); // r = (10 * p2) mod 2^-e // // M+ = buffer * 10^-m + 10^-m * (1/10 * (d * 2^-e + r) * 2^e // = buffer * 10^-m + 10^-m * (1/10 * (d + r * 2^e)) // = (buffer * 10 + d) * 10^(-m-1) + 10^(-m-1) * r * 2^e // JSON_ASSERT(d <= 9); - buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d + buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d // // M+ = buffer * 10^(-m-1) + 10^(-m-1) * r * 2^e // @@ -17691,7 +17423,7 @@ // p2 * 2^e <= 10^m * delta * 2^e // p2 <= 10^m * delta delta *= 10; - dist *= 10; + dist *= 10; if (p2 <= delta) { break; @@ -17732,8 +17464,7 @@ The buffer must be large enough, i.e. >= max_digits10. */ JSON_HEDLEY_NON_NULL(1) -inline void grisu2(char* buf, int& len, int& decimal_exponent, - diyfp m_minus, diyfp v, diyfp m_plus) +inline void grisu2(char* buf, int& len, int& decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus) { JSON_ASSERT(m_plus.e == m_minus.e); JSON_ASSERT(m_plus.e == v.e); @@ -17749,12 +17480,12 @@ const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e); - const diyfp c_minus_k(cached.f, cached.e); // = c ~= 10^-k + const diyfp c_minus_k(cached.f, cached.e); // = c ~= 10^-k // The exponent of the products is = v.e + c_minus_k.e + q and is in the range [alpha,gamma] - const diyfp w = diyfp::mul(v, c_minus_k); + const diyfp w = diyfp::mul(v, c_minus_k); const diyfp w_minus = diyfp::mul(m_minus, c_minus_k); - const diyfp w_plus = diyfp::mul(m_plus, c_minus_k); + const diyfp w_plus = diyfp::mul(m_plus, c_minus_k); // ----(---+---)---------------(---+---)---------------(---+---)---- // w- w w+ @@ -17778,9 +17509,9 @@ // Note that this does not mean that Grisu2 always generates the shortest // possible number in the interval (m-, m+). const diyfp M_minus(w_minus.f + 1, w_minus.e); - const diyfp M_plus (w_plus.f - 1, w_plus.e ); + const diyfp M_plus(w_plus.f - 1, w_plus.e); - decimal_exponent = -cached.k; // = -(-k) = k + decimal_exponent = -cached.k; // = -(-k) = k grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus); } @@ -17816,7 +17547,7 @@ // NB: If the neighbors are computed for single-precision numbers, there is a single float // (7.0385307e-26f) which can't be recovered using strtod. The resulting double precision // value is off by 1 ulp. -#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if) +#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if) const boundaries w = compute_boundaries(static_cast<double>(value)); #else const boundaries w = compute_boundaries(value); @@ -17835,7 +17566,7 @@ inline char* append_exponent(char* buf, int e) { JSON_ASSERT(e > -1000); - JSON_ASSERT(e < 1000); + JSON_ASSERT(e < 1000); if (e < 0) { @@ -17884,8 +17615,7 @@ */ JSON_HEDLEY_NON_NULL(1) JSON_HEDLEY_RETURNS_NON_NULL -inline char* format_buffer(char* buf, int len, int decimal_exponent, - int min_exp, int max_exp) +inline char* format_buffer(char* buf, int len, int decimal_exponent, int min_exp, int max_exp) { JSON_ASSERT(min_exp < 0); JSON_ASSERT(max_exp > 0); @@ -17969,9 +17699,9 @@ template<typename FloatType> JSON_HEDLEY_NON_NULL(1, 2) JSON_HEDLEY_RETURNS_NON_NULL -char* to_chars(char* first, const char* last, FloatType value) + char* to_chars(char* first, const char* last, FloatType value) { - static_cast<void>(last); // maybe unused - fix warning + static_cast<void>(last); // maybe unused - fix warning JSON_ASSERT(std::isfinite(value)); // Use signbit(value) instead of (value < 0) since signbit works for -0. @@ -17982,10 +17712,10 @@ } #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" #endif - if (value == 0) // +-0 + if (value == 0) // +-0 { *first++ = '0'; // Make it look like a floating-point number (#362, #378) @@ -17994,7 +17724,7 @@ return first; } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10); @@ -18038,10 +17768,8 @@ // #include <nlohmann/detail/value_t.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { /////////////////// // serialization // @@ -18050,9 +17778,9 @@ /// how to treat decoding errors enum class error_handler_t { - strict, ///< throw a type_error exception in case of invalid UTF-8 - replace, ///< replace invalid UTF-8 sequences with U+FFFD - ignore ///< ignore invalid UTF-8 sequences + strict, ///< throw a type_error exception in case of invalid UTF-8 + replace, ///< replace invalid UTF-8 sequences with U+FFFD + ignore ///< ignore invalid UTF-8 sequences }; template<typename BasicJsonType> @@ -18072,15 +17800,14 @@ @param[in] ichar indentation character to use @param[in] error_handler_ how to react on decoding errors */ - serializer(output_adapter_t<char> s, const char ichar, - error_handler_t error_handler_ = error_handler_t::strict) - : o(std::move(s)) - , loc(std::localeconv()) - , thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep))) - , decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point))) - , indent_char(ichar) - , indent_string(512, indent_char) - , error_handler(error_handler_) + serializer(output_adapter_t<char> s, const char ichar, error_handler_t error_handler_ = error_handler_t::strict) + : o(std::move(s)) + , loc(std::localeconv()) + , thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(*(loc->thousands_sep))) + , decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(*(loc->decimal_point))) + , indent_char(ichar) + , indent_string(512, indent_char) + , error_handler(error_handler_) {} // delete because of pointer members @@ -18214,7 +17941,8 @@ // first n-1 elements for (auto i = val.m_data.m_value.array->cbegin(); - i != val.m_data.m_value.array->cend() - 1; ++i) + i != val.m_data.m_value.array->cend() - 1; + ++i) { o->write_characters(indent_string.c_str(), new_indent); dump(*i, true, ensure_ascii, indent_step, new_indent); @@ -18236,7 +17964,8 @@ // first n-1 elements for (auto i = val.m_data.m_value.array->cbegin(); - i != val.m_data.m_value.array->cend() - 1; ++i) + i != val.m_data.m_value.array->cend() - 1; + ++i) { dump(*i, false, ensure_ascii, indent_step, current_indent); o->write_character(','); @@ -18280,7 +18009,8 @@ if (!val.m_data.m_value.binary->empty()) { for (auto i = val.m_data.m_value.binary->cbegin(); - i != val.m_data.m_value.binary->cend() - 1; ++i) + i != val.m_data.m_value.binary->cend() - 1; + ++i) { dump_integer(*i); o->write_characters(", ", 2); @@ -18311,7 +18041,8 @@ if (!val.m_data.m_value.binary->empty()) { for (auto i = val.m_data.m_value.binary->cbegin(); - i != val.m_data.m_value.binary->cend() - 1; ++i) + i != val.m_data.m_value.binary->cend() - 1; + ++i) { dump_integer(*i); o->write_character(','); @@ -18376,13 +18107,13 @@ return; } - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } } - JSON_PRIVATE_UNLESS_TESTED: - /*! + JSON_PRIVATE_UNLESS_TESTED : + /*! @brief dump escaped string Escape a string by replacing certain special characters by a sequence of an @@ -18396,7 +18127,8 @@ @complexity Linear in the length of string @a s. */ - void dump_escaped(const string_t& s, const bool ensure_ascii) + void + dump_escaped(const string_t& s, const bool ensure_ascii) { std::uint32_t codepoint{}; std::uint8_t state = UTF8_ACCEPT; @@ -18416,49 +18148,49 @@ { switch (codepoint) { - case 0x08: // backspace + case 0x08: // backspace { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = 'b'; break; } - case 0x09: // horizontal tab + case 0x09: // horizontal tab { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = 't'; break; } - case 0x0A: // newline + case 0x0A: // newline { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = 'n'; break; } - case 0x0C: // formfeed + case 0x0C: // formfeed { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = 'f'; break; } - case 0x0D: // carriage return + case 0x0D: // carriage return { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = 'r'; break; } - case 0x22: // quotation mark + case 0x22: // quotation mark { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = '\"'; break; } - case 0x5C: // reverse solidus + case 0x5C: // reverse solidus { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = '\\'; @@ -18474,16 +18206,13 @@ if (codepoint <= 0xFFFF) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", - static_cast<std::uint16_t>(codepoint))); + static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", static_cast<std::uint16_t>(codepoint))); bytes += 6; } else { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", - static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)), - static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu)))); + static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)), static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu)))); bytes += 12; } } @@ -18575,8 +18304,8 @@ break; } - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } break; } @@ -18636,8 +18365,8 @@ break; } - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } } } @@ -18692,13 +18421,13 @@ } // templates to avoid warnings about useless casts - template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value, int> = 0> + template<typename NumberType, enable_if_t<std::is_signed<NumberType>::value, int> = 0> bool is_negative_number(NumberType x) { return x < 0; } - template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value, int > = 0 > + template<typename NumberType, enable_if_t<std::is_unsigned<NumberType>::value, int> = 0> bool is_negative_number(NumberType /*unused*/) { return false; @@ -18713,29 +18442,112 @@ @param[in] x integer number (signed or unsigned) to dump @tparam NumberType either @a number_integer_t or @a number_unsigned_t */ - template < typename NumberType, detail::enable_if_t < - std::is_integral<NumberType>::value || - std::is_same<NumberType, number_unsigned_t>::value || - std::is_same<NumberType, number_integer_t>::value || - std::is_same<NumberType, binary_char_t>::value, - int > = 0 > + template<typename NumberType, detail::enable_if_t<std::is_integral<NumberType>::value || std::is_same<NumberType, number_unsigned_t>::value || std::is_same<NumberType, number_integer_t>::value || std::is_same<NumberType, binary_char_t>::value, int> = 0> void dump_integer(NumberType x) { - static constexpr std::array<std::array<char, 2>, 100> digits_to_99 - { + static constexpr std::array<std::array<char, 2>, 100> digits_to_99{ { - {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}}, - {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}}, - {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}}, - {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}}, - {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}}, - {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}}, - {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}}, - {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}}, - {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}}, - {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}}, - } - }; + {{'0', '0'}}, + {{'0', '1'}}, + {{'0', '2'}}, + {{'0', '3'}}, + {{'0', '4'}}, + {{'0', '5'}}, + {{'0', '6'}}, + {{'0', '7'}}, + {{'0', '8'}}, + {{'0', '9'}}, + {{'1', '0'}}, + {{'1', '1'}}, + {{'1', '2'}}, + {{'1', '3'}}, + {{'1', '4'}}, + {{'1', '5'}}, + {{'1', '6'}}, + {{'1', '7'}}, + {{'1', '8'}}, + {{'1', '9'}}, + {{'2', '0'}}, + {{'2', '1'}}, + {{'2', '2'}}, + {{'2', '3'}}, + {{'2', '4'}}, + {{'2', '5'}}, + {{'2', '6'}}, + {{'2', '7'}}, + {{'2', '8'}}, + {{'2', '9'}}, + {{'3', '0'}}, + {{'3', '1'}}, + {{'3', '2'}}, + {{'3', '3'}}, + {{'3', '4'}}, + {{'3', '5'}}, + {{'3', '6'}}, + {{'3', '7'}}, + {{'3', '8'}}, + {{'3', '9'}}, + {{'4', '0'}}, + {{'4', '1'}}, + {{'4', '2'}}, + {{'4', '3'}}, + {{'4', '4'}}, + {{'4', '5'}}, + {{'4', '6'}}, + {{'4', '7'}}, + {{'4', '8'}}, + {{'4', '9'}}, + {{'5', '0'}}, + {{'5', '1'}}, + {{'5', '2'}}, + {{'5', '3'}}, + {{'5', '4'}}, + {{'5', '5'}}, + {{'5', '6'}}, + {{'5', '7'}}, + {{'5', '8'}}, + {{'5', '9'}}, + {{'6', '0'}}, + {{'6', '1'}}, + {{'6', '2'}}, + {{'6', '3'}}, + {{'6', '4'}}, + {{'6', '5'}}, + {{'6', '6'}}, + {{'6', '7'}}, + {{'6', '8'}}, + {{'6', '9'}}, + {{'7', '0'}}, + {{'7', '1'}}, + {{'7', '2'}}, + {{'7', '3'}}, + {{'7', '4'}}, + {{'7', '5'}}, + {{'7', '6'}}, + {{'7', '7'}}, + {{'7', '8'}}, + {{'7', '9'}}, + {{'8', '0'}}, + {{'8', '1'}}, + {{'8', '2'}}, + {{'8', '3'}}, + {{'8', '4'}}, + {{'8', '5'}}, + {{'8', '6'}}, + {{'8', '7'}}, + {{'8', '8'}}, + {{'8', '9'}}, + {{'9', '0'}}, + {{'9', '1'}}, + {{'9', '2'}}, + {{'9', '3'}}, + {{'9', '4'}}, + {{'9', '5'}}, + {{'9', '6'}}, + {{'9', '7'}}, + {{'9', '8'}}, + {{'9', '9'}}, + }}; // special case for "0" if (x == 0) @@ -18745,7 +18557,7 @@ } // use a pointer to fill the buffer - auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg) + auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg) number_unsigned_t abs_value; @@ -18818,9 +18630,8 @@ // guaranteed to round-trip, using strtof and strtod, resp. // // NB: The test below works if <long double> == <double>. - static constexpr bool is_ieee_single_or_double - = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) || - (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024); + static constexpr bool is_ieee_single_or_double = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) || + (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024); dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>()); } @@ -18872,11 +18683,9 @@ // determine if we need to append ".0" const bool value_is_int_like = - std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, - [](char c) - { - return c == '.' || c == 'e'; - }); + std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, [](char c) { + return c == '.' || c == 'e'; + }); if (value_is_int_like) { @@ -18908,31 +18717,416 @@ static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept { static const std::array<std::uint8_t, 400> utf8d = - { { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00..1F - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20..3F - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40..5F - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60..7F - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // 80..9F - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // A0..BF - 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C0..DF - 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF - 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF - 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, // s1..s2 - 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // s3..s4 - 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, // s5..s6 - 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // s7..s8 - } - }; + { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, // 00..1F + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, // 20..3F + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, // 40..5F + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, // 60..7F + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, // 80..9F + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, // A0..BF + 8, + 8, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, // C0..DF + 0xA, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x3, + 0x4, + 0x3, + 0x3, // E0..EF + 0xB, + 0x6, + 0x6, + 0x6, + 0x5, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, + 0x8, // F0..FF + 0x0, + 0x1, + 0x2, + 0x3, + 0x5, + 0x8, + 0x7, + 0x1, + 0x1, + 0x1, + 0x4, + 0x6, + 0x1, + 0x1, + 0x1, + 0x1, // s0..s0 + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 1, + 0, + 1, + 1, + 1, + 1, + 1, + 1, // s1..s2 + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 2, + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, // s3..s4 + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 3, + 1, + 3, + 1, + 1, + 1, + 1, + 1, + 1, // s5..s6 + 1, + 3, + 1, + 1, + 1, + 1, + 1, + 3, + 1, + 3, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 3, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 // s7..s8 + }}; JSON_ASSERT(byte < utf8d.size()); const std::uint8_t type = utf8d[byte]; codep = (state != UTF8_ACCEPT) - ? (byte & 0x3fu) | (codep << 6u) - : (0xFFu >> type) & (byte); + ? (byte & 0x3fu) | (codep << 6u) + : (0xFFu >> type) & (byte); const std::size_t index = 256u + static_cast<size_t>(state) * 16u + static_cast<size_t>(type); JSON_ASSERT(index < utf8d.size()); @@ -18947,8 +19141,8 @@ */ number_unsigned_t remove_sign(number_unsigned_t x) { - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE - return x; // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + return x; // LCOV_EXCL_LINE } /* @@ -18962,7 +19156,7 @@ */ inline number_unsigned_t remove_sign(number_integer_t x) noexcept { - JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression) + JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression) return static_cast<number_unsigned_t>(-(x + 1)) + 1; } @@ -18995,6 +19189,10 @@ } // namespace detail NLOHMANN_JSON_NAMESPACE_END +// #include <nlohmann/detail/string_concat.hpp> + +// #include <nlohmann/detail/string_escape.hpp> + // #include <nlohmann/detail/value_t.hpp> // #include <nlohmann/json_fwd.hpp> @@ -19008,29 +19206,25 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - -#include <functional> // equal_to, less -#include <initializer_list> // initializer_list -#include <iterator> // input_iterator_tag, iterator_traits -#include <memory> // allocator -#include <stdexcept> // for out_of_range -#include <type_traits> // enable_if, is_convertible -#include <utility> // pair -#include <vector> // vector +#include <functional> // equal_to, less +#include <initializer_list> // initializer_list +#include <iterator> // input_iterator_tag, iterator_traits +#include <memory> // allocator +#include <stdexcept> // for out_of_range +#include <type_traits> // enable_if, is_convertible +#include <utility> // pair +#include <vector> // vector // #include <nlohmann/detail/macro_scope.hpp> // #include <nlohmann/detail/meta/type_traits.hpp> - NLOHMANN_JSON_NAMESPACE_BEGIN /// ordered_map: a minimal map-like container that preserves insertion order /// for use within nlohmann::basic_json<ordered_map> -template <class Key, class T, class IgnoredLess = std::less<Key>, - class Allocator = std::allocator<std::pair<const Key, T>>> - struct ordered_map : std::vector<std::pair<const Key, T>, Allocator> +template<class Key, class T, class IgnoredLess = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>> +struct ordered_map : std::vector<std::pair<const Key, T>, Allocator> { using key_type = Key; using mapped_type = T; @@ -19047,13 +19241,19 @@ // Explicit constructors instead of `using Container::Container` // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) - ordered_map() noexcept(noexcept(Container())) : Container{} {} - explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {} - template <class It> + ordered_map() noexcept(noexcept(Container())) + : Container{} + {} + explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) + : Container{alloc} + {} + template<class It> ordered_map(It first, It last, const Allocator& alloc = Allocator()) - : Container{first, last, alloc} {} - ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator() ) - : Container{init, alloc} {} + : Container{first, last, alloc} + {} + ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator()) + : Container{init, alloc} + {} std::pair<iterator, bool> emplace(const key_type& key, T&& t) { @@ -19068,9 +19268,8 @@ return {std::prev(this->end()), true}; } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - std::pair<iterator, bool> emplace(KeyType && key, T && t) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + std::pair<iterator, bool> emplace(KeyType&& key, T&& t) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -19088,9 +19287,8 @@ return emplace(key, T{}).first->second; } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - T & operator[](KeyType && key) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + T& operator[](KeyType&& key) { return emplace(std::forward<KeyType>(key), T{}).first->second; } @@ -19100,9 +19298,8 @@ return at(key); } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - const T & operator[](KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + const T& operator[](KeyType&& key) const { return at(std::forward<KeyType>(key)); } @@ -19120,9 +19317,8 @@ JSON_THROW(std::out_of_range("key not found")); } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - T & at(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + T& at(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -19148,9 +19344,8 @@ JSON_THROW(std::out_of_range("key not found")); } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - const T & at(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + const T& at(KeyType&& key) const // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -19172,7 +19367,7 @@ // Since we cannot move const Keys, re-construct them in place for (auto next = it; ++next != this->end(); ++it) { - it->~value_type(); // Destroy but keep allocation + it->~value_type(); // Destroy but keep allocation new (&*it) value_type{std::move(*next)}; } Container::pop_back(); @@ -19182,9 +19377,8 @@ return 0; } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + size_type erase(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -19193,7 +19387,7 @@ // Since we cannot move const Keys, re-construct them in place for (auto next = it; ++next != this->end(); ++it) { - it->~value_type(); // Destroy but keep allocation + it->~value_type(); // Destroy but keep allocation new (&*it) value_type{std::move(*next)}; } Container::pop_back(); @@ -19240,8 +19434,8 @@ for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) { - it->~value_type(); // destroy but keep allocation - new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it + it->~value_type(); // destroy but keep allocation + new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it } // [ a, b, c, d, h, i, j, h, i, j ] @@ -19273,9 +19467,8 @@ return 0; } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - size_type count(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + size_type count(KeyType&& key) const // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -19299,9 +19492,8 @@ return Container::end(); } - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> - iterator find(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> + iterator find(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -19325,12 +19517,12 @@ return Container::end(); } - std::pair<iterator, bool> insert( value_type&& value ) + std::pair<iterator, bool> insert(value_type&& value) { return emplace(value.first, std::move(value.second)); } - std::pair<iterator, bool> insert( const value_type& value ) + std::pair<iterator, bool> insert(const value_type& value) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -19345,7 +19537,7 @@ template<typename InputIt> using require_input_iter = typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category, - std::input_iterator_tag>::value>::type; + std::input_iterator_tag>::value>::type; template<typename InputIt, typename = require_input_iter<InputIt>> void insert(InputIt first, InputIt last) @@ -19356,13 +19548,12 @@ } } -private: + private: JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare(); }; NLOHMANN_JSON_NAMESPACE_END - #if defined(JSON_HAS_CPP_17) #if JSON_HAS_STATIC_RTTI #include <any> @@ -19396,11 +19587,12 @@ @nosubgrouping */ NLOHMANN_BASIC_JSON_TPL_DECLARATION -class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) - : public ::nlohmann::detail::json_base_class<CustomBaseClass> +class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) + : public ::nlohmann::detail::json_base_class<CustomBaseClass> { private: - template<detail::value_t> friend struct detail::external_constructor; + template<detail::value_t> + friend struct detail::external_constructor; template<typename> friend class ::nlohmann::json_pointer; @@ -19426,20 +19618,21 @@ using basic_json_t = NLOHMANN_BASIC_JSON_TPL; using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>; - JSON_PRIVATE_UNLESS_TESTED: - // convenience aliases for types residing in namespace detail; - using lexer = ::nlohmann::detail::lexer_base<basic_json>; + JSON_PRIVATE_UNLESS_TESTED : + // convenience aliases for types residing in namespace detail; + using lexer = ::nlohmann::detail::lexer_base<basic_json>; template<typename InputAdapterType> static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser( InputAdapterType adapter, - detail::parser_callback_t<basic_json>cb = nullptr, + detail::parser_callback_t<basic_json> cb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false - ) + const bool ignore_comments = false) { return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter), - std::move(cb), allow_exceptions, ignore_comments); + std::move(cb), + allow_exceptions, + ignore_comments); } private: @@ -19450,17 +19643,18 @@ using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>; template<typename Iterator> using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>; - template<typename Base> using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>; + template<typename Base> + using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>; template<typename CharType> using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>; template<typename InputType> using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>; - template<typename CharType> using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>; + template<typename CharType> + using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>; - JSON_PRIVATE_UNLESS_TESTED: - using serializer = ::nlohmann::detail::serializer<basic_json>; + JSON_PRIVATE_UNLESS_TESTED : using serializer = ::nlohmann::detail::serializer<basic_json>; public: using value_t = detail::value_t; @@ -19555,9 +19749,7 @@ result["name"] = "JSON for Modern C++"; result["url"] = "https://github.com/nlohmann/json"; result["version"]["string"] = - detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR), '.', - std::to_string(NLOHMANN_JSON_VERSION_MINOR), '.', - std::to_string(NLOHMANN_JSON_VERSION_PATCH)); + detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR), '.', std::to_string(NLOHMANN_JSON_VERSION_MINOR), '.', std::to_string(NLOHMANN_JSON_VERSION_PATCH)); result["version"]["major"] = NLOHMANN_JSON_VERSION_MAJOR; result["version"]["minor"] = NLOHMANN_JSON_VERSION_MINOR; result["version"]["patch"] = NLOHMANN_JSON_VERSION_PATCH; @@ -19575,26 +19767,34 @@ #endif #if defined(__ICC) || defined(__INTEL_COMPILER) - result["compiler"] = {{"family", "icc"}, {"version", __INTEL_COMPILER}}; + result["compiler"] = {{"family", "icc"}, { "version", + __INTEL_COMPILER }}; #elif defined(__clang__) - result["compiler"] = {{"family", "clang"}, {"version", __clang_version__}}; + result["compiler"] = {{"family", "clang"}, { "version", + __clang_version__ }}; #elif defined(__GNUC__) || defined(__GNUG__) - result["compiler"] = {{"family", "gcc"}, {"version", detail::concat( - std::to_string(__GNUC__), '.', - std::to_string(__GNUC_MINOR__), '.', - std::to_string(__GNUC_PATCHLEVEL__)) - } - }; + result["compiler"] = {{"family", "gcc"}, { "version", + detail::concat( + std::to_string(__GNUC__), + '.', + std::to_string(__GNUC_MINOR__), + '.', + std::to_string(__GNUC_PATCHLEVEL__)) + }}; #elif defined(__HP_cc) || defined(__HP_aCC) result["compiler"] = "hp" #elif defined(__IBMCPP__) - result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}}; + result["compiler"] = {{"family", "ilecpp"}, { "version", + __IBMCPP__ }}; #elif defined(_MSC_VER) - result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}}; + result["compiler"] = {{"family", "msvc"}, { "version", + _MSC_VER }}; #elif defined(__PGI) - result["compiler"] = {{"family", "pgcpp"}, {"version", __PGI}}; + result["compiler"] = {{"family", "pgcpp"}, { "version", + __PGI }}; #elif defined(__SUNPRO_CC) - result["compiler"] = {{"family", "sunpro"}, {"version", __SUNPRO_CC}}; + result["compiler"] = {{"family", "sunpro"}, { "version", + __SUNPRO_CC }}; #else result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}}; #endif @@ -19633,10 +19833,10 @@ /// @brief a type for an object /// @sa https://json.nlohmann.me/api/basic_json/object_t/ using object_t = ObjectType<StringType, - basic_json, - default_object_comparator_t, - AllocatorType<std::pair<const StringType, - basic_json>>>; + basic_json, + default_object_comparator_t, + AllocatorType<std::pair<const StringType, + basic_json>>>; /// @brief a type for an array /// @sa https://json.nlohmann.me/api/basic_json/array_t/ @@ -19673,17 +19873,14 @@ /// @} private: - /// helper for exception-safe object creation template<typename T, typename... Args> - JSON_HEDLEY_RETURNS_NON_NULL - static T* create(Args&& ... args) + JSON_HEDLEY_RETURNS_NON_NULL static T* create(Args&&... args) { AllocatorType<T> alloc; using AllocatorTraits = std::allocator_traits<AllocatorType<T>>; - auto deleter = [&](T * obj) - { + auto deleter = [&](T* obj) { AllocatorTraits::deallocate(alloc, obj, 1); }; std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter); @@ -19696,8 +19893,8 @@ // JSON value storage // //////////////////////// - JSON_PRIVATE_UNLESS_TESTED: - /*! + JSON_PRIVATE_UNLESS_TESTED : + /*! @brief a JSON value The actual storage for a JSON value of the @ref basic_json class. This @@ -19722,7 +19919,7 @@ @since version 1.0.0 */ - union json_value + union json_value { /// object (stored with pointer to save storage) object_t* object; @@ -19744,13 +19941,21 @@ /// default constructor (for null values) json_value() = default; /// constructor for booleans - json_value(boolean_t v) noexcept : boolean(v) {} + json_value(boolean_t v) noexcept + : boolean(v) + {} /// constructor for numbers (integer) - json_value(number_integer_t v) noexcept : number_integer(v) {} + json_value(number_integer_t v) noexcept + : number_integer(v) + {} /// constructor for numbers (unsigned) - json_value(number_unsigned_t v) noexcept : number_unsigned(v) {} + json_value(number_unsigned_t v) noexcept + : number_unsigned(v) + {} /// constructor for numbers (floating-point) - json_value(number_float_t v) noexcept : number_float(v) {} + json_value(number_float_t v) noexcept + : number_float(v) + {} /// constructor for empty values of a given type json_value(value_t t) { @@ -19816,7 +20021,7 @@ object = nullptr; // silence warning, see #821 if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) { - JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.11.3", nullptr)); // LCOV_EXCL_LINE + JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.11.3", nullptr)); // LCOV_EXCL_LINE } break; } @@ -19824,34 +20029,54 @@ } /// constructor for strings - json_value(const string_t& value) : string(create<string_t>(value)) {} + json_value(const string_t& value) + : string(create<string_t>(value)) + {} /// constructor for rvalue strings - json_value(string_t&& value) : string(create<string_t>(std::move(value))) {} + json_value(string_t&& value) + : string(create<string_t>(std::move(value))) + {} /// constructor for objects - json_value(const object_t& value) : object(create<object_t>(value)) {} + json_value(const object_t& value) + : object(create<object_t>(value)) + {} /// constructor for rvalue objects - json_value(object_t&& value) : object(create<object_t>(std::move(value))) {} + json_value(object_t&& value) + : object(create<object_t>(std::move(value))) + {} /// constructor for arrays - json_value(const array_t& value) : array(create<array_t>(value)) {} + json_value(const array_t& value) + : array(create<array_t>(value)) + {} /// constructor for rvalue arrays - json_value(array_t&& value) : array(create<array_t>(std::move(value))) {} + json_value(array_t&& value) + : array(create<array_t>(std::move(value))) + {} /// constructor for binary arrays - json_value(const typename binary_t::container_type& value) : binary(create<binary_t>(value)) {} + json_value(const typename binary_t::container_type& value) + : binary(create<binary_t>(value)) + {} /// constructor for rvalue binary arrays - json_value(typename binary_t::container_type&& value) : binary(create<binary_t>(std::move(value))) {} + json_value(typename binary_t::container_type&& value) + : binary(create<binary_t>(std::move(value))) + {} /// constructor for binary arrays (internal type) - json_value(const binary_t& value) : binary(create<binary_t>(value)) {} + json_value(const binary_t& value) + : binary(create<binary_t>(value)) + {} /// constructor for rvalue binary arrays (internal type) - json_value(binary_t&& value) : binary(create<binary_t>(std::move(value))) {} + json_value(binary_t&& value) + : binary(create<binary_t>(std::move(value))) + {} void destroy(value_t t) { @@ -19859,8 +20084,7 @@ (t == value_t::object && object == nullptr) || (t == value_t::array && array == nullptr) || (t == value_t::string && string == nullptr) || - (t == value_t::binary && binary == nullptr) - ) + (t == value_t::binary && binary == nullptr)) { //not initialized (e.g. due to exception in the ctor) return; @@ -19992,12 +20216,11 @@ JSON_TRY { // cppcheck-suppress assertWithSideEffect - JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json & j) - { + JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json& j) { return j.m_parent == this; })); } - JSON_CATCH(...) {} // LCOV_EXCL_LINE + JSON_CATCH(...) {} // LCOV_EXCL_LINE #endif static_cast<void>(check_parents); } @@ -20067,20 +20290,20 @@ } } - // ordered_json uses a vector internally, so pointers could have - // been invalidated; see https://github.com/nlohmann/json/issues/2962 -#ifdef JSON_HEDLEY_MSVC_VERSION -#pragma warning(push ) -#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr -#endif + // ordered_json uses a vector internally, so pointers could have + // been invalidated; see https://github.com/nlohmann/json/issues/2962 + #ifdef JSON_HEDLEY_MSVC_VERSION + #pragma warning(push) + #pragma warning(disable : 4127) // ignore warning to replace if with if constexpr + #endif if (detail::is_ordered_map<object_t>::value) { set_parents(); return j; } -#ifdef JSON_HEDLEY_MSVC_VERSION -#pragma warning( pop ) -#endif + #ifdef JSON_HEDLEY_MSVC_VERSION + #pragma warning(pop) + #endif j.m_parent = this; #else @@ -20115,28 +20338,29 @@ /// @brief create an empty value with a given type /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(const value_t v) - : m_data(v) + : m_data(v) { assert_invariant(); } /// @brief create a null object /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ - basic_json(std::nullptr_t = nullptr) noexcept // NOLINT(bugprone-exception-escape) - : basic_json(value_t::null) + basic_json(std::nullptr_t = nullptr) noexcept // NOLINT(bugprone-exception-escape) + : basic_json(value_t::null) { assert_invariant(); } /// @brief create a JSON value from compatible types /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ - template < typename CompatibleType, - typename U = detail::uncvref_t<CompatibleType>, - detail::enable_if_t < - !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value, int > = 0 > - basic_json(CompatibleType && val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape) - JSONSerializer<U>::to_json(std::declval<basic_json_t&>(), - std::forward<CompatibleType>(val)))) + template<typename CompatibleType, + typename U = detail::uncvref_t<CompatibleType>, + detail::enable_if_t< + !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value, + int> = 0> + basic_json(CompatibleType&& val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape) + JSONSerializer<U>::to_json(std::declval<basic_json_t&>(), + std::forward<CompatibleType>(val)))) { JSONSerializer<U>::to_json(*this, std::forward<CompatibleType>(val)); set_parents(); @@ -20145,9 +20369,10 @@ /// @brief create a JSON value from an existing one /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ - template < typename BasicJsonType, - detail::enable_if_t < - detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value, int > = 0 > + template<typename BasicJsonType, + detail::enable_if_t< + detail::is_basic_json<BasicJsonType>::value && !std::is_same<basic_json, BasicJsonType>::value, + int> = 0> basic_json(const BasicJsonType& val) { using other_boolean_t = typename BasicJsonType::boolean_t; @@ -20191,8 +20416,8 @@ case value_t::discarded: m_data.m_type = value_t::discarded; break; - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } JSON_ASSERT(m_data.m_type == val.type()); set_parents(); @@ -20207,9 +20432,7 @@ { // check if each element is an array with two elements whose first // element is a string - bool is_an_object = std::all_of(init.begin(), init.end(), - [](const detail::json_ref<basic_json>& element_ref) - { + bool is_an_object = std::all_of(init.begin(), init.end(), [](const detail::json_ref<basic_json>& element_ref) { // The cast is to ensure op[size_type] is called, bearing in mind size_type may not be int; // (many string types can be constructed from 0 via its null-pointer guise, so we get a // broken call to op[key_type], the wrong semantics and a 4804 warning on Windows) @@ -20319,8 +20542,8 @@ /// @brief construct an array with count copies of given value /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ - basic_json(size_type cnt, const basic_json& val): - m_data{cnt, val} + basic_json(size_type cnt, const basic_json& val) + : m_data{cnt, val} { set_parents(); assert_invariant(); @@ -20328,9 +20551,7 @@ /// @brief construct a JSON container given an iterator range /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ - template < class InputIT, typename std::enable_if < - std::is_same<InputIT, typename basic_json_t::iterator>::value || - std::is_same<InputIT, typename basic_json_t::const_iterator>::value, int >::type = 0 > + template<class InputIT, typename std::enable_if<std::is_same<InputIT, typename basic_json_t::iterator>::value || std::is_same<InputIT, typename basic_json_t::const_iterator>::value, int>::type = 0> basic_json(InputIT first, InputIT last) { JSON_ASSERT(first.m_object != nullptr); @@ -20354,8 +20575,7 @@ case value_t::number_unsigned: case value_t::string: { - if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin() - || !last.m_it.primitive_iterator.is_end())) + if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin() || !last.m_it.primitive_iterator.is_end())) { JSON_THROW(invalid_iterator::create(204, "iterators out of range", first.m_object)); } @@ -20406,7 +20626,7 @@ case value_t::object: { m_data.m_value.object = create<object_t>(first.m_it.object_iterator, - last.m_it.object_iterator); + last.m_it.object_iterator); break; } @@ -20439,13 +20659,16 @@ template<typename JsonRef, detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>, - std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 > - basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {} + std::is_same<typename JsonRef::value_type, basic_json>>::value, + int> = 0> + basic_json(const JsonRef& ref) + : basic_json(ref.moved_or_copied()) + {} /// @brief copy constructor /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(const basic_json& other) - : json_base_class_t(other) + : json_base_class_t(other) { m_data.m_type = other.m_data.m_type; // check of passed value is valid @@ -20514,8 +20737,8 @@ /// @brief move constructor /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(basic_json&& other) noexcept - : json_base_class_t(std::forward<json_base_class_t>(other)), - m_data(std::move(other.m_data)) + : json_base_class_t(std::forward<json_base_class_t>(other)) + , m_data(std::move(other.m_data)) { // check that passed value is valid other.assert_invariant(false); @@ -20530,13 +20753,12 @@ /// @brief copy assignment /// @sa https://json.nlohmann.me/api/basic_json/operator=/ - basic_json& operator=(basic_json other) noexcept ( - std::is_nothrow_move_constructible<value_t>::value&& - std::is_nothrow_move_assignable<value_t>::value&& - std::is_nothrow_move_constructible<json_value>::value&& - std::is_nothrow_move_assignable<json_value>::value&& - std::is_nothrow_move_assignable<json_base_class_t>::value - ) + basic_json& operator=(basic_json other) noexcept( + std::is_nothrow_move_constructible<value_t>::value && + std::is_nothrow_move_assignable<value_t>::value && + std::is_nothrow_move_constructible<json_value>::value && + std::is_nothrow_move_assignable<json_value>::value && + std::is_nothrow_move_assignable<json_base_class_t>::value) { // check that passed value is valid other.assert_invariant(); @@ -20842,8 +21064,7 @@ /// @brief get a pointer value (implicit) /// @sa https://json.nlohmann.me/api/basic_json/get_ptr/ - template<typename PointerType, typename std::enable_if< - std::is_pointer<PointerType>::value, int>::type = 0> + template<typename PointerType, typename std::enable_if<std::is_pointer<PointerType>::value, int>::type = 0> auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>())) { // delegate the call to get_impl_ptr<>() @@ -20852,9 +21073,7 @@ /// @brief get a pointer value (implicit) /// @sa https://json.nlohmann.me/api/basic_json/get_ptr/ - template < typename PointerType, typename std::enable_if < - std::is_pointer<PointerType>::value&& - std::is_const<typename std::remove_pointer<PointerType>::type>::value, int >::type = 0 > + template<typename PointerType, typename std::enable_if<std::is_pointer<PointerType>::value && std::is_const<typename std::remove_pointer<PointerType>::type>::value, int>::type = 0> constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>())) { // delegate the call to get_impl_ptr<>() const @@ -20900,13 +21119,13 @@ @since version 2.1.0 */ - template < typename ValueType, - detail::enable_if_t < - detail::is_default_constructible<ValueType>::value&& - detail::has_from_json<basic_json_t, ValueType>::value, - int > = 0 > + template<typename ValueType, + detail::enable_if_t< + detail::is_default_constructible<ValueType>::value && + detail::has_from_json<basic_json_t, ValueType>::value, + int> = 0> ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept( - JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>()))) + JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>()))) { auto ret = ValueType(); JSONSerializer<ValueType>::from_json(*this, ret); @@ -20943,12 +21162,12 @@ @since version 2.1.0 */ - template < typename ValueType, - detail::enable_if_t < - detail::has_non_default_from_json<basic_json_t, ValueType>::value, - int > = 0 > + template<typename ValueType, + detail::enable_if_t< + detail::has_non_default_from_json<basic_json_t, ValueType>::value, + int> = 0> ValueType get_impl(detail::priority_tag<1> /*unused*/) const noexcept(noexcept( - JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>()))) + JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>()))) { return JSONSerializer<ValueType>::from_json(*this); } @@ -20968,10 +21187,10 @@ @since version 3.2.0 */ - template < typename BasicJsonType, - detail::enable_if_t < - detail::is_basic_json<BasicJsonType>::value, - int > = 0 > + template<typename BasicJsonType, + detail::enable_if_t< + detail::is_basic_json<BasicJsonType>::value, + int> = 0> BasicJsonType get_impl(detail::priority_tag<2> /*unused*/) const { return *this; @@ -21009,7 +21228,7 @@ std::is_pointer<PointerType>::value, int> = 0> constexpr auto get_impl(detail::priority_tag<4> /*unused*/) const noexcept - -> decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>()) + -> decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>()) { // delegate the call to get_ptr return get_ptr<PointerType>(); @@ -21039,20 +21258,21 @@ @since version 2.1.0 */ - template < typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>> + template<typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>> #if defined(JSON_HAS_CPP_14) constexpr #endif - auto get() const noexcept( - noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))) - -> decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {})) + auto + get() const noexcept( + noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4>{}))) + -> decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4>{})) { // we cannot static_assert on ValueTypeCV being non-const, because // there is support for get<const basic_json_t>(), which is why we // still need the uncvref static_assert(!std::is_reference<ValueTypeCV>::value, "get() cannot be used with reference types, you might want to use get_ref()"); - return get_impl<ValueType>(detail::priority_tag<4> {}); + return get_impl<ValueType>(detail::priority_tag<4>{}); } /*! @@ -21082,8 +21302,7 @@ @since version 1.0.0 */ - template<typename PointerType, typename std::enable_if< - std::is_pointer<PointerType>::value, int>::type = 0> + template<typename PointerType, typename std::enable_if<std::is_pointer<PointerType>::value, int>::type = 0> auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>()) { // delegate the call to get_ptr @@ -21092,13 +21311,13 @@ /// @brief get a value (explicit) /// @sa https://json.nlohmann.me/api/basic_json/get_to/ - template < typename ValueType, - detail::enable_if_t < - !detail::is_basic_json<ValueType>::value&& - detail::has_from_json<basic_json_t, ValueType>::value, - int > = 0 > - ValueType & get_to(ValueType& v) const noexcept(noexcept( - JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v))) + template<typename ValueType, + detail::enable_if_t< + !detail::is_basic_json<ValueType>::value && + detail::has_from_json<basic_json_t, ValueType>::value, + int> = 0> + ValueType& get_to(ValueType& v) const noexcept(noexcept( + JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v))) { JSONSerializer<ValueType>::from_json(*this, v); return v; @@ -21107,23 +21326,26 @@ // specialization to allow calling get_to with a basic_json value // see https://github.com/nlohmann/json/issues/2175 template<typename ValueType, - detail::enable_if_t < + detail::enable_if_t< detail::is_basic_json<ValueType>::value, int> = 0> - ValueType & get_to(ValueType& v) const + ValueType& get_to(ValueType& v) const { v = *this; return v; } - template < - typename T, std::size_t N, - typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - detail::enable_if_t < - detail::has_from_json<basic_json_t, Array>::value, int > = 0 > - Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - noexcept(noexcept(JSONSerializer<Array>::from_json( - std::declval<const basic_json_t&>(), v))) + template< + typename T, + std::size_t N, + typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + detail::enable_if_t< + detail::has_from_json<basic_json_t, Array>::value, + int> = 0> + Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + noexcept(noexcept(JSONSerializer<Array>::from_json( + std::declval<const basic_json_t&>(), + v))) { JSONSerializer<Array>::from_json(*this, v); return v; @@ -21131,8 +21353,7 @@ /// @brief get a reference value (implicit) /// @sa https://json.nlohmann.me/api/basic_json/get_ref/ - template<typename ReferenceType, typename std::enable_if< - std::is_reference<ReferenceType>::value, int>::type = 0> + template<typename ReferenceType, typename std::enable_if<std::is_reference<ReferenceType>::value, int>::type = 0> ReferenceType get_ref() { // delegate call to get_ref_impl @@ -21141,9 +21362,7 @@ /// @brief get a reference value (implicit) /// @sa https://json.nlohmann.me/api/basic_json/get_ref/ - template < typename ReferenceType, typename std::enable_if < - std::is_reference<ReferenceType>::value&& - std::is_const<typename std::remove_reference<ReferenceType>::type>::value, int >::type = 0 > + template<typename ReferenceType, typename std::enable_if<std::is_reference<ReferenceType>::value && std::is_const<typename std::remove_reference<ReferenceType>::type>::value, int>::type = 0> ReferenceType get_ref() const { // delegate call to get_ref_impl @@ -21179,23 +21398,16 @@ @since version 1.0.0 */ - template < typename ValueType, typename std::enable_if < - detail::conjunction < - detail::negation<std::is_pointer<ValueType>>, - detail::negation<std::is_same<ValueType, std::nullptr_t>>, - detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>, - detail::negation<std::is_same<ValueType, typename string_t::value_type>>, - detail::negation<detail::is_basic_json<ValueType>>, - detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>, + template<typename ValueType, typename std::enable_if<detail::conjunction<detail::negation<std::is_pointer<ValueType>>, detail::negation<std::is_same<ValueType, std::nullptr_t>>, detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>, detail::negation<std::is_same<ValueType, typename string_t::value_type>>, detail::negation<detail::is_basic_json<ValueType>>, detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>, #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914)) - detail::negation<std::is_same<ValueType, std::string_view>>, + detail::negation<std::is_same<ValueType, std::string_view>>, #endif #if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI - detail::negation<std::is_same<ValueType, std::any>>, + detail::negation<std::is_same<ValueType, std::any>>, #endif - detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType> - >::value, int >::type = 0 > - JSON_EXPLICIT operator ValueType() const + detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>>::value, + int>::type = 0> + JSON_EXPLICIT operator ValueType() const { // delegate the call to get<>() const return get<ValueType>(); @@ -21246,7 +21458,7 @@ { return set_parent(m_data.m_value.array->at(idx)); } - JSON_CATCH (std::out_of_range&) + JSON_CATCH(std::out_of_range&) { // create better exception explanation JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); @@ -21269,7 +21481,7 @@ { return m_data.m_value.array->at(idx); } - JSON_CATCH (std::out_of_range&) + JSON_CATCH(std::out_of_range&) { // create better exception explanation JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); @@ -21301,9 +21513,8 @@ /// @brief access specified object element with bounds checking /// @sa https://json.nlohmann.me/api/basic_json/at/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - reference at(KeyType && key) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + reference at(KeyType&& key) { // at only works for objects if (JSON_HEDLEY_UNLIKELY(!is_object())) @@ -21339,9 +21550,8 @@ /// @brief access specified object element with bounds checking /// @sa https://json.nlohmann.me/api/basic_json/at/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - const_reference at(KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + const_reference at(KeyType&& key) const { // at only works for objects if (JSON_HEDLEY_UNLIKELY(!is_object())) @@ -21469,9 +21679,8 @@ /// @brief access specified object element /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int > = 0 > - reference operator[](KeyType && key) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + reference operator[](KeyType&& key) { // implicitly convert null value to an empty object if (is_null()) @@ -21493,9 +21702,8 @@ /// @brief access specified object element /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int > = 0 > - const_reference operator[](KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + const_reference operator[](KeyType&& key) const { // const operator[] only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -21510,21 +21718,21 @@ private: template<typename KeyType> - using is_comparable_with_object_key = detail::is_comparable < - object_comparator_t, const typename object_t::key_type&, KeyType >; + using is_comparable_with_object_key = detail::is_comparable< + object_comparator_t, + const typename object_t::key_type&, + KeyType>; template<typename ValueType> - using value_return_type = std::conditional < + using value_return_type = std::conditional< detail::is_c_string_uncvref<ValueType>::value, - string_t, typename std::decay<ValueType>::type >; + string_t, + typename std::decay<ValueType>::type>; public: /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, detail::enable_if_t < - !detail::is_transparent<object_comparator_t>::value - && detail::is_getable<basic_json_t, ValueType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > + template<class ValueType, detail::enable_if_t<!detail::is_transparent<object_comparator_t>::value && detail::is_getable<basic_json_t, ValueType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const { // value only works for objects @@ -21545,12 +21753,8 @@ /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type, - detail::enable_if_t < - !detail::is_transparent<object_comparator_t>::value - && detail::is_getable<basic_json_t, ReturnType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - ReturnType value(const typename object_t::key_type& key, ValueType && default_value) const + template<class ValueType, class ReturnType = typename value_return_type<ValueType>::type, detail::enable_if_t<!detail::is_transparent<object_comparator_t>::value && detail::is_getable<basic_json_t, ReturnType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + ReturnType value(const typename object_t::key_type& key, ValueType&& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -21570,13 +21774,8 @@ /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, class KeyType, detail::enable_if_t < - detail::is_transparent<object_comparator_t>::value - && !detail::is_json_pointer<KeyType>::value - && is_comparable_with_object_key<KeyType>::value - && detail::is_getable<basic_json_t, ValueType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - ValueType value(KeyType && key, const ValueType& default_value) const + template<class ValueType, class KeyType, detail::enable_if_t<detail::is_transparent<object_comparator_t>::value && !detail::is_json_pointer<KeyType>::value && is_comparable_with_object_key<KeyType>::value && detail::is_getable<basic_json_t, ValueType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + ValueType value(KeyType&& key, const ValueType& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -21596,14 +21795,8 @@ /// @brief access specified object element via JSON Pointer with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type, - detail::enable_if_t < - detail::is_transparent<object_comparator_t>::value - && !detail::is_json_pointer<KeyType>::value - && is_comparable_with_object_key<KeyType>::value - && detail::is_getable<basic_json_t, ReturnType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - ReturnType value(KeyType && key, ValueType && default_value) const + template<class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type, detail::enable_if_t<detail::is_transparent<object_comparator_t>::value && !detail::is_json_pointer<KeyType>::value && is_comparable_with_object_key<KeyType>::value && detail::is_getable<basic_json_t, ReturnType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + ReturnType value(KeyType&& key, ValueType&& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -21623,9 +21816,7 @@ /// @brief access specified object element via JSON Pointer with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, detail::enable_if_t < - detail::is_getable<basic_json_t, ValueType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > + template<class ValueType, detail::enable_if_t<detail::is_getable<basic_json_t, ValueType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> ValueType value(const json_pointer& ptr, const ValueType& default_value) const { // value only works for objects @@ -21636,7 +21827,7 @@ { return ptr.get_checked(this).template get<ValueType>(); } - JSON_INTERNAL_CATCH (out_of_range&) + JSON_INTERNAL_CATCH(out_of_range&) { return default_value; } @@ -21647,11 +21838,8 @@ /// @brief access specified object element via JSON Pointer with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type, - detail::enable_if_t < - detail::is_getable<basic_json_t, ReturnType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - ReturnType value(const json_pointer& ptr, ValueType && default_value) const + template<class ValueType, class ReturnType = typename value_return_type<ValueType>::type, detail::enable_if_t<detail::is_getable<basic_json_t, ReturnType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + ReturnType value(const json_pointer& ptr, ValueType&& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -21661,7 +21849,7 @@ { return ptr.get_checked(this).template get<ReturnType>(); } - JSON_INTERNAL_CATCH (out_of_range&) + JSON_INTERNAL_CATCH(out_of_range&) { return std::forward<ValueType>(default_value); } @@ -21670,23 +21858,16 @@ JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); } - template < class ValueType, class BasicJsonType, detail::enable_if_t < - detail::is_basic_json<BasicJsonType>::value - && detail::is_getable<basic_json_t, ValueType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + template<class ValueType, class BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value && detail::is_getable<basic_json_t, ValueType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, const ValueType& default_value) const { return value(ptr.convert(), default_value); } - template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type, - detail::enable_if_t < - detail::is_basic_json<BasicJsonType>::value - && detail::is_getable<basic_json_t, ReturnType>::value - && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) - ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType && default_value) const + template<class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value && detail::is_getable<basic_json_t, ReturnType>::value && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int> = 0> + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType&& default_value) const { return value(ptr.convert(), std::forward<ValueType>(default_value)); } @@ -21725,9 +21906,7 @@ /// @brief remove element given an iterator /// @sa https://json.nlohmann.me/api/basic_json/erase/ - template < class IteratorType, detail::enable_if_t < - std::is_same<IteratorType, typename basic_json_t::iterator>::value || - std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int > = 0 > + template<class IteratorType, detail::enable_if_t<std::is_same<IteratorType, typename basic_json_t::iterator>::value || std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int> = 0> IteratorType erase(IteratorType pos) { // make sure iterator fits the current value @@ -21795,9 +21974,7 @@ /// @brief remove elements given an iterator range /// @sa https://json.nlohmann.me/api/basic_json/erase/ - template < class IteratorType, detail::enable_if_t < - std::is_same<IteratorType, typename basic_json_t::iterator>::value || - std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int > = 0 > + template<class IteratorType, detail::enable_if_t<std::is_same<IteratorType, typename basic_json_t::iterator>::value || std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int> = 0> IteratorType erase(IteratorType first, IteratorType last) { // make sure iterator fits the current value @@ -21817,8 +21994,7 @@ case value_t::string: case value_t::binary: { - if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin() - || !last.m_it.primitive_iterator.is_end())) + if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin() || !last.m_it.primitive_iterator.is_end())) { JSON_THROW(invalid_iterator::create(204, "iterators out of range", this)); } @@ -21846,14 +22022,14 @@ case value_t::object: { result.m_it.object_iterator = m_data.m_value.object->erase(first.m_it.object_iterator, - last.m_it.object_iterator); + last.m_it.object_iterator); break; } case value_t::array: { result.m_it.array_iterator = m_data.m_value.array->erase(first.m_it.array_iterator, - last.m_it.array_iterator); + last.m_it.array_iterator); break; } @@ -21867,9 +22043,8 @@ } private: - template < typename KeyType, detail::enable_if_t < - detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int > = 0 > - size_type erase_internal(KeyType && key) + template<typename KeyType, detail::enable_if_t<detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int> = 0> + size_type erase_internal(KeyType&& key) { // this erase only works for objects if (JSON_HEDLEY_UNLIKELY(!is_object())) @@ -21880,9 +22055,8 @@ return m_data.m_value.object->erase(std::forward<KeyType>(key)); } - template < typename KeyType, detail::enable_if_t < - !detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int > = 0 > - size_type erase_internal(KeyType && key) + template<typename KeyType, detail::enable_if_t<!detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int> = 0> + size_type erase_internal(KeyType&& key) { // this erase only works for objects if (JSON_HEDLEY_UNLIKELY(!is_object())) @@ -21900,7 +22074,6 @@ } public: - /// @brief remove element from a JSON object given a key /// @sa https://json.nlohmann.me/api/basic_json/erase/ size_type erase(const typename object_t::key_type& key) @@ -21912,9 +22085,8 @@ /// @brief remove element from a JSON object given a key /// @sa https://json.nlohmann.me/api/basic_json/erase/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - size_type erase(KeyType && key) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + size_type erase(KeyType&& key) { return erase_internal(std::forward<KeyType>(key)); } @@ -21978,9 +22150,8 @@ /// @brief find an element in a JSON object /// @sa https://json.nlohmann.me/api/basic_json/find/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - iterator find(KeyType && key) + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + iterator find(KeyType&& key) { auto result = end(); @@ -21994,9 +22165,8 @@ /// @brief find an element in a JSON object /// @sa https://json.nlohmann.me/api/basic_json/find/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - const_iterator find(KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + const_iterator find(KeyType&& key) const { auto result = cend(); @@ -22018,9 +22188,8 @@ /// @brief returns the number of occurrences of a key in a JSON object /// @sa https://json.nlohmann.me/api/basic_json/count/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - size_type count(KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + size_type count(KeyType&& key) const { // return 0 for all nonobject types return is_object() ? m_data.m_value.object->count(std::forward<KeyType>(key)) : 0; @@ -22035,9 +22204,8 @@ /// @brief check the existence of an element in a JSON object /// @sa https://json.nlohmann.me/api/basic_json/contains/ - template<class KeyType, detail::enable_if_t< - detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> - bool contains(KeyType && key) const + template<class KeyType, detail::enable_if_t<detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> + bool contains(KeyType&& key) const { return is_object() && m_data.m_value.object->find(std::forward<KeyType>(key)) != m_data.m_value.object->end(); } @@ -22050,7 +22218,7 @@ } template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) bool contains(const typename ::nlohmann::json_pointer<BasicJsonType>& ptr) const { return ptr.contains(this); @@ -22489,7 +22657,8 @@ { basic_json&& key = init.begin()->moved_or_copied(); push_back(typename object_t::value_type( - std::move(key.get_ref<string_t&>()), (init.begin() + 1)->moved_or_copied())); + std::move(key.get_ref<string_t&>()), + (init.begin() + 1)->moved_or_copied())); } else { @@ -22508,7 +22677,7 @@ /// @brief add an object to an array /// @sa https://json.nlohmann.me/api/basic_json/emplace_back/ template<class... Args> - reference emplace_back(Args&& ... args) + reference emplace_back(Args&&... args) { // emplace_back only works for null objects or arrays if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) @@ -22533,7 +22702,7 @@ /// @brief add an object to an object if key does not exist /// @sa https://json.nlohmann.me/api/basic_json/emplace/ template<class... Args> - std::pair<iterator, bool> emplace(Args&& ... args) + std::pair<iterator, bool> emplace(Args&&... args) { // emplace only works for null objects or arrays if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object()))) @@ -22565,7 +22734,7 @@ /// @note: This uses std::distance to support GCC 4.8, /// see https://github.com/nlohmann/json/pull/1257 template<typename... Args> - iterator insert_iterator(const_iterator pos, Args&& ... args) + iterator insert_iterator(const_iterator pos, Args&&... args) { iterator result(this); JSON_ASSERT(m_data.m_value.array != nullptr); @@ -22761,12 +22930,11 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(reference other) noexcept ( - std::is_nothrow_move_constructible<value_t>::value&& - std::is_nothrow_move_assignable<value_t>::value&& - std::is_nothrow_move_constructible<json_value>::value&& // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap) - std::is_nothrow_move_assignable<json_value>::value - ) + void swap(reference other) noexcept( + std::is_nothrow_move_constructible<value_t>::value && + std::is_nothrow_move_assignable<value_t>::value && + std::is_nothrow_move_constructible<json_value>::value && // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + std::is_nothrow_move_assignable<json_value>::value) { std::swap(m_data.m_type, other.m_data.m_type); std::swap(m_data.m_value, other.m_data.m_value); @@ -22778,19 +22946,18 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - friend void swap(reference left, reference right) noexcept ( - std::is_nothrow_move_constructible<value_t>::value&& - std::is_nothrow_move_assignable<value_t>::value&& - std::is_nothrow_move_constructible<json_value>::value&& // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap) - std::is_nothrow_move_assignable<json_value>::value - ) + friend void swap(reference left, reference right) noexcept( + std::is_nothrow_move_constructible<value_t>::value && + std::is_nothrow_move_assignable<value_t>::value && + std::is_nothrow_move_constructible<json_value>::value && // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + std::is_nothrow_move_assignable<json_value>::value) { left.swap(right); } /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(array_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + void swap(array_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) { // swap only works for arrays if (JSON_HEDLEY_LIKELY(is_array())) @@ -22806,7 +22973,7 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(object_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + void swap(object_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) { // swap only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -22822,7 +22989,7 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(string_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + void swap(string_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) { // swap only works for strings if (JSON_HEDLEY_LIKELY(is_string())) @@ -22838,7 +23005,7 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(binary_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + void swap(binary_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) { // swap only works for strings if (JSON_HEDLEY_LIKELY(is_binary())) @@ -22854,7 +23021,7 @@ /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ - void swap(typename binary_t::container_type& other) // NOLINT(bugprone-exception-escape) + void swap(typename binary_t::container_type& other) // NOLINT(bugprone-exception-escape) { // swap only works for strings if (JSON_HEDLEY_LIKELY(is_binary())) @@ -22879,87 +23046,87 @@ // note parentheses around operands are necessary; see // https://github.com/nlohmann/json/issues/1530 -#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \ - const auto lhs_type = lhs.type(); \ - const auto rhs_type = rhs.type(); \ - \ - if (lhs_type == rhs_type) /* NOLINT(readability/braces) */ \ - { \ - switch (lhs_type) \ - { \ - case value_t::array: \ - return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array); \ - \ - case value_t::object: \ - return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object); \ - \ - case value_t::null: \ - return (null_result); \ - \ - case value_t::string: \ - return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string); \ - \ - case value_t::boolean: \ - return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean); \ - \ - case value_t::number_integer: \ - return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer); \ - \ - case value_t::number_unsigned: \ - return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned); \ - \ - case value_t::number_float: \ - return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float); \ - \ - case value_t::binary: \ - return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary); \ - \ - case value_t::discarded: \ - default: \ - return (unordered_result); \ - } \ - } \ - else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \ - { \ +#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \ + const auto lhs_type = lhs.type(); \ + const auto rhs_type = rhs.type(); \ + \ + if (lhs_type == rhs_type) /* NOLINT(readability/braces) */ \ + { \ + switch (lhs_type) \ + { \ + case value_t::array: \ + return (*lhs.m_data.m_value.array)op(*rhs.m_data.m_value.array); \ + \ + case value_t::object: \ + return (*lhs.m_data.m_value.object)op(*rhs.m_data.m_value.object); \ + \ + case value_t::null: \ + return (null_result); \ + \ + case value_t::string: \ + return (*lhs.m_data.m_value.string)op(*rhs.m_data.m_value.string); \ + \ + case value_t::boolean: \ + return (lhs.m_data.m_value.boolean)op(rhs.m_data.m_value.boolean); \ + \ + case value_t::number_integer: \ + return (lhs.m_data.m_value.number_integer)op(rhs.m_data.m_value.number_integer); \ + \ + case value_t::number_unsigned: \ + return (lhs.m_data.m_value.number_unsigned)op(rhs.m_data.m_value.number_unsigned); \ + \ + case value_t::number_float: \ + return (lhs.m_data.m_value.number_float)op(rhs.m_data.m_value.number_float); \ + \ + case value_t::binary: \ + return (*lhs.m_data.m_value.binary)op(*rhs.m_data.m_value.binary); \ + \ + case value_t::discarded: \ + default: \ + return (unordered_result); \ + } \ + } \ + else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \ + { \ return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float; \ - } \ - else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \ - { \ + } \ + else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \ + { \ return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer); \ - } \ - else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \ - { \ + } \ + else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \ + { \ return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float; \ - } \ - else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \ - { \ + } \ + else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \ + { \ return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned); \ - } \ - else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \ - { \ + } \ + else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \ + { \ return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \ - } \ - else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \ - { \ + } \ + else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \ + { \ return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \ - } \ - else if(compares_unordered(lhs, rhs))\ - {\ - return (unordered_result);\ - }\ - \ + } \ + else if (compares_unordered(lhs, rhs)) \ + { \ + return (unordered_result); \ + } \ + \ return (default_result); - JSON_PRIVATE_UNLESS_TESTED: - // returns true if: - // - any operand is NaN and the other operand is of number type - // - any operand is discarded - // in legacy mode, discarded values are considered ordered if - // an operation is computed as an odd number of inverses of others - static bool compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept + JSON_PRIVATE_UNLESS_TESTED : + // returns true if: + // - any operand is NaN and the other operand is of number type + // - any operand is discarded + // in legacy mode, discarded values are considered ordered if + // an operation is computed as an odd number of inverses of others + static bool + compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept { - if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number()) - || (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number())) + if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number()) || (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number())) { return true; } @@ -22983,22 +23150,21 @@ /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ bool operator==(const_reference rhs) const noexcept { -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" -#endif + #ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" + #endif const_reference lhs = *this; - JSON_IMPLEMENT_OPERATOR( ==, true, false, false) -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + JSON_IMPLEMENT_OPERATOR(==, true, false, false) + #ifdef __GNUC__ + #pragma GCC diagnostic pop + #endif } /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ template<typename ScalarType> - requires std::is_scalar_v<ScalarType> - bool operator==(ScalarType rhs) const noexcept + requires std::is_scalar_v<ScalarType> bool operator==(ScalarType rhs) const noexcept { return *this == basic_json(rhs); } @@ -23016,27 +23182,27 @@ /// @brief comparison: 3-way /// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/ - std::partial_ordering operator<=>(const_reference rhs) const noexcept // *NOPAD* + std::partial_ordering operator<= > (const_reference rhs) const noexcept // *NOPAD* { const_reference lhs = *this; // default_result is used if we cannot compare values. In that case, // we compare types. - JSON_IMPLEMENT_OPERATOR(<=>, // *NOPAD* + JSON_IMPLEMENT_OPERATOR(<= >, // *NOPAD* std::partial_ordering::equivalent, std::partial_ordering::unordered, - lhs_type <=> rhs_type) // *NOPAD* + lhs_type <= > rhs_type) // *NOPAD* } /// @brief comparison: 3-way /// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/ template<typename ScalarType> - requires std::is_scalar_v<ScalarType> - std::partial_ordering operator<=>(ScalarType rhs) const noexcept // *NOPAD* + requires std::is_scalar_v<ScalarType> + std::partial_ordering operator<= > (ScalarType rhs) const noexcept // *NOPAD* { - return *this <=> basic_json(rhs); // *NOPAD* + return *this <= > basic_json(rhs); // *NOPAD* } -#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON // all operators that are computed as an odd number of inverses of others // need to be overloaded to emulate the legacy comparison behavior @@ -23055,8 +23221,7 @@ /// @brief comparison: less than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_le/ template<typename ScalarType> - requires std::is_scalar_v<ScalarType> - bool operator<=(ScalarType rhs) const noexcept + requires std::is_scalar_v<ScalarType> bool operator<=(ScalarType rhs) const noexcept { return *this <= basic_json(rhs); } @@ -23076,31 +23241,29 @@ /// @brief comparison: greater than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ template<typename ScalarType> - requires std::is_scalar_v<ScalarType> - bool operator>=(ScalarType rhs) const noexcept + requires std::is_scalar_v<ScalarType> bool operator>=(ScalarType rhs) const noexcept { return *this >= basic_json(rhs); } -#endif + #endif #else /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ friend bool operator==(const_reference lhs, const_reference rhs) noexcept { -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" -#endif - JSON_IMPLEMENT_OPERATOR( ==, true, false, false) -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + #ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" + #endif + JSON_IMPLEMENT_OPERATOR(==, true, false, false) + #ifdef __GNUC__ + #pragma GCC diagnostic pop + #endif } /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator==(const_reference lhs, ScalarType rhs) noexcept { return lhs == basic_json(rhs); @@ -23108,8 +23271,7 @@ /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator==(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) == rhs; @@ -23128,8 +23290,7 @@ /// @brief comparison: not equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept { return lhs != basic_json(rhs); @@ -23137,8 +23298,7 @@ /// @brief comparison: not equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) != rhs; @@ -23151,13 +23311,12 @@ // default_result is used if we cannot compare values. In that case, // we compare types. Note we have to call the operator explicitly, // because MSVC has problems otherwise. - JSON_IMPLEMENT_OPERATOR( <, false, false, operator<(lhs_type, rhs_type)) + JSON_IMPLEMENT_OPERATOR(<, false, false, operator<(lhs_type, rhs_type)) } /// @brief comparison: less than /// @sa https://json.nlohmann.me/api/basic_json/operator_lt/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator<(const_reference lhs, ScalarType rhs) noexcept { return lhs < basic_json(rhs); @@ -23165,8 +23324,7 @@ /// @brief comparison: less than /// @sa https://json.nlohmann.me/api/basic_json/operator_lt/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator<(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) < rhs; @@ -23185,8 +23343,7 @@ /// @brief comparison: less than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_le/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept { return lhs <= basic_json(rhs); @@ -23194,8 +23351,7 @@ /// @brief comparison: less than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_le/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) <= rhs; @@ -23215,8 +23371,7 @@ /// @brief comparison: greater than /// @sa https://json.nlohmann.me/api/basic_json/operator_gt/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator>(const_reference lhs, ScalarType rhs) noexcept { return lhs > basic_json(rhs); @@ -23224,8 +23379,7 @@ /// @brief comparison: greater than /// @sa https://json.nlohmann.me/api/basic_json/operator_gt/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator>(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) > rhs; @@ -23244,8 +23398,7 @@ /// @brief comparison: greater than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept { return lhs >= basic_json(rhs); @@ -23253,8 +23406,7 @@ /// @brief comparison: greater than or equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ - template<typename ScalarType, typename std::enable_if< - std::is_scalar<ScalarType>::value, int>::type = 0> + template<typename ScalarType, typename std::enable_if<std::is_scalar<ScalarType>::value, int>::type = 0> friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept { return basic_json(lhs) >= rhs; @@ -23313,11 +23465,10 @@ /// @brief deserialize from a compatible input /// @sa https://json.nlohmann.me/api/basic_json/parse/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json parse(InputType&& i, - const parser_callback_t cb = nullptr, - const bool allow_exceptions = true, - const bool ignore_comments = false) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json parse(InputType&& i, + const parser_callback_t cb = nullptr, + const bool allow_exceptions = true, + const bool ignore_comments = false) { basic_json result; parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(true, result); @@ -23327,12 +23478,11 @@ /// @brief deserialize from a pair of character iterators /// @sa https://json.nlohmann.me/api/basic_json/parse/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json parse(IteratorType first, - IteratorType last, - const parser_callback_t cb = nullptr, - const bool allow_exceptions = true, - const bool ignore_comments = false) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json parse(IteratorType first, + IteratorType last, + const parser_callback_t cb = nullptr, + const bool allow_exceptions = true, + const bool ignore_comments = false) { basic_json result; parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(true, result); @@ -23363,8 +23513,7 @@ /// @brief check if the input is valid JSON /// @sa https://json.nlohmann.me/api/basic_json/accept/ template<typename IteratorType> - static bool accept(IteratorType first, IteratorType last, - const bool ignore_comments = false) + static bool accept(IteratorType first, IteratorType last, const bool ignore_comments = false) { return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true); } @@ -23379,32 +23528,26 @@ /// @brief generate SAX events /// @sa https://json.nlohmann.me/api/basic_json/sax_parse/ - template <typename InputType, typename SAX> + template<typename InputType, typename SAX> JSON_HEDLEY_NON_NULL(2) - static bool sax_parse(InputType&& i, SAX* sax, - input_format_t format = input_format_t::json, - const bool strict = true, - const bool ignore_comments = false) + static bool sax_parse(InputType&& i, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, const bool ignore_comments = false) { auto ia = detail::input_adapter(std::forward<InputType>(i)); return format == input_format_t::json - ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) - : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) + : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); } /// @brief generate SAX events /// @sa https://json.nlohmann.me/api/basic_json/sax_parse/ template<class IteratorType, class SAX> JSON_HEDLEY_NON_NULL(3) - static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, - input_format_t format = input_format_t::json, - const bool strict = true, - const bool ignore_comments = false) + static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, const bool ignore_comments = false) { auto ia = detail::input_adapter(std::move(first), std::move(last)); return format == input_format_t::json - ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) - : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) + : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); } /// @brief generate SAX events @@ -23412,20 +23555,16 @@ /// @deprecated This function is deprecated since 3.8.0 and will be removed in /// version 4.0.0 of the library. Please use /// sax_parse(ptr, ptr + len) instead. - template <typename SAX> + template<typename SAX> JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...)) - JSON_HEDLEY_NON_NULL(2) - static bool sax_parse(detail::span_input_adapter&& i, SAX* sax, - input_format_t format = input_format_t::json, - const bool strict = true, - const bool ignore_comments = false) + JSON_HEDLEY_NON_NULL(2) static bool sax_parse(detail::span_input_adapter&& i, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, const bool ignore_comments = false) { auto ia = i.get(); return format == input_format_t::json - // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) - // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); } #ifndef JSON_NO_IO /// @brief deserialize from stream @@ -23483,12 +23622,12 @@ } } - JSON_PRIVATE_UNLESS_TESTED: - ////////////////////// - // member variables // - ////////////////////// + JSON_PRIVATE_UNLESS_TESTED : + ////////////////////// + // member variables // + ////////////////////// - struct data + struct data { /// the type of the current element value_t m_type = value_t::null; @@ -23497,12 +23636,13 @@ json_value m_value = {}; data(const value_t v) - : m_type(v), m_value(v) + : m_type(v) + , m_value(v) { } data(size_type cnt, const basic_json& val) - : m_type(value_t::array) + : m_type(value_t::array) { m_value.array = create<array_t>(cnt, val); } @@ -23583,8 +23723,8 @@ /// @brief create a UBJSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ static std::vector<std::uint8_t> to_ubjson(const basic_json& j, - const bool use_size = false, - const bool use_type = false) + const bool use_size = false, + const bool use_type = false) { std::vector<std::uint8_t> result; to_ubjson(j, result, use_size, use_type); @@ -23593,16 +23733,14 @@ /// @brief create a UBJSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ - static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o, - const bool use_size = false, const bool use_type = false) + static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o, const bool use_size = false, const bool use_type = false) { binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type); } /// @brief create a UBJSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ - static void to_ubjson(const basic_json& j, detail::output_adapter<char> o, - const bool use_size = false, const bool use_type = false) + static void to_ubjson(const basic_json& j, detail::output_adapter<char> o, const bool use_size = false, const bool use_type = false) { binary_writer<char>(o).write_ubjson(j, use_size, use_type); } @@ -23610,8 +23748,8 @@ /// @brief create a BJData serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ static std::vector<std::uint8_t> to_bjdata(const basic_json& j, - const bool use_size = false, - const bool use_type = false) + const bool use_size = false, + const bool use_type = false) { std::vector<std::uint8_t> result; to_bjdata(j, result, use_size, use_type); @@ -23620,16 +23758,14 @@ /// @brief create a BJData serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ - static void to_bjdata(const basic_json& j, detail::output_adapter<std::uint8_t> o, - const bool use_size = false, const bool use_type = false) + static void to_bjdata(const basic_json& j, detail::output_adapter<std::uint8_t> o, const bool use_size = false, const bool use_type = false) { binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type, true, true); } /// @brief create a BJData serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ - static void to_bjdata(const basic_json& j, detail::output_adapter<char> o, - const bool use_size = false, const bool use_type = false) + static void to_bjdata(const basic_json& j, detail::output_adapter<char> o, const bool use_size = false, const bool use_type = false) { binary_writer<char>(o).write_ubjson(j, use_size, use_type, true, true); } @@ -23660,11 +23796,10 @@ /// @brief create a JSON value from an input in CBOR format /// @sa https://json.nlohmann.me/api/basic_json/from_cbor/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_cbor(InputType&& i, - const bool strict = true, - const bool allow_exceptions = true, - const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_cbor(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true, + const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -23676,11 +23811,7 @@ /// @brief create a JSON value from an input in CBOR format /// @sa https://json.nlohmann.me/api/basic_json/from_cbor/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_cbor(IteratorType first, IteratorType last, - const bool strict = true, - const bool allow_exceptions = true, - const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_cbor(IteratorType first, IteratorType last, const bool strict = true, const bool allow_exceptions = true, const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -23691,11 +23822,7 @@ template<typename T> JSON_HEDLEY_WARN_UNUSED_RESULT - JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len)) - static basic_json from_cbor(const T* ptr, std::size_t len, - const bool strict = true, - const bool allow_exceptions = true, - const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len)) static basic_json from_cbor(const T* ptr, std::size_t len, const bool strict = true, const bool allow_exceptions = true, const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) { return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler); } @@ -23718,10 +23845,9 @@ /// @brief create a JSON value from an input in MessagePack format /// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_msgpack(InputType&& i, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_msgpack(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -23733,10 +23859,7 @@ /// @brief create a JSON value from an input in MessagePack format /// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_msgpack(IteratorType first, IteratorType last, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_msgpack(IteratorType first, IteratorType last, const bool strict = true, const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -23747,10 +23870,7 @@ template<typename T> JSON_HEDLEY_WARN_UNUSED_RESULT - JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len)) - static basic_json from_msgpack(const T* ptr, std::size_t len, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len)) static basic_json from_msgpack(const T* ptr, std::size_t len, const bool strict = true, const bool allow_exceptions = true) { return from_msgpack(ptr, ptr + len, strict, allow_exceptions); } @@ -23772,10 +23892,9 @@ /// @brief create a JSON value from an input in UBJSON format /// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_ubjson(InputType&& i, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_ubjson(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -23787,10 +23906,7 @@ /// @brief create a JSON value from an input in UBJSON format /// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_ubjson(IteratorType first, IteratorType last, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_ubjson(IteratorType first, IteratorType last, const bool strict = true, const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -23801,10 +23917,7 @@ template<typename T> JSON_HEDLEY_WARN_UNUSED_RESULT - JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len)) - static basic_json from_ubjson(const T* ptr, std::size_t len, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len)) static basic_json from_ubjson(const T* ptr, std::size_t len, const bool strict = true, const bool allow_exceptions = true) { return from_ubjson(ptr, ptr + len, strict, allow_exceptions); } @@ -23826,10 +23939,9 @@ /// @brief create a JSON value from an input in BJData format /// @sa https://json.nlohmann.me/api/basic_json/from_bjdata/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_bjdata(InputType&& i, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bjdata(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -23841,10 +23953,7 @@ /// @brief create a JSON value from an input in BJData format /// @sa https://json.nlohmann.me/api/basic_json/from_bjdata/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_bjdata(IteratorType first, IteratorType last, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bjdata(IteratorType first, IteratorType last, const bool strict = true, const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -23856,10 +23965,9 @@ /// @brief create a JSON value from an input in BSON format /// @sa https://json.nlohmann.me/api/basic_json/from_bson/ template<typename InputType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_bson(InputType&& i, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bson(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -23871,10 +23979,7 @@ /// @brief create a JSON value from an input in BSON format /// @sa https://json.nlohmann.me/api/basic_json/from_bson/ template<typename IteratorType> - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json from_bson(IteratorType first, IteratorType last, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bson(IteratorType first, IteratorType last, const bool strict = true, const bool allow_exceptions = true) { basic_json result; detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); @@ -23885,10 +23990,7 @@ template<typename T> JSON_HEDLEY_WARN_UNUSED_RESULT - JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len)) - static basic_json from_bson(const T* ptr, std::size_t len, - const bool strict = true, - const bool allow_exceptions = true) + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len)) static basic_json from_bson(const T* ptr, std::size_t len, const bool strict = true, const bool allow_exceptions = true) { return from_bson(ptr, ptr + len, strict, allow_exceptions); } @@ -23923,7 +24025,7 @@ } template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr) { return ptr.get_unchecked(this); @@ -23937,7 +24039,7 @@ } template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) const_reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr) const { return ptr.get_unchecked(this); @@ -23951,7 +24053,7 @@ } template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr) { return ptr.get_checked(this); @@ -23965,7 +24067,7 @@ } template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr) const { return ptr.get_checked(this); @@ -24002,10 +24104,18 @@ { basic_json& result = *this; // the valid JSON Patch operations - enum class patch_operations {add, remove, replace, move, copy, test, invalid}; - - const auto get_op = [](const std::string & op) + enum class patch_operations { + add, + remove, + replace, + move, + copy, + test, + invalid + }; + + const auto get_op = [](const std::string& op) { if (op == "add") { return patch_operations::add; @@ -24035,8 +24145,7 @@ }; // wrapper for "add" operation; add value at ptr - const auto operation_add = [&result](json_pointer & ptr, basic_json val) - { + const auto operation_add = [&result](json_pointer& ptr, basic_json val) { // adding to the root of the target document means replacing it if (ptr.empty()) { @@ -24090,21 +24199,20 @@ } // if there exists a parent it cannot be primitive - case value_t::string: // LCOV_EXCL_LINE - case value_t::boolean: // LCOV_EXCL_LINE - case value_t::number_integer: // LCOV_EXCL_LINE - case value_t::number_unsigned: // LCOV_EXCL_LINE - case value_t::number_float: // LCOV_EXCL_LINE - case value_t::binary: // LCOV_EXCL_LINE - case value_t::discarded: // LCOV_EXCL_LINE - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + case value_t::string: // LCOV_EXCL_LINE + case value_t::boolean: // LCOV_EXCL_LINE + case value_t::number_integer: // LCOV_EXCL_LINE + case value_t::number_unsigned: // LCOV_EXCL_LINE + case value_t::number_float: // LCOV_EXCL_LINE + case value_t::binary: // LCOV_EXCL_LINE + case value_t::discarded: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } }; // wrapper for "remove" operation; remove value at ptr - const auto operation_remove = [this, & result](json_pointer & ptr) - { + const auto operation_remove = [this, &result](json_pointer& ptr) { // get reference to parent of JSON pointer ptr const auto last_path = ptr.back(); ptr.pop_back(); @@ -24141,10 +24249,9 @@ for (const auto& val : json_patch) { // wrapper to get a value for an operation - const auto get_value = [&val](const std::string & op, - const std::string & member, - bool string_type) -> basic_json & - { + const auto get_value = [&val](const std::string& op, + const std::string& member, + bool string_type) -> basic_json& { // find value auto it = val.m_data.m_value.object->find(member); @@ -24242,7 +24349,7 @@ // the "path" location must exist - use at() success = (result.at(ptr) == get_value("test", "value", false)); } - JSON_INTERNAL_CATCH (out_of_range&) + JSON_INTERNAL_CATCH(out_of_range&) { // ignore out of range errors: success remains false } @@ -24279,8 +24386,7 @@ /// @brief creates a diff as a JSON patch /// @sa https://json.nlohmann.me/api/basic_json/diff/ JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json diff(const basic_json& source, const basic_json& target, - const std::string& path = "") + static basic_json diff(const basic_json& source, const basic_json& target, const std::string& path = "") { // the patch basic_json result(value_t::array); @@ -24295,9 +24401,7 @@ { // different types: replace value result.push_back( - { - {"op", "replace"}, {"path", path}, {"value", target} - }); + {{"op", "replace"}, {"path", path}, {"value", target}}); return result; } @@ -24324,11 +24428,7 @@ { // add operations in reverse order to avoid invalid // indices - result.insert(result.begin() + end_index, object( - { - {"op", "remove"}, - {"path", detail::concat(path, '/', std::to_string(i))} - })); + result.insert(result.begin() + end_index, object({{"op", "remove"}, {"path", detail::concat(path, '/', std::to_string(i))}})); ++i; } @@ -24336,11 +24436,9 @@ while (i < target.size()) { result.push_back( - { - {"op", "add"}, - {"path", detail::concat(path, "/-")}, - {"value", target[i]} - }); + {{"op", "add"}, + {"path", detail::concat(path, "/-")}, + {"value", target[i]}}); ++i; } @@ -24365,9 +24463,7 @@ { // found a key that is not in o -> remove it result.push_back(object( - { - {"op", "remove"}, {"path", path_key} - })); + {{"op", "remove"}, {"path", path_key}})); } } @@ -24379,10 +24475,7 @@ // found a key that is not in this -> add it const auto path_key = detail::concat(path, '/', detail::escape(it.key())); result.push_back( - { - {"op", "add"}, {"path", path_key}, - {"value", it.value()} - }); + {{"op", "add"}, {"path", path_key}, {"value", it.value()}}); } } @@ -24401,9 +24494,7 @@ { // both primitive type: replace value result.push_back( - { - {"op", "replace"}, {"path", path}, {"value", target} - }); + {{"op", "replace"}, {"path", path}, {"value", target}}); break; } } @@ -24458,18 +24549,16 @@ return j.dump(); } -inline namespace literals -{ -inline namespace json_literals -{ +inline namespace literals { +inline namespace json_literals { /// @brief user-defined string literal for JSON values /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/ JSON_HEDLEY_NON_NULL(1) -#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - inline nlohmann::json operator ""_json(const char* s, std::size_t n) +#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) +inline nlohmann::json operator""_json(const char* s, std::size_t n) #else - inline nlohmann::json operator "" _json(const char* s, std::size_t n) +inline nlohmann::json operator"" _json(const char* s, std::size_t n) #endif { return nlohmann::json::parse(s, s + n); @@ -24478,10 +24567,10 @@ /// @brief user-defined string literal for JSON pointer /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ JSON_HEDLEY_NON_NULL(1) -#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - inline nlohmann::json::json_pointer operator ""_json_pointer(const char* s, std::size_t n) +#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) +inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std::size_t n) #else - inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n) +inline nlohmann::json::json_pointer operator"" _json_pointer(const char* s, std::size_t n) #endif { return nlohmann::json::json_pointer(std::string(s, n)); @@ -24495,13 +24584,13 @@ // nonmember support // /////////////////////// -namespace std // NOLINT(cert-dcl58-cpp) +namespace std // NOLINT(cert-dcl58-cpp) { /// @brief hash value for JSON objects /// @sa https://json.nlohmann.me/api/basic_json/std_hash/ NLOHMANN_BASIC_JSON_TPL_DECLARATION -struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL> // NOLINT(cert-dcl58-cpp) +struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL> // NOLINT(cert-dcl58-cpp) { std::size_t operator()(const nlohmann::NLOHMANN_BASIC_JSON_TPL& j) const { @@ -24511,7 +24600,7 @@ // specialization for std::less<value_t> template<> -struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', see https://github.com/nlohmann/json/pull/679 +struct less<::nlohmann::detail::value_t> // do not remove the space after '<', see https://github.com/nlohmann/json/pull/679 { /*! @brief compare two value_t enum values @@ -24521,7 +24610,7 @@ ::nlohmann::detail::value_t rhs) const noexcept { #if JSON_HAS_THREE_WAY_COMPARISON - return std::is_lt(lhs <=> rhs); // *NOPAD* + return std::is_lt(lhs <= > rhs); // *NOPAD* #else return ::nlohmann::detail::operator<(lhs, rhs); #endif @@ -24535,7 +24624,7 @@ /// @sa https://json.nlohmann.me/api/basic_json/std_swap/ NLOHMANN_BASIC_JSON_TPL_DECLARATION inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) - is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value&& // NOLINT(misc-redundant-expression,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value && // NOLINT(misc-redundant-expression,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value) { j1.swap(j2); @@ -24546,12 +24635,12 @@ } // namespace std #if JSON_USE_GLOBAL_UDLS - #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - using nlohmann::literals::json_literals::operator ""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) - using nlohmann::literals::json_literals::operator ""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) + #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) +using nlohmann::literals::json_literals::operator""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) +using nlohmann::literals::json_literals::operator""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) #else - using nlohmann::literals::json_literals::operator "" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) - using nlohmann::literals::json_literals::operator "" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) +using nlohmann::literals::json_literals::operator"" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) +using nlohmann::literals::json_literals::operator"" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) #endif #endif @@ -24564,8 +24653,6 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - // restore clang diagnostic settings #if defined(__clang__) #pragma clang diagnostic pop @@ -24609,8 +24696,6 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - #undef JSON_HEDLEY_ALWAYS_INLINE #undef JSON_HEDLEY_ARM_VERSION #undef JSON_HEDLEY_ARM_VERSION_CHECK @@ -24760,6 +24845,4 @@ #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG #undef JSON_HEDLEY_FALL_THROUGH - - #endif // INCLUDE_NLOHMANN_JSON_HPP_
diff --git a/single_include/nlohmann/json_fwd.hpp b/single_include/nlohmann/json_fwd.hpp index 29a6036..71a88a5 100644 --- a/single_include/nlohmann/json_fwd.hpp +++ b/single_include/nlohmann/json_fwd.hpp
@@ -9,11 +9,11 @@ #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ -#include <cstdint> // int64_t, uint64_t -#include <map> // map -#include <memory> // allocator -#include <string> // string -#include <vector> // vector +#include <cstdint> // int64_t, uint64_t +#include <map> // map +#include <memory> // allocator +#include <string> // string +#include <vector> // vector // #include <nlohmann/detail/abi_macros.hpp> // __ _____ _____ _____ @@ -24,8 +24,6 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT - - // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK @@ -65,59 +63,56 @@ #endif // Construct the namespace ABI tags component -#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b +#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi##a##b #define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) -#define NLOHMANN_JSON_ABI_TAGS \ - NLOHMANN_JSON_ABI_TAGS_CONCAT( \ - NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ - NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) +#define NLOHMANN_JSON_ABI_TAGS \ + NLOHMANN_JSON_ABI_TAGS_CONCAT( \ + NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ + NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) // Construct the namespace version component #define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ - _v ## major ## _ ## minor ## _ ## patch + _v##major##_##minor##_##patch #define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) #if NLOHMANN_JSON_NAMESPACE_NO_VERSION -#define NLOHMANN_JSON_NAMESPACE_VERSION + #define NLOHMANN_JSON_NAMESPACE_VERSION #else -#define NLOHMANN_JSON_NAMESPACE_VERSION \ - NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ - NLOHMANN_JSON_VERSION_MINOR, \ - NLOHMANN_JSON_VERSION_PATCH) + #define NLOHMANN_JSON_NAMESPACE_VERSION \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH) #endif // Combine namespace components -#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b +#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a##b #define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) #ifndef NLOHMANN_JSON_NAMESPACE -#define NLOHMANN_JSON_NAMESPACE \ - nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ - NLOHMANN_JSON_ABI_TAGS, \ + #define NLOHMANN_JSON_NAMESPACE \ + nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ NLOHMANN_JSON_NAMESPACE_VERSION) #endif #ifndef NLOHMANN_JSON_NAMESPACE_BEGIN -#define NLOHMANN_JSON_NAMESPACE_BEGIN \ - namespace nlohmann \ - { \ - inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ - NLOHMANN_JSON_ABI_TAGS, \ - NLOHMANN_JSON_NAMESPACE_VERSION) \ - { + #define NLOHMANN_JSON_NAMESPACE_BEGIN \ + namespace nlohmann { \ + inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) { #endif #ifndef NLOHMANN_JSON_NAMESPACE_END -#define NLOHMANN_JSON_NAMESPACE_END \ - } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ - } // namespace nlohmann + #define NLOHMANN_JSON_NAMESPACE_END \ + } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ + } // namespace nlohmann #endif - /*! @brief namespace for Niels Lohmann @see https://github.com/nlohmann @@ -138,16 +133,17 @@ /// a class to store JSON values /// @sa https://json.nlohmann.me/api/basic_json/ template<template<typename U, typename V, typename... Args> class ObjectType = - std::map, + std::map, template<typename U, typename... Args> class ArrayType = std::vector, - class StringType = std::string, class BooleanType = bool, + class StringType = std::string, + class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template<typename U> class AllocatorType = std::allocator, template<typename T, typename SFINAE = void> class JSONSerializer = - adl_serializer, - class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError + adl_serializer, + class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError class CustomBaseClass = void> class basic_json;
diff --git a/tests/abi/config/config.hpp b/tests/abi/config/config.hpp index 8762b2a..cf847c4 100644 --- a/tests/abi/config/config.hpp +++ b/tests/abi/config/config.hpp
@@ -18,7 +18,7 @@ #define STRINGIZE(x) STRINGIZE_EX(x) template<typename T> -std::string namespace_name(std::string ns, T* /*unused*/ = nullptr) // NOLINT(performance-unnecessary-value-param) +std::string namespace_name(std::string ns, T* /*unused*/ = nullptr) // NOLINT(performance-unnecessary-value-param) { #if DOCTEST_MSVC && !DOCTEST_CLANG ns = __FUNCSIG__;
diff --git a/tests/abi/config/custom.cpp b/tests/abi/config/custom.cpp index 9e5bb89..dbbb9ca 100644 --- a/tests/abi/config/custom.cpp +++ b/tests/abi/config/custom.cpp
@@ -11,7 +11,7 @@ #include "config.hpp" // define custom namespace -#define NLOHMANN_JSON_NAMESPACE nlohmann // this line may be omitted +#define NLOHMANN_JSON_NAMESPACE nlohmann // this line may be omitted #define NLOHMANN_JSON_NAMESPACE_BEGIN namespace nlohmann { #define NLOHMANN_JSON_NAMESPACE_END } #include <nlohmann/json_fwd.hpp>
diff --git a/tests/abi/config/default.cpp b/tests/abi/config/default.cpp index d54ca6f..ae7b9be 100644 --- a/tests/abi/config/default.cpp +++ b/tests/abi/config/default.cpp
@@ -20,13 +20,13 @@ { std::string expected = "nlohmann::json_abi"; -#if JSON_DIAGNOSTICS + #if JSON_DIAGNOSTICS expected += "_diag"; -#endif + #endif -#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON expected += "_ldvcmp"; -#endif + #endif expected += "_v" STRINGIZE(NLOHMANN_JSON_VERSION_MAJOR); expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_MINOR);
diff --git a/tests/abi/config/noversion.cpp b/tests/abi/config/noversion.cpp index 2a7c277..97d9808 100644 --- a/tests/abi/config/noversion.cpp +++ b/tests/abi/config/noversion.cpp
@@ -21,13 +21,13 @@ { std::string expected = "nlohmann::json_abi"; -#if JSON_DIAGNOSTICS + #if JSON_DIAGNOSTICS expected += "_diag"; -#endif + #endif -#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON expected += "_ldvcmp"; -#endif + #endif expected += "::basic_json";
diff --git a/tests/benchmarks/src/benchmarks.cpp b/tests/benchmarks/src/benchmarks.cpp index 0210b9f..f8d8b90 100644 --- a/tests/benchmarks/src/benchmarks.cpp +++ b/tests/benchmarks/src/benchmarks.cpp
@@ -7,11 +7,11 @@ // SPDX-License-Identifier: MIT #include <benchmark/benchmark.h> -#include <nlohmann/json.hpp> #include <fstream> +#include <nlohmann/json.hpp> #include <numeric> -#include <vector> #include <test_data.hpp> +#include <vector> using json = nlohmann::json; @@ -39,13 +39,13 @@ std::ifstream file(filename, std::ios::binary | std::ios::ate); state.SetBytesProcessed(state.iterations() * file.tellg()); } -BENCHMARK_CAPTURE(ParseFile, jeopardy, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"); -BENCHMARK_CAPTURE(ParseFile, canada, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json"); -BENCHMARK_CAPTURE(ParseFile, citm_catalog, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json"); -BENCHMARK_CAPTURE(ParseFile, twitter, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json"); -BENCHMARK_CAPTURE(ParseFile, floats, TEST_DATA_DIRECTORY "/regression/floats.json"); -BENCHMARK_CAPTURE(ParseFile, signed_ints, TEST_DATA_DIRECTORY "/regression/signed_ints.json"); -BENCHMARK_CAPTURE(ParseFile, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json"); +BENCHMARK_CAPTURE(ParseFile, jeopardy, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"); +BENCHMARK_CAPTURE(ParseFile, canada, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json"); +BENCHMARK_CAPTURE(ParseFile, citm_catalog, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json"); +BENCHMARK_CAPTURE(ParseFile, twitter, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json"); +BENCHMARK_CAPTURE(ParseFile, floats, TEST_DATA_DIRECTORY "/regression/floats.json"); +BENCHMARK_CAPTURE(ParseFile, signed_ints, TEST_DATA_DIRECTORY "/regression/signed_ints.json"); +BENCHMARK_CAPTURE(ParseFile, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json"); BENCHMARK_CAPTURE(ParseFile, small_signed_ints, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"); ////////////////////////////////////////////////////////////////////////////// @@ -72,13 +72,13 @@ state.SetBytesProcessed(state.iterations() * str.size()); } -BENCHMARK_CAPTURE(ParseString, jeopardy, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"); -BENCHMARK_CAPTURE(ParseString, canada, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json"); -BENCHMARK_CAPTURE(ParseString, citm_catalog, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json"); -BENCHMARK_CAPTURE(ParseString, twitter, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json"); -BENCHMARK_CAPTURE(ParseString, floats, TEST_DATA_DIRECTORY "/regression/floats.json"); -BENCHMARK_CAPTURE(ParseString, signed_ints, TEST_DATA_DIRECTORY "/regression/signed_ints.json"); -BENCHMARK_CAPTURE(ParseString, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json"); +BENCHMARK_CAPTURE(ParseString, jeopardy, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"); +BENCHMARK_CAPTURE(ParseString, canada, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json"); +BENCHMARK_CAPTURE(ParseString, citm_catalog, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json"); +BENCHMARK_CAPTURE(ParseString, twitter, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json"); +BENCHMARK_CAPTURE(ParseString, floats, TEST_DATA_DIRECTORY "/regression/floats.json"); +BENCHMARK_CAPTURE(ParseString, signed_ints, TEST_DATA_DIRECTORY "/regression/signed_ints.json"); +BENCHMARK_CAPTURE(ParseString, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json"); BENCHMARK_CAPTURE(ParseString, small_signed_ints, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"); ////////////////////////////////////////////////////////////////////////////// @@ -98,22 +98,22 @@ state.SetBytesProcessed(state.iterations() * j.dump(indent).size()); } -BENCHMARK_CAPTURE(Dump, jeopardy / -, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json", -1); -BENCHMARK_CAPTURE(Dump, jeopardy / 4, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json", 4); -BENCHMARK_CAPTURE(Dump, canada / -, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json", -1); -BENCHMARK_CAPTURE(Dump, canada / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json", 4); -BENCHMARK_CAPTURE(Dump, citm_catalog / -, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json", -1); -BENCHMARK_CAPTURE(Dump, citm_catalog / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json", 4); -BENCHMARK_CAPTURE(Dump, twitter / -, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json", -1); -BENCHMARK_CAPTURE(Dump, twitter / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json", 4); -BENCHMARK_CAPTURE(Dump, floats / -, TEST_DATA_DIRECTORY "/regression/floats.json", -1); -BENCHMARK_CAPTURE(Dump, floats / 4, TEST_DATA_DIRECTORY "/regression/floats.json", 4); -BENCHMARK_CAPTURE(Dump, signed_ints / -, TEST_DATA_DIRECTORY "/regression/signed_ints.json", -1); -BENCHMARK_CAPTURE(Dump, signed_ints / 4, TEST_DATA_DIRECTORY "/regression/signed_ints.json", 4); -BENCHMARK_CAPTURE(Dump, unsigned_ints / -, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", -1); -BENCHMARK_CAPTURE(Dump, unsigned_ints / 4, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", 4); -BENCHMARK_CAPTURE(Dump, small_signed_ints / -, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json", -1); -BENCHMARK_CAPTURE(Dump, small_signed_ints / 4, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json", 4); +BENCHMARK_CAPTURE(Dump, jeopardy / -, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json", -1); +BENCHMARK_CAPTURE(Dump, jeopardy / 4, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json", 4); +BENCHMARK_CAPTURE(Dump, canada / -, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json", -1); +BENCHMARK_CAPTURE(Dump, canada / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json", 4); +BENCHMARK_CAPTURE(Dump, citm_catalog / -, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json", -1); +BENCHMARK_CAPTURE(Dump, citm_catalog / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json", 4); +BENCHMARK_CAPTURE(Dump, twitter / -, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json", -1); +BENCHMARK_CAPTURE(Dump, twitter / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json", 4); +BENCHMARK_CAPTURE(Dump, floats / -, TEST_DATA_DIRECTORY "/regression/floats.json", -1); +BENCHMARK_CAPTURE(Dump, floats / 4, TEST_DATA_DIRECTORY "/regression/floats.json", 4); +BENCHMARK_CAPTURE(Dump, signed_ints / -, TEST_DATA_DIRECTORY "/regression/signed_ints.json", -1); +BENCHMARK_CAPTURE(Dump, signed_ints / 4, TEST_DATA_DIRECTORY "/regression/signed_ints.json", 4); +BENCHMARK_CAPTURE(Dump, unsigned_ints / -, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", -1); +BENCHMARK_CAPTURE(Dump, unsigned_ints / 4, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", 4); +BENCHMARK_CAPTURE(Dump, small_signed_ints / -, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json", -1); +BENCHMARK_CAPTURE(Dump, small_signed_ints / 4, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json", 4); ////////////////////////////////////////////////////////////////////////////// // serialize CBOR @@ -131,13 +131,13 @@ state.SetBytesProcessed(state.iterations() * json::to_cbor(j).size()); } -BENCHMARK_CAPTURE(ToCbor, jeopardy, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"); -BENCHMARK_CAPTURE(ToCbor, canada, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json"); -BENCHMARK_CAPTURE(ToCbor, citm_catalog, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json"); -BENCHMARK_CAPTURE(ToCbor, twitter, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json"); -BENCHMARK_CAPTURE(ToCbor, floats, TEST_DATA_DIRECTORY "/regression/floats.json"); -BENCHMARK_CAPTURE(ToCbor, signed_ints, TEST_DATA_DIRECTORY "/regression/signed_ints.json"); -BENCHMARK_CAPTURE(ToCbor, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json"); +BENCHMARK_CAPTURE(ToCbor, jeopardy, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"); +BENCHMARK_CAPTURE(ToCbor, canada, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json"); +BENCHMARK_CAPTURE(ToCbor, citm_catalog, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json"); +BENCHMARK_CAPTURE(ToCbor, twitter, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json"); +BENCHMARK_CAPTURE(ToCbor, floats, TEST_DATA_DIRECTORY "/regression/floats.json"); +BENCHMARK_CAPTURE(ToCbor, signed_ints, TEST_DATA_DIRECTORY "/regression/signed_ints.json"); +BENCHMARK_CAPTURE(ToCbor, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json"); BENCHMARK_CAPTURE(ToCbor, small_signed_ints, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"); //////////////////////////////////////////////////////////////////////////////
diff --git a/tests/cmake_target_include_directories/project/Bar.hpp b/tests/cmake_target_include_directories/project/Bar.hpp index a56257c..c817c7c 100644 --- a/tests/cmake_target_include_directories/project/Bar.hpp +++ b/tests/cmake_target_include_directories/project/Bar.hpp
@@ -6,7 +6,8 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT -#include <nlohmann/json.hpp> #include "Foo.hpp" +#include <nlohmann/json.hpp> -class Bar : public Foo {}; +class Bar : public Foo +{};
diff --git a/tests/cmake_target_include_directories/project/Foo.hpp b/tests/cmake_target_include_directories/project/Foo.hpp index 18fe976..c092a6c 100644 --- a/tests/cmake_target_include_directories/project/Foo.hpp +++ b/tests/cmake_target_include_directories/project/Foo.hpp
@@ -9,4 +9,5 @@ #pragma once #include <nlohmann/json.hpp> -class Foo {}; +class Foo +{};
diff --git a/tests/src/fuzzer-driver_afl.cpp b/tests/src/fuzzer-driver_afl.cpp index ae3aefe..db4832c 100644 --- a/tests/src/fuzzer-driver_afl.cpp +++ b/tests/src/fuzzer-driver_afl.cpp
@@ -12,9 +12,9 @@ passed byte array. */ -#include <vector> // for vector #include <cstdint> // for uint8_t #include <iostream> // for cin +#include <vector> // for vector extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
diff --git a/tests/src/fuzzer-parse_bjdata.cpp b/tests/src/fuzzer-parse_bjdata.cpp index 30f1ddd..c52a27d 100644 --- a/tests/src/fuzzer-parse_bjdata.cpp +++ b/tests/src/fuzzer-parse_bjdata.cpp
@@ -26,8 +26,8 @@ */ #include <iostream> -#include <sstream> #include <nlohmann/json.hpp> +#include <sstream> using json = nlohmann::json;
diff --git a/tests/src/fuzzer-parse_bson.cpp b/tests/src/fuzzer-parse_bson.cpp index fa2a221..9e514e8 100644 --- a/tests/src/fuzzer-parse_bson.cpp +++ b/tests/src/fuzzer-parse_bson.cpp
@@ -20,8 +20,8 @@ */ #include <iostream> -#include <sstream> #include <nlohmann/json.hpp> +#include <sstream> using json = nlohmann::json;
diff --git a/tests/src/fuzzer-parse_cbor.cpp b/tests/src/fuzzer-parse_cbor.cpp index db92aca..aea2585 100644 --- a/tests/src/fuzzer-parse_cbor.cpp +++ b/tests/src/fuzzer-parse_cbor.cpp
@@ -20,8 +20,8 @@ */ #include <iostream> -#include <sstream> #include <nlohmann/json.hpp> +#include <sstream> using json = nlohmann::json;
diff --git a/tests/src/fuzzer-parse_json.cpp b/tests/src/fuzzer-parse_json.cpp index be04e80..152ac5b 100644 --- a/tests/src/fuzzer-parse_json.cpp +++ b/tests/src/fuzzer-parse_json.cpp
@@ -21,8 +21,8 @@ */ #include <iostream> -#include <sstream> #include <nlohmann/json.hpp> +#include <sstream> using json = nlohmann::json;
diff --git a/tests/src/fuzzer-parse_msgpack.cpp b/tests/src/fuzzer-parse_msgpack.cpp index 0106b40..861d7b2 100644 --- a/tests/src/fuzzer-parse_msgpack.cpp +++ b/tests/src/fuzzer-parse_msgpack.cpp
@@ -20,8 +20,8 @@ */ #include <iostream> -#include <sstream> #include <nlohmann/json.hpp> +#include <sstream> using json = nlohmann::json;
diff --git a/tests/src/fuzzer-parse_ubjson.cpp b/tests/src/fuzzer-parse_ubjson.cpp index 2830bef..0c04a3d 100644 --- a/tests/src/fuzzer-parse_ubjson.cpp +++ b/tests/src/fuzzer-parse_ubjson.cpp
@@ -26,8 +26,8 @@ */ #include <iostream> -#include <sstream> #include <nlohmann/json.hpp> +#include <sstream> using json = nlohmann::json;
diff --git a/tests/src/make_test_data_available.hpp b/tests/src/make_test_data_available.hpp index a2ffefa..35d4ee2 100644 --- a/tests/src/make_test_data_available.hpp +++ b/tests/src/make_test_data_available.hpp
@@ -8,13 +8,12 @@ #pragma once -#include <cstdio> // fopen, fclose, FILE -#include <memory> // unique_ptr -#include <test_data.hpp> +#include <cstdio> // fopen, fclose, FILE #include <doctest.h> +#include <memory> // unique_ptr +#include <test_data.hpp> -namespace utils -{ +namespace utils { inline bool check_testsuite_downloaded() {
diff --git a/tests/src/test_utils.hpp b/tests/src/test_utils.hpp index dbb0a9b..c52c7eb 100644 --- a/tests/src/test_utils.hpp +++ b/tests/src/test_utils.hpp
@@ -8,12 +8,11 @@ #pragma once -#include <cstdint> // uint8_t -#include <fstream> // ifstream, istreambuf_iterator, ios -#include <vector> // vector +#include <cstdint> // uint8_t +#include <fstream> // ifstream, istreambuf_iterator, ios +#include <vector> // vector -namespace utils -{ +namespace utils { inline std::vector<std::uint8_t> read_binary_file(const std::string& filename) { @@ -30,4 +29,4 @@ return byte_vector; } -} // namespace utils +} // namespace utils
diff --git a/tests/src/unit-32bit.cpp b/tests/src/unit-32bit.cpp index 22a2ad2..32f5b83 100644 --- a/tests/src/unit-32bit.cpp +++ b/tests/src/unit-32bit.cpp
@@ -11,10 +11,10 @@ #include <nlohmann/json.hpp> using nlohmann::json; -#include <climits> // SIZE_MAX -#include <limits> // numeric_limits +#include <climits> // SIZE_MAX +#include <limits> // numeric_limits -template <typename OfType, typename T, bool MinInRange, bool MaxInRange> +template<typename OfType, typename T, bool MinInRange, bool MaxInRange> struct trait_test_arg { using of_type = OfType; @@ -92,10 +92,10 @@ REQUIRE(SIZE_MAX == 0xffffffff); } -TEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, \ - trait_test_arg<std::size_t, std::int32_t, false, true>, \ - trait_test_arg<std::size_t, std::uint32_t, true, true>, \ - trait_test_arg<std::size_t, std::int64_t, false, false>, \ +TEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, + trait_test_arg<std::size_t, std::int32_t, false, true>, + trait_test_arg<std::size_t, std::uint32_t, true, true>, + trait_test_arg<std::size_t, std::int64_t, false, false>, trait_test_arg<std::size_t, std::uint64_t, true, false>); TEST_CASE("BJData")
diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index 3fb1640..e4b6106 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp
@@ -21,36 +21,30 @@ { SECTION("std::all_of") { - CHECK(std::all_of(j_array.begin(), j_array.end(), [](const json & value) - { + CHECK(std::all_of(j_array.begin(), j_array.end(), [](const json& value) { return !value.empty(); })); - CHECK(std::all_of(j_object.begin(), j_object.end(), [](const json & value) - { + CHECK(std::all_of(j_object.begin(), j_object.end(), [](const json& value) { return value.type() == json::value_t::number_integer; })); } SECTION("std::any_of") { - CHECK(std::any_of(j_array.begin(), j_array.end(), [](const json & value) - { + CHECK(std::any_of(j_array.begin(), j_array.end(), [](const json& value) { return value.is_string() && value.get<std::string>() == "foo"; })); - CHECK(std::any_of(j_object.begin(), j_object.end(), [](const json & value) - { + CHECK(std::any_of(j_object.begin(), j_object.end(), [](const json& value) { return value.get<int>() > 1; })); } SECTION("std::none_of") { - CHECK(std::none_of(j_array.begin(), j_array.end(), [](const json & value) - { + CHECK(std::none_of(j_array.begin(), j_array.end(), [](const json& value) { return value.empty(); })); - CHECK(std::none_of(j_object.begin(), j_object.end(), [](const json & value) - { + CHECK(std::none_of(j_object.begin(), j_object.end(), [](const json& value) { return value.get<int>() <= 0; })); } @@ -61,8 +55,7 @@ { int sum = 0; - std::for_each(j_array.cbegin(), j_array.cend(), [&sum](const json & value) - { + std::for_each(j_array.cbegin(), j_array.cend(), [&sum](const json& value) { if (value.is_number()) { sum += static_cast<int>(value); @@ -74,8 +67,7 @@ SECTION("writing") { - auto add17 = [](json & value) - { + auto add17 = [](json& value) { if (value.is_array()) { value.push_back(17); @@ -95,14 +87,12 @@ SECTION("std::count_if") { - CHECK(std::count_if(j_array.begin(), j_array.end(), [](const json & value) - { - return (value.is_number()); - }) == 3); - CHECK(std::count_if(j_array.begin(), j_array.end(), [](const json&) - { - return true; - }) == 9); + CHECK(std::count_if(j_array.begin(), j_array.end(), [](const json& value) { + return (value.is_number()); + }) == 3); + CHECK(std::count_if(j_array.begin(), j_array.end(), [](const json&) { + return true; + }) == 9); } SECTION("std::mismatch") @@ -127,9 +117,7 @@ // compare objects only by size of its elements json j_array2 = {13, 29, 3, {"Hello", "World"}, true, false, {{"one", 1}, {"two", 2}, {"three", 3}}, "foo", "baz"}; CHECK(!std::equal(j_array.begin(), j_array.end(), j_array2.begin())); - CHECK(std::equal(j_array.begin(), j_array.end(), j_array2.begin(), - [](const json & a, const json & b) - { + CHECK(std::equal(j_array.begin(), j_array.end(), j_array2.begin(), [](const json& a, const json& b) { return (a.size() == b.size()); })); } @@ -143,9 +131,7 @@ SECTION("std::find_if") { - auto it = std::find_if(j_array.begin(), j_array.end(), - [](const json & value) - { + auto it = std::find_if(j_array.begin(), j_array.end(), [](const json& value) { return value.is_boolean(); }); CHECK(std::distance(j_array.begin(), it) == 4); @@ -153,9 +139,7 @@ SECTION("std::find_if_not") { - auto it = std::find_if_not(j_array.begin(), j_array.end(), - [](const json & value) - { + auto it = std::find_if_not(j_array.begin(), j_array.end(), [](const json& value) { return value.is_number(); }); CHECK(std::distance(j_array.begin(), it) == 3); @@ -164,11 +148,9 @@ SECTION("std::adjacent_find") { CHECK(std::adjacent_find(j_array.begin(), j_array.end()) == j_array.end()); - CHECK(std::adjacent_find(j_array.begin(), j_array.end(), - [](const json & v1, const json & v2) - { - return v1.type() == v2.type(); - }) == j_array.begin()); + CHECK(std::adjacent_find(j_array.begin(), j_array.end(), [](const json& v1, const json& v2) { + return v1.type() == v2.type(); + }) == j_array.begin()); } } @@ -188,8 +170,7 @@ SECTION("std::partition") { - auto it = std::partition(j_array.begin(), j_array.end(), [](const json & v) - { + auto it = std::partition(j_array.begin(), j_array.end(), [](const json& v) { return v.is_string(); }); CHECK(std::distance(j_array.begin(), it) == 2); @@ -211,8 +192,7 @@ SECTION("with user-defined comparison") { json j = {3, {{"one", 1}, {"two", 2}}, {1, 2, 3}, nullptr}; - std::sort(j.begin(), j.end(), [](const json & a, const json & b) - { + std::sort(j.begin(), j.end(), [](const json& a, const json& b) { return a.size() < b.size(); }); CHECK(j == json({nullptr, 3, {{"one", 1}, {"two", 2}}, {1, 2, 3}})); @@ -335,8 +315,7 @@ json dest_arr; const json source_arr = {0, 3, 6, 9, 12, 15, 20}; - std::copy_if(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr), [](const json & _value) - { + std::copy_if(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr), [](const json& _value) { return _value.get<int>() % 3 == 0; }); CHECK(dest_arr == json({0, 3, 6, 9, 12, 15})); @@ -349,7 +328,6 @@ std::copy_n(source_arr.begin(), numToCopy, std::back_inserter(dest_arr)); CHECK(dest_arr == json{0, 1}); - } SECTION("copy n chars") { @@ -361,5 +339,4 @@ CHECK(dest_arr == json{'1', '2', '3', '4'}); } } - }
diff --git a/tests/src/unit-allocator.cpp b/tests/src/unit-allocator.cpp index 399c8bf..f5c028c 100644 --- a/tests/src/unit-allocator.cpp +++ b/tests/src/unit-allocator.cpp
@@ -12,8 +12,7 @@ #include <nlohmann/json.hpp> using nlohmann::json; -namespace -{ +namespace { // special test case to check if memory is leaked if constructor throws template<class T> struct bad_allocator : std::allocator<T> @@ -21,21 +20,23 @@ using std::allocator<T>::allocator; bad_allocator() = default; - template<class U> bad_allocator(const bad_allocator<U>& /*unused*/) { } + template<class U> + bad_allocator(const bad_allocator<U>& /*unused*/) + {} template<class... Args> - void construct(T* /*unused*/, Args&& ... /*unused*/) // NOLINT(cppcoreguidelines-missing-std-forward) + void construct(T* /*unused*/, Args&&... /*unused*/) // NOLINT(cppcoreguidelines-missing-std-forward) { throw std::bad_alloc(); } - template <class U> + template<class U> struct rebind { using other = bad_allocator<U>; }; }; -} // namespace +} // namespace TEST_CASE("bad_alloc") { @@ -43,21 +44,20 @@ { // create JSON type using the throwing allocator using bad_json = nlohmann::basic_json<std::map, - std::vector, - std::string, - bool, - std::int64_t, - std::uint64_t, - double, - bad_allocator>; + std::vector, + std::string, + bool, + std::int64_t, + std::uint64_t, + double, + bad_allocator>; // creating an object should throw CHECK_THROWS_AS(bad_json(bad_json::value_t::object), std::bad_alloc&); } } -namespace -{ +namespace { bool next_construct_fails = false; bool next_destroy_fails = false; bool next_deallocate_fails = false; @@ -68,7 +68,7 @@ using std::allocator<T>::allocator; template<class... Args> - void construct(T* p, Args&& ... args) + void construct(T* p, Args&&... args) { if (next_construct_fails) { @@ -98,11 +98,11 @@ throw std::bad_alloc(); } - static_cast<void>(p); // fix MSVC's C4100 warning + static_cast<void>(p); // fix MSVC's C4100 warning p->~T(); } - template <class U> + template<class U> struct rebind { using other = my_allocator<U>; @@ -118,19 +118,19 @@ alloc.destroy(p); alloc.deallocate(p, 1); } -} // namespace +} // namespace TEST_CASE("controlled bad_alloc") { // create JSON type using the throwing allocator using my_json = nlohmann::basic_json<std::map, - std::vector, - std::string, - bool, - std::int64_t, - std::uint64_t, - double, - my_allocator>; + std::vector, + std::string, + bool, + std::int64_t, + std::uint64_t, + double, + my_allocator>; SECTION("class json_value") { @@ -181,7 +181,7 @@ SECTION("basic_json(const CompatibleObjectType&)") { next_construct_fails = false; - const std::map<std::string, std::string> v {{"foo", "bar"}}; + const std::map<std::string, std::string> v{{"foo", "bar"}}; CHECK_NOTHROW(my_json(v)); next_construct_fails = true; CHECK_THROWS_AS(my_json(v), std::bad_alloc&); @@ -191,7 +191,7 @@ SECTION("basic_json(const CompatibleArrayType&)") { next_construct_fails = false; - const std::vector<std::string> v {"foo", "bar", "baz"}; + const std::vector<std::string> v{"foo", "bar", "baz"}; CHECK_NOTHROW(my_json(v)); next_construct_fails = true; CHECK_THROWS_AS(my_json(v), std::bad_alloc&); @@ -219,42 +219,42 @@ } } -namespace -{ +namespace { template<class T> struct allocator_no_forward : std::allocator<T> { allocator_no_forward() = default; - template <class U> - allocator_no_forward(allocator_no_forward<U> /*unused*/) {} + template<class U> + allocator_no_forward(allocator_no_forward<U> /*unused*/) + {} - template <class U> + template<class U> struct rebind { - using other = allocator_no_forward<U>; + using other = allocator_no_forward<U>; }; - template <class... Args> - void construct(T* p, const Args& ... args) noexcept(noexcept(::new (static_cast<void*>(p)) T(args...))) + template<class... Args> + void construct(T* p, const Args&... args) noexcept(noexcept(::new(static_cast<void*>(p)) T(args...))) { // force copy even if move is available ::new (static_cast<void*>(p)) T(args...); } }; -} // namespace +} // namespace TEST_CASE("bad my_allocator::construct") { SECTION("my_allocator::construct doesn't forward") { using bad_alloc_json = nlohmann::basic_json<std::map, - std::vector, - std::string, - bool, - std::int64_t, - std::uint64_t, - double, - allocator_no_forward>; + std::vector, + std::string, + bool, + std::int64_t, + std::uint64_t, + double, + allocator_no_forward>; bad_alloc_json j; j["test"] = bad_alloc_json::array_t();
diff --git a/tests/src/unit-alt-string.cpp b/tests/src/unit-alt-string.cpp index 7efe2e2..d86f9d7 100644 --- a/tests/src/unit-alt-string.cpp +++ b/tests/src/unit-alt-string.cpp
@@ -30,13 +30,19 @@ static constexpr auto npos = static_cast<std::size_t>(-1); - alt_string(const char* str): str_impl(str) {} - alt_string(const char* str, std::size_t count): str_impl(str, count) {} - alt_string(size_t count, char chr): str_impl(count, chr) {} + alt_string(const char* str) + : str_impl(str) + {} + alt_string(const char* str, std::size_t count) + : str_impl(str, count) + {} + alt_string(size_t count, char chr) + : str_impl(count, chr) + {} alt_string() = default; - template <typename...TParams> - alt_string& append(TParams&& ...params) + template<typename... TParams> + alt_string& append(TParams&&... params) { str_impl.append(std::forward<TParams>(params)...); return *this; @@ -47,7 +53,7 @@ str_impl.push_back(c); } - template <typename op_type> + template<typename op_type> bool operator==(const op_type& op) const { return str_impl == op; @@ -58,7 +64,7 @@ return str_impl == op.str_impl; } - template <typename op_type> + template<typename op_type> bool operator!=(const op_type& op) const { return str_impl != op; @@ -74,17 +80,17 @@ return str_impl.size(); } - void resize (std::size_t n) + void resize(std::size_t n) { str_impl.resize(n); } - void resize (std::size_t n, char c) + void resize(std::size_t n, char c) { str_impl.resize(n, c); } - template <typename op_type> + template<typename op_type> bool operator<(const op_type& op) const noexcept { return str_impl < op; @@ -158,7 +164,7 @@ } private: - std::string str_impl {}; + std::string str_impl{}; friend bool operator<(const char* /*op1*/, const alt_string& /*op2*/) noexcept; }; @@ -168,16 +174,16 @@ target = std::to_string(value).c_str(); } -using alt_json = nlohmann::basic_json < - std::map, - std::vector, - alt_string, - bool, - std::int64_t, - std::uint64_t, - double, - std::allocator, - nlohmann::adl_serializer >; +using alt_json = nlohmann::basic_json< + std::map, + std::vector, + alt_string, + bool, + std::int64_t, + std::uint64_t, + double, + std::allocator, + nlohmann::adl_serializer>; bool operator<(const char* op1, const alt_string& op2) noexcept { @@ -225,14 +231,14 @@ { alt_json doc; - doc["list"] = { 1, 0, 2 }; + doc["list"] = {1, 0, 2}; alt_string dump = doc.dump(); CHECK(dump == R"({"list":[1,0,2]})"); } { alt_json doc; - doc["object"] = { {"currency", "USD"}, {"value", 42.99} }; + doc["object"] = {{"currency", "USD"}, {"value", 42.99}}; alt_string dump = doc.dump(); CHECK(dump == R"({"object":{"currency":"USD","value":42.99}})"); } @@ -259,11 +265,11 @@ for (const auto& item : doc_array.items()) { - if (item.key() == "0" ) + if (item.key() == "0") { - CHECK( item.value() == "foo" ); + CHECK(item.value() == "foo"); } - else if (item.key() == "1" ) + else if (item.key() == "1") { CHECK(item.value() == "bar"); } @@ -280,14 +286,14 @@ doc["Who are you?"] = "I'm Batman"; CHECK("I'm Batman" == doc["Who are you?"]); - CHECK(doc["Who are you?"] == "I'm Batman"); + CHECK(doc["Who are you?"] == "I'm Batman"); CHECK_FALSE("I'm Batman" != doc["Who are you?"]); - CHECK_FALSE(doc["Who are you?"] != "I'm Batman"); + CHECK_FALSE(doc["Who are you?"] != "I'm Batman"); CHECK("I'm Bruce Wayne" != doc["Who are you?"]); - CHECK(doc["Who are you?"] != "I'm Bruce Wayne"); + CHECK(doc["Who are you?"] != "I'm Bruce Wayne"); CHECK_FALSE("I'm Bruce Wayne" == doc["Who are you?"]); - CHECK_FALSE(doc["Who are you?"] == "I'm Bruce Wayne"); + CHECK_FALSE(doc["Who are you?"] == "I'm Bruce Wayne"); { const alt_json& const_doc = doc;
diff --git a/tests/src/unit-assert_macro.cpp b/tests/src/unit-assert_macro.cpp index 55eb3b9..d059130 100644 --- a/tests/src/unit-assert_macro.cpp +++ b/tests/src/unit-assert_macro.cpp
@@ -18,7 +18,11 @@ static int assert_counter; /// set failure variable to true instead of calling assert(x) -#define JSON_ASSERT(x) {if (!(x)) ++assert_counter; } +#define JSON_ASSERT(x) \ + { \ + if (!(x)) \ + ++assert_counter; \ + } #include <nlohmann/json.hpp> using nlohmann::json;
diff --git a/tests/src/unit-binary_formats.cpp b/tests/src/unit-binary_formats.cpp index b41a6fe..615b431 100644 --- a/tests/src/unit-binary_formats.cpp +++ b/tests/src/unit-binary_formats.cpp
@@ -11,8 +11,8 @@ #include <nlohmann/json.hpp> using nlohmann::json; -#include <fstream> #include "make_test_data_available.hpp" +#include <fstream> TEST_CASE("Binary Formats" * doctest::skip()) { @@ -142,7 +142,7 @@ const auto bjdata_1_size = json::to_bjdata(j).size(); const auto bjdata_2_size = json::to_bjdata(j, true).size(); const auto bjdata_3_size = json::to_bjdata(j, true, true).size(); - const auto bson_size = json::to_bson({{"", j}}).size(); // wrap array in object for BSON + const auto bson_size = json::to_bson({{"", j}}).size(); // wrap array in object for BSON const auto cbor_size = json::to_cbor(j).size(); const auto msgpack_size = json::to_msgpack(j).size(); const auto ubjson_1_size = json::to_ubjson(j).size();
diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index 9f247fe..6cd927d 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp
@@ -12,21 +12,21 @@ #include <nlohmann/json.hpp> using nlohmann::json; -#include <algorithm> -#include <climits> -#include <limits> -#include <iostream> -#include <fstream> -#include <set> #include "make_test_data_available.hpp" #include "test_utils.hpp" +#include <algorithm> +#include <climits> +#include <fstream> +#include <iostream> +#include <limits> +#include <set> -namespace -{ +namespace { class SaxCountdown { public: - explicit SaxCountdown(const int count) : events_left(count) + explicit SaxCountdown(const int count) + : events_left(count) {} bool null() @@ -89,7 +89,7 @@ return events_left-- > 0; } - bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static) + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static) { return false; } @@ -97,10 +97,10 @@ private: int events_left = 0; }; -} // namespace +} // namespace // at some point in the future, a unit test dedicated to type traits might be a good idea -template <typename OfType, typename T, bool MinInRange, bool MaxInRange> +template<typename OfType, typename T, bool MinInRange, bool MaxInRange> struct trait_test_arg { using of_type = OfType; @@ -173,35 +173,35 @@ } } -TEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, \ - trait_test_arg<std::int32_t, std::int32_t, true, true>, \ - trait_test_arg<std::int32_t, std::uint32_t, true, false>, \ - trait_test_arg<std::uint32_t, std::int32_t, false, true>, \ - trait_test_arg<std::uint32_t, std::uint32_t, true, true>, \ - trait_test_arg<std::int32_t, std::int64_t, false, false>, \ - trait_test_arg<std::int32_t, std::uint64_t, true, false>, \ - trait_test_arg<std::uint32_t, std::int64_t, false, false>, \ - trait_test_arg<std::uint32_t, std::uint64_t, true, false>, \ - trait_test_arg<std::int64_t, std::int32_t, true, true>, \ - trait_test_arg<std::int64_t, std::uint32_t, true, true>, \ - trait_test_arg<std::uint64_t, std::int32_t, false, true>, \ - trait_test_arg<std::uint64_t, std::uint32_t, true, true>, \ - trait_test_arg<std::int64_t, std::int64_t, true, true>, \ - trait_test_arg<std::int64_t, std::uint64_t, true, false>, \ - trait_test_arg<std::uint64_t, std::int64_t, false, true>, \ +TEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, + trait_test_arg<std::int32_t, std::int32_t, true, true>, + trait_test_arg<std::int32_t, std::uint32_t, true, false>, + trait_test_arg<std::uint32_t, std::int32_t, false, true>, + trait_test_arg<std::uint32_t, std::uint32_t, true, true>, + trait_test_arg<std::int32_t, std::int64_t, false, false>, + trait_test_arg<std::int32_t, std::uint64_t, true, false>, + trait_test_arg<std::uint32_t, std::int64_t, false, false>, + trait_test_arg<std::uint32_t, std::uint64_t, true, false>, + trait_test_arg<std::int64_t, std::int32_t, true, true>, + trait_test_arg<std::int64_t, std::uint32_t, true, true>, + trait_test_arg<std::uint64_t, std::int32_t, false, true>, + trait_test_arg<std::uint64_t, std::uint32_t, true, true>, + trait_test_arg<std::int64_t, std::int64_t, true, true>, + trait_test_arg<std::int64_t, std::uint64_t, true, false>, + trait_test_arg<std::uint64_t, std::int64_t, false, true>, trait_test_arg<std::uint64_t, std::uint64_t, true, true>); #if SIZE_MAX == 0xffffffff -TEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, \ - trait_test_arg<std::size_t, std::int32_t, false, true>, \ - trait_test_arg<std::size_t, std::uint32_t, true, true>, \ - trait_test_arg<std::size_t, std::int64_t, false, false>, \ +TEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, + trait_test_arg<std::size_t, std::int32_t, false, true>, + trait_test_arg<std::size_t, std::uint32_t, true, true>, + trait_test_arg<std::size_t, std::int64_t, false, false>, trait_test_arg<std::size_t, std::uint64_t, true, false>); #else -TEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, \ - trait_test_arg<std::size_t, std::int32_t, false, true>, \ - trait_test_arg<std::size_t, std::uint32_t, true, true>, \ - trait_test_arg<std::size_t, std::int64_t, false, true>, \ +TEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, + trait_test_arg<std::size_t, std::int32_t, false, true>, + trait_test_arg<std::size_t, std::uint32_t, true, true>, + trait_test_arg<std::size_t, std::int64_t, false, true>, trait_test_arg<std::size_t, std::uint64_t, true, true>); #endif @@ -273,8 +273,7 @@ { SECTION("-9223372036854775808..-2147483649 (int64)") { - std::vector<int64_t> const numbers - { + std::vector<int64_t> const numbers{ (std::numeric_limits<int64_t>::min)(), -1000000000000000000LL, -100000000000000000LL, @@ -298,8 +297,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('L'), static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 8) & 0xff), @@ -336,16 +334,15 @@ SECTION("-2147483648..-32769 (int32)") { - std::vector<int32_t> const numbers - { + std::vector<int32_t> const numbers{ -32769, - -100000, - -1000000, - -10000000, - -100000000, - -1000000000, - -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 - }; + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 + }; for (const auto i : numbers) { CAPTURE(i) @@ -357,8 +354,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('l'), static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 8) & 0xff), @@ -398,8 +394,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('I'), static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 8) & 0xff), @@ -454,8 +449,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'i', static_cast<uint8_t>(i), }; @@ -489,8 +483,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('i'), static_cast<uint8_t>(i), }; @@ -524,8 +517,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('U'), static_cast<uint8_t>(i), }; @@ -559,8 +551,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('I'), static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 8) & 0xff), @@ -585,9 +576,10 @@ SECTION("32768..65535 (uint16)") { for (const uint32_t i : - { - 32768u, 55555u, 65535u - }) + { + 32768u, + 55555u, + 65535u}) { CAPTURE(i) @@ -599,8 +591,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('u'), static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 8) & 0xff), @@ -625,9 +616,10 @@ SECTION("65536..2147483647 (int32)") { for (const uint32_t i : - { - 65536u, 77777u, 2147483647u - }) + { + 65536u, + 77777u, + 2147483647u}) { CAPTURE(i) @@ -639,8 +631,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'l', static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 8) & 0xff), @@ -670,9 +661,10 @@ SECTION("2147483648..4294967295 (uint32)") { for (const uint32_t i : - { - 2147483648u, 3333333333u, 4294967295u - }) + { + 2147483648u, + 3333333333u, + 4294967295u}) { CAPTURE(i) @@ -684,8 +676,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'm', static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 8) & 0xff), @@ -727,8 +718,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'L', static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 010) & 0xff), @@ -777,8 +767,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'M', static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 010) & 0xff), @@ -891,8 +880,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'I', static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 8) & 0xff), @@ -917,9 +905,10 @@ SECTION("32768..65535 (uint16)") { for (const uint32_t i : - { - 32768u, 55555u, 65535u - }) + { + 32768u, + 55555u, + 65535u}) { CAPTURE(i) @@ -930,8 +919,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'u', static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 8) & 0xff), @@ -955,9 +943,10 @@ SECTION("65536..2147483647 (int32)") { for (const uint32_t i : - { - 65536u, 77777u, 2147483647u - }) + { + 65536u, + 77777u, + 2147483647u}) { CAPTURE(i) @@ -968,8 +957,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'l', static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 8) & 0xff), @@ -999,9 +987,10 @@ SECTION("2147483648..4294967295 (uint32)") { for (const uint32_t i : - { - 2147483648u, 3333333333u, 4294967295u - }) + { + 2147483648u, + 3333333333u, + 4294967295u}) { CAPTURE(i) @@ -1012,8 +1001,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'm', static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 8) & 0xff), @@ -1054,8 +1042,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'L', static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 010) & 0xff), @@ -1104,8 +1091,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'M', static_cast<uint8_t>(i & 0xff), static_cast<uint8_t>((i >> 010) & 0xff), @@ -1147,9 +1133,16 @@ double v = 3.1415925; json const j = v; std::vector<uint8_t> const expected = - { - 'D', 0xfc, 0xde, 0xa6, 0x3f, 0xfb, 0x21, 0x09, 0x40 - }; + { + 'D', + 0xfc, + 0xde, + 0xa6, + 0x3f, + 0xfb, + 0x21, + 0x09, + 0x40}; const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -1270,7 +1263,7 @@ SECTION("NaN") { - json const j = json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x7e })); + json const j = json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x7e})); json::number_float_t const d{j}; CHECK(std::isnan(d)); CHECK(j.dump() == "null"); @@ -1297,7 +1290,7 @@ SECTION("floating-point number") { - std::vector<uint8_t> const vec = {'H', 'i', 0x16, '3', '.', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5', '8', '9', '7', '9', '3', '2', '3', '8', '4', '6'}; + std::vector<uint8_t> const vec = {'H', 'i', 0x16, '3', '.', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5', '8', '9', '7', '9', '3', '2', '3', '8', '4', '6'}; const auto j = json::from_bjdata(vec); CHECK(j.is_number_float()); CHECK(j.dump() == "3.141592653589793"); @@ -1397,9 +1390,13 @@ SECTION("N = 256..32767") { for (const size_t N : - { - 256u, 999u, 1025u, 3333u, 2048u, 32767u - }) + { + 256u, + 999u, + 1025u, + 3333u, + 2048u, + 32767u}) { CAPTURE(N) @@ -1431,9 +1428,10 @@ SECTION("N = 32768..65535") { for (const size_t N : - { - 32768u, 55555u, 65535u - }) + { + 32768u, + 55555u, + 65535u}) { CAPTURE(N) @@ -1465,9 +1463,10 @@ SECTION("N = 65536..2147483647") { for (const size_t N : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(N) @@ -1592,9 +1591,13 @@ SECTION("N = 256..32767") { for (const std::size_t N : - { - 256u, 999u, 1025u, 3333u, 2048u, 32767u - }) + { + 256u, + 999u, + 1025u, + 3333u, + 2048u, + 32767u}) { CAPTURE(N) @@ -1629,9 +1632,10 @@ SECTION("N = 32768..65535") { for (const std::size_t N : - { - 32768u, 55555u, 65535u - }) + { + 32768u, + 55555u, + 65535u}) { CAPTURE(N) @@ -1666,9 +1670,10 @@ SECTION("N = 65536..2147483647") { for (const std::size_t N : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(N) @@ -1923,9 +1928,9 @@ SECTION("size=false type=false") { json j(257, nullptr); - std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null - expected[0] = '['; // opening array - expected[258] = ']'; // closing array + std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null + expected[0] = '['; // opening array + expected[258] = ']'; // closing array const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -1937,12 +1942,12 @@ SECTION("size=true type=false") { json j(257, nullptr); - std::vector<uint8_t> expected(j.size() + 5, 'Z'); // all null - expected[0] = '['; // opening array - expected[1] = '#'; // array size - expected[2] = 'I'; // int16 - expected[3] = 0x01; // 0x0101, first byte - expected[4] = 0x01; // 0x0101, second byte + std::vector<uint8_t> expected(j.size() + 5, 'Z'); // all null + expected[0] = '['; // opening array + expected[1] = '#'; // array size + expected[2] = 'I'; // int16 + expected[3] = 0x01; // 0x0101, first byte + expected[4] = 0x01; // 0x0101, second byte const auto result = json::to_bjdata(j, true); CHECK(result == expected); @@ -1957,9 +1962,9 @@ SECTION("size=false type=false") { json j(32768, nullptr); - std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null - expected[0] = '['; // opening array - expected[32769] = ']'; // closing array + std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null + expected[0] = '['; // opening array + expected[32769] = ']'; // closing array const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -1971,12 +1976,12 @@ SECTION("size=true type=false") { json j(32768, nullptr); - std::vector<uint8_t> expected(j.size() + 5, 'Z'); // all null - expected[0] = '['; // opening array - expected[1] = '#'; // array size - expected[2] = 'u'; // int16 - expected[3] = 0x00; // 0x0101, first byte - expected[4] = 0x80; // 0x0101, second byte + std::vector<uint8_t> expected(j.size() + 5, 'Z'); // all null + expected[0] = '['; // opening array + expected[1] = '#'; // array size + expected[2] = 'u'; // int16 + expected[3] = 0x00; // 0x0101, first byte + expected[4] = 0x80; // 0x0101, second byte const auto result = json::to_bjdata(j, true); CHECK(result == expected); @@ -1991,9 +1996,9 @@ SECTION("size=false type=false") { json j(65793, nullptr); - std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null - expected[0] = '['; // opening array - expected[65794] = ']'; // closing array + std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null + expected[0] = '['; // opening array + expected[65794] = ']'; // closing array const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -2005,14 +2010,14 @@ SECTION("size=true type=false") { json j(65793, nullptr); - std::vector<uint8_t> expected(j.size() + 7, 'Z'); // all null - expected[0] = '['; // opening array - expected[1] = '#'; // array size - expected[2] = 'l'; // int32 - expected[3] = 0x01; // 0x00010101, fourth byte - expected[4] = 0x01; // 0x00010101, third byte - expected[5] = 0x01; // 0x00010101, second byte - expected[6] = 0x00; // 0x00010101, first byte + std::vector<uint8_t> expected(j.size() + 7, 'Z'); // all null + expected[0] = '['; // opening array + expected[1] = '#'; // array size + expected[2] = 'l'; // int32 + expected[3] = 0x01; // 0x00010101, fourth byte + expected[4] = 0x01; // 0x00010101, third byte + expected[5] = 0x01; // 0x00010101, second byte + expected[6] = 0x00; // 0x00010101, first byte const auto result = json::to_bjdata(j, true); CHECK(result == expected); @@ -2097,9 +2102,24 @@ { json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); std::vector<uint8_t> const expected = - { - '{', 'i', 1, 'a', '{', 'i', 1, 'b', '{', 'i', 1, 'c', '{', '}', '}', '}', '}' - }; + { + '{', + 'i', + 1, + 'a', + '{', + 'i', + 1, + 'b', + '{', + 'i', + 1, + 'c', + '{', + '}', + '}', + '}', + '}'}; const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -2112,9 +2132,32 @@ { json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); std::vector<uint8_t> const expected = - { - '{', '#', 'i', 1, 'i', 1, 'a', '{', '#', 'i', 1, 'i', 1, 'b', '{', '#', 'i', 1, 'i', 1, 'c', '{', '#', 'i', 0 - }; + { + '{', + '#', + 'i', + 1, + 'i', + 1, + 'a', + '{', + '#', + 'i', + 1, + 'i', + 1, + 'b', + '{', + '#', + 'i', + 1, + 'i', + 1, + 'c', + '{', + '#', + 'i', + 0}; const auto result = json::to_bjdata(j, true); CHECK(result == expected); @@ -2127,9 +2170,32 @@ { json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); std::vector<uint8_t> const expected = - { - '{', '#', 'i', 1, 'i', 1, 'a', '{', '#', 'i', 1, 'i', 1, 'b', '{', '#', 'i', 1, 'i', 1, 'c', '{', '#', 'i', 0 - }; + { + '{', + '#', + 'i', + 1, + 'i', + 1, + 'a', + '{', + '#', + 'i', + 1, + 'i', + 1, + 'b', + '{', + '#', + 'i', + 1, + 'i', + 1, + 'c', + '{', + '#', + 'i', + 0}; const auto result = json::to_bjdata(j, true, true); CHECK(result == expected); @@ -2156,7 +2222,8 @@ { json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec), - "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData value: expected end of input; last byte: 0x5A", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData value: expected end of input; last byte: 0x5A", + json::parse_error&); } } } @@ -2366,7 +2433,7 @@ CHECK(json::to_bjdata(json::from_bjdata(v_M), true) == v_M); CHECK(json::to_bjdata(json::from_bjdata(v_D), true) == v_D); CHECK(json::to_bjdata(json::from_bjdata(v_S), true) == v_S); - CHECK(json::to_bjdata(json::from_bjdata(v_C), true) == v_S); // char is serialized to string + CHECK(json::to_bjdata(json::from_bjdata(v_C), true) == v_S); // char is serialized to string } SECTION("optimized version (type and length)") @@ -2409,7 +2476,7 @@ CHECK(json::to_bjdata(json::from_bjdata(v_M), true, true) == v_M); CHECK(json::to_bjdata(json::from_bjdata(v_D), true, true) == v_D); CHECK(json::to_bjdata(json::from_bjdata(v_S), true, true) == v_S); - CHECK(json::to_bjdata(json::from_bjdata(v_C), true, true) == v_S); // char is serialized to string + CHECK(json::to_bjdata(json::from_bjdata(v_C), true, true) == v_S); // char is serialized to string } SECTION("optimized ndarray (type and vector-size as optimized 1D array)") @@ -2574,7 +2641,8 @@ { json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(std::vector<uint8_t>()), - "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing BJData value: unexpected end of input", + json::parse_error&); } SECTION("char") @@ -3136,14 +3204,8 @@ SECTION("No-Op Value") { json const j = {"foo", "bar", "baz"}; - std::vector<uint8_t> v = {'[', 'S', 'i', 3, 'f', 'o', 'o', - 'S', 'i', 3, 'b', 'a', 'r', - 'S', 'i', 3, 'b', 'a', 'z', ']' - }; - std::vector<uint8_t> const v2 = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'N', - 'S', 'i', 3, 'b', 'a', 'r', 'N', 'N', 'N', - 'S', 'i', 3, 'b', 'a', 'z', 'N', 'N', ']' - }; + std::vector<uint8_t> v = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'S', 'i', 3, 'b', 'a', 'r', 'S', 'i', 3, 'b', 'a', 'z', ']'}; + std::vector<uint8_t> const v2 = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'N', 'S', 'i', 3, 'b', 'a', 'r', 'N', 'N', 'N', 'S', 'i', 3, 'b', 'a', 'z', 'N', 'N', ']'}; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); CHECK(json::from_bjdata(v2) == j); @@ -3152,9 +3214,7 @@ SECTION("Boolean Types") { json const j = {{"authorized", true}, {"verified", false}}; - std::vector<uint8_t> v = {'{', 'i', 10, 'a', 'u', 't', 'h', 'o', 'r', 'i', 'z', 'e', 'd', 'T', - 'i', 8, 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'F', '}' - }; + std::vector<uint8_t> v = {'{', 'i', 10, 'a', 'u', 't', 'h', 'o', 'r', 'i', 'z', 'e', 'd', 'T', 'i', 8, 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'F', '}'}; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); } @@ -3162,29 +3222,132 @@ SECTION("Numeric Types") { json j = - { - {"int8", 16}, - {"uint8", 255}, - {"int16", 32767}, - {"uint16", 42767}, - {"int32", 2147483647}, - {"uint32", 3147483647}, - {"int64", 9223372036854775807}, - {"uint64", 10223372036854775807ull}, - {"float64", 113243.7863123} - }; + { + {"int8", 16}, + {"uint8", 255}, + {"int16", 32767}, + {"uint16", 42767}, + {"int32", 2147483647}, + {"uint32", 3147483647}, + {"int64", 9223372036854775807}, + {"uint64", 10223372036854775807ull}, + {"float64", 113243.7863123}}; std::vector<uint8_t> v = {'{', - 'i', 7, 'f', 'l', 'o', 'a', 't', '6', '4', 'D', 0xcf, 0x34, 0xbc, 0x94, 0xbc, 0xa5, 0xfb, 0x40, - 'i', 5, 'i', 'n', 't', '1', '6', 'I', 0xff, 0x7f, - 'i', 5, 'i', 'n', 't', '3', '2', 'l', 0xff, 0xff, 0xff, 0x7f, - 'i', 5, 'i', 'n', 't', '6', '4', 'L', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, - 'i', 4, 'i', 'n', 't', '8', 'i', 16, - 'i', 6, 'u', 'i', 'n', 't', '1', '6', 'u', 0x0F, 0xA7, - 'i', 6, 'u', 'i', 'n', 't', '3', '2', 'm', 0xFF, 0xC9, 0x9A, 0xBB, - 'i', 6, 'u', 'i', 'n', 't', '6', '4', 'M', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, - 'i', 5, 'u', 'i', 'n', 't', '8', 'U', 0xff, - '}' - }; + 'i', + 7, + 'f', + 'l', + 'o', + 'a', + 't', + '6', + '4', + 'D', + 0xcf, + 0x34, + 0xbc, + 0x94, + 0xbc, + 0xa5, + 0xfb, + 0x40, + 'i', + 5, + 'i', + 'n', + 't', + '1', + '6', + 'I', + 0xff, + 0x7f, + 'i', + 5, + 'i', + 'n', + 't', + '3', + '2', + 'l', + 0xff, + 0xff, + 0xff, + 0x7f, + 'i', + 5, + 'i', + 'n', + 't', + '6', + '4', + 'L', + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0x7f, + 'i', + 4, + 'i', + 'n', + 't', + '8', + 'i', + 16, + 'i', + 6, + 'u', + 'i', + 'n', + 't', + '1', + '6', + 'u', + 0x0F, + 0xA7, + 'i', + 6, + 'u', + 'i', + 'n', + 't', + '3', + '2', + 'm', + 0xFF, + 0xC9, + 0x9A, + 0xBB, + 'i', + 6, + 'u', + 'i', + 'n', + 't', + '6', + '4', + 'M', + 0xFF, + 0xFF, + 0x63, + 0xA7, + 0xB3, + 0xB6, + 0xE0, + 0x8D, + 'i', + 5, + 'u', + 'i', + 'n', + 't', + '8', + 'U', + 0xff, + '}'}; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); } @@ -3259,23 +3422,9 @@ SECTION("size=false type=false") { json j = - { { - "post", { - {"id", 1137}, - {"author", "rkalla"}, - {"timestamp", 1364482090592}, - {"body", "I totally agree!"} - } - } - }; - std::vector<uint8_t> v = {'{', 'i', 4, 'p', 'o', 's', 't', '{', - 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', - 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', - 'i', 2, 'i', 'd', 'I', 0x71, 0x04, - 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x60, 0x66, 0x78, 0xB1, 0x3D, 0x01, 0x00, 0x00, - '}', '}' - }; + {"post", {{"id", 1137}, {"author", "rkalla"}, {"timestamp", 1364482090592}, {"body", "I totally agree!"}}}}; + std::vector<uint8_t> v = {'{', 'i', 4, 'p', 'o', 's', 't', '{', 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', 'i', 2, 'i', 'd', 'I', 0x71, 0x04, 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x60, 0x66, 0x78, 0xB1, 0x3D, 0x01, 0x00, 0x00, '}', '}'}; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); } @@ -3283,22 +3432,93 @@ SECTION("size=true type=false") { json j = - { { - "post", { - {"id", 1137}, - {"author", "rkalla"}, - {"timestamp", 1364482090592}, - {"body", "I totally agree!"} - } - } + {"post", {{"id", 1137}, {"author", "rkalla"}, {"timestamp", 1364482090592}, {"body", "I totally agree!"}}}}; + std::vector<uint8_t> v = { + '{', + '#', + 'i', + 1, + 'i', + 4, + 'p', + 'o', + 's', + 't', + '{', + '#', + 'i', + 4, + 'i', + 6, + 'a', + 'u', + 't', + 'h', + 'o', + 'r', + 'S', + 'i', + 6, + 'r', + 'k', + 'a', + 'l', + 'l', + 'a', + 'i', + 4, + 'b', + 'o', + 'd', + 'y', + 'S', + 'i', + 16, + 'I', + ' ', + 't', + 'o', + 't', + 'a', + 'l', + 'l', + 'y', + ' ', + 'a', + 'g', + 'r', + 'e', + 'e', + '!', + 'i', + 2, + 'i', + 'd', + 'I', + 0x71, + 0x04, + 'i', + 9, + 't', + 'i', + 'm', + 'e', + 's', + 't', + 'a', + 'm', + 'p', + 'L', + 0x60, + 0x66, + 0x78, + 0xB1, + 0x3D, + 0x01, + 0x00, + 0x00, }; - std::vector<uint8_t> v = {'{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '{', '#', 'i', 4, - 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', - 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', - 'i', 2, 'i', 'd', 'I', 0x71, 0x04, - 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x60, 0x66, 0x78, 0xB1, 0x3D, 0x01, 0x00, 0x00, - }; CHECK(json::to_bjdata(j, true) == v); CHECK(json::from_bjdata(v) == j); } @@ -3306,22 +3526,93 @@ SECTION("size=true type=true") { json j = - { { - "post", { - {"id", 1137}, - {"author", "rkalla"}, - {"timestamp", 1364482090592}, - {"body", "I totally agree!"} - } - } + {"post", {{"id", 1137}, {"author", "rkalla"}, {"timestamp", 1364482090592}, {"body", "I totally agree!"}}}}; + std::vector<uint8_t> v = { + '{', + '#', + 'i', + 1, + 'i', + 4, + 'p', + 'o', + 's', + 't', + '{', + '#', + 'i', + 4, + 'i', + 6, + 'a', + 'u', + 't', + 'h', + 'o', + 'r', + 'S', + 'i', + 6, + 'r', + 'k', + 'a', + 'l', + 'l', + 'a', + 'i', + 4, + 'b', + 'o', + 'd', + 'y', + 'S', + 'i', + 16, + 'I', + ' ', + 't', + 'o', + 't', + 'a', + 'l', + 'l', + 'y', + ' ', + 'a', + 'g', + 'r', + 'e', + 'e', + '!', + 'i', + 2, + 'i', + 'd', + 'I', + 0x71, + 0x04, + 'i', + 9, + 't', + 'i', + 'm', + 'e', + 's', + 't', + 'a', + 'm', + 'p', + 'L', + 0x60, + 0x66, + 0x78, + 0xB1, + 0x3D, + 0x01, + 0x00, + 0x00, }; - std::vector<uint8_t> v = {'{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '{', '#', 'i', 4, - 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', - 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', - 'i', 2, 'i', 'd', 'I', 0x71, 0x04, - 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x60, 0x66, 0x78, 0xB1, 0x3D, 0x01, 0x00, 0x00, - }; CHECK(json::to_bjdata(j, true, true) == v); CHECK(json::from_bjdata(v) == j); } @@ -3336,13 +3627,52 @@ // note the floats have been replaced by doubles json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; std::vector<uint8_t> v = {'[', - 'D', 0xb8, 0x1e, 0x85, 0xeb, 0x51, 0xf8, 0x3d, 0x40, - 'D', 0xe1, 0x7a, 0x14, 0xae, 0x47, 0x21, 0x3f, 0x40, - 'D', 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40, - 'D', 0x81, 0x95, 0x43, 0x8b, 0x6c, 0xe7, 0x00, 0x40, - 'D', 0x17, 0xd9, 0xce, 0xf7, 0x53, 0xe3, 0x37, 0x40, - ']' - }; + 'D', + 0xb8, + 0x1e, + 0x85, + 0xeb, + 0x51, + 0xf8, + 0x3d, + 0x40, + 'D', + 0xe1, + 0x7a, + 0x14, + 0xae, + 0x47, + 0x21, + 0x3f, + 0x40, + 'D', + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xc0, + 0x50, + 0x40, + 'D', + 0x81, + 0x95, + 0x43, + 0x8b, + 0x6c, + 0xe7, + 0x00, + 0x40, + 'D', + 0x17, + 0xd9, + 0xce, + 0xf7, + 0x53, + 0xe3, + 0x37, + 0x40, + ']'}; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); } @@ -3351,13 +3681,57 @@ { // note the floats have been replaced by doubles json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; - std::vector<uint8_t> v = {'[', '#', 'i', 5, - 'D', 0xb8, 0x1e, 0x85, 0xeb, 0x51, 0xf8, 0x3d, 0x40, - 'D', 0xe1, 0x7a, 0x14, 0xae, 0x47, 0x21, 0x3f, 0x40, - 'D', 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40, - 'D', 0x81, 0x95, 0x43, 0x8b, 0x6c, 0xe7, 0x00, 0x40, - 'D', 0x17, 0xd9, 0xce, 0xf7, 0x53, 0xe3, 0x37, 0x40, - }; + std::vector<uint8_t> v = { + '[', + '#', + 'i', + 5, + 'D', + 0xb8, + 0x1e, + 0x85, + 0xeb, + 0x51, + 0xf8, + 0x3d, + 0x40, + 'D', + 0xe1, + 0x7a, + 0x14, + 0xae, + 0x47, + 0x21, + 0x3f, + 0x40, + 'D', + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xc0, + 0x50, + 0x40, + 'D', + 0x81, + 0x95, + 0x43, + 0x8b, + 0x6c, + 0xe7, + 0x00, + 0x40, + 'D', + 0x17, + 0xd9, + 0xce, + 0xf7, + 0x53, + 0xe3, + 0x37, + 0x40, + }; CHECK(json::to_bjdata(j, true) == v); CHECK(json::from_bjdata(v) == j); } @@ -3366,13 +3740,54 @@ { // note the floats have been replaced by doubles json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; - std::vector<uint8_t> v = {'[', '$', 'D', '#', 'i', 5, - 0xb8, 0x1e, 0x85, 0xeb, 0x51, 0xf8, 0x3d, 0x40, - 0xe1, 0x7a, 0x14, 0xae, 0x47, 0x21, 0x3f, 0x40, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40, - 0x81, 0x95, 0x43, 0x8b, 0x6c, 0xe7, 0x00, 0x40, - 0x17, 0xd9, 0xce, 0xf7, 0x53, 0xe3, 0x37, 0x40, - }; + std::vector<uint8_t> v = { + '[', + '$', + 'D', + '#', + 'i', + 5, + 0xb8, + 0x1e, + 0x85, + 0xeb, + 0x51, + 0xf8, + 0x3d, + 0x40, + 0xe1, + 0x7a, + 0x14, + 0xae, + 0x47, + 0x21, + 0x3f, + 0x40, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xc0, + 0x50, + 0x40, + 0x81, + 0x95, + 0x43, + 0x8b, + 0x6c, + 0xe7, + 0x00, + 0x40, + 0x17, + 0xd9, + 0xce, + 0xf7, + 0x53, + 0xe3, + 0x37, + 0x40, + }; CHECK(json::to_bjdata(j, true, true) == v); CHECK(json::from_bjdata(v) == j); } @@ -3383,13 +3798,52 @@ SECTION("No Optimization") { // note the floats have been replaced by doubles - json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; + json const j = {{"lat", 29.976}, {"long", 31.131}, {"alt", 67.0}}; std::vector<uint8_t> v = {'{', - 'i', 3, 'a', 'l', 't', 'D', 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40, - 'i', 3, 'l', 'a', 't', 'D', 0x60, 0xe5, 0xd0, 0x22, 0xdb, 0xf9, 0x3d, 0x40, - 'i', 4, 'l', 'o', 'n', 'g', 'D', 0xa8, 0xc6, 0x4b, 0x37, 0x89, 0x21, 0x3f, 0x40, - '}' - }; + 'i', + 3, + 'a', + 'l', + 't', + 'D', + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xc0, + 0x50, + 0x40, + 'i', + 3, + 'l', + 'a', + 't', + 'D', + 0x60, + 0xe5, + 0xd0, + 0x22, + 0xdb, + 0xf9, + 0x3d, + 0x40, + 'i', + 4, + 'l', + 'o', + 'n', + 'g', + 'D', + 0xa8, + 0xc6, + 0x4b, + 0x37, + 0x89, + 0x21, + 0x3f, + 0x40, + '}'}; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); } @@ -3397,12 +3851,56 @@ SECTION("Optimized with count") { // note the floats have been replaced by doubles - json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; - std::vector<uint8_t> v = {'{', '#', 'i', 3, - 'i', 3, 'a', 'l', 't', 'D', 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40, - 'i', 3, 'l', 'a', 't', 'D', 0x60, 0xe5, 0xd0, 0x22, 0xdb, 0xf9, 0x3d, 0x40, - 'i', 4, 'l', 'o', 'n', 'g', 'D', 0xa8, 0xc6, 0x4b, 0x37, 0x89, 0x21, 0x3f, 0x40, - }; + json const j = {{"lat", 29.976}, {"long", 31.131}, {"alt", 67.0}}; + std::vector<uint8_t> v = { + '{', + '#', + 'i', + 3, + 'i', + 3, + 'a', + 'l', + 't', + 'D', + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xc0, + 0x50, + 0x40, + 'i', + 3, + 'l', + 'a', + 't', + 'D', + 0x60, + 0xe5, + 0xd0, + 0x22, + 0xdb, + 0xf9, + 0x3d, + 0x40, + 'i', + 4, + 'l', + 'o', + 'n', + 'g', + 'D', + 0xa8, + 0xc6, + 0x4b, + 0x37, + 0x89, + 0x21, + 0x3f, + 0x40, + }; CHECK(json::to_bjdata(j, true) == v); CHECK(json::from_bjdata(v) == j); } @@ -3410,12 +3908,55 @@ SECTION("Optimized with type & count") { // note the floats have been replaced by doubles - json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; - std::vector<uint8_t> v = {'{', '$', 'D', '#', 'i', 3, - 'i', 3, 'a', 'l', 't', 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40, - 'i', 3, 'l', 'a', 't', 0x60, 0xe5, 0xd0, 0x22, 0xdb, 0xf9, 0x3d, 0x40, - 'i', 4, 'l', 'o', 'n', 'g', 0xa8, 0xc6, 0x4b, 0x37, 0x89, 0x21, 0x3f, 0x40, - }; + json const j = {{"lat", 29.976}, {"long", 31.131}, {"alt", 67.0}}; + std::vector<uint8_t> v = { + '{', + '$', + 'D', + '#', + 'i', + 3, + 'i', + 3, + 'a', + 'l', + 't', + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xc0, + 0x50, + 0x40, + 'i', + 3, + 'l', + 'a', + 't', + 0x60, + 0xe5, + 0xd0, + 0x22, + 0xdb, + 0xf9, + 0x3d, + 0x40, + 'i', + 4, + 'l', + 'o', + 'n', + 'g', + 0xa8, + 0xc6, + 0x4b, + 0x37, + 0x89, + 0x21, + 0x3f, + 0x40, + }; CHECK(json::to_bjdata(j, true, true) == v); CHECK(json::from_bjdata(v) == j); } @@ -3447,9 +3988,27 @@ { // these bytes will fail immediately with exception parse_error.112 std::set<uint8_t> supported = - { - 'T', 'F', 'Z', 'U', 'i', 'I', 'l', 'L', 'd', 'D', 'C', 'S', '[', '{', 'N', 'H', 'u', 'm', 'M', 'h' - }; + { + 'T', + 'F', + 'Z', + 'U', + 'i', + 'I', + 'l', + 'L', + 'd', + 'D', + 'C', + 'S', + '[', + '{', + 'N', + 'H', + 'u', + 'm', + 'M', + 'h'}; for (auto i = 0; i < 256; ++i) { @@ -3483,50 +4042,49 @@ SECTION("input from self-generated BJData files") { for (const std::string filename : - { - TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json", - TEST_DATA_DIRECTORY "/json.org/1.json", - TEST_DATA_DIRECTORY "/json.org/2.json", - TEST_DATA_DIRECTORY "/json.org/3.json", - TEST_DATA_DIRECTORY "/json.org/4.json", - TEST_DATA_DIRECTORY "/json.org/5.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json", - TEST_DATA_DIRECTORY "/json_testsuite/sample.json", - TEST_DATA_DIRECTORY "/json_tests/pass1.json", - TEST_DATA_DIRECTORY "/json_tests/pass2.json", - TEST_DATA_DIRECTORY "/json_tests/pass3.json" - }) + { + TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json", + TEST_DATA_DIRECTORY "/json.org/1.json", + TEST_DATA_DIRECTORY "/json.org/2.json", + TEST_DATA_DIRECTORY "/json.org/3.json", + TEST_DATA_DIRECTORY "/json.org/4.json", + TEST_DATA_DIRECTORY "/json.org/5.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json", + TEST_DATA_DIRECTORY "/json_testsuite/sample.json", + TEST_DATA_DIRECTORY "/json_tests/pass1.json", + TEST_DATA_DIRECTORY "/json_tests/pass2.json", + TEST_DATA_DIRECTORY "/json_tests/pass3.json"}) { CAPTURE(filename)
diff --git a/tests/src/unit-bson.cpp b/tests/src/unit-bson.cpp index 13216f2..fd6c166 100644 --- a/tests/src/unit-bson.cpp +++ b/tests/src/unit-bson.cpp
@@ -11,11 +11,11 @@ #include <nlohmann/json.hpp> using nlohmann::json; +#include "make_test_data_available.hpp" +#include "test_utils.hpp" #include <fstream> #include <limits> #include <sstream> -#include "make_test_data_available.hpp" -#include "test_utils.hpp" TEST_CASE("BSON") { @@ -62,7 +62,7 @@ SECTION("array") { - json const j = std::vector<int> {1, 2, 3, 4, 5, 6, 7}; + json const j = std::vector<int>{1, 2, 3, 4, 5, 6, 7}; CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is array", json::type_error&); } } @@ -70,9 +70,8 @@ SECTION("keys containing code-point U+0000 cannot be serialized to BSON") { json const j = - { - { std::string("en\0try", 6), true } - }; + { + {std::string("en\0try", 6), true}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.out_of_range.409] (/en) BSON key cannot contain code point U+0000 (at byte 2)", json::out_of_range&); #else @@ -84,12 +83,17 @@ { // from https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11175 std::vector<std::uint8_t> const v = - { - 0x20, 0x20, 0x20, 0x20, - 0x02, - 0x00, - 0x00, 0x00, 0x00, 0x80 - }; + { + 0x20, + 0x20, + 0x20, + 0x20, + 0x02, + 0x00, + 0x00, + 0x00, + 0x00, + 0x80}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bson(v), "[json.exception.parse_error.112] parse error at byte 10: syntax error while parsing BSON string: string length must be at least 1, is -2147483648", json::parse_error&); } @@ -100,11 +104,14 @@ { json const j = json::object(); std::vector<std::uint8_t> const expected = - { - 0x05, 0x00, 0x00, 0x00, // size (little endian) - // no entries - 0x00 // end marker - }; + { + 0x05, + 0x00, + 0x00, + 0x00, // size (little endian) + // no entries + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -117,18 +124,25 @@ SECTION("non-empty object with bool") { json const j = - { - { "entry", true } - }; + { + {"entry", true}}; std::vector<std::uint8_t> const expected = - { - 0x0D, 0x00, 0x00, 0x00, // size (little endian) - 0x08, // entry: boolean - 'e', 'n', 't', 'r', 'y', '\x00', - 0x01, // value = true - 0x00 // end marker - }; + { + 0x0D, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x08, // entry: boolean + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0x01, // value = true + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -141,18 +155,25 @@ SECTION("non-empty object with bool") { json const j = - { - { "entry", false } - }; + { + {"entry", false}}; std::vector<std::uint8_t> const expected = - { - 0x0D, 0x00, 0x00, 0x00, // size (little endian) - 0x08, // entry: boolean - 'e', 'n', 't', 'r', 'y', '\x00', - 0x00, // value = false - 0x00 // end marker - }; + { + 0x0D, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x08, // entry: boolean + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0x00, // value = false + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -165,18 +186,32 @@ SECTION("non-empty object with double") { json const j = - { - { "entry", 4.2 } - }; + { + {"entry", 4.2}}; std::vector<std::uint8_t> const expected = - { - 0x14, 0x00, 0x00, 0x00, // size (little endian) - 0x01, /// entry: double - 'e', 'n', 't', 'r', 'y', '\x00', - 0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x10, 0x40, - 0x00 // end marker - }; + { + 0x14, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x01, /// entry: double + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0xcd, + 0xcc, + 0xcc, + 0xcc, + 0xcc, + 0xcc, + 0x10, + 0x40, + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -189,18 +224,36 @@ SECTION("non-empty object with string") { json const j = - { - { "entry", "bsonstr" } - }; + { + {"entry", "bsonstr"}}; std::vector<std::uint8_t> const expected = - { - 0x18, 0x00, 0x00, 0x00, // size (little endian) - 0x02, /// entry: string (UTF-8) - 'e', 'n', 't', 'r', 'y', '\x00', - 0x08, 0x00, 0x00, 0x00, 'b', 's', 'o', 'n', 's', 't', 'r', '\x00', - 0x00 // end marker - }; + { + 0x18, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x02, /// entry: string (UTF-8) + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0x08, + 0x00, + 0x00, + 0x00, + 'b', + 's', + 'o', + 'n', + 's', + 't', + 'r', + '\x00', + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -213,17 +266,24 @@ SECTION("non-empty object with null member") { json const j = - { - { "entry", nullptr } - }; + { + {"entry", nullptr}}; std::vector<std::uint8_t> const expected = - { - 0x0C, 0x00, 0x00, 0x00, // size (little endian) - 0x0A, /// entry: null - 'e', 'n', 't', 'r', 'y', '\x00', - 0x00 // end marker - }; + { + 0x0C, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x0A, /// entry: null + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -236,18 +296,28 @@ SECTION("non-empty object with integer (32-bit) member") { json const j = - { - { "entry", std::int32_t{0x12345678} } - }; + { + {"entry", std::int32_t{0x12345678}}}; std::vector<std::uint8_t> const expected = - { - 0x10, 0x00, 0x00, 0x00, // size (little endian) - 0x10, /// entry: int32 - 'e', 'n', 't', 'r', 'y', '\x00', - 0x78, 0x56, 0x34, 0x12, - 0x00 // end marker - }; + { + 0x10, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x10, /// entry: int32 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0x78, + 0x56, + 0x34, + 0x12, + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -260,18 +330,32 @@ SECTION("non-empty object with integer (64-bit) member") { json const j = - { - { "entry", std::int64_t{0x1234567804030201} } - }; + { + {"entry", std::int64_t{0x1234567804030201}}}; std::vector<std::uint8_t> const expected = - { - 0x14, 0x00, 0x00, 0x00, // size (little endian) - 0x12, /// entry: int64 - 'e', 'n', 't', 'r', 'y', '\x00', - 0x01, 0x02, 0x03, 0x04, 0x78, 0x56, 0x34, 0x12, - 0x00 // end marker - }; + { + 0x14, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x12, /// entry: int64 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0x01, + 0x02, + 0x03, + 0x04, + 0x78, + 0x56, + 0x34, + 0x12, + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -284,18 +368,28 @@ SECTION("non-empty object with negative integer (32-bit) member") { json const j = - { - { "entry", std::int32_t{-1} } - }; + { + {"entry", std::int32_t{-1}}}; std::vector<std::uint8_t> const expected = - { - 0x10, 0x00, 0x00, 0x00, // size (little endian) - 0x10, /// entry: int32 - 'e', 'n', 't', 'r', 'y', '\x00', - 0xFF, 0xFF, 0xFF, 0xFF, - 0x00 // end marker - }; + { + 0x10, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x10, /// entry: int32 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -308,18 +402,28 @@ SECTION("non-empty object with negative integer (64-bit) member") { json const j = - { - { "entry", std::int64_t{-1} } - }; + { + {"entry", std::int64_t{-1}}}; std::vector<std::uint8_t> const expected = - { - 0x10, 0x00, 0x00, 0x00, // size (little endian) - 0x10, /// entry: int32 - 'e', 'n', 't', 'r', 'y', '\x00', - 0xFF, 0xFF, 0xFF, 0xFF, - 0x00 // end marker - }; + { + 0x10, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x10, /// entry: int32 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -333,18 +437,32 @@ { // directly encoding uint64 is not supported in bson (only for timestamp values) json const j = - { - { "entry", std::uint64_t{0x1234567804030201} } - }; + { + {"entry", std::uint64_t{0x1234567804030201}}}; std::vector<std::uint8_t> const expected = - { - 0x14, 0x00, 0x00, 0x00, // size (little endian) - 0x12, /// entry: int64 - 'e', 'n', 't', 'r', 'y', '\x00', - 0x01, 0x02, 0x03, 0x04, 0x78, 0x56, 0x34, 0x12, - 0x00 // end marker - }; + { + 0x14, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x12, /// entry: int64 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0x01, + 0x02, + 0x03, + 0x04, + 0x78, + 0x56, + 0x34, + 0x12, + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -357,18 +475,28 @@ SECTION("non-empty object with small unsigned integer member") { json const j = - { - { "entry", std::uint64_t{0x42} } - }; + { + {"entry", std::uint64_t{0x42}}}; std::vector<std::uint8_t> const expected = - { - 0x10, 0x00, 0x00, 0x00, // size (little endian) - 0x10, /// entry: int32 - 'e', 'n', 't', 'r', 'y', '\x00', - 0x42, 0x00, 0x00, 0x00, - 0x00 // end marker - }; + { + 0x10, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x10, /// entry: int32 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0x42, + 0x00, + 0x00, + 0x00, + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -381,22 +509,32 @@ SECTION("non-empty object with object member") { json const j = - { - { "entry", json::object() } - }; + { + {"entry", json::object()}}; std::vector<std::uint8_t> const expected = - { - 0x11, 0x00, 0x00, 0x00, // size (little endian) - 0x03, /// entry: embedded document - 'e', 'n', 't', 'r', 'y', '\x00', + { + 0x11, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x03, /// entry: embedded document + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', - 0x05, 0x00, 0x00, 0x00, // size (little endian) - // no entries - 0x00, // end marker (embedded document) + 0x05, + 0x00, + 0x00, + 0x00, // size (little endian) + // no entries + 0x00, // end marker (embedded document) - 0x00 // end marker - }; + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -409,22 +547,32 @@ SECTION("non-empty object with array member") { json const j = - { - { "entry", json::array() } - }; + { + {"entry", json::array()}}; std::vector<std::uint8_t> const expected = - { - 0x11, 0x00, 0x00, 0x00, // size (little endian) - 0x04, /// entry: embedded document - 'e', 'n', 't', 'r', 'y', '\x00', + { + 0x11, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x04, /// entry: embedded document + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', - 0x05, 0x00, 0x00, 0x00, // size (little endian) - // no entries - 0x00, // end marker (embedded document) + 0x05, + 0x00, + 0x00, + 0x00, // size (little endian) + // no entries + 0x00, // end marker (embedded document) - 0x00 // end marker - }; + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -437,29 +585,87 @@ SECTION("non-empty object with non-empty array member") { json const j = - { - { "entry", json::array({1, 2, 3, 4, 5, 6, 7, 8}) } - }; + { + {"entry", json::array({1, 2, 3, 4, 5, 6, 7, 8})}}; std::vector<std::uint8_t> const expected = - { - 0x49, 0x00, 0x00, 0x00, // size (little endian) - 0x04, /// entry: embedded document - 'e', 'n', 't', 'r', 'y', '\x00', + { + 0x49, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x04, /// entry: embedded document + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', - 0x3D, 0x00, 0x00, 0x00, // size (little endian) - 0x10, '0', 0x00, 0x01, 0x00, 0x00, 0x00, - 0x10, '1', 0x00, 0x02, 0x00, 0x00, 0x00, - 0x10, '2', 0x00, 0x03, 0x00, 0x00, 0x00, - 0x10, '3', 0x00, 0x04, 0x00, 0x00, 0x00, - 0x10, '4', 0x00, 0x05, 0x00, 0x00, 0x00, - 0x10, '5', 0x00, 0x06, 0x00, 0x00, 0x00, - 0x10, '6', 0x00, 0x07, 0x00, 0x00, 0x00, - 0x10, '7', 0x00, 0x08, 0x00, 0x00, 0x00, - 0x00, // end marker (embedded document) + 0x3D, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x10, + '0', + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x10, + '1', + 0x00, + 0x02, + 0x00, + 0x00, + 0x00, + 0x10, + '2', + 0x00, + 0x03, + 0x00, + 0x00, + 0x00, + 0x10, + '3', + 0x00, + 0x04, + 0x00, + 0x00, + 0x00, + 0x10, + '4', + 0x00, + 0x05, + 0x00, + 0x00, + 0x00, + 0x10, + '5', + 0x00, + 0x06, + 0x00, + 0x00, + 0x00, + 0x10, + '6', + 0x00, + 0x07, + 0x00, + 0x00, + 0x00, + 0x10, + '7', + 0x00, + 0x08, + 0x00, + 0x00, + 0x00, + 0x00, // end marker (embedded document) - 0x00 // end marker - }; + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -474,22 +680,41 @@ const size_t N = 10; const auto s = std::vector<std::uint8_t>(N, 'x'); json const j = - { - { "entry", json::binary(s, 0) } - }; + { + {"entry", json::binary(s, 0)}}; std::vector<std::uint8_t> const expected = - { - 0x1B, 0x00, 0x00, 0x00, // size (little endian) - 0x05, // entry: binary - 'e', 'n', 't', 'r', 'y', '\x00', + { + 0x1B, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x05, // entry: binary + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', - 0x0A, 0x00, 0x00, 0x00, // size of binary (little endian) - 0x00, // Generic binary subtype - 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, + 0x0A, + 0x00, + 0x00, + 0x00, // size of binary (little endian) + 0x00, // Generic binary subtype + 0x78, + 0x78, + 0x78, + 0x78, + 0x78, + 0x78, + 0x78, + 0x78, + 0x78, + 0x78, - 0x00 // end marker - }; + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -504,22 +729,47 @@ // an MD5 hash const std::vector<std::uint8_t> md5hash = {0xd7, 0x7e, 0x27, 0x54, 0xbe, 0x12, 0x37, 0xfe, 0xd6, 0x0c, 0x33, 0x98, 0x30, 0x3b, 0x8d, 0xc4}; json const j = - { - { "entry", json::binary(md5hash, 5) } - }; + { + {"entry", json::binary(md5hash, 5)}}; std::vector<std::uint8_t> const expected = - { - 0x21, 0x00, 0x00, 0x00, // size (little endian) - 0x05, // entry: binary - 'e', 'n', 't', 'r', 'y', '\x00', + { + 0x21, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x05, // entry: binary + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', - 0x10, 0x00, 0x00, 0x00, // size of binary (little endian) - 0x05, // MD5 binary subtype - 0xd7, 0x7e, 0x27, 0x54, 0xbe, 0x12, 0x37, 0xfe, 0xd6, 0x0c, 0x33, 0x98, 0x30, 0x3b, 0x8d, 0xc4, + 0x10, + 0x00, + 0x00, + 0x00, // size of binary (little endian) + 0x05, // MD5 binary subtype + 0xd7, + 0x7e, + 0x27, + 0x54, + 0xbe, + 0x12, + 0x37, + 0xfe, + 0xd6, + 0x0c, + 0x33, + 0x98, + 0x30, + 0x3b, + 0x8d, + 0xc4, - 0x00 // end marker - }; + 0x00 // end marker + }; const auto result = json::to_bson(j); CHECK(result == expected); @@ -533,25 +783,93 @@ { // directly encoding uint64 is not supported in bson (only for timestamp values) json const j = - { - {"double", 42.5}, - {"entry", 4.2}, - {"number", 12345}, - {"object", {{ "string", "value" }}} - }; + { + {"double", 42.5}, + {"entry", 4.2}, + {"number", 12345}, + {"object", {{"string", "value"}}}}; std::vector<std::uint8_t> const expected = - { - /*size */ 0x4f, 0x00, 0x00, 0x00, - /*entry*/ 0x01, 'd', 'o', 'u', 'b', 'l', 'e', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x45, 0x40, - /*entry*/ 0x01, 'e', 'n', 't', 'r', 'y', 0x00, 0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x10, 0x40, - /*entry*/ 0x10, 'n', 'u', 'm', 'b', 'e', 'r', 0x00, 0x39, 0x30, 0x00, 0x00, - /*entry*/ 0x03, 'o', 'b', 'j', 'e', 'c', 't', 0x00, - /*entry: obj-size */ 0x17, 0x00, 0x00, 0x00, - /*entry: obj-entry*/0x02, 's', 't', 'r', 'i', 'n', 'g', 0x00, 0x06, 0x00, 0x00, 0x00, 'v', 'a', 'l', 'u', 'e', 0, - /*entry: obj-term.*/0x00, - /*obj-term*/ 0x00 - }; + { + /*size */ 0x4f, + 0x00, + 0x00, + 0x00, + /*entry*/ 0x01, + 'd', + 'o', + 'u', + 'b', + 'l', + 'e', + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x40, + 0x45, + 0x40, + /*entry*/ 0x01, + 'e', + 'n', + 't', + 'r', + 'y', + 0x00, + 0xcd, + 0xcc, + 0xcc, + 0xcc, + 0xcc, + 0xcc, + 0x10, + 0x40, + /*entry*/ 0x10, + 'n', + 'u', + 'm', + 'b', + 'e', + 'r', + 0x00, + 0x39, + 0x30, + 0x00, + 0x00, + /*entry*/ 0x03, + 'o', + 'b', + 'j', + 'e', + 'c', + 't', + 0x00, + /*entry: obj-size */ 0x17, + 0x00, + 0x00, + 0x00, + /*entry: obj-entry*/ 0x02, + 's', + 't', + 'r', + 'i', + 'n', + 'g', + 0x00, + 0x06, + 0x00, + 0x00, + 0x00, + 'v', + 'a', + 'l', + 'u', + 'e', + 0, + /*entry: obj-term.*/ 0x00, + /*obj-term*/ 0x00}; const auto result = json::to_bson(j); CHECK(result == expected); @@ -591,25 +909,93 @@ TEST_CASE("BSON input/output_adapters") { json json_representation = - { - {"double", 42.5}, - {"entry", 4.2}, - {"number", 12345}, - {"object", {{ "string", "value" }}} - }; + { + {"double", 42.5}, + {"entry", 4.2}, + {"number", 12345}, + {"object", {{"string", "value"}}}}; std::vector<std::uint8_t> const bson_representation = - { - /*size */ 0x4f, 0x00, 0x00, 0x00, - /*entry*/ 0x01, 'd', 'o', 'u', 'b', 'l', 'e', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x45, 0x40, - /*entry*/ 0x01, 'e', 'n', 't', 'r', 'y', 0x00, 0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x10, 0x40, - /*entry*/ 0x10, 'n', 'u', 'm', 'b', 'e', 'r', 0x00, 0x39, 0x30, 0x00, 0x00, - /*entry*/ 0x03, 'o', 'b', 'j', 'e', 'c', 't', 0x00, - /*entry: obj-size */ 0x17, 0x00, 0x00, 0x00, - /*entry: obj-entry*/0x02, 's', 't', 'r', 'i', 'n', 'g', 0x00, 0x06, 0x00, 0x00, 0x00, 'v', 'a', 'l', 'u', 'e', 0, - /*entry: obj-term.*/0x00, - /*obj-term*/ 0x00 - }; + { + /*size */ 0x4f, + 0x00, + 0x00, + 0x00, + /*entry*/ 0x01, + 'd', + 'o', + 'u', + 'b', + 'l', + 'e', + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x40, + 0x45, + 0x40, + /*entry*/ 0x01, + 'e', + 'n', + 't', + 'r', + 'y', + 0x00, + 0xcd, + 0xcc, + 0xcc, + 0xcc, + 0xcc, + 0xcc, + 0x10, + 0x40, + /*entry*/ 0x10, + 'n', + 'u', + 'm', + 'b', + 'e', + 'r', + 0x00, + 0x39, + 0x30, + 0x00, + 0x00, + /*entry*/ 0x03, + 'o', + 'b', + 'j', + 'e', + 'c', + 't', + 0x00, + /*entry: obj-size */ 0x17, + 0x00, + 0x00, + 0x00, + /*entry: obj-entry*/ 0x02, + 's', + 't', + 'r', + 'i', + 'n', + 'g', + 0x00, + 0x06, + 0x00, + 0x00, + 0x00, + 'v', + 'a', + 'l', + 'u', + 'e', + 0, + /*entry: obj-term.*/ 0x00, + /*obj-term*/ 0x00}; json j2; CHECK_NOTHROW(j2 = json::from_bson(bson_representation)); @@ -645,12 +1031,12 @@ } } -namespace -{ +namespace { class SaxCountdown { public: - explicit SaxCountdown(const int count) : events_left(count) + explicit SaxCountdown(const int count) + : events_left(count) {} bool null() @@ -713,7 +1099,7 @@ return events_left-- > 0; } - bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static) + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static) { return false; } @@ -721,18 +1107,23 @@ private: int events_left = 0; }; -} // namespace +} // namespace TEST_CASE("Incomplete BSON Input") { SECTION("Incomplete BSON Input 1") { std::vector<std::uint8_t> const incomplete_bson = - { - 0x0D, 0x00, 0x00, 0x00, // size (little endian) - 0x08, // entry: boolean - 'e', 'n', 't' // unexpected EOF - }; + { + 0x0D, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x08, // entry: boolean + 'e', + 'n', + 't' // unexpected EOF + }; json _; CHECK_THROWS_WITH_AS(_ = json::from_bson(incomplete_bson), "[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing BSON cstring: unexpected end of input", json::parse_error&); @@ -746,10 +1137,13 @@ SECTION("Incomplete BSON Input 2") { std::vector<std::uint8_t> const incomplete_bson = - { - 0x0D, 0x00, 0x00, 0x00, // size (little endian) - 0x08, // entry: boolean, unexpected EOF - }; + { + 0x0D, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x08, // entry: boolean, unexpected EOF + }; json _; CHECK_THROWS_WITH_AS(_ = json::from_bson(incomplete_bson), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing BSON cstring: unexpected end of input", json::parse_error&); @@ -762,16 +1156,37 @@ SECTION("Incomplete BSON Input 3") { std::vector<std::uint8_t> const incomplete_bson = - { - 0x41, 0x00, 0x00, 0x00, // size (little endian) - 0x04, /// entry: embedded document - 'e', 'n', 't', 'r', 'y', '\x00', + { + 0x41, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x04, /// entry: embedded document + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', - 0x35, 0x00, 0x00, 0x00, // size (little endian) - 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x02, 0x00, 0x00, 0x00 - // missing input data... - }; + 0x35, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x10, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x10, + 0x00, + 0x02, + 0x00, + 0x00, + 0x00 + // missing input data... + }; json _; CHECK_THROWS_WITH_AS(_ = json::from_bson(incomplete_bson), "[json.exception.parse_error.110] parse error at byte 28: syntax error while parsing BSON element list: unexpected end of input", json::parse_error&); @@ -784,9 +1199,10 @@ SECTION("Incomplete BSON Input 4") { std::vector<std::uint8_t> const incomplete_bson = - { - 0x0D, 0x00, // size (incomplete), unexpected EOF - }; + { + 0x0D, + 0x00, // size (incomplete), unexpected EOF + }; json _; CHECK_THROWS_WITH_AS(_ = json::from_bson(incomplete_bson), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing BSON number: unexpected end of input", json::parse_error&); @@ -809,9 +1225,8 @@ SECTION("array") { json const j = - { - { "entry", json::array() } - }; + { + {"entry", json::array()}}; auto bson_vec = json::to_bson(j); SaxCountdown scp(2); CHECK(!json::sax_parse(bson_vec, &scp, json::input_format_t::bson)); @@ -823,17 +1238,43 @@ { // invalid BSON: the size of the binary value is -1 std::vector<std::uint8_t> const input = - { - 0x21, 0x00, 0x00, 0x00, // size (little endian) - 0x05, // entry: binary - 'e', 'n', 't', 'r', 'y', '\x00', + { + 0x21, + 0x00, + 0x00, + 0x00, // size (little endian) + 0x05, // entry: binary + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', - 0xFF, 0xFF, 0xFF, 0xFF, // size of binary (little endian) - 0x05, // MD5 binary subtype - 0xd7, 0x7e, 0x27, 0x54, 0xbe, 0x12, 0x37, 0xfe, 0xd6, 0x0c, 0x33, 0x98, 0x30, 0x3b, 0x8d, 0xc4, + 0xFF, + 0xFF, + 0xFF, + 0xFF, // size of binary (little endian) + 0x05, // MD5 binary subtype + 0xd7, + 0x7e, + 0x27, + 0x54, + 0xbe, + 0x12, + 0x37, + 0xfe, + 0xd6, + 0x0c, + 0x33, + 0x98, + 0x30, + 0x3b, + 0x8d, + 0xc4, - 0x00 // end marker - }; + 0x00 // end marker + }; json _; CHECK_THROWS_WITH_AS(_ = json::from_bson(input), "[json.exception.parse_error.112] parse error at byte 15: syntax error while parsing BSON binary: byte array length cannot be negative, is -1", json::parse_error); } @@ -841,12 +1282,20 @@ TEST_CASE("Unsupported BSON input") { std::vector<std::uint8_t> const bson = - { - 0x0C, 0x00, 0x00, 0x00, // size (little endian) - 0xFF, // entry type: Min key (not supported yet) - 'e', 'n', 't', 'r', 'y', '\x00', - 0x00 // end marker - }; + { + 0x0C, + 0x00, + 0x00, + 0x00, // size (little endian) + 0xFF, // entry type: Min key (not supported yet) + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + 0x00 // end marker + }; json _; CHECK_THROWS_WITH_AS(_ = json::from_bson(bson), "[json.exception.parse_error.114] parse error at byte 5: Unsupported BSON record type 0xFF", json::parse_error&); @@ -864,8 +1313,7 @@ { SECTION("std::int64_t: INT64_MIN .. INT32_MIN-1") { - std::vector<int64_t> const numbers - { + std::vector<int64_t> const numbers{ (std::numeric_limits<int64_t>::min)(), -1000000000000000000LL, -100000000000000000LL, @@ -881,31 +1329,37 @@ for (const auto i : numbers) { - CAPTURE(i) json const j = - { - { "entry", i } - }; + { + {"entry", i}}; CHECK(j.at("entry").is_number_integer()); std::uint64_t const iu = *reinterpret_cast<const std::uint64_t*>(&i); std::vector<std::uint8_t> const expected_bson = - { - 0x14u, 0x00u, 0x00u, 0x00u, // size (little endian) - 0x12u, /// entry: int64 - 'e', 'n', 't', 'r', 'y', '\x00', - static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 4u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 5u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 6u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 7u)) & 0xffu), - 0x00u // end marker - }; + { + 0x14u, + 0x00u, + 0x00u, + 0x00u, // size (little endian) + 0x12u, /// entry: int64 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 4u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 5u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 6u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 7u)) & 0xffu), + 0x00u // end marker + }; const auto bson = json::to_bson(j); CHECK(bson == expected_bson); @@ -915,14 +1369,12 @@ CHECK(j_roundtrip.at("entry").is_number_integer()); CHECK(j_roundtrip == j); CHECK(json::from_bson(bson, true, false) == j); - } } SECTION("signed std::int32_t: INT32_MIN .. INT32_MAX") { - std::vector<int32_t> const numbers - { + std::vector<int32_t> const numbers{ (std::numeric_limits<int32_t>::min)(), -2147483647L, -1000000000L, @@ -947,32 +1399,37 @@ 100000000L, 1000000000L, 2147483646L, - (std::numeric_limits<int32_t>::max)() - }; + (std::numeric_limits<int32_t>::max)()}; for (const auto i : numbers) { - CAPTURE(i) json const j = - { - { "entry", i } - }; + { + {"entry", i}}; CHECK(j.at("entry").is_number_integer()); std::uint32_t const iu = *reinterpret_cast<const std::uint32_t*>(&i); std::vector<std::uint8_t> const expected_bson = - { - 0x10u, 0x00u, 0x00u, 0x00u, // size (little endian) - 0x10u, /// entry: int32 - 'e', 'n', 't', 'r', 'y', '\x00', - static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), - 0x00u // end marker - }; + { + 0x10u, + 0x00u, + 0x00u, + 0x00u, // size (little endian) + 0x10u, /// entry: int32 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), + 0x00u // end marker + }; const auto bson = json::to_bson(j); CHECK(bson == expected_bson); @@ -982,14 +1439,12 @@ CHECK(j_roundtrip.at("entry").is_number_integer()); CHECK(j_roundtrip == j); CHECK(json::from_bson(bson, true, false) == j); - } } SECTION("signed std::int64_t: INT32_MAX+1 .. INT64_MAX") { - std::vector<int64_t> const numbers - { + std::vector<int64_t> const numbers{ (std::numeric_limits<int64_t>::max)(), 1000000000000000000LL, 100000000000000000LL, @@ -1005,31 +1460,37 @@ for (const auto i : numbers) { - CAPTURE(i) json const j = - { - { "entry", i } - }; + { + {"entry", i}}; CHECK(j.at("entry").is_number_integer()); std::uint64_t const iu = *reinterpret_cast<const std::uint64_t*>(&i); std::vector<std::uint8_t> const expected_bson = - { - 0x14u, 0x00u, 0x00u, 0x00u, // size (little endian) - 0x12u, /// entry: int64 - 'e', 'n', 't', 'r', 'y', '\x00', - static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 4u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 5u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 6u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 7u)) & 0xffu), - 0x00u // end marker - }; + { + 0x14u, + 0x00u, + 0x00u, + 0x00u, // size (little endian) + 0x12u, /// entry: int64 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 4u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 5u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 6u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 7u)) & 0xffu), + 0x00u // end marker + }; const auto bson = json::to_bson(j); CHECK(bson == expected_bson); @@ -1039,7 +1500,6 @@ CHECK(j_roundtrip.at("entry").is_number_integer()); CHECK(j_roundtrip == j); CHECK(json::from_bson(bson, true, false) == j); - } } } @@ -1048,8 +1508,7 @@ { SECTION("unsigned std::uint64_t: 0 .. INT32_MAX") { - std::vector<std::uint64_t> const numbers - { + std::vector<std::uint64_t> const numbers{ 0ULL, 1ULL, 10ULL, @@ -1062,31 +1521,36 @@ 100000000ULL, 1000000000ULL, 2147483646ULL, - static_cast<std::uint64_t>((std::numeric_limits<int32_t>::max)()) - }; + static_cast<std::uint64_t>((std::numeric_limits<int32_t>::max)())}; for (const auto i : numbers) { - CAPTURE(i) json const j = - { - { "entry", i } - }; + { + {"entry", i}}; auto iu = i; std::vector<std::uint8_t> const expected_bson = - { - 0x10u, 0x00u, 0x00u, 0x00u, // size (little endian) - 0x10u, /// entry: int32 - 'e', 'n', 't', 'r', 'y', '\x00', - static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), - 0x00u // end marker - }; + { + 0x10u, + 0x00u, + 0x00u, + 0x00u, // size (little endian) + 0x10u, /// entry: int32 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), + 0x00u // end marker + }; const auto bson = json::to_bson(j); CHECK(bson == expected_bson); @@ -1097,14 +1561,12 @@ CHECK(j_roundtrip.at("entry").is_number_integer()); CHECK(j_roundtrip == j); CHECK(json::from_bson(bson, true, false) == j); - } } SECTION("unsigned std::uint64_t: INT32_MAX+1 .. INT64_MAX") { - std::vector<std::uint64_t> const numbers - { + std::vector<std::uint64_t> const numbers{ static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()) + 1, 4000000000ULL, static_cast<std::uint64_t>((std::numeric_limits<std::uint32_t>::max)()), @@ -1122,30 +1584,36 @@ for (const auto i : numbers) { - CAPTURE(i) json const j = - { - { "entry", i } - }; + { + {"entry", i}}; auto iu = i; std::vector<std::uint8_t> const expected_bson = - { - 0x14u, 0x00u, 0x00u, 0x00u, // size (little endian) - 0x12u, /// entry: int64 - 'e', 'n', 't', 'r', 'y', '\x00', - static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 4u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 5u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 6u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 7u)) & 0xffu), - 0x00u // end marker - }; + { + 0x14u, + 0x00u, + 0x00u, + 0x00u, // size (little endian) + 0x12u, /// entry: int64 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 4u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 5u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 6u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 7u)) & 0xffu), + 0x00u // end marker + }; const auto bson = json::to_bson(j); CHECK(bson == expected_bson); @@ -1161,8 +1629,7 @@ SECTION("unsigned std::uint64_t: INT64_MAX+1 .. UINT64_MAX") { - std::vector<std::uint64_t> const numbers - { + std::vector<std::uint64_t> const numbers{ static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()) + 1ULL, 10000000000000000000ULL, 18000000000000000000ULL, @@ -1172,30 +1639,36 @@ for (const auto i : numbers) { - CAPTURE(i) json const j = - { - { "entry", i } - }; + { + {"entry", i}}; auto iu = i; std::vector<std::uint8_t> const expected_bson = - { - 0x14u, 0x00u, 0x00u, 0x00u, // size (little endian) - 0x12u, /// entry: int64 - 'e', 'n', 't', 'r', 'y', '\x00', - static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 4u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 5u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 6u)) & 0xffu), - static_cast<std::uint8_t>((iu >> (8u * 7u)) & 0xffu), - 0x00u // end marker - }; + { + 0x14u, + 0x00u, + 0x00u, + 0x00u, // size (little endian) + 0x12u, /// entry: int64 + 'e', + 'n', + 't', + 'r', + 'y', + '\x00', + static_cast<std::uint8_t>((iu >> (8u * 0u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 1u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 2u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 3u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 4u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 5u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 6u)) & 0xffu), + static_cast<std::uint8_t>((iu >> (8u * 7u)) & 0xffu), + 0x00u // end marker + }; CHECK_THROWS_AS(json::to_bson(j), json::out_of_range&); #if JSON_DIAGNOSTICS @@ -1205,7 +1678,6 @@ #endif } } - } } } @@ -1215,13 +1687,12 @@ SECTION("reference files") { for (const std::string filename : - { - TEST_DATA_DIRECTORY "/json.org/1.json", - TEST_DATA_DIRECTORY "/json.org/2.json", - TEST_DATA_DIRECTORY "/json.org/3.json", - TEST_DATA_DIRECTORY "/json.org/4.json", - TEST_DATA_DIRECTORY "/json.org/5.json" - }) + { + TEST_DATA_DIRECTORY "/json.org/1.json", + TEST_DATA_DIRECTORY "/json.org/2.json", + TEST_DATA_DIRECTORY "/json.org/3.json", + TEST_DATA_DIRECTORY "/json.org/4.json", + TEST_DATA_DIRECTORY "/json.org/5.json"}) { CAPTURE(filename)
diff --git a/tests/src/unit-capacity.cpp b/tests/src/unit-capacity.cpp index 61203cc..2a0b5ab 100644 --- a/tests/src/unit-capacity.cpp +++ b/tests/src/unit-capacity.cpp
@@ -18,7 +18,7 @@ { SECTION("boolean") { - json j = true; // NOLINT(misc-const-correctness) + json j = true; // NOLINT(misc-const-correctness) const json j_const = true; SECTION("result of empty") @@ -36,7 +36,7 @@ SECTION("string") { - json j = "hello world"; // NOLINT(misc-const-correctness) + json j = "hello world"; // NOLINT(misc-const-correctness) const json j_const = "hello world"; SECTION("result of empty") @@ -56,7 +56,7 @@ { SECTION("empty array") { - json j = json::array(); // NOLINT(misc-const-correctness) + json j = json::array(); // NOLINT(misc-const-correctness) const json j_const = json::array(); SECTION("result of empty") @@ -74,7 +74,7 @@ SECTION("filled array") { - json j = {1, 2, 3}; // NOLINT(misc-const-correctness) + json j = {1, 2, 3}; // NOLINT(misc-const-correctness) const json j_const = {1, 2, 3}; SECTION("result of empty") @@ -95,7 +95,7 @@ { SECTION("empty object") { - json j = json::object(); // NOLINT(misc-const-correctness) + json j = json::object(); // NOLINT(misc-const-correctness) const json j_const = json::object(); SECTION("result of empty") @@ -113,7 +113,7 @@ SECTION("filled object") { - json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) + json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}}; SECTION("result of empty") @@ -132,7 +132,7 @@ SECTION("number (integer)") { - json j = -23; // NOLINT(misc-const-correctness) + json j = -23; // NOLINT(misc-const-correctness) const json j_const = -23; SECTION("result of empty") @@ -150,7 +150,7 @@ SECTION("number (unsigned)") { - json j = 23u; // NOLINT(misc-const-correctness) + json j = 23u; // NOLINT(misc-const-correctness) const json j_const = 23u; SECTION("result of empty") @@ -168,7 +168,7 @@ SECTION("number (float)") { - json j = 23.42; // NOLINT(misc-const-correctness) + json j = 23.42; // NOLINT(misc-const-correctness) const json j_const = 23.42; SECTION("result of empty") @@ -186,7 +186,7 @@ SECTION("null") { - json j = nullptr; // NOLINT(misc-const-correctness) + json j = nullptr; // NOLINT(misc-const-correctness) const json j_const = nullptr; SECTION("result of empty") @@ -207,7 +207,7 @@ { SECTION("boolean") { - json j = true; // NOLINT(misc-const-correctness) + json j = true; // NOLINT(misc-const-correctness) const json j_const = true; SECTION("result of size") @@ -227,7 +227,7 @@ SECTION("string") { - json j = "hello world"; // NOLINT(misc-const-correctness) + json j = "hello world"; // NOLINT(misc-const-correctness) const json j_const = "hello world"; SECTION("result of size") @@ -249,7 +249,7 @@ { SECTION("empty array") { - json j = json::array(); // NOLINT(misc-const-correctness) + json j = json::array(); // NOLINT(misc-const-correctness) const json j_const = json::array(); SECTION("result of size") @@ -269,7 +269,7 @@ SECTION("filled array") { - json j = {1, 2, 3}; // NOLINT(misc-const-correctness) + json j = {1, 2, 3}; // NOLINT(misc-const-correctness) const json j_const = {1, 2, 3}; SECTION("result of size") @@ -292,7 +292,7 @@ { SECTION("empty object") { - json j = json::object(); // NOLINT(misc-const-correctness) + json j = json::object(); // NOLINT(misc-const-correctness) const json j_const = json::object(); SECTION("result of size") @@ -312,7 +312,7 @@ SECTION("filled object") { - json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) + json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}}; SECTION("result of size") @@ -333,7 +333,7 @@ SECTION("number (integer)") { - json j = -23; // NOLINT(misc-const-correctness) + json j = -23; // NOLINT(misc-const-correctness) const json j_const = -23; SECTION("result of size") @@ -353,7 +353,7 @@ SECTION("number (unsigned)") { - json j = 23u; // NOLINT(misc-const-correctness) + json j = 23u; // NOLINT(misc-const-correctness) const json j_const = 23u; SECTION("result of size") @@ -373,7 +373,7 @@ SECTION("number (float)") { - json j = 23.42; // NOLINT(misc-const-correctness) + json j = 23.42; // NOLINT(misc-const-correctness) const json j_const = 23.42; SECTION("result of size") @@ -393,7 +393,7 @@ SECTION("null") { - json j = nullptr; // NOLINT(misc-const-correctness) + json j = nullptr; // NOLINT(misc-const-correctness) const json j_const = nullptr; SECTION("result of size") @@ -416,7 +416,7 @@ { SECTION("boolean") { - json j = true; // NOLINT(misc-const-correctness) + json j = true; // NOLINT(misc-const-correctness) const json j_const = true; SECTION("result of max_size") @@ -428,7 +428,7 @@ SECTION("string") { - json j = "hello world"; // NOLINT(misc-const-correctness) + json j = "hello world"; // NOLINT(misc-const-correctness) const json j_const = "hello world"; SECTION("result of max_size") @@ -442,7 +442,7 @@ { SECTION("empty array") { - json j = json::array(); // NOLINT(misc-const-correctness) + json j = json::array(); // NOLINT(misc-const-correctness) const json j_const = json::array(); SECTION("result of max_size") @@ -454,7 +454,7 @@ SECTION("filled array") { - json j = {1, 2, 3}; // NOLINT(misc-const-correctness) + json j = {1, 2, 3}; // NOLINT(misc-const-correctness) const json j_const = {1, 2, 3}; SECTION("result of max_size") @@ -469,7 +469,7 @@ { SECTION("empty object") { - json j = json::object(); // NOLINT(misc-const-correctness) + json j = json::object(); // NOLINT(misc-const-correctness) const json j_const = json::object(); SECTION("result of max_size") @@ -481,7 +481,7 @@ SECTION("filled object") { - json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) + json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}}; SECTION("result of max_size") @@ -494,7 +494,7 @@ SECTION("number (integer)") { - json j = -23; // NOLINT(misc-const-correctness) + json j = -23; // NOLINT(misc-const-correctness) const json j_const = -23; SECTION("result of max_size") @@ -506,7 +506,7 @@ SECTION("number (unsigned)") { - json j = 23u; // NOLINT(misc-const-correctness) + json j = 23u; // NOLINT(misc-const-correctness) const json j_const = 23u; SECTION("result of max_size") @@ -518,7 +518,7 @@ SECTION("number (float)") { - json j = 23.42; // NOLINT(misc-const-correctness) + json j = 23.42; // NOLINT(misc-const-correctness) const json j_const = 23.42; SECTION("result of max_size") @@ -530,7 +530,7 @@ SECTION("null") { - json j = nullptr; // NOLINT(misc-const-correctness) + json j = nullptr; // NOLINT(misc-const-correctness) const json j_const = nullptr; SECTION("result of max_size")
diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index be94d2f..d094dd3 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp
@@ -11,21 +11,21 @@ #include <nlohmann/json.hpp> using nlohmann::json; +#include "make_test_data_available.hpp" +#include "test_utils.hpp" #include <fstream> -#include <sstream> #include <iomanip> #include <iostream> #include <limits> #include <set> -#include "make_test_data_available.hpp" -#include "test_utils.hpp" +#include <sstream> -namespace -{ +namespace { class SaxCountdown { public: - explicit SaxCountdown(const int count) : events_left(count) + explicit SaxCountdown(const int count) + : events_left(count) {} bool null() @@ -88,7 +88,7 @@ return events_left-- > 0; } - bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static) + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static) { return false; } @@ -96,7 +96,7 @@ private: int events_left = 0; }; -} // namespace +} // namespace TEST_CASE("CBOR") { @@ -173,8 +173,7 @@ { SECTION("-9223372036854775808..-4294967297") { - const std::vector<int64_t> numbers - { + const std::vector<int64_t> numbers{ (std::numeric_limits<int64_t>::min)(), -1000000000000000000, -100000000000000000, @@ -199,8 +198,7 @@ // create expected byte vector const auto positive = static_cast<uint64_t>(-1 - i); - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ static_cast<uint8_t>(0x3b), static_cast<uint8_t>((positive >> 56) & 0xff), static_cast<uint8_t>((positive >> 48) & 0xff), @@ -238,16 +236,15 @@ SECTION("-4294967296..-65537") { - const std::vector<int64_t> numbers - { + const std::vector<int64_t> numbers{ -65537, - -100000, - -1000000, - -10000000, - -100000000, - -1000000000, - -4294967296, - }; + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -4294967296, + }; for (const auto i : numbers) { CAPTURE(i) @@ -260,8 +257,7 @@ // create expected byte vector auto positive = static_cast<uint32_t>(static_cast<uint64_t>(-1 - i) & 0x00000000ffffffff); - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ static_cast<uint8_t>(0x3a), static_cast<uint8_t>((positive >> 24) & 0xff), static_cast<uint8_t>((positive >> 16) & 0xff), @@ -303,8 +299,7 @@ // create expected byte vector const auto positive = static_cast<uint16_t>(-1 - i); - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ static_cast<uint8_t>(0x39), static_cast<uint8_t>((positive >> 8) & 0xff), static_cast<uint8_t>(positive & 0xff), @@ -356,8 +351,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ 0x38, static_cast<uint8_t>(-1 - i), }; @@ -390,8 +384,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ static_cast<uint8_t>(0x20 - 1 - static_cast<uint8_t>(i)), }; @@ -423,8 +416,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ static_cast<uint8_t>(i), }; @@ -456,8 +448,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ static_cast<uint8_t>(0x18), static_cast<uint8_t>(i), }; @@ -491,8 +482,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ static_cast<uint8_t>(0x19), static_cast<uint8_t>((i >> 8) & 0xff), static_cast<uint8_t>(i & 0xff), @@ -517,9 +507,10 @@ SECTION("65536..4294967295") { for (const uint32_t i : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(i) @@ -531,8 +522,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ 0x1a, static_cast<uint8_t>((i >> 24) & 0xff), static_cast<uint8_t>((i >> 16) & 0xff), @@ -562,9 +552,9 @@ SECTION("4294967296..4611686018427387903") { for (const uint64_t i : - { - 4294967296ul, 4611686018427387903ul - }) + { + 4294967296ul, + 4611686018427387903ul}) { CAPTURE(i) @@ -576,8 +566,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ 0x1b, static_cast<uint8_t>((i >> 070) & 0xff), static_cast<uint8_t>((i >> 060) & 0xff), @@ -625,8 +614,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ 0xd1, static_cast<uint8_t>((i >> 8) & 0xff), static_cast<uint8_t>(i & 0xff), @@ -663,8 +651,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ static_cast<uint8_t>(i), }; @@ -695,8 +682,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ 0x18, static_cast<uint8_t>(i), }; @@ -730,8 +716,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ 0x19, static_cast<uint8_t>((i >> 8) & 0xff), static_cast<uint8_t>(i & 0xff), @@ -756,9 +741,10 @@ SECTION("65536..4294967295 (four-byte uint32_t)") { for (const uint32_t i : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(i) @@ -769,8 +755,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ 0x1a, static_cast<uint8_t>((i >> 24) & 0xff), static_cast<uint8_t>((i >> 16) & 0xff), @@ -800,9 +785,9 @@ SECTION("4294967296..4611686018427387903 (eight-byte uint64_t)") { for (const uint64_t i : - { - 4294967296ul, 4611686018427387903ul - }) + { + 4294967296ul, + 4611686018427387903ul}) { CAPTURE(i) @@ -813,8 +798,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - const std::vector<uint8_t> expected - { + const std::vector<uint8_t> expected{ 0x1b, static_cast<uint8_t>((i >> 070) & 0xff), static_cast<uint8_t>((i >> 060) & 0xff), @@ -857,9 +841,16 @@ double v = 3.1415925; const json j = v; std::vector<uint8_t> expected = - { - 0xfb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc - }; + { + 0xfb, + 0x40, + 0x09, + 0x21, + 0xfb, + 0x3f, + 0xa6, + 0xde, + 0xfc}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -944,9 +935,12 @@ float v = (std::numeric_limits<float>::max)(); const json j = v; const std::vector<uint8_t> expected = - { - 0xfa, 0x7f, 0x7f, 0xff, 0xff - }; + { + 0xfa, + 0x7f, + 0x7f, + 0xff, + 0xff}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -958,9 +952,12 @@ auto v = static_cast<double>(std::numeric_limits<float>::lowest()); const json j = v; const std::vector<uint8_t> expected = - { - 0xfa, 0xff, 0x7f, 0xff, 0xff - }; + { + 0xfa, + 0xff, + 0x7f, + 0xff, + 0xff}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -972,9 +969,16 @@ double v = static_cast<double>((std::numeric_limits<float>::max)()) + 0.1e+34; const json j = v; const std::vector<uint8_t> expected = - { - 0xfb, 0x47, 0xf0, 0x00, 0x03, 0x04, 0xdc, 0x64, 0x49 - }; + { + 0xfb, + 0x47, + 0xf0, + 0x00, + 0x03, + 0x04, + 0xdc, + 0x64, + 0x49}; // double const auto result = json::to_cbor(j); CHECK(result == expected); @@ -987,9 +991,12 @@ double v = static_cast<double>(std::numeric_limits<float>::lowest()) - 1.0; const json j = v; const std::vector<uint8_t> expected = - { - 0xfa, 0xff, 0x7f, 0xff, 0xff - }; + { + 0xfa, + 0xff, + 0x7f, + 0xff, + 0xff}; // the same with lowest float const auto result = json::to_cbor(j); CHECK(result == expected); @@ -997,7 +1004,6 @@ CHECK(json::from_cbor(result) == j); CHECK(json::from_cbor(result) == v); } - } SECTION("half-precision float (edge cases)") @@ -1175,9 +1181,13 @@ SECTION("N = 256..65535") { for (const size_t N : - { - 256u, 999u, 1025u, 3333u, 2048u, 65535u - }) + { + 256u, + 999u, + 1025u, + 3333u, + 2048u, + 65535u}) { CAPTURE(N) @@ -1208,9 +1218,10 @@ SECTION("N = 65536..4294967295") { for (const size_t N : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(N) @@ -1294,10 +1305,10 @@ SECTION("array with uint16_t elements") { const json j(257, nullptr); - std::vector<uint8_t> expected(j.size() + 3, 0xf6); // all null - expected[0] = 0x99; // array 16 bit - expected[1] = 0x01; // size (0x0101), byte 0 - expected[2] = 0x01; // size (0x0101), byte 1 + std::vector<uint8_t> expected(j.size() + 3, 0xf6); // all null + expected[0] = 0x99; // array 16 bit + expected[1] = 0x01; // size (0x0101), byte 0 + expected[2] = 0x01; // size (0x0101), byte 1 const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1309,12 +1320,12 @@ SECTION("array with uint32_t elements") { const json j(65793, nullptr); - std::vector<uint8_t> expected(j.size() + 5, 0xf6); // all null - expected[0] = 0x9a; // array 32 bit - expected[1] = 0x00; // size (0x00010101), byte 0 - expected[2] = 0x01; // size (0x00010101), byte 1 - expected[3] = 0x01; // size (0x00010101), byte 2 - expected[4] = 0x01; // size (0x00010101), byte 3 + std::vector<uint8_t> expected(j.size() + 5, 0xf6); // all null + expected[0] = 0x9a; // array 32 bit + expected[1] = 0x00; // size (0x00010101), byte 0 + expected[2] = 0x01; // size (0x00010101), byte 1 + expected[3] = 0x01; // size (0x00010101), byte 2 + expected[4] = 0x01; // size (0x00010101), byte 3 const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1354,9 +1365,17 @@ { const json j = json::parse(R"({"a": {"b": {"c": {}}}})"); const std::vector<uint8_t> expected = - { - 0xa1, 0x61, 0x61, 0xa1, 0x61, 0x62, 0xa1, 0x61, 0x63, 0xa0 - }; + { + 0xa1, + 0x61, + 0x61, + 0xa1, + 0x61, + 0x62, + 0xa1, + 0x61, + 0x63, + 0xa0}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1384,9 +1403,9 @@ // pairs are made. We therefore only check the prefix (type and // size and the overall size. The rest is then handled in the // roundtrip check. - CHECK(result.size() == 1787); // 1 type, 1 size, 255*7 content - CHECK(result[0] == 0xb8); // map 8 bit - CHECK(result[1] == 0xff); // size byte (0xff) + CHECK(result.size() == 1787); // 1 type, 1 size, 255*7 content + CHECK(result[0] == 0xb8); // map 8 bit + CHECK(result[1] == 0xff); // size byte (0xff) // roundtrip CHECK(json::from_cbor(result) == j); CHECK(json::from_cbor(result, true, false) == j); @@ -1411,10 +1430,10 @@ // pairs are made. We therefore only check the prefix (type and // size and the overall size. The rest is then handled in the // roundtrip check. - CHECK(result.size() == 1795); // 1 type, 2 size, 256*7 content - CHECK(result[0] == 0xb9); // map 16 bit - CHECK(result[1] == 0x01); // byte 0 of size (0x0100) - CHECK(result[2] == 0x00); // byte 1 of size (0x0100) + CHECK(result.size() == 1795); // 1 type, 2 size, 256*7 content + CHECK(result[0] == 0xb9); // map 16 bit + CHECK(result[1] == 0x01); // byte 0 of size (0x0100) + CHECK(result[2] == 0x00); // byte 1 of size (0x0100) // roundtrip CHECK(json::from_cbor(result) == j); @@ -1440,12 +1459,12 @@ // pairs are made. We therefore only check the prefix (type and // size and the overall size. The rest is then handled in the // roundtrip check. - CHECK(result.size() == 458757); // 1 type, 4 size, 65536*7 content - CHECK(result[0] == 0xba); // map 32 bit - CHECK(result[1] == 0x00); // byte 0 of size (0x00010000) - CHECK(result[2] == 0x01); // byte 1 of size (0x00010000) - CHECK(result[3] == 0x00); // byte 2 of size (0x00010000) - CHECK(result[4] == 0x00); // byte 3 of size (0x00010000) + CHECK(result.size() == 458757); // 1 type, 4 size, 65536*7 content + CHECK(result[0] == 0xba); // map 32 bit + CHECK(result[1] == 0x00); // byte 0 of size (0x00010000) + CHECK(result[2] == 0x01); // byte 1 of size (0x00010000) + CHECK(result[3] == 0x00); // byte 2 of size (0x00010000) + CHECK(result[4] == 0x00); // byte 3 of size (0x00010000) // roundtrip CHECK(json::from_cbor(result) == j); @@ -1524,9 +1543,13 @@ SECTION("N = 256..65535") { for (const size_t N : - { - 256u, 999u, 1025u, 3333u, 2048u, 65535u - }) + { + 256u, + 999u, + 1025u, + 3333u, + 2048u, + 65535u}) { CAPTURE(N) @@ -1557,9 +1580,10 @@ SECTION("N = 65536..4294967295") { for (const size_t N : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(N) @@ -1622,8 +1646,7 @@ // callback to set binary_seen to true if a binary value was seen bool binary_seen = false; - auto callback = [&binary_seen](int /*depth*/, json::parse_event_t /*event*/, json & parsed) noexcept - { + auto callback = [&binary_seen](int /*depth*/, json::parse_event_t /*event*/, json& parsed) noexcept { if (parsed.is_binary()) { binary_seen = true; @@ -1644,36 +1667,28 @@ { SECTION("0x5b (byte array)") { - std::vector<uint8_t> const given = {0x5b, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x61 - }; + std::vector<uint8_t> const given = {0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x61}; const json j = json::from_cbor(given); - CHECK(j == json::binary(std::vector<uint8_t> {'a'})); + CHECK(j == json::binary(std::vector<uint8_t>{'a'})); } SECTION("0x7b (string)") { - std::vector<uint8_t> const given = {0x7b, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x61 - }; + std::vector<uint8_t> const given = {0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x61}; const json j = json::from_cbor(given); CHECK(j == "a"); } SECTION("0x9b (array)") { - std::vector<uint8_t> const given = {0x9b, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0xf4 - }; + std::vector<uint8_t> const given = {0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf4}; const json j = json::from_cbor(given); CHECK(j == json::parse("[false]")); } SECTION("0xbb (map)") { - std::vector<uint8_t> const given = {0xbb, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x60, 0xf4 - }; + std::vector<uint8_t> const given = {0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x60, 0xf4}; const json j = json::from_cbor(given); CHECK(j == json::parse("{\"\": false}")); } @@ -1763,42 +1778,98 @@ SECTION("all unsupported bytes") { for (const auto byte : - { - // ? - 0x1c, 0x1d, 0x1e, 0x1f, - // ? - 0x3c, 0x3d, 0x3e, 0x3f, - // ? - 0x5c, 0x5d, 0x5e, - // ? - 0x7c, 0x7d, 0x7e, - // ? - 0x9c, 0x9d, 0x9e, - // ? - 0xbc, 0xbd, 0xbe, - // date/time - 0xc0, 0xc1, - // bignum - 0xc2, 0xc3, - // fraction - 0xc4, - // bigfloat - 0xc5, - // tagged item - 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, - // expected conversion - 0xd5, 0xd6, 0xd7, - // more tagged items - 0xd8, 0xd9, 0xda, 0xdb, - // ? - 0xdc, 0xdd, 0xde, 0xdf, - // (simple value) - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, - // undefined - 0xf7, - // simple value - 0xf8 - }) + { + // ? + 0x1c, + 0x1d, + 0x1e, + 0x1f, + // ? + 0x3c, + 0x3d, + 0x3e, + 0x3f, + // ? + 0x5c, + 0x5d, + 0x5e, + // ? + 0x7c, + 0x7d, + 0x7e, + // ? + 0x9c, + 0x9d, + 0x9e, + // ? + 0xbc, + 0xbd, + 0xbe, + // date/time + 0xc0, + 0xc1, + // bignum + 0xc2, + 0xc3, + // fraction + 0xc4, + // bigfloat + 0xc5, + // tagged item + 0xc6, + 0xc7, + 0xc8, + 0xc9, + 0xca, + 0xcb, + 0xcc, + 0xcd, + 0xce, + 0xcf, + 0xd0, + 0xd1, + 0xd2, + 0xd3, + 0xd4, + // expected conversion + 0xd5, + 0xd6, + 0xd7, + // more tagged items + 0xd8, + 0xd9, + 0xda, + 0xdb, + // ? + 0xdc, + 0xdd, + 0xde, + 0xdf, + // (simple value) + 0xe0, + 0xe1, + 0xe2, + 0xe3, + 0xe4, + 0xe5, + 0xe6, + 0xe7, + 0xe8, + 0xe9, + 0xea, + 0xeb, + 0xec, + 0xed, + 0xee, + 0xef, + 0xf0, + 0xf1, + 0xf2, + 0xf3, + // undefined + 0xf7, + // simple value + 0xf8}) { json _; CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&); @@ -1913,29 +1984,28 @@ detected. */ for (const std::string filename : - { - TEST_DATA_DIRECTORY "/cbor_regression/test01", - TEST_DATA_DIRECTORY "/cbor_regression/test02", - TEST_DATA_DIRECTORY "/cbor_regression/test03", - TEST_DATA_DIRECTORY "/cbor_regression/test04", - TEST_DATA_DIRECTORY "/cbor_regression/test05", - TEST_DATA_DIRECTORY "/cbor_regression/test06", - TEST_DATA_DIRECTORY "/cbor_regression/test07", - TEST_DATA_DIRECTORY "/cbor_regression/test08", - TEST_DATA_DIRECTORY "/cbor_regression/test09", - TEST_DATA_DIRECTORY "/cbor_regression/test10", - TEST_DATA_DIRECTORY "/cbor_regression/test11", - TEST_DATA_DIRECTORY "/cbor_regression/test12", - TEST_DATA_DIRECTORY "/cbor_regression/test13", - TEST_DATA_DIRECTORY "/cbor_regression/test14", - TEST_DATA_DIRECTORY "/cbor_regression/test15", - TEST_DATA_DIRECTORY "/cbor_regression/test16", - TEST_DATA_DIRECTORY "/cbor_regression/test17", - TEST_DATA_DIRECTORY "/cbor_regression/test18", - TEST_DATA_DIRECTORY "/cbor_regression/test19", - TEST_DATA_DIRECTORY "/cbor_regression/test20", - TEST_DATA_DIRECTORY "/cbor_regression/test21" - }) + { + TEST_DATA_DIRECTORY "/cbor_regression/test01", + TEST_DATA_DIRECTORY "/cbor_regression/test02", + TEST_DATA_DIRECTORY "/cbor_regression/test03", + TEST_DATA_DIRECTORY "/cbor_regression/test04", + TEST_DATA_DIRECTORY "/cbor_regression/test05", + TEST_DATA_DIRECTORY "/cbor_regression/test06", + TEST_DATA_DIRECTORY "/cbor_regression/test07", + TEST_DATA_DIRECTORY "/cbor_regression/test08", + TEST_DATA_DIRECTORY "/cbor_regression/test09", + TEST_DATA_DIRECTORY "/cbor_regression/test10", + TEST_DATA_DIRECTORY "/cbor_regression/test11", + TEST_DATA_DIRECTORY "/cbor_regression/test12", + TEST_DATA_DIRECTORY "/cbor_regression/test13", + TEST_DATA_DIRECTORY "/cbor_regression/test14", + TEST_DATA_DIRECTORY "/cbor_regression/test15", + TEST_DATA_DIRECTORY "/cbor_regression/test16", + TEST_DATA_DIRECTORY "/cbor_regression/test17", + TEST_DATA_DIRECTORY "/cbor_regression/test18", + TEST_DATA_DIRECTORY "/cbor_regression/test19", + TEST_DATA_DIRECTORY "/cbor_regression/test20", + TEST_DATA_DIRECTORY "/cbor_regression/test21"}) { CAPTURE(filename) @@ -1962,7 +2032,7 @@ CHECK(false); } } - catch (const json::parse_error&) // NOLINT(bugprone-empty-catch) + catch (const json::parse_error&) // NOLINT(bugprone-empty-catch) { // parse errors are ok, because input may be random bytes } @@ -1982,7 +2052,7 @@ exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/3.json"); exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/4.json"); exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/5.json"); - exclude_packed.insert(TEST_DATA_DIRECTORY "/json_testsuite/sample.json"); // kills AppVeyor + exclude_packed.insert(TEST_DATA_DIRECTORY "/json_testsuite/sample.json"); // kills AppVeyor exclude_packed.insert(TEST_DATA_DIRECTORY "/json_tests/pass1.json"); exclude_packed.insert(TEST_DATA_DIRECTORY "/regression/working_file.json"); exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json"); @@ -1990,153 +2060,152 @@ exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json"); for (const std::string filename : - { - TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json", - TEST_DATA_DIRECTORY "/json.org/1.json", - TEST_DATA_DIRECTORY "/json.org/2.json", - TEST_DATA_DIRECTORY "/json.org/3.json", - TEST_DATA_DIRECTORY "/json.org/4.json", - TEST_DATA_DIRECTORY "/json.org/5.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json", - TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor - TEST_DATA_DIRECTORY "/json_tests/pass1.json", - TEST_DATA_DIRECTORY "/json_tests/pass2.json", - TEST_DATA_DIRECTORY "/json_tests/pass3.json", - TEST_DATA_DIRECTORY "/regression/floats.json", - TEST_DATA_DIRECTORY "/regression/signed_ints.json", - TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", - TEST_DATA_DIRECTORY "/regression/working_file.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json", - // TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json" - }) + { + TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json", + TEST_DATA_DIRECTORY "/json.org/1.json", + TEST_DATA_DIRECTORY "/json.org/2.json", + TEST_DATA_DIRECTORY "/json.org/3.json", + TEST_DATA_DIRECTORY "/json.org/4.json", + TEST_DATA_DIRECTORY "/json.org/5.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json", + TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor + TEST_DATA_DIRECTORY "/json_tests/pass1.json", + TEST_DATA_DIRECTORY "/json_tests/pass2.json", + TEST_DATA_DIRECTORY "/json_tests/pass3.json", + TEST_DATA_DIRECTORY "/regression/floats.json", + TEST_DATA_DIRECTORY "/regression/signed_ints.json", + TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", + TEST_DATA_DIRECTORY "/regression/working_file.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json", + // TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"}) { CAPTURE(filename) @@ -2213,47 +2282,101 @@ { // these bytes will fail immediately with exception parse_error.112 std::set<uint8_t> unsupported = - { - //// types not supported by this library + { + //// types not supported by this library - // date/time - 0xc0, 0xc1, - // bignum - 0xc2, 0xc3, - // decimal fracion - 0xc4, - // bigfloat - 0xc5, - // tagged item - 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, - 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd8, - 0xd9, 0xda, 0xdb, - // expected conversion - 0xd5, 0xd6, 0xd7, - // simple value - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, - 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xef, 0xf0, - 0xf1, 0xf2, 0xf3, - 0xf8, - // undefined - 0xf7, + // date/time + 0xc0, + 0xc1, + // bignum + 0xc2, + 0xc3, + // decimal fracion + 0xc4, + // bigfloat + 0xc5, + // tagged item + 0xc6, + 0xc7, + 0xc8, + 0xc9, + 0xca, + 0xcb, + 0xcc, + 0xcd, + 0xce, + 0xcf, + 0xd0, + 0xd1, + 0xd2, + 0xd3, + 0xd4, + 0xd8, + 0xd9, + 0xda, + 0xdb, + // expected conversion + 0xd5, + 0xd6, + 0xd7, + // simple value + 0xe0, + 0xe1, + 0xe2, + 0xe3, + 0xe4, + 0xe5, + 0xe6, + 0xe7, + 0xe8, + 0xe9, + 0xea, + 0xeb, + 0xec, + 0xed, + 0xef, + 0xf0, + 0xf1, + 0xf2, + 0xf3, + 0xf8, + // undefined + 0xf7, - //// bytes not specified by CBOR + //// bytes not specified by CBOR - 0x1c, 0x1d, 0x1e, 0x1f, - 0x3c, 0x3d, 0x3e, 0x3f, - 0x5c, 0x5d, 0x5e, - 0x7c, 0x7d, 0x7e, - 0x9c, 0x9d, 0x9e, - 0xbc, 0xbd, 0xbe, - 0xdc, 0xdd, 0xde, 0xdf, - 0xee, - 0xfc, 0xfe, 0xfd, + 0x1c, + 0x1d, + 0x1e, + 0x1f, + 0x3c, + 0x3d, + 0x3e, + 0x3f, + 0x5c, + 0x5d, + 0x5e, + 0x7c, + 0x7d, + 0x7e, + 0x9c, + 0x9d, + 0x9e, + 0xbc, + 0xbd, + 0xbe, + 0xdc, + 0xdd, + 0xde, + 0xdf, + 0xee, + 0xfc, + 0xfe, + 0xfd, - /// break cannot be the first byte + /// break cannot be the first byte - 0xff - }; + 0xff}; for (auto i = 0; i < 256; ++i) { @@ -2435,21 +2558,21 @@ CHECK(j == json::binary(expected)); // 0xd8 - CHECK(json::to_cbor(json::binary(std::vector<uint8_t> {}, 0x42)) == std::vector<uint8_t> {0xd8, 0x42, 0x40}); - CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 0x42)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); - CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 0x42)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 0x42); + CHECK(json::to_cbor(json::binary(std::vector<uint8_t>{}, 0x42)) == std::vector<uint8_t>{0xd8, 0x42, 0x40}); + CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t>{}, 0x42)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); + CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t>{}, 0x42)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 0x42); // 0xd9 - CHECK(json::to_cbor(json::binary(std::vector<uint8_t> {}, 1000)) == std::vector<uint8_t> {0xd9, 0x03, 0xe8, 0x40}); - CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 1000)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); - CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 1000)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 1000); + CHECK(json::to_cbor(json::binary(std::vector<uint8_t>{}, 1000)) == std::vector<uint8_t>{0xd9, 0x03, 0xe8, 0x40}); + CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t>{}, 1000)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); + CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t>{}, 1000)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 1000); // 0xda - CHECK(json::to_cbor(json::binary(std::vector<uint8_t> {}, 394216)) == std::vector<uint8_t> {0xda, 0x00, 0x06, 0x03, 0xe8, 0x40}); - CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 394216)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); - CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 394216)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 394216); + CHECK(json::to_cbor(json::binary(std::vector<uint8_t>{}, 394216)) == std::vector<uint8_t>{0xda, 0x00, 0x06, 0x03, 0xe8, 0x40}); + CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t>{}, 394216)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); + CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t>{}, 394216)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 394216); // 0xdb - CHECK(json::to_cbor(json::binary(std::vector<uint8_t> {}, 8589934590)) == std::vector<uint8_t> {0xdb, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x40}); - CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 8589934590)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); - CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 8589934590)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 8589934590); + CHECK(json::to_cbor(json::binary(std::vector<uint8_t>{}, 8589934590)) == std::vector<uint8_t>{0xdb, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x40}); + CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t>{}, 8589934590)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); + CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t>{}, 8589934590)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 8589934590); } SECTION("arrays") @@ -2503,10 +2626,22 @@ SECTION("0xC6..0xD4") { - for (const auto b : std::vector<std::uint8_t> - { - 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4 - }) + for (const auto b : std::vector<std::uint8_t>{ + 0xC6, + 0xC7, + 0xC8, + 0xC9, + 0xCA, + 0xCB, + 0xCC, + 0xCD, + 0xCE, + 0xCF, + 0xD0, + 0xD1, + 0xD2, + 0xD3, + 0xD4}) { CAPTURE(b); @@ -2534,8 +2669,8 @@ { // add tag to value auto v_tagged = v; - v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte - v_tagged.insert(v_tagged.begin(), 0xD8); // tag + v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte + v_tagged.insert(v_tagged.begin(), 0xD8); // tag // check that parsing fails in error mode json _; @@ -2551,7 +2686,7 @@ { // add tag to value auto v_tagged = v; - v_tagged.insert(v_tagged.begin(), 0xD8); // tag + v_tagged.insert(v_tagged.begin(), 0xD8); // tag // check that parsing fails in all modes json _; @@ -2567,9 +2702,9 @@ { // add tag to value auto v_tagged = v; - v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte - v_tagged.insert(v_tagged.begin(), 0xD9); // tag + v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte + v_tagged.insert(v_tagged.begin(), 0xD9); // tag // check that parsing fails in error mode json _; @@ -2585,8 +2720,8 @@ { // add tag to value auto v_tagged = v; - v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte - v_tagged.insert(v_tagged.begin(), 0xD9); // tag + v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte + v_tagged.insert(v_tagged.begin(), 0xD9); // tag // check that parsing fails in all modes json _; @@ -2602,11 +2737,11 @@ { // add tag to value auto v_tagged = v; - v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte - v_tagged.insert(v_tagged.begin(), 0xDA); // tag + v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte + v_tagged.insert(v_tagged.begin(), 0xDA); // tag // check that parsing fails in error mode json _; @@ -2622,10 +2757,10 @@ { // add tag to value auto v_tagged = v; - v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte - v_tagged.insert(v_tagged.begin(), 0xDA); // tag + v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte + v_tagged.insert(v_tagged.begin(), 0xDA); // tag // check that parsing fails in all modes json _; @@ -2641,15 +2776,15 @@ { // add tag to value auto v_tagged = v; - v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte - v_tagged.insert(v_tagged.begin(), 0xDB); // tag + v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte + v_tagged.insert(v_tagged.begin(), 0xDB); // tag // check that parsing fails in error mode json _; @@ -2665,14 +2800,14 @@ { // add tag to value auto v_tagged = v; - v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte - v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte - v_tagged.insert(v_tagged.begin(), 0xDB); // tag + v_tagged.insert(v_tagged.begin(), 0x42); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x23); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x22); // 1 byte + v_tagged.insert(v_tagged.begin(), 0x11); // 1 byte + v_tagged.insert(v_tagged.begin(), 0xDB); // tag // check that parsing fails in all modes json _; @@ -2690,7 +2825,7 @@ // convert to CBOR const auto vec = json::to_cbor(j_binary); - CHECK(vec == std::vector<std::uint8_t> {0xA1, 0x66, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79, 0xD8, 0x2A, 0x44, 0xCA, 0xFE, 0xBA, 0xBE}); + CHECK(vec == std::vector<std::uint8_t>{0xA1, 0x66, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79, 0xD8, 0x2A, 0x44, 0xCA, 0xFE, 0xBA, 0xBE}); // parse error when parsing tagged value json _;
diff --git a/tests/src/unit-class_const_iterator.cpp b/tests/src/unit-class_const_iterator.cpp index 003ce88..d94e520 100644 --- a/tests/src/unit-class_const_iterator.cpp +++ b/tests/src/unit-class_const_iterator.cpp
@@ -49,7 +49,7 @@ { SECTION("create from uninitialized iterator") { - const json::iterator it {}; + const json::iterator it{}; json::const_iterator const cit(it); }
diff --git a/tests/src/unit-class_iterator.cpp b/tests/src/unit-class_iterator.cpp index 296ffa3..1e8342e 100644 --- a/tests/src/unit-class_iterator.cpp +++ b/tests/src/unit-class_iterator.cpp
@@ -387,18 +387,18 @@ SECTION("primitive_iterator_t") { using Iter = nlohmann::detail::primitive_iterator_t; - CHECK(std::is_same < decltype(std::declval<Iter&>()++), Iter >::value); + CHECK(std::is_same<decltype(std::declval<Iter&>()++), Iter>::value); } SECTION("iter_impl") { using Iter = nlohmann::detail::iter_impl<json>; - CHECK(std::is_same < decltype(std::declval<Iter&>()++), Iter >::value); + CHECK(std::is_same<decltype(std::declval<Iter&>()++), Iter>::value); } SECTION("json_reverse_iterator") { using Base = nlohmann::detail::iter_impl<json>; using Iter = nlohmann::detail::json_reverse_iterator<Base>; - CHECK(std::is_same < decltype(std::declval<Iter&>()++), Iter >::value); + CHECK(std::is_same<decltype(std::declval<Iter&>()++), Iter>::value); } } SECTION("post-decrement") @@ -406,18 +406,18 @@ SECTION("primitive_iterator_t") { using Iter = nlohmann::detail::primitive_iterator_t; - CHECK(std::is_same < decltype(std::declval<Iter&>()--), Iter >::value); + CHECK(std::is_same<decltype(std::declval<Iter&>()--), Iter>::value); } SECTION("iter_impl") { using Iter = nlohmann::detail::iter_impl<json>; - CHECK(std::is_same < decltype(std::declval<Iter&>()--), Iter >::value ); + CHECK(std::is_same<decltype(std::declval<Iter&>()--), Iter>::value); } SECTION("json_reverse_iterator") { using Base = nlohmann::detail::iter_impl<json>; using Iter = nlohmann::detail::json_reverse_iterator<Base>; - CHECK(std::is_same < decltype(std::declval<Iter&>()--), Iter >::value ); + CHECK(std::is_same<decltype(std::declval<Iter&>()--), Iter>::value); } } } @@ -462,7 +462,6 @@ using Iter = nlohmann::detail::json_reverse_iterator<Base>; CHECK_FALSE(is_detected<can_post_decrement_temporary, Iter&>::value); } - } } }
diff --git a/tests/src/unit-class_lexer.cpp b/tests/src/unit-class_lexer.cpp index ac02925..5fb4357 100644 --- a/tests/src/unit-class_lexer.cpp +++ b/tests/src/unit-class_lexer.cpp
@@ -12,22 +12,21 @@ #include <nlohmann/json.hpp> using nlohmann::json; -namespace -{ +namespace { // shortcut to scan a string literal json::lexer::token_type scan_string(const char* s, bool ignore_comments = false); json::lexer::token_type scan_string(const char* s, const bool ignore_comments) { auto ia = nlohmann::detail::input_adapter(s); - return nlohmann::detail::lexer<json, decltype(ia)>(std::move(ia), ignore_comments).scan(); // NOLINT(hicpp-move-const-arg,performance-move-const-arg) + return nlohmann::detail::lexer<json, decltype(ia)>(std::move(ia), ignore_comments).scan(); // NOLINT(hicpp-move-const-arg,performance-move-const-arg) } -} // namespace +} // namespace std::string get_error_message(const char* s, bool ignore_comments = false); std::string get_error_message(const char* s, const bool ignore_comments) { auto ia = nlohmann::detail::input_adapter(s); - auto lexer = nlohmann::detail::lexer<json, decltype(ia)>(std::move(ia), ignore_comments); // NOLINT(hicpp-move-const-arg,performance-move-const-arg) + auto lexer = nlohmann::detail::lexer<json, decltype(ia)>(std::move(ia), ignore_comments); // NOLINT(hicpp-move-const-arg,performance-move-const-arg) lexer.scan(); return lexer.get_error_message(); }
diff --git a/tests/src/unit-class_parser.cpp b/tests/src/unit-class_parser.cpp index f766842..d47f9d1 100644 --- a/tests/src/unit-class_parser.cpp +++ b/tests/src/unit-class_parser.cpp
@@ -12,13 +12,12 @@ #include <nlohmann/json.hpp> using nlohmann::json; #ifdef JSON_TEST_NO_GLOBAL_UDLS - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) +using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif #include <valarray> -namespace -{ +namespace { class SaxEventLogger { public: @@ -124,14 +123,15 @@ return false; } - std::vector<std::string> events {}; + std::vector<std::string> events{}; bool errored = false; }; class SaxCountdown : public nlohmann::json::json_sax_t { public: - explicit SaxCountdown(const int count) : events_left(count) + explicit SaxCountdown(const int count) + : events_left(count) {} bool null() override @@ -249,8 +249,7 @@ CHECK(json::parser(nlohmann::detail::input_adapter(s)).accept(false) == !el.errored); // 5. parse with simple callback - json::parser_callback_t const cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/) noexcept - { + json::parser_callback_t const cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/) noexcept { return true; }; json const j_cb = json::parse(s, cb, false); @@ -302,7 +301,7 @@ } } -} // namespace +} // namespace TEST_CASE("parser class") { @@ -369,7 +368,7 @@ CHECK_THROWS_AS(parser_helper("\uFF01"), json::parse_error&); CHECK_THROWS_AS(parser_helper("[-4:1,]"), json::parse_error&); // unescaped control characters - CHECK_THROWS_WITH_AS(parser_helper("\"\x00\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: missing closing quote; last read: '\"'", json::parse_error&); // NOLINT(bugprone-string-literal-with-embedded-nul) + CHECK_THROWS_WITH_AS(parser_helper("\"\x00\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: missing closing quote; last read: '\"'", json::parse_error&); // NOLINT(bugprone-string-literal-with-embedded-nul) CHECK_THROWS_WITH_AS(parser_helper("\"\x01\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0001 (SOH) must be escaped to \\u0001; last read: '\"<U+0001>'", json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("\"\x02\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0002 (STX) must be escaped to \\u0002; last read: '\"<U+0002>'", json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("\"\x03\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0003 (ETX) must be escaped to \\u0003; last read: '\"<U+0003>'", json::parse_error&); @@ -592,39 +591,56 @@ CHECK_THROWS_AS(parser_helper("+0"), json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("01"), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - unexpected number literal; expected end of input", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - unexpected number literal; expected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-01"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - unexpected number literal; expected end of input", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - unexpected number literal; expected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("--1"), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '--'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '--'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("1."), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '1.'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '1.'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("1E"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("1E-"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '1E-'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '1E-'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("1.E1"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '1.E'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '1.E'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-1E"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '-1E'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '-1E'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-0E#"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '-0E#'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '-0E#'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-0E-#"), - "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '-0E-#'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '-0E-#'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-0#"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: '-0#'; expected end of input", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: '-0#'; expected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-0.0:"), - "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - unexpected ':'; expected end of input", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - unexpected ':'; expected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-0.0Z"), - "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: '-0.0Z'; expected end of input", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: '-0.0Z'; expected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-0E123:"), - "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - unexpected ':'; expected end of input", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - unexpected ':'; expected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-0e0-:"), - "[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-:'; expected end of input", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-:'; expected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-0e-:"), - "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '-0e-:'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '-0e-:'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-0f"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: '-0f'; expected end of input", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: '-0f'; expected end of input", + json::parse_error&); } } } @@ -692,7 +708,7 @@ CHECK(accept_helper("\uFF01") == false); CHECK(accept_helper("[-4:1,]") == false); // unescaped control characters - CHECK(accept_helper("\"\x00\"") == false); // NOLINT(bugprone-string-literal-with-embedded-nul) + CHECK(accept_helper("\"\x00\"") == false); // NOLINT(bugprone-string-literal-with-embedded-nul) CHECK(accept_helper("\"\x01\"") == false); CHECK(accept_helper("\"\x02\"") == false); CHECK(accept_helper("\"\x03\"") == false); @@ -895,119 +911,170 @@ { // unexpected end of number CHECK_THROWS_WITH_AS(parser_helper("0."), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '0.'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '0.'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-"), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("--"), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '--'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '--'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-0."), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected digit after '.'; last read: '-0.'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected digit after '.'; last read: '-0.'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-."), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-.'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-.'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("-:"), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-:'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-:'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("0.:"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '0.:'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '0.:'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("e."), - "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'e'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'e'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("1e."), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e.'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e.'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("1e/"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e/'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e/'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("1e:"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e:'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e:'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("1E."), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E.'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E.'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("1E/"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E/'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E/'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("1E:"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E:'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E:'", + json::parse_error&); // unexpected end of null CHECK_THROWS_WITH_AS(parser_helper("n"), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 'n'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 'n'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("nu"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'nu'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'nu'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("nul"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nul'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nul'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("nulk"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nulk'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nulk'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("nulm"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nulm'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nulm'", + json::parse_error&); // unexpected end of true CHECK_THROWS_WITH_AS(parser_helper("t"), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 't'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 't'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("tr"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'tr'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'tr'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("tru"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'tru'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'tru'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("trud"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'trud'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'trud'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("truf"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'truf'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'truf'", + json::parse_error&); // unexpected end of false CHECK_THROWS_WITH_AS(parser_helper("f"), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 'f'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 'f'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("fa"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'fa'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'fa'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("fal"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'fal'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'fal'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("fals"), - "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'fals'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'fals'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("falsd"), - "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'falsd'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'falsd'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("falsf"), - "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'falsf'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'falsf'", + json::parse_error&); // missing/unexpected end of array CHECK_THROWS_WITH_AS(parser_helper("["), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("[1"), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing array - unexpected end of input; expected ']'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing array - unexpected end of input; expected ']'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("[1,"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("[1,]"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("]"), - "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal", + json::parse_error&); // missing/unexpected end of object CHECK_THROWS_WITH_AS(parser_helper("{"), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - unexpected end of input; expected string literal", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - unexpected end of input; expected string literal", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("{\"foo\""), - "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing object separator - unexpected end of input; expected ':'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing object separator - unexpected end of input; expected ':'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("{\"foo\":"), - "[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("{\"foo\":}"), - "[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected '}'; expected '[', '{', or a literal", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected '}'; expected '[', '{', or a literal", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("{\"foo\":1,}"), - "[json.exception.parse_error.101] parse error at line 1, column 10: syntax error while parsing object key - unexpected '}'; expected string literal", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 10: syntax error while parsing object key - unexpected '}'; expected string literal", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("}"), - "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected '}'; expected '[', '{', or a literal", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected '}'; expected '[', '{', or a literal", + json::parse_error&); // missing/unexpected end of string CHECK_THROWS_WITH_AS(parser_helper("\""), - "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: missing closing quote; last read: '\"'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: missing closing quote; last read: '\"'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("\"\\\""), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: missing closing quote; last read: '\"\\\"'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: missing closing quote; last read: '\"\\\"'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("\"\\u\""), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u\"'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u\"'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("\"\\u0\""), - "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u0\"'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u0\"'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("\"\\u01\""), - "[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u01\"'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u01\"'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("\"\\u012\""), - "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u012\"'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u012\"'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("\"\\u"), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("\"\\u0"), - "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u0'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u0'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("\"\\u01"), - "[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u01'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u01'", + json::parse_error&); CHECK_THROWS_WITH_AS(parser_helper("\"\\u012"), - "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u012'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\u012'", + json::parse_error&); // invalid escapes for (int c = 1; c < 128; ++c) @@ -1054,8 +1121,7 @@ // invalid \uxxxx escapes { // check whether character is a valid hex character - const auto valid = [](int c) - { + const auto valid = [](int c) { switch (c) { case ('0'): @@ -1159,11 +1225,14 @@ CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD80C\""), "[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\"'", json::parse_error&); // invalid surrogate pair CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD80C\\uD80C\""), - "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uD80C'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uD80C'", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD80C\\u0000\""), - "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\u0000'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\u0000'", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD80C\\uFFFF\""), - "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uFFFF'", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uFFFF'", + json::parse_error&); } SECTION("parse errors (accept)") @@ -1269,8 +1338,7 @@ // invalid \uxxxx escapes { // check whether character is a valid hex character - const auto valid = [](int c) - { + const auto valid = [](int c) { switch (c) { case ('0'): @@ -1361,8 +1429,7 @@ // test case to make sure the callback is properly evaluated after reading a key { - json::parser_callback_t const cb = [](int /*unused*/, json::parse_event_t event, json& /*unused*/) noexcept - { + json::parser_callback_t const cb = [](int /*unused*/, json::parse_event_t event, json& /*unused*/) noexcept { return event != json::parse_event_t::key; }; @@ -1400,77 +1467,69 @@ SECTION("filter nothing") { - json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept - { + json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return true; }); - CHECK (j_object == json({{"foo", 2}, {"bar", {{"baz", 1}}}})); + CHECK(j_object == json({{"foo", 2}, {"bar", {{"baz", 1}}}})); - json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept - { + json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return true; }); - CHECK (j_array == json({1, 2, {3, 4, 5}, 4, 5})); + CHECK(j_array == json({1, 2, {3, 4, 5}, 4, 5})); } SECTION("filter everything") { - json const j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept - { + json const j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return false; }); // the top-level object will be discarded, leaving a null - CHECK (j_object.is_null()); + CHECK(j_object.is_null()); - json const j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept - { + json const j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return false; }); // the top-level array will be discarded, leaving a null - CHECK (j_array.is_null()); + CHECK(j_array.is_null()); } SECTION("filter specific element") { - json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t event, const json & j) noexcept - { + json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t event, const json& j) noexcept { // filter all number(2) elements return event != json::parse_event_t::value || j != json(2); }); - CHECK (j_object == json({{"bar", {{"baz", 1}}}})); + CHECK(j_object == json({{"bar", {{"baz", 1}}}})); - json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t event, const json & j) noexcept - { + json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t event, const json& j) noexcept { return event != json::parse_event_t::value || j != json(2); }); - CHECK (j_array == json({1, {3, 4, 5}, 4, 5})); + CHECK(j_array == json({1, {3, 4, 5}, 4, 5})); } SECTION("filter object in array") { - json j_filtered1 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json & parsed) - { + json j_filtered1 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& parsed) { return !(e == json::parse_event_t::object_end && parsed.contains("foo")); }); // the specified object will be discarded, and removed. - CHECK (j_filtered1.size() == 2); - CHECK (j_filtered1 == json({1, {{"qux", "baz"}}})); + CHECK(j_filtered1.size() == 2); + CHECK(j_filtered1 == json({1, {{"qux", "baz"}}})); - json j_filtered2 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& /*parsed*/) noexcept - { + json j_filtered2 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& /*parsed*/) noexcept { return e != json::parse_event_t::object_end; }); // removed all objects in array. - CHECK (j_filtered2.size() == 1); - CHECK (j_filtered2 == json({1})); + CHECK(j_filtered2.size() == 1); + CHECK(j_filtered2 == json({1})); } SECTION("filter specific events") @@ -1478,8 +1537,7 @@ SECTION("first closing event") { { - json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept - { + json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { static bool first = true; if (e == json::parse_event_t::object_end && first) { @@ -1491,12 +1549,11 @@ }); // the first completed object will be discarded - CHECK (j_object == json({{"foo", 2}})); + CHECK(j_object == json({{"foo", 2}})); } { - json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept - { + json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { static bool first = true; if (e == json::parse_event_t::array_end && first) { @@ -1508,7 +1565,7 @@ }); // the first completed array will be discarded - CHECK (j_array == json({1, 2, 4, 5})); + CHECK(j_array == json({1, 2, 4, 5})); } } } @@ -1519,14 +1576,12 @@ // object and array is discarded only after the closing character // has been read - json j_empty_object = json::parse("{}", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept - { + json j_empty_object = json::parse("{}", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { return e != json::parse_event_t::object_end; }); CHECK(j_empty_object == json()); - json j_empty_array = json::parse("[]", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept - { + json j_empty_array = json::parse("[]", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { return e != json::parse_event_t::array_end; }); CHECK(j_empty_array == json()); @@ -1545,7 +1600,7 @@ SECTION("from std::array") { - std::array<uint8_t, 5> v { {'t', 'r', 'u', 'e'} }; + std::array<uint8_t, 5> v{{'t', 'r', 'u', 'e'}}; json j; json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j); CHECK(j == json(true)); @@ -1553,7 +1608,7 @@ SECTION("from array") { - uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) json j; json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j); CHECK(j == json(true)); @@ -1593,8 +1648,7 @@ { SECTION("parser with callback") { - json::parser_callback_t const cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/) noexcept - { + json::parser_callback_t const cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/) noexcept { return true; };
diff --git a/tests/src/unit-comparison.cpp b/tests/src/unit-comparison.cpp index 7df2048..73a1361 100644 --- a/tests/src/unit-comparison.cpp +++ b/tests/src/unit-comparison.cpp
@@ -21,9 +21,9 @@ #if JSON_HAS_THREE_WAY_COMPARISON // this can be replaced with the doctest stl extension header in version 2.5 -namespace doctest -{ -template<> struct StringMaker<std::partial_ordering> +namespace doctest { +template<> +struct StringMaker<std::partial_ordering> { static String convert(const std::partial_ordering& order) { @@ -46,20 +46,19 @@ return "{?}"; } }; -} // namespace doctest +} // namespace doctest #endif -namespace -{ +namespace { // helper function to check std::less<json::value_t> // see https://en.cppreference.com/w/cpp/utility/functional/less -template <typename A, typename B, typename U = std::less<json::value_t>> +template<typename A, typename B, typename U = std::less<json::value_t>> bool f(A a, B b, U u = U()) { return u(a, b); } -} // namespace +} // namespace TEST_CASE("lexicographical comparison operators") { @@ -87,33 +86,32 @@ SECTION("types") { std::vector<json::value_t> j_types = - { - json::value_t::null, - json::value_t::boolean, - json::value_t::number_integer, - json::value_t::number_unsigned, - json::value_t::number_float, - json::value_t::object, - json::value_t::array, - json::value_t::string, - json::value_t::binary, - json::value_t::discarded - }; + { + json::value_t::null, + json::value_t::boolean, + json::value_t::number_integer, + json::value_t::number_unsigned, + json::value_t::number_float, + json::value_t::object, + json::value_t::array, + json::value_t::string, + json::value_t::binary, + json::value_t::discarded}; std::vector<std::vector<bool>> expected_lt = - { - //0 1 2 3 4 5 6 7 8 9 - {f_, _t, _t, _t, _t, _t, _t, _t, _t, f_}, // 0 - {f_, f_, _t, _t, _t, _t, _t, _t, _t, f_}, // 1 - {f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 2 - {f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 3 - {f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 4 - {f_, f_, f_, f_, f_, f_, _t, _t, _t, f_}, // 5 - {f_, f_, f_, f_, f_, f_, f_, _t, _t, f_}, // 6 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, f_}, // 7 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9 - }; + { + //0 1 2 3 4 5 6 7 8 9 + {f_, _t, _t, _t, _t, _t, _t, _t, _t, f_}, // 0 + {f_, f_, _t, _t, _t, _t, _t, _t, _t, f_}, // 1 + {f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 2 + {f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 3 + {f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 4 + {f_, f_, f_, f_, f_, f_, _t, _t, _t, f_}, // 5 + {f_, f_, f_, f_, f_, f_, f_, _t, _t, f_}, // 6 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, f_}, // 7 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9 + }; SECTION("comparison: less") { @@ -141,19 +139,19 @@ SECTION("comparison: 3-way") { std::vector<std::vector<std::partial_ordering>> expected = - { - //0 1 2 3 4 5 6 7 8 9 - {eq, lt, lt, lt, lt, lt, lt, lt, lt, un}, // 0 - {gt, eq, lt, lt, lt, lt, lt, lt, lt, un}, // 1 - {gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 2 - {gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 3 - {gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 4 - {gt, gt, gt, gt, gt, eq, lt, lt, lt, un}, // 5 - {gt, gt, gt, gt, gt, gt, eq, lt, lt, un}, // 6 - {gt, gt, gt, gt, gt, gt, gt, eq, lt, un}, // 7 - {gt, gt, gt, gt, gt, gt, gt, gt, eq, un}, // 8 - {un, un, un, un, un, un, un, un, un, un}, // 9 - }; + { + //0 1 2 3 4 5 6 7 8 9 + {eq, lt, lt, lt, lt, lt, lt, lt, lt, un}, // 0 + {gt, eq, lt, lt, lt, lt, lt, lt, lt, un}, // 1 + {gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 2 + {gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 3 + {gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 4 + {gt, gt, gt, gt, gt, eq, lt, lt, lt, un}, // 5 + {gt, gt, gt, gt, gt, gt, eq, lt, lt, un}, // 6 + {gt, gt, gt, gt, gt, gt, gt, eq, lt, un}, // 7 + {gt, gt, gt, gt, gt, gt, gt, gt, eq, un}, // 8 + {un, un, un, un, un, un, un, un, un, un}, // 9 + }; // check expected partial_ordering against expected boolean REQUIRE(expected.size() == expected_lt.size()); @@ -177,7 +175,7 @@ { CAPTURE(i) CAPTURE(j) - CHECK((j_types[i] <=> j_types[j]) == expected[i][j]); // *NOPAD* + CHECK((j_types[i] <= > j_types[j]) == expected[i][j]); // *NOPAD* } } } @@ -187,102 +185,113 @@ SECTION("values") { json j_values = - { - nullptr, nullptr, // 0 1 - -17, 42, // 2 3 - 8u, 13u, // 4 5 - 3.14159, 23.42, // 6 7 - nan, nan, // 8 9 - "foo", "bar", // 10 11 - true, false, // 12 13 - {1, 2, 3}, {"one", "two", "three"}, // 14 15 - {{"first", 1}, {"second", 2}}, {{"a", "A"}, {"b", {"B"}}}, // 16 17 - json::binary({1, 2, 3}), json::binary({1, 2, 4}), // 18 19 - json(json::value_t::discarded), json(json::value_t::discarded) // 20 21 - }; + { + nullptr, + nullptr, // 0 1 + -17, + 42, // 2 3 + 8u, + 13u, // 4 5 + 3.14159, + 23.42, // 6 7 + nan, + nan, // 8 9 + "foo", + "bar", // 10 11 + true, + false, // 12 13 + {1, 2, 3}, + {"one", "two", "three"}, // 14 15 + {{"first", 1}, {"second", 2}}, + {{"a", "A"}, {"b", {"B"}}}, // 16 17 + json::binary({1, 2, 3}), + json::binary({1, 2, 4}), // 18 19 + json(json::value_t::discarded), + json(json::value_t::discarded) // 20 21 + }; std::vector<std::vector<bool>> expected_eq = - { - //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 - {_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0 - {_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1 - {f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2 - {f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3 - {f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4 - {f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5 - {f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6 - {f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_}, // 13 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_}, // 14 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_}, // 15 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_}, // 16 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_}, // 17 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_}, // 18 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 19 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21 - }; + { + //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 + {_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0 + {_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1 + {f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2 + {f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3 + {f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4 + {f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5 + {f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6 + {f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_}, // 13 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_}, // 14 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_}, // 15 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_}, // 16 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_}, // 17 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_}, // 18 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 19 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21 + }; std::vector<std::vector<bool>> expected_lt = - { - //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 - {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 0 - {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 1 - {f_, f_, f_, _t, _t, _t, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 2 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 3 - {f_, f_, f_, _t, f_, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 4 - {f_, f_, f_, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 5 - {f_, f_, f_, _t, _t, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 6 - {f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 7 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 8 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 9 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 10 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 11 - {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 12 - {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 13 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_}, // 14 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 15 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_}, // 16 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, f_, _t, _t, f_, f_}, // 17 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 18 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21 - }; + { + //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 + {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 0 + {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 1 + {f_, f_, f_, _t, _t, _t, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 2 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 3 + {f_, f_, f_, _t, f_, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 4 + {f_, f_, f_, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 5 + {f_, f_, f_, _t, _t, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 6 + {f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 7 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 8 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 9 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 10 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 11 + {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 12 + {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 13 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_}, // 14 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 15 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_}, // 16 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, f_, _t, _t, f_, f_}, // 17 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 18 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21 + }; SECTION("compares unordered") { std::vector<std::vector<bool>> expected = - { - //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 0 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 1 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 2 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 3 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 4 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 5 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 6 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 7 - {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 8 - {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 9 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 10 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 11 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 12 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 13 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 14 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 15 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 16 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 17 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 18 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 19 - {_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 20 - {_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 21 - }; + { + //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 0 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 1 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 2 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 3 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 4 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 5 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 6 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 7 + {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 8 + {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 9 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 10 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 11 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 12 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 13 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 14 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 15 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 16 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 17 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 18 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 19 + {_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 20 + {_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 21 + }; // check if two values compare unordered as expected REQUIRE(expected.size() == j_values.size()); @@ -302,31 +311,31 @@ SECTION("compares unordered (inverse)") { std::vector<std::vector<bool>> expected = - { - //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6 - {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7 - {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8 - {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 13 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 14 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 15 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 16 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 17 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 18 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20 - {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21 - }; + { + //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6 + {f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7 + {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8 + {f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 13 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 14 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 15 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 16 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 17 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 18 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20 + {f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21 + }; // check that two values compare unordered as expected (with legacy-mode enabled) REQUIRE(expected.size() == j_values.size()); @@ -497,31 +506,31 @@ SECTION("comparison: 3-way") { std::vector<std::vector<std::partial_ordering>> expected = - { - //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 - {eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 0 - {eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 1 - {gt, gt, eq, lt, lt, lt, lt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 2 - {gt, gt, gt, eq, gt, gt, gt, gt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 3 - {gt, gt, gt, lt, eq, lt, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 4 - {gt, gt, gt, lt, gt, eq, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 5 - {gt, gt, gt, lt, lt, lt, eq, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 6 - {gt, gt, gt, lt, gt, gt, gt, eq, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 7 - {gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 8 - {gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 9 - {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, gt, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 10 - {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, eq, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 11 - {gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, gt, lt, lt, lt, lt, lt, lt, un, un}, // 12 - {gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, lt, lt, lt, lt, lt, lt, un, un}, // 13 - {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, eq, lt, gt, gt, lt, lt, un, un}, // 14 - {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, gt, eq, gt, gt, lt, lt, un, un}, // 15 - {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, eq, gt, lt, lt, un, un}, // 16 - {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, lt, eq, lt, lt, un, un}, // 17 - {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, lt, un, un}, // 18 - {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, un, un}, // 19 - {un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 20 - {un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 21 - }; + { + //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 + {eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 0 + {eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 1 + {gt, gt, eq, lt, lt, lt, lt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 2 + {gt, gt, gt, eq, gt, gt, gt, gt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 3 + {gt, gt, gt, lt, eq, lt, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 4 + {gt, gt, gt, lt, gt, eq, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 5 + {gt, gt, gt, lt, lt, lt, eq, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 6 + {gt, gt, gt, lt, gt, gt, gt, eq, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 7 + {gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 8 + {gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 9 + {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, gt, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 10 + {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, eq, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 11 + {gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, gt, lt, lt, lt, lt, lt, lt, un, un}, // 12 + {gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, lt, lt, lt, lt, lt, lt, un, un}, // 13 + {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, eq, lt, gt, gt, lt, lt, un, un}, // 14 + {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, gt, eq, gt, gt, lt, lt, un, un}, // 15 + {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, eq, gt, lt, lt, un, un}, // 16 + {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, lt, eq, lt, lt, un, un}, // 17 + {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, lt, un, un}, // 18 + {gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, un, un}, // 19 + {un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 20 + {un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 21 + }; // check expected partial_ordering against expected booleans REQUIRE(expected.size() == expected_eq.size()); @@ -552,7 +561,7 @@ { CAPTURE(i) CAPTURE(j) - CHECK((j_values[i] <=> j_values[j]) == expected[i][j]); // *NOPAD* + CHECK((j_values[i] <= > j_values[j]) == expected[i][j]); // *NOPAD* } } } @@ -576,20 +585,18 @@ [1,2,[3,4,5],4,5] )"; - json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j) noexcept - { + json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& j) noexcept { // filter all number(2) elements return j != json(2); }); - CHECK (j_object == json({{"bar", {{"baz", 1}}}})); + CHECK(j_object == json({{"bar", {{"baz", 1}}}})); - json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j) noexcept - { + json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& j) noexcept { return j != json(2); }); - CHECK (j_array == json({1, {3, 4, 5}, 4, 5})); + CHECK(j_array == json({1, {3, 4, 5}, 4, 5})); } } #endif
diff --git a/tests/src/unit-concepts.cpp b/tests/src/unit-concepts.cpp index e042991..629142e 100644 --- a/tests/src/unit-concepts.cpp +++ b/tests/src/unit-concepts.cpp
@@ -130,7 +130,7 @@ SECTION("Swappable") { { - json j {1, 2, 3}; + json j{1, 2, 3}; json::iterator it1 = j.begin(); json::iterator it2 = j.end(); swap(it1, it2); @@ -138,7 +138,7 @@ CHECK(it2 == j.begin()); } { - json j {1, 2, 3}; + json j{1, 2, 3}; json::const_iterator it1 = j.cbegin(); json::const_iterator it2 = j.cend(); swap(it1, it2);
diff --git a/tests/src/unit-constructor1.cpp b/tests/src/unit-constructor1.cpp index bbd5760..b8ebdb6 100644 --- a/tests/src/unit-constructor1.cpp +++ b/tests/src/unit-constructor1.cpp
@@ -131,7 +131,7 @@ SECTION("filled object") { - json::object_t const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + json::object_t const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; json const j(o); CHECK(j.type() == json::value_t::object); } @@ -140,12 +140,12 @@ SECTION("create an object (implicit)") { // reference object - json::object_t const o_reference {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + json::object_t const o_reference{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; json const j_reference(o_reference); SECTION("std::map<json::string_t, json>") { - std::map<json::string_t, json> const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + std::map<json::string_t, json> const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; json const j(o); CHECK(j.type() == json::value_t::object); CHECK(j == j_reference); @@ -153,8 +153,7 @@ SECTION("std::map<std::string, std::string> #600") { - const std::map<std::string, std::string> m - { + const std::map<std::string, std::string> m{ {"a", "b"}, {"c", "d"}, {"e", "f"}, @@ -166,7 +165,7 @@ SECTION("std::map<const char*, json>") { - std::map<const char*, json> const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + std::map<const char*, json> const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; json const j(o); CHECK(j.type() == json::value_t::object); CHECK(j == j_reference); @@ -174,7 +173,7 @@ SECTION("std::multimap<json::string_t, json>") { - std::multimap<json::string_t, json> const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + std::multimap<json::string_t, json> const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; json const j(o); CHECK(j.type() == json::value_t::object); CHECK(j == j_reference); @@ -182,7 +181,7 @@ SECTION("std::unordered_map<json::string_t, json>") { - std::unordered_map<json::string_t, json> const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + std::unordered_map<json::string_t, json> const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; json const j(o); CHECK(j.type() == json::value_t::object); CHECK(j == j_reference); @@ -190,7 +189,7 @@ SECTION("std::unordered_multimap<json::string_t, json>") { - std::unordered_multimap<json::string_t, json> const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + std::unordered_multimap<json::string_t, json> const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; json const j(o); CHECK(j.type() == json::value_t::object); CHECK(j == j_reference); @@ -215,7 +214,7 @@ SECTION("filled array") { - json::array_t const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + json::array_t const a{json(1), json(1u), json(2.2), json(false), json("string"), json()}; json const j(a); CHECK(j.type() == json::value_t::array); } @@ -224,12 +223,12 @@ SECTION("create an array (implicit)") { // reference array - json::array_t const a_reference {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + json::array_t const a_reference{json(1), json(1u), json(2.2), json(false), json("string"), json()}; json const j_reference(a_reference); SECTION("std::list<json>") { - std::list<json> const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + std::list<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()}; json const j(a); CHECK(j.type() == json::value_t::array); CHECK(j == j_reference); @@ -258,7 +257,7 @@ SECTION("std::tuple") { - const auto t = std::make_tuple(1.0, std::string{"string"}, 42, std::vector<int> {0, 1}); + const auto t = std::make_tuple(1.0, std::string{"string"}, 42, std::vector<int>{0, 1}); json const j(t); CHECK(j.type() == json::value_t::array); @@ -292,7 +291,7 @@ SECTION("std::forward_list<json>") { - std::forward_list<json> const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + std::forward_list<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()}; json const j(a); CHECK(j.type() == json::value_t::array); CHECK(j == j_reference); @@ -300,7 +299,7 @@ SECTION("std::array<json, 6>") { - std::array<json, 6> const a {{json(1), json(1u), json(2.2), json(false), json("string"), json()}}; + std::array<json, 6> const a{{json(1), json(1u), json(2.2), json(false), json("string"), json()}}; json const j(a); CHECK(j.type() == json::value_t::array); CHECK(j == j_reference); @@ -341,7 +340,7 @@ SECTION("std::vector<json>") { - std::vector<json> const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + std::vector<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()}; json const j(a); CHECK(j.type() == json::value_t::array); CHECK(j == j_reference); @@ -349,7 +348,7 @@ SECTION("std::deque<json>") { - std::deque<json> const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + std::deque<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()}; json const j(a); CHECK(j.type() == json::value_t::array); CHECK(j == j_reference); @@ -357,7 +356,7 @@ SECTION("std::set<json>") { - std::set<json> const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + std::set<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()}; json const j(a); CHECK(j.type() == json::value_t::array); // we cannot really check for equality here @@ -365,7 +364,7 @@ SECTION("std::unordered_set<json>") { - std::unordered_set<json> const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + std::unordered_set<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()}; json const j(a); CHECK(j.type() == json::value_t::array); // we cannot really check for equality here @@ -390,7 +389,7 @@ SECTION("filled string") { - json::string_t const s {"Hello world"}; + json::string_t const s{"Hello world"}; json const j(s); CHECK(j.type() == json::value_t::string); } @@ -399,12 +398,12 @@ SECTION("create a string (implicit)") { // reference string - json::string_t const s_reference {"Hello world"}; + json::string_t const s_reference{"Hello world"}; json const j_reference(s_reference); SECTION("std::string") { - std::string const s {"Hello world"}; + std::string const s{"Hello world"}; json const j(s); CHECK(j.type() == json::value_t::string); CHECK(j == j_reference); @@ -412,7 +411,7 @@ SECTION("char[]") { - char const s[] {"Hello world"}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + char const s[]{"Hello world"}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) json const j(s); CHECK(j.type() == json::value_t::string); CHECK(j == j_reference); @@ -420,7 +419,7 @@ SECTION("const char*") { - const char* s {"Hello world"}; + const char* s{"Hello world"}; json const j(s); CHECK(j.type() == json::value_t::string); CHECK(j == j_reference); @@ -918,13 +917,13 @@ { SECTION("explicit") { - json const j(json::initializer_list_t {}); + json const j(json::initializer_list_t{}); CHECK(j.type() == json::value_t::object); } SECTION("implicit") { - json const j {}; + json const j{}; CHECK(j.type() == json::value_t::null); } } @@ -935,13 +934,13 @@ { SECTION("explicit") { - json const j(json::initializer_list_t {json(json::array_t())}); + json const j(json::initializer_list_t{json(json::array_t())}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json const j {json::array_t()}; + json const j{json::array_t()}; CHECK(j.type() == json::value_t::array); } } @@ -950,13 +949,13 @@ { SECTION("explicit") { - json const j(json::initializer_list_t {json(json::object_t())}); + json const j(json::initializer_list_t{json(json::object_t())}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json const j {json::object_t()}; + json const j{json::object_t()}; CHECK(j.type() == json::value_t::array); } } @@ -965,13 +964,13 @@ { SECTION("explicit") { - json const j(json::initializer_list_t {json("Hello world")}); + json const j(json::initializer_list_t{json("Hello world")}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json const j {"Hello world"}; + json const j{"Hello world"}; CHECK(j.type() == json::value_t::array); } } @@ -980,13 +979,13 @@ { SECTION("explicit") { - json const j(json::initializer_list_t {json(true)}); + json const j(json::initializer_list_t{json(true)}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json const j {true}; + json const j{true}; CHECK(j.type() == json::value_t::array); } } @@ -995,13 +994,13 @@ { SECTION("explicit") { - json const j(json::initializer_list_t {json(1)}); + json const j(json::initializer_list_t{json(1)}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json const j {1}; + json const j{1}; CHECK(j.type() == json::value_t::array); } } @@ -1010,13 +1009,13 @@ { SECTION("explicit") { - json const j(json::initializer_list_t {json(1u)}); + json const j(json::initializer_list_t{json(1u)}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json const j {1u}; + json const j{1u}; CHECK(j.type() == json::value_t::array); } } @@ -1025,13 +1024,13 @@ { SECTION("explicit") { - json const j(json::initializer_list_t {json(42.23)}); + json const j(json::initializer_list_t{json(42.23)}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json const j {42.23}; + json const j{42.23}; CHECK(j.type() == json::value_t::array); } } @@ -1041,13 +1040,13 @@ { SECTION("explicit") { - json const j(json::initializer_list_t {1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()}); + json const j(json::initializer_list_t{1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json const j {1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()}; + json const j{1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()}; CHECK(j.type() == json::value_t::array); } } @@ -1056,13 +1055,13 @@ { SECTION("object") { - json const j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} }; + json const j{{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}}; CHECK(j.type() == json::value_t::object); } SECTION("array") { - json const j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }; + json const j{{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13}; CHECK(j.type() == json::value_t::array); } } @@ -1077,14 +1076,14 @@ SECTION("object") { - json const j = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} }); + json const j = json::object({{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}}); CHECK(j.type() == json::value_t::object); } SECTION("object with error") { json _; - CHECK_THROWS_WITH_AS(_ = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }), "[json.exception.type_error.301] cannot create object from initializer list", json::type_error&); + CHECK_THROWS_WITH_AS(_ = json::object({{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13}), "[json.exception.type_error.301] cannot create object from initializer list", json::type_error&); } SECTION("empty array") @@ -1095,7 +1094,7 @@ SECTION("array") { - json const j = json::array({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} }); + json const j = json::array({{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}}); CHECK(j.type() == json::value_t::array); } } @@ -1144,7 +1143,7 @@ { json::array_t source = {1, 2, 3}; const auto* source_addr = source.data(); - json j {std::move(source)}; + json j{std::move(source)}; const auto* target_addr = j[0].get_ref<json::array_t const&>().data(); const bool success = (target_addr == source_addr); CHECK(success); @@ -1154,7 +1153,7 @@ { json::array_t source = {1, 2, 3}; const auto* source_addr = source.data(); - json const j {{"key", std::move(source)}}; + json const j{{"key", std::move(source)}}; const auto* target_addr = j["key"].get_ref<json::array_t const&>().data(); const bool success = (target_addr == source_addr); CHECK(success); @@ -1187,7 +1186,7 @@ { json::object_t source = {{"hello", "world"}}; const json* source_addr = &source.at("hello"); - json j {std::move(source)}; + json j{std::move(source)}; CHECK(&(j[0].get_ref<json::object_t const&>().at("hello")) == source_addr); } @@ -1195,7 +1194,7 @@ { json::object_t source = {{"hello", "world"}}; const json* source_addr = &source.at("hello"); - json j {{"key", std::move(source)}}; + json j{{"key", std::move(source)}}; CHECK(&(j["key"].get_ref<json::object_t const&>().at("hello")) == source_addr); } @@ -1220,23 +1219,23 @@ { SECTION("constructor with implicit types (array)") { - json source {1, 2, 3}; + json source{1, 2, 3}; const json* source_addr = &source[0]; - json j {std::move(source), {}}; + json j{std::move(source), {}}; CHECK(&j[0][0] == source_addr); } SECTION("constructor with implicit types (object)") { - json source {1, 2, 3}; + json source{1, 2, 3}; const json* source_addr = &source[0]; - json j {{"key", std::move(source)}}; + json j{{"key", std::move(source)}}; CHECK(&j["key"][0] == source_addr); } SECTION("assignment with implicit types (array)") { - json source {1, 2, 3}; + json source{1, 2, 3}; const json* source_addr = &source[0]; json j = {std::move(source), {}}; CHECK(&j[0][0] == source_addr); @@ -1244,13 +1243,12 @@ SECTION("assignment with implicit types (object)") { - json source {1, 2, 3}; + json source{1, 2, 3}; const json* source_addr = &source[0]; json j = {{"key", std::move(source)}}; CHECK(&j["key"][0] == source_addr); } } - } }
diff --git a/tests/src/unit-constructor2.cpp b/tests/src/unit-constructor2.cpp index 85a91ff..64d308e 100644 --- a/tests/src/unit-constructor2.cpp +++ b/tests/src/unit-constructor2.cpp
@@ -17,82 +17,82 @@ { SECTION("object") { - json j {{"foo", 1}, {"bar", false}}; - json k(j); // NOLINT(performance-unnecessary-copy-initialization) + json j{{"foo", 1}, {"bar", false}}; + json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("array") { - json j {"foo", 1, 42.23, false}; - json k(j); // NOLINT(performance-unnecessary-copy-initialization) + json j{"foo", 1, 42.23, false}; + json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("null") { json j(nullptr); - json k(j); // NOLINT(performance-unnecessary-copy-initialization) + json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("boolean") { json j(true); - json k(j); // NOLINT(performance-unnecessary-copy-initialization) + json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("string") { json j("Hello world"); - json k(j); // NOLINT(performance-unnecessary-copy-initialization) + json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("number (integer)") { json j(42); - json k(j); // NOLINT(performance-unnecessary-copy-initialization) + json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("number (unsigned)") { json j(42u); - json k(j); // NOLINT(performance-unnecessary-copy-initialization) + json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("number (floating-point)") { json j(42.23); - json k(j); // NOLINT(performance-unnecessary-copy-initialization) + json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("binary") { json j = json::binary({1, 2, 3}); - json k(j); // NOLINT(performance-unnecessary-copy-initialization) + json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } } SECTION("move constructor") { - json j {{"foo", "bar"}, {"baz", {1, 2, 3, 4}}, {"a", 42u}, {"b", 42.23}, {"c", nullptr}}; + json j{{"foo", "bar"}, {"baz", {1, 2, 3, 4}}, {"a", 42u}, {"b", 42.23}, {"c", nullptr}}; CHECK(j.type() == json::value_t::object); const json k(std::move(j)); CHECK(k.type() == json::value_t::object); - CHECK(j.type() == json::value_t::null); // NOLINT: access after move is OK here + CHECK(j.type() == json::value_t::null); // NOLINT: access after move is OK here } SECTION("copy assignment") { SECTION("object") { - json j {{"foo", 1}, {"bar", false}}; + json j{{"foo", 1}, {"bar", false}}; json k; k = j; CHECK(j == k); @@ -100,7 +100,7 @@ SECTION("array") { - json j {"foo", 1, 42.23, false}; + json j{"foo", 1, 42.23, false}; json k; k = j; CHECK(j == k); @@ -167,20 +167,20 @@ { SECTION("object") { - auto* j = new json {{"foo", 1}, {"bar", false}}; // NOLINT(cppcoreguidelines-owning-memory) - delete j; // NOLINT(cppcoreguidelines-owning-memory) + auto* j = new json{{"foo", 1}, {"bar", false}}; // NOLINT(cppcoreguidelines-owning-memory) + delete j; // NOLINT(cppcoreguidelines-owning-memory) } SECTION("array") { - auto* j = new json {"foo", 1, 1u, false, 23.42}; // NOLINT(cppcoreguidelines-owning-memory) - delete j; // NOLINT(cppcoreguidelines-owning-memory) + auto* j = new json{"foo", 1, 1u, false, 23.42}; // NOLINT(cppcoreguidelines-owning-memory) + delete j; // NOLINT(cppcoreguidelines-owning-memory) } SECTION("string") { - auto* j = new json("Hello world"); // NOLINT(cppcoreguidelines-owning-memory) - delete j; // NOLINT(cppcoreguidelines-owning-memory) + auto* j = new json("Hello world"); // NOLINT(cppcoreguidelines-owning-memory) + delete j; // NOLINT(cppcoreguidelines-owning-memory) } } }
diff --git a/tests/src/unit-convenience.cpp b/tests/src/unit-convenience.cpp index 34bbb02..f5c372a 100644 --- a/tests/src/unit-convenience.cpp +++ b/tests/src/unit-convenience.cpp
@@ -14,13 +14,12 @@ #include <sstream> -namespace -{ +namespace { struct alt_string_iter { alt_string_iter() = default; alt_string_iter(const char* cstr) - : impl(cstr) + : impl(cstr) {} void reserve(std::size_t s) @@ -62,7 +61,7 @@ { alt_string_data() = default; alt_string_data(const char* cstr) - : impl(cstr) + : impl(cstr) {} void reserve(std::size_t s) @@ -102,7 +101,7 @@ s.dump_escaped(original, ensure_ascii); CHECK(ss.str() == escaped); } -} // namespace +} // namespace TEST_CASE("convenience functions") {
diff --git a/tests/src/unit-conversions.cpp b/tests/src/unit-conversions.cpp index d7df0be..6be465b 100644 --- a/tests/src/unit-conversions.cpp +++ b/tests/src/unit-conversions.cpp
@@ -37,12 +37,11 @@ SECTION("get an object (explicit)") { const json::object_t o_reference = {{"object", json::object()}, - {"array", {1, 2, 3, 4}}, - {"number", 42}, - {"boolean", false}, - {"null", nullptr}, - {"string", "Hello world"} - }; + {"array", {1, 2, 3, 4}}, + {"number", 42}, + {"boolean", false}, + {"null", nullptr}, + {"string", "Hello world"}}; json j(o_reference); SECTION("json::object_t") @@ -83,37 +82,43 @@ { CHECK_THROWS_WITH_AS( json(json::value_t::null).get<json::object_t>(), - "[json.exception.type_error.302] type must be object, but is null", json::type_error&); + "[json.exception.type_error.302] type must be object, but is null", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::array).get<json::object_t>(), - "[json.exception.type_error.302] type must be object, but is array", json::type_error&); + "[json.exception.type_error.302] type must be object, but is array", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::string).get<json::object_t>(), - "[json.exception.type_error.302] type must be object, but is string", json::type_error&); + "[json.exception.type_error.302] type must be object, but is string", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::object_t>(), "[json.exception.type_error.302] type must be object, " - "but is boolean", json::type_error&); + "but is boolean", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_integer).get<json::object_t>(), - "[json.exception.type_error.302] type must be object, but is number", json::type_error&); + "[json.exception.type_error.302] type must be object, but is number", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_unsigned).get<json::object_t>(), - "[json.exception.type_error.302] type must be object, but is number", json::type_error&); + "[json.exception.type_error.302] type must be object, but is number", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_float).get<json::object_t>(), - "[json.exception.type_error.302] type must be object, but is number", json::type_error&); + "[json.exception.type_error.302] type must be object, but is number", + json::type_error&); } } SECTION("get an object (explicit, get_to)") { const json::object_t o_reference = {{"object", json::object()}, - {"array", {1, 2, 3, 4}}, - {"number", 42}, - {"boolean", false}, - {"null", nullptr}, - {"string", "Hello world"} - }; + {"array", {1, 2, 3, 4}}, + {"number", 42}, + {"boolean", false}, + {"null", nullptr}, + {"string", "Hello world"}}; json j(o_reference); SECTION("json::object_t") @@ -156,12 +161,11 @@ SECTION("get an object (implicit)") { const json::object_t o_reference = {{"object", json::object()}, - {"array", {1, 2, 3, 4}}, - {"number", 42}, - {"boolean", false}, - {"null", nullptr}, - {"string", "Hello world"} - }; + {"array", {1, 2, 3, 4}}, + {"number", 42}, + {"boolean", false}, + {"null", nullptr}, + {"string", "Hello world"}}; json j(o_reference); SECTION("json::object_t") @@ -198,8 +202,7 @@ SECTION("get an array (explicit)") { - const json::array_t a_reference{json(1), json(1u), json(2.2), - json(false), json("string"), json()}; + const json::array_t a_reference{json(1), json(1u), json(2.2), json(false), json("string"), json()}; json j(a_reference); SECTION("json::array_t") @@ -221,7 +224,8 @@ CHECK_THROWS_WITH_AS( json(json::value_t::null).get<std::forward_list<json>>(), - "[json.exception.type_error.302] type must be array, but is null", json::type_error&); + "[json.exception.type_error.302] type must be array, but is null", + json::type_error&); } SECTION("std::vector<json>") @@ -231,7 +235,8 @@ CHECK_THROWS_WITH_AS( json(json::value_t::null).get<std::vector<json>>(), - "[json.exception.type_error.302] type must be array, but is null", json::type_error&); + "[json.exception.type_error.302] type must be array, but is null", + json::type_error&); #if !defined(JSON_NOEXCEPTION) SECTION("reserve is called on containers that supports it") @@ -246,8 +251,8 @@ SECTION("built-in arrays") { - const char str[] = "a string"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - const int nbs[] = {0, 1, 2}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + const char str[] = "a string"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + const int nbs[] = {0, 1, 2}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) const json j2 = nbs; const json j3 = str; @@ -268,35 +273,42 @@ { CHECK_THROWS_WITH_AS( json(json::value_t::object).get<std::vector<int>>(), - "[json.exception.type_error.302] type must be array, but is object", json::type_error&); + "[json.exception.type_error.302] type must be array, but is object", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::null).get<json::array_t>(), - "[json.exception.type_error.302] type must be array, but is null", json::type_error&); + "[json.exception.type_error.302] type must be array, but is null", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::object).get<json::array_t>(), - "[json.exception.type_error.302] type must be array, but is object", json::type_error&); + "[json.exception.type_error.302] type must be array, but is object", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::string).get<json::array_t>(), - "[json.exception.type_error.302] type must be array, but is string", json::type_error&); + "[json.exception.type_error.302] type must be array, but is string", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::boolean).get<json::array_t>(), - "[json.exception.type_error.302] type must be array, but is boolean", json::type_error&); + "[json.exception.type_error.302] type must be array, but is boolean", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_integer).get<json::array_t>(), - "[json.exception.type_error.302] type must be array, but is number", json::type_error&); + "[json.exception.type_error.302] type must be array, but is number", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_unsigned).get<json::array_t>(), - "[json.exception.type_error.302] type must be array, but is number", json::type_error&); + "[json.exception.type_error.302] type must be array, but is number", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_float).get<json::array_t>(), - "[json.exception.type_error.302] type must be array, but is number", json::type_error&); + "[json.exception.type_error.302] type must be array, but is number", + json::type_error&); } } SECTION("get an array (explicit, get_to)") { - const json::array_t a_reference{json(1), json(1u), json(2.2), - json(false), json("string"), json()}; + const json::array_t a_reference{json(1), json(1u), json(2.2), json(false), json("string"), json()}; json j(a_reference); SECTION("json::array_t") @@ -336,8 +348,8 @@ SECTION("built-in arrays") { - const int nbs[] = {0, 1, 2}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - int nbs2[] = {0, 0, 0}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + const int nbs[] = {0, 1, 2}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + int nbs2[] = {0, 0, 0}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) const json j2 = nbs; j2.get_to(nbs2); @@ -355,8 +367,7 @@ #if JSON_USE_IMPLICIT_CONVERSIONS SECTION("get an array (implicit)") { - const json::array_t a_reference{json(1), json(1u), json(2.2), - json(false), json("string"), json()}; + const json::array_t a_reference{json(1), json(1u), json(2.2), json(false), json("string"), json()}; json j(a_reference); SECTION("json::array_t") @@ -419,44 +430,58 @@ { CHECK_THROWS_WITH_AS( json(json::value_t::null).get<json::string_t>(), - "[json.exception.type_error.302] type must be string, but is null", json::type_error&); + "[json.exception.type_error.302] type must be string, but is null", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::object).get<json::string_t>(), - "[json.exception.type_error.302] type must be string, but is object", json::type_error&); + "[json.exception.type_error.302] type must be string, but is object", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::array).get<json::string_t>(), - "[json.exception.type_error.302] type must be string, but is array", json::type_error&); + "[json.exception.type_error.302] type must be string, but is array", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::string_t>(), "[json.exception.type_error.302] type must be string, " - "but is boolean", json::type_error&); + "but is boolean", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_integer).get<json::string_t>(), - "[json.exception.type_error.302] type must be string, but is number", json::type_error&); + "[json.exception.type_error.302] type must be string, but is number", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_unsigned).get<json::string_t>(), - "[json.exception.type_error.302] type must be string, but is number", json::type_error&); + "[json.exception.type_error.302] type must be string, but is number", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_float).get<json::string_t>(), - "[json.exception.type_error.302] type must be string, but is number", json::type_error&); + "[json.exception.type_error.302] type must be string, but is number", + json::type_error&); } #if defined(JSON_HAS_CPP_17) SECTION("exception in case of a non-string type using string_view") { CHECK_THROWS_WITH_AS(json(json::value_t::null).get<std::string_view>(), - "[json.exception.type_error.302] type must be string, but is null", json::type_error&); + "[json.exception.type_error.302] type must be string, but is null", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::object).get<std::string_view>(), - "[json.exception.type_error.302] type must be string, but is object", json::type_error&); + "[json.exception.type_error.302] type must be string, but is object", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::array).get<std::string_view>(), - "[json.exception.type_error.302] type must be string, but is array", json::type_error&); + "[json.exception.type_error.302] type must be string, but is array", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<std::string_view>(), - "[json.exception.type_error.302] type must be string, but is boolean", json::type_error&); + "[json.exception.type_error.302] type must be string, but is boolean", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::number_integer).get<std::string_view>(), - "[json.exception.type_error.302] type must be string, but is number", json::type_error&); + "[json.exception.type_error.302] type must be string, but is number", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::number_unsigned).get<std::string_view>(), - "[json.exception.type_error.302] type must be string, but is number", json::type_error&); + "[json.exception.type_error.302] type must be string, but is number", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::number_float).get<std::string_view>(), - "[json.exception.type_error.302] type must be string, but is number", json::type_error&); + "[json.exception.type_error.302] type must be string, but is number", + json::type_error&); } #endif } @@ -499,19 +524,26 @@ CHECK(n2 == n); CHECK_THROWS_WITH_AS(json(json::value_t::string).get<std::nullptr_t>(), - "[json.exception.type_error.302] type must be null, but is string", json::type_error&); + "[json.exception.type_error.302] type must be null, but is string", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::object).get<std::nullptr_t>(), - "[json.exception.type_error.302] type must be null, but is object", json::type_error&); + "[json.exception.type_error.302] type must be null, but is object", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::array).get<std::nullptr_t>(), - "[json.exception.type_error.302] type must be null, but is array", json::type_error&); + "[json.exception.type_error.302] type must be null, but is array", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<std::nullptr_t>(), - "[json.exception.type_error.302] type must be null, but is boolean", json::type_error&); + "[json.exception.type_error.302] type must be null, but is boolean", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::number_integer).get<std::nullptr_t>(), - "[json.exception.type_error.302] type must be null, but is number", json::type_error&); + "[json.exception.type_error.302] type must be null, but is number", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::number_unsigned).get<std::nullptr_t>(), - "[json.exception.type_error.302] type must be null, but is number", json::type_error&); + "[json.exception.type_error.302] type must be null, but is number", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::number_float).get<std::nullptr_t>(), - "[json.exception.type_error.302] type must be null, but is number", json::type_error&); + "[json.exception.type_error.302] type must be null, but is number", + json::type_error&); } #if JSON_USE_IMPLICIT_CONVERSIONS @@ -526,13 +558,13 @@ CHECK(json(s) == j); } -#if defined(JSON_HAS_CPP_17) + #if defined(JSON_HAS_CPP_17) SECTION("std::string_view") { std::string_view const s = j.get<std::string_view>(); CHECK(json(s) == j); } -#endif + #endif SECTION("std::string") { @@ -572,28 +604,35 @@ CHECK_THROWS_WITH_AS( json(json::value_t::null).get<json::boolean_t>(), - "[json.exception.type_error.302] type must be boolean, but is null", json::type_error&); + "[json.exception.type_error.302] type must be boolean, but is null", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::object).get<json::boolean_t>(), "[json.exception.type_error.302] type must be boolean, " - "but is object", json::type_error&); + "but is object", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::array).get<json::boolean_t>(), - "[json.exception.type_error.302] type must be boolean, but is array", json::type_error&); + "[json.exception.type_error.302] type must be boolean, but is array", + json::type_error&); CHECK_THROWS_WITH_AS(json(json::value_t::string).get<json::boolean_t>(), "[json.exception.type_error.302] type must be boolean, " - "but is string", json::type_error&); + "but is string", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_integer).get<json::boolean_t>(), "[json.exception.type_error.302] type must be boolean, but is " - "number", json::type_error&); + "number", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_unsigned).get<json::boolean_t>(), "[json.exception.type_error.302] type must be boolean, but is " - "number", json::type_error&); + "number", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::number_float).get<json::boolean_t>(), "[json.exception.type_error.302] type must be boolean, but is " - "number", json::type_error&); + "number", + json::type_error&); } } @@ -832,20 +871,25 @@ { CHECK_THROWS_WITH_AS( json(json::value_t::null).get<json::number_integer_t>(), - "[json.exception.type_error.302] type must be number, but is null", json::type_error&); + "[json.exception.type_error.302] type must be number, but is null", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::object).get<json::number_integer_t>(), - "[json.exception.type_error.302] type must be number, but is object", json::type_error&); + "[json.exception.type_error.302] type must be number, but is object", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::array).get<json::number_integer_t>(), - "[json.exception.type_error.302] type must be number, but is array", json::type_error&); + "[json.exception.type_error.302] type must be number, but is array", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::string).get<json::number_integer_t>(), - "[json.exception.type_error.302] type must be number, but is string", json::type_error&); + "[json.exception.type_error.302] type must be number, but is string", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::boolean).get<json::number_integer_t>(), "[json.exception.type_error.302] type must be number, but is " - "boolean", json::type_error&); + "boolean", + json::type_error&); CHECK_NOTHROW( json(json::value_t::number_float).get<json::number_integer_t>()); @@ -1095,20 +1139,25 @@ { CHECK_THROWS_WITH_AS( json(json::value_t::null).get<json::number_float_t>(), - "[json.exception.type_error.302] type must be number, but is null", json::type_error&); + "[json.exception.type_error.302] type must be number, but is null", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::object).get<json::number_float_t>(), - "[json.exception.type_error.302] type must be number, but is object", json::type_error&); + "[json.exception.type_error.302] type must be number, but is object", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::array).get<json::number_float_t>(), - "[json.exception.type_error.302] type must be number, but is array", json::type_error&); + "[json.exception.type_error.302] type must be number, but is array", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::string).get<json::number_float_t>(), - "[json.exception.type_error.302] type must be number, but is string", json::type_error&); + "[json.exception.type_error.302] type must be number, but is string", + json::type_error&); CHECK_THROWS_WITH_AS( json(json::value_t::boolean).get<json::number_float_t>(), "[json.exception.type_error.302] type must be number, but is " - "boolean", json::type_error&); + "boolean", + json::type_error&); CHECK_NOTHROW( json(json::value_t::number_integer).get<json::number_float_t>()); @@ -1265,8 +1314,16 @@ SECTION("get an enum") { - enum c_enum { value_1, value_2 }; - enum class cpp_enum { value_1, value_2 }; + enum c_enum + { + value_1, + value_2 + }; + enum class cpp_enum + { + value_1, + value_2 + }; CHECK(json(value_1).get<c_enum>() == value_1); CHECK(json(cpp_enum::value_1).get<cpp_enum>() == cpp_enum::value_1); @@ -1325,7 +1382,8 @@ { CHECK_THROWS_WITH_AS( (json().get<std::map<std::string, int>>()), - "[json.exception.type_error.302] type must be object, but is null", json::type_error&); + "[json.exception.type_error.302] type must be object, but is null", + json::type_error&); } } @@ -1367,7 +1425,8 @@ { std::array<int, 6> arr6 = {{1, 2, 3, 4, 5, 6}}; CHECK_THROWS_WITH_AS(j1.get_to(arr6), "[json.exception.out_of_range.401] " - "array index 4 is out of range", json::out_of_range&); + "array index 4 is out of range", + json::out_of_range&); } SECTION("std::array is smaller than JSON") @@ -1436,10 +1495,12 @@ json const j8 = 2; CHECK_THROWS_WITH_AS((j7.get<std::map<int, int>>()), "[json.exception.type_error.302] type must be array, " - "but is number", json::type_error&); + "but is number", + json::type_error&); CHECK_THROWS_WITH_AS((j8.get<std::map<int, int>>()), "[json.exception.type_error.302] type must be array, " - "but is number", json::type_error&); + "but is number", + json::type_error&); SECTION("superfluous entries") { @@ -1461,10 +1522,12 @@ json const j8 = 2; CHECK_THROWS_WITH_AS((j7.get<std::unordered_map<int, int>>()), "[json.exception.type_error.302] type must be array, " - "but is number", json::type_error&); + "but is number", + json::type_error&); CHECK_THROWS_WITH_AS((j8.get<std::unordered_map<int, int>>()), "[json.exception.type_error.302] type must be array, " - "but is number", json::type_error&); + "but is number", + json::type_error&); SECTION("superfluous entries") { @@ -1480,38 +1543,48 @@ // that's what I thought when other test like this one broke CHECK_THROWS_WITH_AS( (json().get<std::list<int>>()), - "[json.exception.type_error.302] type must be array, but is null", json::type_error&); + "[json.exception.type_error.302] type must be array, but is null", + json::type_error&); CHECK_THROWS_WITH_AS( (json().get<std::vector<int>>()), - "[json.exception.type_error.302] type must be array, but is null", json::type_error&); + "[json.exception.type_error.302] type must be array, but is null", + json::type_error&); CHECK_THROWS_WITH_AS( (json().get<std::vector<json>>()), - "[json.exception.type_error.302] type must be array, but is null", json::type_error&); + "[json.exception.type_error.302] type must be array, but is null", + json::type_error&); CHECK_THROWS_WITH_AS( (json().get<std::list<json>>()), - "[json.exception.type_error.302] type must be array, but is null", json::type_error&); + "[json.exception.type_error.302] type must be array, but is null", + json::type_error&); CHECK_THROWS_WITH_AS( (json().get<std::valarray<int>>()), - "[json.exception.type_error.302] type must be array, but is null", json::type_error&); + "[json.exception.type_error.302] type must be array, but is null", + json::type_error&); CHECK_THROWS_WITH_AS( (json().get<std::map<int, int>>()), - "[json.exception.type_error.302] type must be array, but is null", json::type_error&); + "[json.exception.type_error.302] type must be array, but is null", + json::type_error&); } } } } -enum class cards {kreuz, pik, herz, karo}; +enum class cards +{ + kreuz, + pik, + herz, + karo +}; // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - false positive NLOHMANN_JSON_SERIALIZE_ENUM(cards, -{ - {cards::kreuz, "kreuz"}, - {cards::pik, "pik"}, - {cards::pik, "puk"}, // second entry for cards::puk; will not be used - {cards::herz, "herz"}, - {cards::karo, "karo"} -}) + {{cards::kreuz, "kreuz"}, + {cards::pik, "pik"}, + {cards::pik, "puk"}, // second entry for cards::puk; will not be used + {cards::herz, "herz"}, + {cards::karo, "karo"}}) enum TaskState { @@ -1523,12 +1596,12 @@ // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - false positive NLOHMANN_JSON_SERIALIZE_ENUM(TaskState, -{ - {TS_INVALID, nullptr}, - {TS_STOPPED, "stopped"}, - {TS_RUNNING, "running"}, - {TS_COMPLETED, "completed"}, -}) + { + {TS_INVALID, nullptr}, + {TS_STOPPED, "stopped"}, + {TS_RUNNING, "running"}, + {TS_COMPLETED, "completed"}, + }) TEST_CASE("JSON to enum mapping") {
diff --git a/tests/src/unit-custom-base-class.cpp b/tests/src/unit-custom-base-class.cpp index 7d3c2ee..03bb4b2 100644 --- a/tests/src/unit-custom-base-class.cpp +++ b/tests/src/unit-custom-base-class.cpp
@@ -30,25 +30,25 @@ { return m_metadata; } + private: metadata_t m_metadata = {}; }; template<class T> using json_with_metadata = - nlohmann::basic_json < - std::map, - std::vector, - std::string, - bool, - std::int64_t, - std::uint64_t, - double, - std::allocator, - nlohmann::adl_serializer, - std::vector<std::uint8_t>, - json_metadata<T> - >; + nlohmann::basic_json< + std::map, + std::vector, + std::string, + bool, + std::int64_t, + std::uint64_t, + double, + std::allocator, + nlohmann::adl_serializer, + std::vector<std::uint8_t>, + json_metadata<T>>; TEST_CASE("JSON Node Metadata") { @@ -56,18 +56,18 @@ { using json = json_with_metadata<int>; json null; - auto obj = json::object(); + auto obj = json::object(); auto array = json::array(); - null.metadata() = 1; - obj.metadata() = 2; + null.metadata() = 1; + obj.metadata() = 2; array.metadata() = 3; auto copy = array; - CHECK(null.metadata() == 1); - CHECK(obj.metadata() == 2); + CHECK(null.metadata() == 1); + CHECK(obj.metadata() == 2); CHECK(array.metadata() == 3); - CHECK(copy.metadata() == 3); + CHECK(copy.metadata() == 3); } SECTION("type vector<int>") { @@ -77,11 +77,11 @@ auto copy = value; value.metadata().emplace_back(2); - CHECK(copy.metadata().size() == 1); - CHECK(copy.metadata().at(0) == 1); + CHECK(copy.metadata().size() == 1); + CHECK(copy.metadata().at(0) == 1); CHECK(value.metadata().size() == 2); - CHECK(value.metadata().at(0) == 1); - CHECK(value.metadata().at(1) == 2); + CHECK(value.metadata().at(0) == 1); + CHECK(value.metadata().at(1) == 2); } SECTION("copy ctor") { @@ -92,15 +92,15 @@ json copy = value; - CHECK(copy.metadata().size() == 2); - CHECK(copy.metadata().at(0) == 1); - CHECK(copy.metadata().at(1) == 2); + CHECK(copy.metadata().size() == 2); + CHECK(copy.metadata().at(0) == 1); + CHECK(copy.metadata().at(1) == 2); CHECK(value.metadata().size() == 2); - CHECK(value.metadata().at(0) == 1); - CHECK(value.metadata().at(1) == 2); + CHECK(value.metadata().at(0) == 1); + CHECK(value.metadata().at(1) == 2); value.metadata().clear(); - CHECK(copy.metadata().size() == 2); + CHECK(copy.metadata().size() == 2); CHECK(value.metadata().size() == 0); } SECTION("move ctor") @@ -112,9 +112,9 @@ const json moved = std::move(value); - CHECK(moved.metadata().size() == 2); - CHECK(moved.metadata().at(0) == 1); - CHECK(moved.metadata().at(1) == 2); + CHECK(moved.metadata().size() == 2); + CHECK(moved.metadata().at(0) == 1); + CHECK(moved.metadata().at(1) == 2); } SECTION("move assign") { @@ -126,9 +126,9 @@ json moved; moved = std::move(value); - CHECK(moved.metadata().size() == 2); - CHECK(moved.metadata().at(0) == 1); - CHECK(moved.metadata().at(1) == 2); + CHECK(moved.metadata().size() == 2); + CHECK(moved.metadata().at(0) == 1); + CHECK(moved.metadata().at(1) == 2); } SECTION("copy assign") { @@ -140,22 +140,22 @@ json copy; copy = value; - CHECK(copy.metadata().size() == 2); - CHECK(copy.metadata().at(0) == 1); - CHECK(copy.metadata().at(1) == 2); + CHECK(copy.metadata().size() == 2); + CHECK(copy.metadata().at(0) == 1); + CHECK(copy.metadata().at(1) == 2); CHECK(value.metadata().size() == 2); - CHECK(value.metadata().at(0) == 1); - CHECK(value.metadata().at(1) == 2); + CHECK(value.metadata().at(0) == 1); + CHECK(value.metadata().at(1) == 2); value.metadata().clear(); - CHECK(copy.metadata().size() == 2); + CHECK(copy.metadata().size() == 2); CHECK(value.metadata().size() == 0); } SECTION("type unique_ptr<int>") { using json = json_with_metadata<std::unique_ptr<int>>; json value; - value.metadata().reset(new int(42)); // NOLINT(cppcoreguidelines-owning-memory) + value.metadata().reset(new int(42)); // NOLINT(cppcoreguidelines-owning-memory) auto moved = std::move(value); CHECK(moved.metadata() != nullptr); @@ -171,14 +171,14 @@ json const array(10, value); CHECK(value.metadata().size() == 2); - CHECK(value.metadata().at(0) == 1); - CHECK(value.metadata().at(1) == 2); + CHECK(value.metadata().at(0) == 1); + CHECK(value.metadata().at(1) == 2); for (const auto& val : array) { CHECK(val.metadata().size() == 2); - CHECK(val.metadata().at(0) == 1); - CHECK(val.metadata().at(1) == 2); + CHECK(val.metadata().at(0) == 1); + CHECK(val.metadata().at(1) == 2); } } } @@ -188,38 +188,38 @@ class visitor_adaptor { public: - template <class Fnc> + template<class Fnc> void visit(const Fnc& fnc) const; + private: - template <class Ptr, class Fnc> + template<class Ptr, class Fnc> void do_visit(const Ptr& ptr, const Fnc& fnc) const; }; -using json_with_visitor_t = nlohmann::basic_json < - std::map, - std::vector, - std::string, - bool, - std::int64_t, - std::uint64_t, - double, - std::allocator, - nlohmann::adl_serializer, - std::vector<std::uint8_t>, - visitor_adaptor - >; +using json_with_visitor_t = nlohmann::basic_json< + std::map, + std::vector, + std::string, + bool, + std::int64_t, + std::uint64_t, + double, + std::allocator, + nlohmann::adl_serializer, + std::vector<std::uint8_t>, + visitor_adaptor>; -template <class Fnc> +template<class Fnc> void visitor_adaptor::visit(const Fnc& fnc) const { do_visit(json_with_visitor_t::json_pointer{}, fnc); } -template <class Ptr, class Fnc> +template<class Ptr, class Fnc> void visitor_adaptor::do_visit(const Ptr& ptr, const Fnc& fnc) const { using value_t = nlohmann::detail::value_t; - const json_with_visitor_t& json = *static_cast<const json_with_visitor_t*>(this); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) + const json_with_visitor_t& json = *static_cast<const json_with_visitor_t*>(this); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) switch (json.type()) { case value_t::object: @@ -252,7 +252,7 @@ { json_with_visitor_t json; json["null"]; - json["int"] = -1; + json["int"] = -1; json["uint"] = 1U; json["float"] = 1.0; json["boolean"] = true; @@ -261,8 +261,7 @@ json["array"].push_back(1); json["array"].push_back(json); - std::set<std::string> expected - { + std::set<std::string> expected{ "/null - null - null", "/int - number_integer - -1", "/uint - number_unsigned - 1", @@ -279,58 +278,55 @@ "/array/2/boolean - boolean - true", "/array/2/string - string - \"string\"", "/array/2/array/0 - number_integer - 0", - "/array/2/array/1 - number_integer - 1" - }; + "/array/2/array/1 - number_integer - 1"}; json.visit( - [&](const json_with_visitor_t::json_pointer & p, - const json_with_visitor_t& j) - { - std::stringstream str; - str << p.to_string() << " - " ; - using value_t = nlohmann::detail::value_t; - switch (j.type()) - { - case value_t::object: - str << "object"; - break; - case value_t::array: - str << "array"; - break; - case value_t::discarded: - str << "discarded"; - break; - case value_t::null: - str << "null"; - break; - case value_t::string: - str << "string"; - break; - case value_t::boolean: - str << "boolean"; - break; - case value_t::number_integer: - str << "number_integer"; - break; - case value_t::number_unsigned: - str << "number_unsigned"; - break; - case value_t::number_float: - str << "number_float"; - break; - case value_t::binary: - str << "binary"; - break; - default: - str << "error"; - break; - } - str << " - " << j.dump(); - CHECK(json.at(p) == j); - INFO(str.str()); - CHECK(expected.count(str.str()) == 1); - expected.erase(str.str()); - } - ); + [&](const json_with_visitor_t::json_pointer& p, + const json_with_visitor_t& j) { + std::stringstream str; + str << p.to_string() << " - "; + using value_t = nlohmann::detail::value_t; + switch (j.type()) + { + case value_t::object: + str << "object"; + break; + case value_t::array: + str << "array"; + break; + case value_t::discarded: + str << "discarded"; + break; + case value_t::null: + str << "null"; + break; + case value_t::string: + str << "string"; + break; + case value_t::boolean: + str << "boolean"; + break; + case value_t::number_integer: + str << "number_integer"; + break; + case value_t::number_unsigned: + str << "number_unsigned"; + break; + case value_t::number_float: + str << "number_float"; + break; + case value_t::binary: + str << "binary"; + break; + default: + str << "error"; + break; + } + str << " - " << j.dump(); + CHECK(json.at(p) == j); + INFO(str.str()); + CHECK(expected.count(str.str()) == 1); + expected.erase(str.str()); + }); CHECK(expected.empty()); }
diff --git a/tests/src/unit-deserialization.cpp b/tests/src/unit-deserialization.cpp index 3bc161f..5b82ebf 100644 --- a/tests/src/unit-deserialization.cpp +++ b/tests/src/unit-deserialization.cpp
@@ -12,7 +12,7 @@ #include <nlohmann/json.hpp> using nlohmann::json; #ifdef JSON_TEST_NO_GLOBAL_UDLS - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) +using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif #include <iostream> @@ -20,8 +20,7 @@ #include <sstream> #include <valarray> -namespace -{ +namespace { struct SaxEventLogger : public nlohmann::json_sax<json> { bool null() override @@ -125,7 +124,7 @@ return false; } - std::vector<std::string> events {}; + std::vector<std::string> events{}; }; struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger @@ -169,7 +168,7 @@ } }; -template <typename T> +template<typename T> class proxy_iterator { public: @@ -182,7 +181,9 @@ using iterator_category = std::input_iterator_tag; proxy_iterator() = default; - explicit proxy_iterator(iterator& it) : m_it(std::addressof(it)) {} + explicit proxy_iterator(iterator& it) + : m_it(std::addressof(it)) + {} proxy_iterator& operator++() { @@ -214,7 +215,7 @@ private: iterator* m_it = nullptr; }; -} // namespace +} // namespace TEST_CASE("deserialization") { @@ -236,12 +237,7 @@ CHECK(json::sax_parse(ss3, &l)); CHECK(l.events.size() == 11); CHECK(l.events == std::vector<std::string>( - { - "start_array()", "string(foo)", "number_unsigned(1)", - "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", - "start_object()", "key(one)", "number_unsigned(1)", - "end_object()", "end_array()" - })); + {"start_array()", "string(foo)", "number_unsigned(1)", "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", "start_object()", "key(one)", "number_unsigned(1)", "end_object()", "end_array()"})); } SECTION("string literal") @@ -255,12 +251,7 @@ CHECK(json::sax_parse(s, &l)); CHECK(l.events.size() == 11); CHECK(l.events == std::vector<std::string>( - { - "start_array()", "string(foo)", "number_unsigned(1)", - "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", - "start_object()", "key(one)", "number_unsigned(1)", - "end_object()", "end_array()" - })); + {"start_array()", "string(foo)", "number_unsigned(1)", "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", "start_object()", "key(one)", "number_unsigned(1)", "end_object()", "end_array()"})); } SECTION("string_t") @@ -274,12 +265,7 @@ CHECK(json::sax_parse(s, &l)); CHECK(l.events.size() == 11); CHECK(l.events == std::vector<std::string>( - { - "start_array()", "string(foo)", "number_unsigned(1)", - "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", - "start_object()", "key(one)", "number_unsigned(1)", - "end_object()", "end_array()" - })); + {"start_array()", "string(foo)", "number_unsigned(1)", "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", "start_object()", "key(one)", "number_unsigned(1)", "end_object()", "end_array()"})); } SECTION("operator<<") @@ -331,12 +317,7 @@ CHECK(!json::sax_parse(ss5, &l)); CHECK(l.events.size() == 11); CHECK(l.events == std::vector<std::string>( - { - "start_array()", "string(foo)", "number_unsigned(1)", - "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", - "start_object()", "key(one)", "number_unsigned(1)", - "end_object()", "parse_error(29)" - })); + {"start_array()", "string(foo)", "number_unsigned(1)", "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", "start_object()", "key(one)", "number_unsigned(1)", "end_object()", "parse_error(29)"})); } SECTION("string") @@ -354,12 +335,7 @@ CHECK(!json::sax_parse(s, &l)); CHECK(l.events.size() == 11); CHECK(l.events == std::vector<std::string>( - { - "start_array()", "string(foo)", "number_unsigned(1)", - "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", - "start_object()", "key(one)", "number_unsigned(1)", - "end_object()", "parse_error(29)" - })); + {"start_array()", "string(foo)", "number_unsigned(1)", "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", "start_object()", "key(one)", "number_unsigned(1)", "end_object()", "parse_error(29)"})); } SECTION("operator<<") @@ -402,7 +378,7 @@ SECTION("from std::array") { - std::array<uint8_t, 5> const v { {'t', 'r', 'u', 'e'} }; + std::array<uint8_t, 5> const v{{'t', 'r', 'u', 'e'}}; CHECK(json::parse(v) == json(true)); CHECK(json::accept(v)); @@ -414,7 +390,7 @@ SECTION("from array") { - uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) CHECK(json::parse(v) == json(true)); CHECK(json::accept(v)); @@ -426,7 +402,7 @@ SECTION("from chars") { - auto* v = new uint8_t[5]; // NOLINT(cppcoreguidelines-owning-memory) + auto* v = new uint8_t[5]; // NOLINT(cppcoreguidelines-owning-memory) v[0] = 't'; v[1] = 'r'; v[2] = 'u'; @@ -440,7 +416,7 @@ CHECK(l.events.size() == 1); CHECK(l.events == std::vector<std::string>({"boolean(true)"})); - delete[] v; // NOLINT(cppcoreguidelines-owning-memory) + delete[] v; // NOLINT(cppcoreguidelines-owning-memory) } SECTION("from std::string") @@ -493,12 +469,11 @@ CHECK(json::sax_parse(std::begin(v), std::end(v), &l)); CHECK(l.events.size() == 1); CHECK(l.events == std::vector<std::string>({"boolean(true)"})); - } SECTION("from std::array") { - std::array<uint8_t, 5> v { {'t', 'r', 'u', 'e'} }; + std::array<uint8_t, 5> v{{'t', 'r', 'u', 'e'}}; CHECK(json::parse(std::begin(v), std::end(v)) == json(true)); CHECK(json::accept(std::begin(v), std::end(v))); @@ -510,7 +485,7 @@ SECTION("from array") { - uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) CHECK(json::parse(std::begin(v), std::end(v)) == json(true)); CHECK(json::accept(std::begin(v), std::end(v))); @@ -585,8 +560,7 @@ json j; json_sax_dom_parser<json> sax(j, true); - CHECK(json::sax_parse(proxy(first), proxy(last), &sax, - input_format_t::json, false)); + CHECK(json::sax_parse(proxy(first), proxy(last), &sax, input_format_t::json, false)); CHECK(j.dump() == str1); CHECK(std::string(first, last) == str2); } @@ -865,10 +839,7 @@ CHECK(!json::sax_parse(std::begin(v), std::end(v), &l)); CHECK(l.events.size() == 4); CHECK(l.events == std::vector<std::string>( - { - "start_object()", "key()", "number_unsigned(11)", - "parse_error(7)" - })); + {"start_object()", "key()", "number_unsigned(11)", "parse_error(7)"})); } } } @@ -888,9 +859,7 @@ CHECK(!json::sax_parse(bom, &l)); CHECK(l.events.size() == 1); CHECK(l.events == std::vector<std::string>( - { - "parse_error(4)" - })); + {"parse_error(4)"})); } SECTION("BOM and content") @@ -904,14 +873,10 @@ CHECK(json::sax_parse(bom + "1", &l2)); CHECK(l1.events.size() == 1); CHECK(l1.events == std::vector<std::string>( - { - "number_unsigned(1)" - })); + {"number_unsigned(1)"})); CHECK(l2.events.size() == 1); CHECK(l2.events == std::vector<std::string>( - { - "number_unsigned(1)" - })); + {"number_unsigned(1)"})); } SECTION("2 byte of BOM") @@ -927,14 +892,10 @@ CHECK(!json::sax_parse(bom.substr(0, 2), &l2)); CHECK(l1.events.size() == 1); CHECK(l1.events == std::vector<std::string>( - { - "parse_error(3)" - })); + {"parse_error(3)"})); CHECK(l2.events.size() == 1); CHECK(l2.events == std::vector<std::string>( - { - "parse_error(3)" - })); + {"parse_error(3)"})); } SECTION("1 byte of BOM") @@ -950,14 +911,10 @@ CHECK(!json::sax_parse(bom.substr(0, 1), &l2)); CHECK(l1.events.size() == 1); CHECK(l1.events == std::vector<std::string>( - { - "parse_error(2)" - })); + {"parse_error(2)"})); CHECK(l2.events.size() == 1); CHECK(l2.events == std::vector<std::string>( - { - "parse_error(2)" - })); + {"parse_error(2)"})); } SECTION("variations") @@ -990,9 +947,7 @@ CHECK(json::sax_parse(s + "null", &l)); CHECK(l.events.size() == 1); CHECK(l.events == std::vector<std::string>( - { - "null()" - })); + {"null()"})); } else { @@ -1008,23 +963,17 @@ if (i0 != 0) { CHECK(l.events == std::vector<std::string>( - { - "parse_error(1)" - })); + {"parse_error(1)"})); } else if (i1 != 0) { CHECK(l.events == std::vector<std::string>( - { - "parse_error(2)" - })); + {"parse_error(2)"})); } else { CHECK(l.events == std::vector<std::string>( - { - "parse_error(3)" - })); + {"parse_error(3)"})); } } } @@ -1055,37 +1004,22 @@ json::sax_parse(s, &default_logger); CHECK(default_logger.events.size() == 14); CHECK(default_logger.events == std::vector<std::string>( - { - "start_array()", "number_unsigned(1)", "start_array()", - "string(string)", "number_float(43.12)", "end_array()", "null()", - "start_object()", "key(key1)", "boolean(true)", "key(key2)", - "boolean(false)", "end_object()", "end_array()" - })); + {"start_array()", "number_unsigned(1)", "start_array()", "string(string)", "number_float(43.12)", "end_array()", "null()", "start_object()", "key(key1)", "boolean(true)", "key(key2)", "boolean(false)", "end_object()", "end_array()"})); json::sax_parse(s, &exit_after_start_object); CHECK(exit_after_start_object.events.size() == 8); CHECK(exit_after_start_object.events == std::vector<std::string>( - { - "start_array()", "number_unsigned(1)", "start_array()", - "string(string)", "number_float(43.12)", "end_array()", "null()", - "start_object()" - })); + {"start_array()", "number_unsigned(1)", "start_array()", "string(string)", "number_float(43.12)", "end_array()", "null()", "start_object()"})); json::sax_parse(s, &exit_after_key); CHECK(exit_after_key.events.size() == 9); CHECK(exit_after_key.events == std::vector<std::string>( - { - "start_array()", "number_unsigned(1)", "start_array()", - "string(string)", "number_float(43.12)", "end_array()", "null()", - "start_object()", "key(key1)" - })); + {"start_array()", "number_unsigned(1)", "start_array()", "string(string)", "number_float(43.12)", "end_array()", "null()", "start_object()", "key(key1)"})); json::sax_parse(s, &exit_after_start_array); CHECK(exit_after_start_array.events.size() == 1); CHECK(exit_after_start_array.events == std::vector<std::string>( - { - "start_array()" - })); + {"start_array()"})); } SECTION("JSON Lines") @@ -1131,13 +1065,7 @@ } } -TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, - char, unsigned char, signed char, - wchar_t, - char16_t, char32_t, - std::uint8_t, std::int8_t, - std::int16_t, std::uint16_t, - std::int32_t, std::uint32_t) +TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, char, unsigned char, signed char, wchar_t, char16_t, char32_t, std::uint8_t, std::int8_t, std::int16_t, std::uint16_t, std::int32_t, std::uint32_t) { std::vector<T> const v = {'t', 'r', 'u', 'e'}; CHECK(json::parse(v) == json(true)); @@ -1149,8 +1077,7 @@ CHECK(l.events == std::vector<std::string>({"boolean(true)"})); } -TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, - char, unsigned char, std::uint8_t) +TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, char, unsigned char, std::uint8_t) { // a star emoji std::vector<T> const v = {'"', static_cast<T>(0xe2u), static_cast<T>(0xadu), static_cast<T>(0x90u), static_cast<T>(0xefu), static_cast<T>(0xb8u), static_cast<T>(0x8fu), '"'}; @@ -1162,8 +1089,7 @@ CHECK(l.events.size() == 1); } -TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, - char16_t, std::uint16_t) +TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, char16_t, std::uint16_t) { // a star emoji std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')}; @@ -1175,8 +1101,7 @@ CHECK(l.events.size() == 1); } -TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, - char32_t, std::uint32_t) +TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, char32_t, std::uint32_t) { // a star emoji std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
diff --git a/tests/src/unit-disabled_exceptions.cpp b/tests/src/unit-disabled_exceptions.cpp index 4ad1551..032b0c6 100644 --- a/tests/src/unit-disabled_exceptions.cpp +++ b/tests/src/unit-disabled_exceptions.cpp
@@ -23,11 +23,13 @@ class sax_no_exception : public nlohmann::detail::json_sax_dom_parser<json> { public: - explicit sax_no_exception(json& j) : nlohmann::detail::json_sax_dom_parser<json>(j, false) {} + explicit sax_no_exception(json& j) + : nlohmann::detail::json_sax_dom_parser<json>(j, false) + {} static bool parse_error(std::size_t /*position*/, const std::string& /*last_token*/, const json::exception& ex) { - error_string = new std::string(ex.what()); // NOLINT(cppcoreguidelines-owning-memory) + error_string = new std::string(ex.what()); // NOLINT(cppcoreguidelines-owning-memory) return false; } @@ -43,9 +45,9 @@ json j; sax_no_exception sax(j); - CHECK (!json::sax_parse("xyz", &sax)); + CHECK(!json::sax_parse("xyz", &sax)); CHECK(*sax_no_exception::error_string == "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'x'"); - delete sax_no_exception::error_string; // NOLINT(cppcoreguidelines-owning-memory) + delete sax_no_exception::error_string; // NOLINT(cppcoreguidelines-owning-memory) } }
diff --git a/tests/src/unit-element_access1.cpp b/tests/src/unit-element_access1.cpp index 55a07ed..95d05d2 100644 --- a/tests/src/unit-element_access1.cpp +++ b/tests/src/unit-element_access1.cpp
@@ -45,9 +45,11 @@ SECTION("access outside bounds") { CHECK_THROWS_WITH_AS(j.at(8), - "[json.exception.out_of_range.401] array index 8 is out of range", json::out_of_range&); + "[json.exception.out_of_range.401] array index 8 is out of range", + json::out_of_range&); CHECK_THROWS_WITH_AS(j_const.at(8), - "[json.exception.out_of_range.401] array index 8 is out of range", json::out_of_range&); + "[json.exception.out_of_range.401] array index 8 is out of range", + json::out_of_range&); } SECTION("access on non-array type") @@ -359,26 +361,34 @@ json jarray2 = {"foo", "bar"}; CHECK_THROWS_WITH_AS(jarray.erase(jarray2.begin()), - "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&); + "[json.exception.invalid_iterator.202] iterator does not fit current value", + json::invalid_iterator&); CHECK_THROWS_WITH_AS(jarray.erase(jarray.begin(), jarray2.end()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); + "[json.exception.invalid_iterator.203] iterators do not fit current value", + json::invalid_iterator&); CHECK_THROWS_WITH_AS(jarray.erase(jarray2.begin(), jarray.end()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); + "[json.exception.invalid_iterator.203] iterators do not fit current value", + json::invalid_iterator&); CHECK_THROWS_WITH_AS(jarray.erase(jarray2.begin(), jarray2.end()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); + "[json.exception.invalid_iterator.203] iterators do not fit current value", + json::invalid_iterator&); } { json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}; json const jarray2 = {"foo", "bar"}; CHECK_THROWS_WITH_AS(jarray.erase(jarray2.cbegin()), - "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&); + "[json.exception.invalid_iterator.202] iterator does not fit current value", + json::invalid_iterator&); CHECK_THROWS_WITH_AS(jarray.erase(jarray.cbegin(), jarray2.cend()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); + "[json.exception.invalid_iterator.203] iterators do not fit current value", + json::invalid_iterator&); CHECK_THROWS_WITH_AS(jarray.erase(jarray2.cbegin(), jarray.cend()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); + "[json.exception.invalid_iterator.203] iterators do not fit current value", + json::invalid_iterator&); CHECK_THROWS_WITH_AS(jarray.erase(jarray2.cbegin(), jarray2.cend()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); + "[json.exception.invalid_iterator.203] iterators do not fit current value", + json::invalid_iterator&); } } } @@ -530,7 +540,8 @@ { json j; CHECK_THROWS_WITH_AS(j.erase(j.begin()), - "[json.exception.type_error.307] cannot use erase() with null", json::type_error&); + "[json.exception.type_error.307] cannot use erase() with null", + json::type_error&); } }
diff --git a/tests/src/unit-element_access2.cpp b/tests/src/unit-element_access2.cpp index 8497fb9..9b1b4b2 100644 --- a/tests/src/unit-element_access2.cpp +++ b/tests/src/unit-element_access2.cpp
@@ -11,7 +11,7 @@ #include <nlohmann/json.hpp> #ifdef JSON_TEST_NO_GLOBAL_UDLS - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) +using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif // build test with C++14 @@ -455,1004 +455,1027 @@ } } - SECTION("non-const operator[]") - { - { - Json j_null; - CHECK(j_null.is_null()); - j_null["key"] = 1; - CHECK(j_null.is_object()); - CHECK(j_null.size() == 1); - j_null["key"] = 2; - CHECK(j_null.size() == 1); - } + SECTION("non-const operator[]"){ + {Json j_null; + CHECK(j_null.is_null()); + j_null["key"] = 1; + CHECK(j_null.is_object()); + CHECK(j_null.size() == 1); + j_null["key"] = 2; + CHECK(j_null.size() == 1); + } #ifdef JSON_HAS_CPP_17 - { - std::string_view const key = "key"; - Json j_null; - CHECK(j_null.is_null()); - j_null[key] = 1; - CHECK(j_null.is_object()); - CHECK(j_null.size() == 1); - j_null[key] = 2; - CHECK(j_null.size() == 1); - } + { + std::string_view const key = "key"; + Json j_null; + CHECK(j_null.is_null()); + j_null[key] = 1; + CHECK(j_null.is_object()); + CHECK(j_null.size() == 1); + j_null[key] = 2; + CHECK(j_null.size() == 1); + } +#endif +} + +SECTION("front and back") +{ + if (std::is_same<Json, nlohmann::ordered_json>::value) + { + // "integer" is the first key + CHECK(j.front() == Json(1)); + CHECK(j_const.front() == Json(1)); + // "array" is last key + CHECK(j.back() == Json({1, 2, 3})); + CHECK(j_const.back() == Json({1, 2, 3})); + } + else + { + // "array" is the smallest key + CHECK(j.front() == Json({1, 2, 3})); + CHECK(j_const.front() == Json({1, 2, 3})); + // "unsigned" is the largest key + CHECK(j.back() == Json(1u)); + CHECK(j_const.back() == Json(1u)); + } +} + +SECTION("access specified element") +{ + SECTION("access within bounds") + { + CHECK(j["integer"] == Json(1)); + CHECK(j[typename Json::object_t::key_type("integer")] == j["integer"]); + + CHECK(j["unsigned"] == Json(1u)); + CHECK(j[typename Json::object_t::key_type("unsigned")] == j["unsigned"]); + + CHECK(j["boolean"] == Json(true)); + CHECK(j[typename Json::object_t::key_type("boolean")] == j["boolean"]); + + CHECK(j["null"] == Json(nullptr)); + CHECK(j[typename Json::object_t::key_type("null")] == j["null"]); + + CHECK(j["string"] == Json("hello world")); + CHECK(j[typename Json::object_t::key_type("string")] == j["string"]); + + CHECK(j["floating"] == Json(42.23)); + CHECK(j[typename Json::object_t::key_type("floating")] == j["floating"]); + + CHECK(j["object"] == Json::object()); + CHECK(j[typename Json::object_t::key_type("object")] == j["object"]); + + CHECK(j["array"] == Json({1, 2, 3})); + CHECK(j[typename Json::object_t::key_type("array")] == j["array"]); + + CHECK(j_const["integer"] == Json(1)); + CHECK(j_const[typename Json::object_t::key_type("integer")] == j["integer"]); + + CHECK(j_const["boolean"] == Json(true)); + CHECK(j_const[typename Json::object_t::key_type("boolean")] == j["boolean"]); + + CHECK(j_const["null"] == Json(nullptr)); + CHECK(j_const[typename Json::object_t::key_type("null")] == j["null"]); + + CHECK(j_const["string"] == Json("hello world")); + CHECK(j_const[typename Json::object_t::key_type("string")] == j["string"]); + + CHECK(j_const["floating"] == Json(42.23)); + CHECK(j_const[typename Json::object_t::key_type("floating")] == j["floating"]); + + CHECK(j_const["object"] == Json::object()); + CHECK(j_const[typename Json::object_t::key_type("object")] == j["object"]); + + CHECK(j_const["array"] == Json({1, 2, 3})); + CHECK(j_const[typename Json::object_t::key_type("array")] == j["array"]); + } + +#ifdef JSON_HAS_CPP_17 + SECTION("access within bounds (string_view)") + { + CHECK(j["integer"] == Json(1)); + CHECK(j[std::string_view("integer")] == j["integer"]); + + CHECK(j["unsigned"] == Json(1u)); + CHECK(j[std::string_view("unsigned")] == j["unsigned"]); + + CHECK(j["boolean"] == Json(true)); + CHECK(j[std::string_view("boolean")] == j["boolean"]); + + CHECK(j["null"] == Json(nullptr)); + CHECK(j[std::string_view("null")] == j["null"]); + + CHECK(j["string"] == Json("hello world")); + CHECK(j[std::string_view("string")] == j["string"]); + + CHECK(j["floating"] == Json(42.23)); + CHECK(j[std::string_view("floating")] == j["floating"]); + + CHECK(j["object"] == Json::object()); + CHECK(j[std::string_view("object")] == j["object"]); + + CHECK(j["array"] == Json({1, 2, 3})); + CHECK(j[std::string_view("array")] == j["array"]); + + CHECK(j_const["integer"] == Json(1)); + CHECK(j_const[std::string_view("integer")] == j["integer"]); + + CHECK(j_const["boolean"] == Json(true)); + CHECK(j_const[std::string_view("boolean")] == j["boolean"]); + + CHECK(j_const["null"] == Json(nullptr)); + CHECK(j_const[std::string_view("null")] == j["null"]); + + CHECK(j_const["string"] == Json("hello world")); + CHECK(j_const[std::string_view("string")] == j["string"]); + + CHECK(j_const["floating"] == Json(42.23)); + CHECK(j_const[std::string_view("floating")] == j["floating"]); + + CHECK(j_const["object"] == Json::object()); + CHECK(j_const[std::string_view("object")] == j["object"]); + + CHECK(j_const["array"] == Json({1, 2, 3})); + CHECK(j_const[std::string_view("array")] == j["array"]); + } +#endif + + SECTION("access on non-object type") + { + SECTION("null") + { + Json j_nonobject(Json::value_t::null); + Json j_nonobject2(Json::value_t::null); + const Json j_const_nonobject(j_nonobject); + + CHECK_NOTHROW(j_nonobject["foo"]); + CHECK_NOTHROW(j_nonobject2[typename Json::object_t::key_type("foo")]); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], "[json.exception.type_error.305] cannot use operator[] with a string argument with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with null", typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_NOTHROW(j_nonobject2[std::string_view("foo")]); + CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with null", typename Json::type_error&); #endif } - SECTION("front and back") + SECTION("boolean") { - if (std::is_same<Json, nlohmann::ordered_json>::value) + Json j_nonobject(Json::value_t::boolean); + const Json j_const_nonobject(j_nonobject); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", + typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typename Json::type_error&); +#endif + } + + SECTION("string") + { + Json j_nonobject(Json::value_t::string); + const Json j_const_nonobject(j_nonobject); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with string", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with string", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with string", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with string", + typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with string", typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with string", typename Json::type_error&); +#endif + } + + SECTION("array") + { + Json j_nonobject(Json::value_t::array); + const Json j_const_nonobject(j_nonobject); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with array", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with array", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with array", + typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&); +#endif + } + + SECTION("number (integer)") + { + Json j_nonobject(Json::value_t::number_integer); + const Json j_const_nonobject(j_nonobject); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); +#endif + } + + SECTION("number (unsigned)") + { + Json j_nonobject(Json::value_t::number_unsigned); + const Json j_const_nonobject(j_nonobject); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); +#endif + } + + SECTION("number (floating-point)") + { + Json j_nonobject(Json::value_t::number_float); + const Json j_const_nonobject(j_nonobject); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", + typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); +#endif + } + } +} + +SECTION("remove specified element") +{ + SECTION("remove element by key") + { + CHECK(j.find("integer") != j.end()); + CHECK(j.erase("integer") == 1); + CHECK(j.find("integer") == j.end()); + CHECK(j.erase("integer") == 0); + + CHECK(j.find("unsigned") != j.end()); + CHECK(j.erase("unsigned") == 1); + CHECK(j.find("unsigned") == j.end()); + CHECK(j.erase("unsigned") == 0); + + CHECK(j.find("boolean") != j.end()); + CHECK(j.erase("boolean") == 1); + CHECK(j.find("boolean") == j.end()); + CHECK(j.erase("boolean") == 0); + + CHECK(j.find("null") != j.end()); + CHECK(j.erase("null") == 1); + CHECK(j.find("null") == j.end()); + CHECK(j.erase("null") == 0); + + CHECK(j.find("string") != j.end()); + CHECK(j.erase("string") == 1); + CHECK(j.find("string") == j.end()); + CHECK(j.erase("string") == 0); + + CHECK(j.find("floating") != j.end()); + CHECK(j.erase("floating") == 1); + CHECK(j.find("floating") == j.end()); + CHECK(j.erase("floating") == 0); + + CHECK(j.find("object") != j.end()); + CHECK(j.erase("object") == 1); + CHECK(j.find("object") == j.end()); + CHECK(j.erase("object") == 0); + + CHECK(j.find("array") != j.end()); + CHECK(j.erase("array") == 1); + CHECK(j.find("array") == j.end()); + CHECK(j.erase("array") == 0); + } + +#ifdef JSON_HAS_CPP_17 + SECTION("remove element by key (string_view)") + { + CHECK(j.find(std::string_view("integer")) != j.end()); + CHECK(j.erase(std::string_view("integer")) == 1); + CHECK(j.find(std::string_view("integer")) == j.end()); + CHECK(j.erase(std::string_view("integer")) == 0); + + CHECK(j.find(std::string_view("unsigned")) != j.end()); + CHECK(j.erase(std::string_view("unsigned")) == 1); + CHECK(j.find(std::string_view("unsigned")) == j.end()); + CHECK(j.erase(std::string_view("unsigned")) == 0); + + CHECK(j.find(std::string_view("boolean")) != j.end()); + CHECK(j.erase(std::string_view("boolean")) == 1); + CHECK(j.find(std::string_view("boolean")) == j.end()); + CHECK(j.erase(std::string_view("boolean")) == 0); + + CHECK(j.find(std::string_view("null")) != j.end()); + CHECK(j.erase(std::string_view("null")) == 1); + CHECK(j.find(std::string_view("null")) == j.end()); + CHECK(j.erase(std::string_view("null")) == 0); + + CHECK(j.find(std::string_view("string")) != j.end()); + CHECK(j.erase(std::string_view("string")) == 1); + CHECK(j.find(std::string_view("string")) == j.end()); + CHECK(j.erase(std::string_view("string")) == 0); + + CHECK(j.find(std::string_view("floating")) != j.end()); + CHECK(j.erase(std::string_view("floating")) == 1); + CHECK(j.find(std::string_view("floating")) == j.end()); + CHECK(j.erase(std::string_view("floating")) == 0); + + CHECK(j.find(std::string_view("object")) != j.end()); + CHECK(j.erase(std::string_view("object")) == 1); + CHECK(j.find(std::string_view("object")) == j.end()); + CHECK(j.erase(std::string_view("object")) == 0); + + CHECK(j.find(std::string_view("array")) != j.end()); + CHECK(j.erase(std::string_view("array")) == 1); + CHECK(j.find(std::string_view("array")) == j.end()); + CHECK(j.erase(std::string_view("array")) == 0); + } +#endif + + SECTION("remove element by iterator") + { + SECTION("erase(begin())") + { { - // "integer" is the first key - CHECK(j.front() == Json(1)); - CHECK(j_const.front() == Json(1)); - // "array" is last key - CHECK(j.back() == Json({1, 2, 3})); - CHECK(j_const.back() == Json({1, 2, 3})); + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + typename Json::iterator const it2 = jobject.erase(jobject.begin()); + CHECK(jobject == Json({{"b", 1}, {"c", 17u}})); + CHECK(*it2 == Json(1)); } - else { - // "array" is the smallest key - CHECK(j.front() == Json({1, 2, 3})); - CHECK(j_const.front() == Json({1, 2, 3})); - // "unsigned" is the largest key - CHECK(j.back() == Json(1u)); - CHECK(j_const.back() == Json(1u)); + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + typename Json::const_iterator const it2 = jobject.erase(jobject.cbegin()); + CHECK(jobject == Json({{"b", 1}, {"c", 17u}})); + CHECK(*it2 == Json(1)); } } - SECTION("access specified element") + SECTION("erase(begin(), end())") { - SECTION("access within bounds") { - CHECK(j["integer"] == Json(1)); - CHECK(j[typename Json::object_t::key_type("integer")] == j["integer"]); - - CHECK(j["unsigned"] == Json(1u)); - CHECK(j[typename Json::object_t::key_type("unsigned")] == j["unsigned"]); - - CHECK(j["boolean"] == Json(true)); - CHECK(j[typename Json::object_t::key_type("boolean")] == j["boolean"]); - - CHECK(j["null"] == Json(nullptr)); - CHECK(j[typename Json::object_t::key_type("null")] == j["null"]); - - CHECK(j["string"] == Json("hello world")); - CHECK(j[typename Json::object_t::key_type("string")] == j["string"]); - - CHECK(j["floating"] == Json(42.23)); - CHECK(j[typename Json::object_t::key_type("floating")] == j["floating"]); - - CHECK(j["object"] == Json::object()); - CHECK(j[typename Json::object_t::key_type("object")] == j["object"]); - - CHECK(j["array"] == Json({1, 2, 3})); - CHECK(j[typename Json::object_t::key_type("array")] == j["array"]); - - CHECK(j_const["integer"] == Json(1)); - CHECK(j_const[typename Json::object_t::key_type("integer")] == j["integer"]); - - CHECK(j_const["boolean"] == Json(true)); - CHECK(j_const[typename Json::object_t::key_type("boolean")] == j["boolean"]); - - CHECK(j_const["null"] == Json(nullptr)); - CHECK(j_const[typename Json::object_t::key_type("null")] == j["null"]); - - CHECK(j_const["string"] == Json("hello world")); - CHECK(j_const[typename Json::object_t::key_type("string")] == j["string"]); - - CHECK(j_const["floating"] == Json(42.23)); - CHECK(j_const[typename Json::object_t::key_type("floating")] == j["floating"]); - - CHECK(j_const["object"] == Json::object()); - CHECK(j_const[typename Json::object_t::key_type("object")] == j["object"]); - - CHECK(j_const["array"] == Json({1, 2, 3})); - CHECK(j_const[typename Json::object_t::key_type("array")] == j["array"]); + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + typename Json::iterator it2 = jobject.erase(jobject.begin(), jobject.end()); + CHECK(jobject == Json::object()); + CHECK(it2 == jobject.end()); } - -#ifdef JSON_HAS_CPP_17 - SECTION("access within bounds (string_view)") { - CHECK(j["integer"] == Json(1)); - CHECK(j[std::string_view("integer")] == j["integer"]); - - CHECK(j["unsigned"] == Json(1u)); - CHECK(j[std::string_view("unsigned")] == j["unsigned"]); - - CHECK(j["boolean"] == Json(true)); - CHECK(j[std::string_view("boolean")] == j["boolean"]); - - CHECK(j["null"] == Json(nullptr)); - CHECK(j[std::string_view("null")] == j["null"]); - - CHECK(j["string"] == Json("hello world")); - CHECK(j[std::string_view("string")] == j["string"]); - - CHECK(j["floating"] == Json(42.23)); - CHECK(j[std::string_view("floating")] == j["floating"]); - - CHECK(j["object"] == Json::object()); - CHECK(j[std::string_view("object")] == j["object"]); - - CHECK(j["array"] == Json({1, 2, 3})); - CHECK(j[std::string_view("array")] == j["array"]); - - CHECK(j_const["integer"] == Json(1)); - CHECK(j_const[std::string_view("integer")] == j["integer"]); - - CHECK(j_const["boolean"] == Json(true)); - CHECK(j_const[std::string_view("boolean")] == j["boolean"]); - - CHECK(j_const["null"] == Json(nullptr)); - CHECK(j_const[std::string_view("null")] == j["null"]); - - CHECK(j_const["string"] == Json("hello world")); - CHECK(j_const[std::string_view("string")] == j["string"]); - - CHECK(j_const["floating"] == Json(42.23)); - CHECK(j_const[std::string_view("floating")] == j["floating"]); - - CHECK(j_const["object"] == Json::object()); - CHECK(j_const[std::string_view("object")] == j["object"]); - - CHECK(j_const["array"] == Json({1, 2, 3})); - CHECK(j_const[std::string_view("array")] == j["array"]); - } -#endif - - SECTION("access on non-object type") - { - SECTION("null") - { - Json j_nonobject(Json::value_t::null); - Json j_nonobject2(Json::value_t::null); - const Json j_const_nonobject(j_nonobject); - - CHECK_NOTHROW(j_nonobject["foo"]); - CHECK_NOTHROW(j_nonobject2[typename Json::object_t::key_type("foo")]); - CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], "[json.exception.type_error.305] cannot use operator[] with a string argument with null", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with null", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_NOTHROW(j_nonobject2[std::string_view("foo")]); - CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with null", typename Json::type_error&); -#endif - } - - SECTION("boolean") - { - Json j_nonobject(Json::value_t::boolean); - const Json j_const_nonobject(j_nonobject); - CHECK_THROWS_WITH_AS(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typename Json::type_error&); -#endif - } - - SECTION("string") - { - Json j_nonobject(Json::value_t::string); - const Json j_const_nonobject(j_nonobject); - CHECK_THROWS_WITH_AS(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with string", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with string", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with string", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with string", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with string", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with string", typename Json::type_error&); -#endif - } - - SECTION("array") - { - Json j_nonobject(Json::value_t::array); - const Json j_const_nonobject(j_nonobject); - CHECK_THROWS_WITH_AS(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&); -#endif - } - - SECTION("number (integer)") - { - Json j_nonobject(Json::value_t::number_integer); - const Json j_const_nonobject(j_nonobject); - CHECK_THROWS_WITH_AS(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); -#endif - } - - SECTION("number (unsigned)") - { - Json j_nonobject(Json::value_t::number_unsigned); - const Json j_const_nonobject(j_nonobject); - CHECK_THROWS_WITH_AS(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); -#endif - } - - SECTION("number (floating-point)") - { - Json j_nonobject(Json::value_t::number_float); - const Json j_const_nonobject(j_nonobject); - CHECK_THROWS_WITH_AS(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); - CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&); -#endif - } + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + typename Json::const_iterator it2 = jobject.erase(jobject.cbegin(), jobject.cend()); + CHECK(jobject == Json::object()); + CHECK(it2 == jobject.cend()); } } - SECTION("remove specified element") + SECTION("erase(begin(), begin())") { - SECTION("remove element by key") { - CHECK(j.find("integer") != j.end()); - CHECK(j.erase("integer") == 1); - CHECK(j.find("integer") == j.end()); - CHECK(j.erase("integer") == 0); - - CHECK(j.find("unsigned") != j.end()); - CHECK(j.erase("unsigned") == 1); - CHECK(j.find("unsigned") == j.end()); - CHECK(j.erase("unsigned") == 0); - - CHECK(j.find("boolean") != j.end()); - CHECK(j.erase("boolean") == 1); - CHECK(j.find("boolean") == j.end()); - CHECK(j.erase("boolean") == 0); - - CHECK(j.find("null") != j.end()); - CHECK(j.erase("null") == 1); - CHECK(j.find("null") == j.end()); - CHECK(j.erase("null") == 0); - - CHECK(j.find("string") != j.end()); - CHECK(j.erase("string") == 1); - CHECK(j.find("string") == j.end()); - CHECK(j.erase("string") == 0); - - CHECK(j.find("floating") != j.end()); - CHECK(j.erase("floating") == 1); - CHECK(j.find("floating") == j.end()); - CHECK(j.erase("floating") == 0); - - CHECK(j.find("object") != j.end()); - CHECK(j.erase("object") == 1); - CHECK(j.find("object") == j.end()); - CHECK(j.erase("object") == 0); - - CHECK(j.find("array") != j.end()); - CHECK(j.erase("array") == 1); - CHECK(j.find("array") == j.end()); - CHECK(j.erase("array") == 0); + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + typename Json::iterator const it2 = jobject.erase(jobject.begin(), jobject.begin()); + CHECK(jobject == Json({{"a", "a"}, {"b", 1}, {"c", 17u}})); + CHECK(*it2 == Json("a")); } - -#ifdef JSON_HAS_CPP_17 - SECTION("remove element by key (string_view)") { - CHECK(j.find(std::string_view("integer")) != j.end()); - CHECK(j.erase(std::string_view("integer")) == 1); - CHECK(j.find(std::string_view("integer")) == j.end()); - CHECK(j.erase(std::string_view("integer")) == 0); - - CHECK(j.find(std::string_view("unsigned")) != j.end()); - CHECK(j.erase(std::string_view("unsigned")) == 1); - CHECK(j.find(std::string_view("unsigned")) == j.end()); - CHECK(j.erase(std::string_view("unsigned")) == 0); - - CHECK(j.find(std::string_view("boolean")) != j.end()); - CHECK(j.erase(std::string_view("boolean")) == 1); - CHECK(j.find(std::string_view("boolean")) == j.end()); - CHECK(j.erase(std::string_view("boolean")) == 0); - - CHECK(j.find(std::string_view("null")) != j.end()); - CHECK(j.erase(std::string_view("null")) == 1); - CHECK(j.find(std::string_view("null")) == j.end()); - CHECK(j.erase(std::string_view("null")) == 0); - - CHECK(j.find(std::string_view("string")) != j.end()); - CHECK(j.erase(std::string_view("string")) == 1); - CHECK(j.find(std::string_view("string")) == j.end()); - CHECK(j.erase(std::string_view("string")) == 0); - - CHECK(j.find(std::string_view("floating")) != j.end()); - CHECK(j.erase(std::string_view("floating")) == 1); - CHECK(j.find(std::string_view("floating")) == j.end()); - CHECK(j.erase(std::string_view("floating")) == 0); - - CHECK(j.find(std::string_view("object")) != j.end()); - CHECK(j.erase(std::string_view("object")) == 1); - CHECK(j.find(std::string_view("object")) == j.end()); - CHECK(j.erase(std::string_view("object")) == 0); - - CHECK(j.find(std::string_view("array")) != j.end()); - CHECK(j.erase(std::string_view("array")) == 1); - CHECK(j.find(std::string_view("array")) == j.end()); - CHECK(j.erase(std::string_view("array")) == 0); - } -#endif - - SECTION("remove element by iterator") - { - SECTION("erase(begin())") - { - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - typename Json::iterator const it2 = jobject.erase(jobject.begin()); - CHECK(jobject == Json({{"b", 1}, {"c", 17u}})); - CHECK(*it2 == Json(1)); - } - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - typename Json::const_iterator const it2 = jobject.erase(jobject.cbegin()); - CHECK(jobject == Json({{"b", 1}, {"c", 17u}})); - CHECK(*it2 == Json(1)); - } - } - - SECTION("erase(begin(), end())") - { - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - typename Json::iterator it2 = jobject.erase(jobject.begin(), jobject.end()); - CHECK(jobject == Json::object()); - CHECK(it2 == jobject.end()); - } - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - typename Json::const_iterator it2 = jobject.erase(jobject.cbegin(), jobject.cend()); - CHECK(jobject == Json::object()); - CHECK(it2 == jobject.cend()); - } - } - - SECTION("erase(begin(), begin())") - { - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - typename Json::iterator const it2 = jobject.erase(jobject.begin(), jobject.begin()); - CHECK(jobject == Json({{"a", "a"}, {"b", 1}, {"c", 17u}})); - CHECK(*it2 == Json("a")); - } - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - typename Json::const_iterator const it2 = jobject.erase(jobject.cbegin(), jobject.cbegin()); - CHECK(jobject == Json({{"a", "a"}, {"b", 1}, {"c", 17u}})); - CHECK(*it2 == Json("a")); - } - } - - SECTION("erase at offset") - { - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - typename Json::iterator const it = jobject.find("b"); - typename Json::iterator const it2 = jobject.erase(it); - CHECK(jobject == Json({{"a", "a"}, {"c", 17u}})); - CHECK(*it2 == Json(17)); - } - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - typename Json::const_iterator const it = jobject.find("b"); - typename Json::const_iterator const it2 = jobject.erase(it); - CHECK(jobject == Json({{"a", "a"}, {"c", 17u}})); - CHECK(*it2 == Json(17)); - } - } - - SECTION("erase subrange") - { - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; - typename Json::iterator const it2 = jobject.erase(jobject.find("b"), jobject.find("e")); - CHECK(jobject == Json({{"a", "a"}, {"e", true}})); - CHECK(*it2 == Json(true)); - } - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; - typename Json::const_iterator const it2 = jobject.erase(jobject.find("b"), jobject.find("e")); - CHECK(jobject == Json({{"a", "a"}, {"e", true}})); - CHECK(*it2 == Json(true)); - } - } - - SECTION("different objects") - { - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; - Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin()), - "[json.exception.invalid_iterator.202] iterator does not fit current value", typename Json::invalid_iterator&); - CHECK_THROWS_WITH_AS(jobject.erase(jobject.begin(), jobject2.end()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid_iterator&); - CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin(), jobject.end()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid_iterator&); - CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin(), jobject2.end()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid_iterator&); - } - { - Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; - Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin()), - "[json.exception.invalid_iterator.202] iterator does not fit current value", typename Json::invalid_iterator&); - CHECK_THROWS_WITH_AS(jobject.erase(jobject.cbegin(), jobject2.cend()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid_iterator&); - CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin(), jobject.cend()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid_iterator&); - CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin(), jobject2.cend()), - "[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid_iterator&); - } - } - } - - SECTION("remove element by key in non-object type") - { - SECTION("null") - { - Json j_nonobject(Json::value_t::null); - CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with null", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with null", typename Json::type_error&); -#endif - } - - SECTION("boolean") - { - Json j_nonobject(Json::value_t::boolean); - CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with boolean", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with boolean", typename Json::type_error&); -#endif - } - - SECTION("string") - { - Json j_nonobject(Json::value_t::string); - CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with string", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with string", typename Json::type_error&); -#endif - } - - SECTION("array") - { - Json j_nonobject(Json::value_t::array); - CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with array", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with array", typename Json::type_error&); -#endif - } - - SECTION("number (integer)") - { - Json j_nonobject(Json::value_t::number_integer); - CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&); -#endif - } - - SECTION("number (floating-point)") - { - Json j_nonobject(Json::value_t::number_float); - CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&); - -#ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&); -#endif - } + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + typename Json::const_iterator const it2 = jobject.erase(jobject.cbegin(), jobject.cbegin()); + CHECK(jobject == Json({{"a", "a"}, {"b", 1}, {"c", 17u}})); + CHECK(*it2 == Json("a")); } } - SECTION("find an element in an object") + SECTION("erase at offset") { - SECTION("existing element") { - for (const auto* key : - {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" - }) - { - CHECK(j.find(key) != j.end()); - CHECK(*j.find(key) == j.at(key)); - CHECK(j_const.find(key) != j_const.end()); - CHECK(*j_const.find(key) == j_const.at(key)); - } -#ifdef JSON_HAS_CPP_17 - for (const std::string_view key : - {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" - }) - { - CHECK(j.find(key) != j.end()); - CHECK(*j.find(key) == j.at(key)); - CHECK(j_const.find(key) != j_const.end()); - CHECK(*j_const.find(key) == j_const.at(key)); - } -#endif + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + typename Json::iterator const it = jobject.find("b"); + typename Json::iterator const it2 = jobject.erase(it); + CHECK(jobject == Json({{"a", "a"}, {"c", 17u}})); + CHECK(*it2 == Json(17)); } - - SECTION("nonexisting element") { - CHECK(j.find("foo") == j.end()); - CHECK(j_const.find("foo") == j_const.end()); - -#ifdef JSON_HAS_CPP_17 - CHECK(j.find(std::string_view("foo")) == j.end()); - CHECK(j_const.find(std::string_view("foo")) == j_const.end()); -#endif - } - - SECTION("all types") - { - SECTION("null") - { - Json j_nonarray(Json::value_t::null); - const Json j_nonarray_const(j_nonarray); - - CHECK(j_nonarray.find("foo") == j_nonarray.end()); - CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); - CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); -#endif - } - - SECTION("string") - { - Json j_nonarray(Json::value_t::string); - const Json j_nonarray_const(j_nonarray); - - CHECK(j_nonarray.find("foo") == j_nonarray.end()); - CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); - CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); -#endif - } - - SECTION("object") - { - Json j_nonarray(Json::value_t::object); - const Json j_nonarray_const(j_nonarray); - - CHECK(j_nonarray.find("foo") == j_nonarray.end()); - CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); - CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); -#endif - } - - SECTION("array") - { - Json j_nonarray(Json::value_t::array); - const Json j_nonarray_const(j_nonarray); - - CHECK(j_nonarray.find("foo") == j_nonarray.end()); - CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); - CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); -#endif - } - - SECTION("boolean") - { - Json j_nonarray(Json::value_t::boolean); - const Json j_nonarray_const(j_nonarray); - - CHECK(j_nonarray.find("foo") == j_nonarray.end()); - CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); - CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); -#endif - } - - SECTION("number (integer)") - { - Json j_nonarray(Json::value_t::number_integer); - const Json j_nonarray_const(j_nonarray); - - CHECK(j_nonarray.find("foo") == j_nonarray.end()); - CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); - CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); -#endif - } - - SECTION("number (unsigned)") - { - Json j_nonarray(Json::value_t::number_unsigned); - const Json j_nonarray_const(j_nonarray); - - CHECK(j_nonarray.find("foo") == j_nonarray.end()); - CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); - CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); -#endif - } - - SECTION("number (floating-point)") - { - Json j_nonarray(Json::value_t::number_float); - const Json j_nonarray_const(j_nonarray); - - CHECK(j_nonarray.find("foo") == j_nonarray.end()); - CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); - CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); -#endif - } + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + typename Json::const_iterator const it = jobject.find("b"); + typename Json::const_iterator const it2 = jobject.erase(it); + CHECK(jobject == Json({{"a", "a"}, {"c", 17u}})); + CHECK(*it2 == Json(17)); } } - SECTION("count keys in an object") + SECTION("erase subrange") { - SECTION("existing element") { - for (const auto* key : - {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" - }) - { - CHECK(j.count(key) == 1); - CHECK(j_const.count(key) == 1); - } -#ifdef JSON_HAS_CPP_17 - for (const std::string_view key : - {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" - }) - { - CHECK(j.count(key) == 1); - CHECK(j_const.count(key) == 1); - } -#endif + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; + typename Json::iterator const it2 = jobject.erase(jobject.find("b"), jobject.find("e")); + CHECK(jobject == Json({{"a", "a"}, {"e", true}})); + CHECK(*it2 == Json(true)); } - - SECTION("nonexisting element") { - CHECK(j.count("foo") == 0); - CHECK(j_const.count("foo") == 0); - -#ifdef JSON_HAS_CPP_17 - CHECK(j.count(std::string_view("foo")) == 0); - CHECK(j_const.count(std::string_view("foo")) == 0); -#endif - } - - SECTION("all types") - { - SECTION("null") - { - Json j_nonobject(Json::value_t::null); - const Json j_nonobject_const(Json::value_t::null); - - CHECK(j_nonobject.count("foo") == 0); - CHECK(j_nonobject_const.count("foo") == 0); - -#ifdef JSON_HAS_CPP_17 - CHECK(j.count(std::string_view("foo")) == 0); - CHECK(j_const.count(std::string_view("foo")) == 0); -#endif - } - - SECTION("string") - { - Json j_nonobject(Json::value_t::string); - const Json j_nonobject_const(Json::value_t::string); - - CHECK(j_nonobject.count("foo") == 0); - CHECK(j_nonobject_const.count("foo") == 0); - -#ifdef JSON_HAS_CPP_17 - CHECK(j.count(std::string_view("foo")) == 0); - CHECK(j_const.count(std::string_view("foo")) == 0); -#endif - } - - SECTION("object") - { - Json j_nonobject(Json::value_t::object); - const Json j_nonobject_const(Json::value_t::object); - - CHECK(j_nonobject.count("foo") == 0); - CHECK(j_nonobject_const.count("foo") == 0); - -#ifdef JSON_HAS_CPP_17 - CHECK(j.count(std::string_view("foo")) == 0); - CHECK(j_const.count(std::string_view("foo")) == 0); -#endif - } - - SECTION("array") - { - Json j_nonobject(Json::value_t::array); - const Json j_nonobject_const(Json::value_t::array); - - CHECK(j_nonobject.count("foo") == 0); - CHECK(j_nonobject_const.count("foo") == 0); - -#ifdef JSON_HAS_CPP_17 - CHECK(j.count(std::string_view("foo")) == 0); - CHECK(j_const.count(std::string_view("foo")) == 0); -#endif - } - - SECTION("boolean") - { - Json j_nonobject(Json::value_t::boolean); - const Json j_nonobject_const(Json::value_t::boolean); - - CHECK(j_nonobject.count("foo") == 0); - CHECK(j_nonobject_const.count("foo") == 0); - -#ifdef JSON_HAS_CPP_17 - CHECK(j.count(std::string_view("foo")) == 0); - CHECK(j_const.count(std::string_view("foo")) == 0); -#endif - } - - SECTION("number (integer)") - { - Json j_nonobject(Json::value_t::number_integer); - const Json j_nonobject_const(Json::value_t::number_integer); - - CHECK(j_nonobject.count("foo") == 0); - CHECK(j_nonobject_const.count("foo") == 0); - -#ifdef JSON_HAS_CPP_17 - CHECK(j.count(std::string_view("foo")) == 0); - CHECK(j_const.count(std::string_view("foo")) == 0); -#endif - } - - SECTION("number (unsigned)") - { - Json j_nonobject(Json::value_t::number_unsigned); - const Json j_nonobject_const(Json::value_t::number_unsigned); - - CHECK(j_nonobject.count("foo") == 0); - CHECK(j_nonobject_const.count("foo") == 0); - -#ifdef JSON_HAS_CPP_17 - CHECK(j.count(std::string_view("foo")) == 0); - CHECK(j_const.count(std::string_view("foo")) == 0); -#endif - } - - SECTION("number (floating-point)") - { - Json j_nonobject(Json::value_t::number_float); - const Json j_nonobject_const(Json::value_t::number_float); - - CHECK(j_nonobject.count("foo") == 0); - CHECK(j_nonobject_const.count("foo") == 0); - -#ifdef JSON_HAS_CPP_17 - CHECK(j.count(std::string_view("foo")) == 0); - CHECK(j_const.count(std::string_view("foo")) == 0); -#endif - } + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; + typename Json::const_iterator const it2 = jobject.erase(jobject.find("b"), jobject.find("e")); + CHECK(jobject == Json({{"a", "a"}, {"e", true}})); + CHECK(*it2 == Json(true)); } } - SECTION("check existence of key in an object") + SECTION("different objects") { - SECTION("existing element") { - for (const auto* key : - {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" - }) - { - CHECK(j.contains(key) == true); - CHECK(j_const.contains(key) == true); - } - -#ifdef JSON_HAS_CPP_17 - for (const std::string_view key : - {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" - }) - { - CHECK(j.contains(key) == true); - CHECK(j_const.contains(key) == true); - } -#endif + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; + Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin()), + "[json.exception.invalid_iterator.202] iterator does not fit current value", + typename Json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject.begin(), jobject2.end()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", + typename Json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin(), jobject.end()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", + typename Json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin(), jobject2.end()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", + typename Json::invalid_iterator&); } - - SECTION("nonexisting element") { - CHECK(j.contains("foo") == false); - CHECK(j_const.contains("foo") == false); - -#ifdef JSON_HAS_CPP_17 - CHECK(j.contains(std::string_view("foo")) == false); - CHECK(j_const.contains(std::string_view("foo")) == false); -#endif - } - - SECTION("all types") - { - SECTION("null") - { - Json j_nonobject(Json::value_t::null); - const Json j_nonobject_const(Json::value_t::null); - - CHECK(j_nonobject.contains("foo") == false); - CHECK(j_nonobject_const.contains("foo") == false); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonobject.contains(std::string_view("foo")) == false); - CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); -#endif - } - - SECTION("string") - { - Json j_nonobject(Json::value_t::string); - const Json j_nonobject_const(Json::value_t::string); - - CHECK(j_nonobject.contains("foo") == false); - CHECK(j_nonobject_const.contains("foo") == false); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonobject.contains(std::string_view("foo")) == false); - CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); -#endif - } - - SECTION("object") - { - Json j_nonobject(Json::value_t::object); - const Json j_nonobject_const(Json::value_t::object); - - CHECK(j_nonobject.contains("foo") == false); - CHECK(j_nonobject_const.contains("foo") == false); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonobject.contains(std::string_view("foo")) == false); - CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); -#endif - } - - SECTION("array") - { - Json j_nonobject(Json::value_t::array); - const Json j_nonobject_const(Json::value_t::array); - - CHECK(j_nonobject.contains("foo") == false); - CHECK(j_nonobject_const.contains("foo") == false); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonobject.contains(std::string_view("foo")) == false); - CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); -#endif - } - - SECTION("boolean") - { - Json j_nonobject(Json::value_t::boolean); - const Json j_nonobject_const(Json::value_t::boolean); - - CHECK(j_nonobject.contains("foo") == false); - CHECK(j_nonobject_const.contains("foo") == false); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonobject.contains(std::string_view("foo")) == false); - CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); -#endif - } - - SECTION("number (integer)") - { - Json j_nonobject(Json::value_t::number_integer); - const Json j_nonobject_const(Json::value_t::number_integer); - - CHECK(j_nonobject.contains("foo") == false); - CHECK(j_nonobject_const.contains("foo") == false); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonobject.contains(std::string_view("foo")) == false); - CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); -#endif - } - - SECTION("number (unsigned)") - { - Json j_nonobject(Json::value_t::number_unsigned); - const Json j_nonobject_const(Json::value_t::number_unsigned); - - CHECK(j_nonobject.contains("foo") == false); - CHECK(j_nonobject_const.contains("foo") == false); - -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonobject.contains(std::string_view("foo")) == false); - CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); -#endif - } - - SECTION("number (floating-point)") - { - Json j_nonobject(Json::value_t::number_float); - const Json j_nonobject_const(Json::value_t::number_float); - CHECK(j_nonobject.contains("foo") == false); - CHECK(j_nonobject_const.contains("foo") == false); -#ifdef JSON_HAS_CPP_17 - CHECK(j_nonobject.contains(std::string_view("foo")) == false); - CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); -#endif - } + Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; + Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin()), + "[json.exception.invalid_iterator.202] iterator does not fit current value", + typename Json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject.cbegin(), jobject2.cend()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", + typename Json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin(), jobject.cend()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", + typename Json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin(), jobject2.cend()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", + typename Json::invalid_iterator&); } } } + + SECTION("remove element by key in non-object type") + { + SECTION("null") + { + Json j_nonobject(Json::value_t::null); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with null", typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with null", typename Json::type_error&); +#endif + } + + SECTION("boolean") + { + Json j_nonobject(Json::value_t::boolean); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with boolean", typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with boolean", typename Json::type_error&); +#endif + } + + SECTION("string") + { + Json j_nonobject(Json::value_t::string); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with string", typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with string", typename Json::type_error&); +#endif + } + + SECTION("array") + { + Json j_nonobject(Json::value_t::array); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with array", typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with array", typename Json::type_error&); +#endif + } + + SECTION("number (integer)") + { + Json j_nonobject(Json::value_t::number_integer); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&); +#endif + } + + SECTION("number (floating-point)") + { + Json j_nonobject(Json::value_t::number_float); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&); + +#ifdef JSON_HAS_CPP_17 + CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&); +#endif + } + } +} + +SECTION("find an element in an object") +{ + SECTION("existing element") + { + for (const auto* key : + {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"}) + { + CHECK(j.find(key) != j.end()); + CHECK(*j.find(key) == j.at(key)); + CHECK(j_const.find(key) != j_const.end()); + CHECK(*j_const.find(key) == j_const.at(key)); + } +#ifdef JSON_HAS_CPP_17 + for (const std::string_view key : + {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"}) + { + CHECK(j.find(key) != j.end()); + CHECK(*j.find(key) == j.at(key)); + CHECK(j_const.find(key) != j_const.end()); + CHECK(*j_const.find(key) == j_const.at(key)); + } +#endif + } + + SECTION("nonexisting element") + { + CHECK(j.find("foo") == j.end()); + CHECK(j_const.find("foo") == j_const.end()); + +#ifdef JSON_HAS_CPP_17 + CHECK(j.find(std::string_view("foo")) == j.end()); + CHECK(j_const.find(std::string_view("foo")) == j_const.end()); +#endif + } + + SECTION("all types") + { + SECTION("null") + { + Json j_nonarray(Json::value_t::null); + const Json j_nonarray_const(j_nonarray); + + CHECK(j_nonarray.find("foo") == j_nonarray.end()); + CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); + CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); +#endif + } + + SECTION("string") + { + Json j_nonarray(Json::value_t::string); + const Json j_nonarray_const(j_nonarray); + + CHECK(j_nonarray.find("foo") == j_nonarray.end()); + CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); + CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); +#endif + } + + SECTION("object") + { + Json j_nonarray(Json::value_t::object); + const Json j_nonarray_const(j_nonarray); + + CHECK(j_nonarray.find("foo") == j_nonarray.end()); + CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); + CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); +#endif + } + + SECTION("array") + { + Json j_nonarray(Json::value_t::array); + const Json j_nonarray_const(j_nonarray); + + CHECK(j_nonarray.find("foo") == j_nonarray.end()); + CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); + CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); +#endif + } + + SECTION("boolean") + { + Json j_nonarray(Json::value_t::boolean); + const Json j_nonarray_const(j_nonarray); + + CHECK(j_nonarray.find("foo") == j_nonarray.end()); + CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); + CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); +#endif + } + + SECTION("number (integer)") + { + Json j_nonarray(Json::value_t::number_integer); + const Json j_nonarray_const(j_nonarray); + + CHECK(j_nonarray.find("foo") == j_nonarray.end()); + CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); + CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); +#endif + } + + SECTION("number (unsigned)") + { + Json j_nonarray(Json::value_t::number_unsigned); + const Json j_nonarray_const(j_nonarray); + + CHECK(j_nonarray.find("foo") == j_nonarray.end()); + CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); + CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); +#endif + } + + SECTION("number (floating-point)") + { + Json j_nonarray(Json::value_t::number_float); + const Json j_nonarray_const(j_nonarray); + + CHECK(j_nonarray.find("foo") == j_nonarray.end()); + CHECK(j_nonarray_const.find("foo") == j_nonarray_const.end()); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonarray.find(std::string_view("foo")) == j_nonarray.end()); + CHECK(j_nonarray_const.find(std::string_view("foo")) == j_nonarray_const.end()); +#endif + } + } +} + +SECTION("count keys in an object") +{ + SECTION("existing element") + { + for (const auto* key : + {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"}) + { + CHECK(j.count(key) == 1); + CHECK(j_const.count(key) == 1); + } +#ifdef JSON_HAS_CPP_17 + for (const std::string_view key : + {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"}) + { + CHECK(j.count(key) == 1); + CHECK(j_const.count(key) == 1); + } +#endif + } + + SECTION("nonexisting element") + { + CHECK(j.count("foo") == 0); + CHECK(j_const.count("foo") == 0); + +#ifdef JSON_HAS_CPP_17 + CHECK(j.count(std::string_view("foo")) == 0); + CHECK(j_const.count(std::string_view("foo")) == 0); +#endif + } + + SECTION("all types") + { + SECTION("null") + { + Json j_nonobject(Json::value_t::null); + const Json j_nonobject_const(Json::value_t::null); + + CHECK(j_nonobject.count("foo") == 0); + CHECK(j_nonobject_const.count("foo") == 0); + +#ifdef JSON_HAS_CPP_17 + CHECK(j.count(std::string_view("foo")) == 0); + CHECK(j_const.count(std::string_view("foo")) == 0); +#endif + } + + SECTION("string") + { + Json j_nonobject(Json::value_t::string); + const Json j_nonobject_const(Json::value_t::string); + + CHECK(j_nonobject.count("foo") == 0); + CHECK(j_nonobject_const.count("foo") == 0); + +#ifdef JSON_HAS_CPP_17 + CHECK(j.count(std::string_view("foo")) == 0); + CHECK(j_const.count(std::string_view("foo")) == 0); +#endif + } + + SECTION("object") + { + Json j_nonobject(Json::value_t::object); + const Json j_nonobject_const(Json::value_t::object); + + CHECK(j_nonobject.count("foo") == 0); + CHECK(j_nonobject_const.count("foo") == 0); + +#ifdef JSON_HAS_CPP_17 + CHECK(j.count(std::string_view("foo")) == 0); + CHECK(j_const.count(std::string_view("foo")) == 0); +#endif + } + + SECTION("array") + { + Json j_nonobject(Json::value_t::array); + const Json j_nonobject_const(Json::value_t::array); + + CHECK(j_nonobject.count("foo") == 0); + CHECK(j_nonobject_const.count("foo") == 0); + +#ifdef JSON_HAS_CPP_17 + CHECK(j.count(std::string_view("foo")) == 0); + CHECK(j_const.count(std::string_view("foo")) == 0); +#endif + } + + SECTION("boolean") + { + Json j_nonobject(Json::value_t::boolean); + const Json j_nonobject_const(Json::value_t::boolean); + + CHECK(j_nonobject.count("foo") == 0); + CHECK(j_nonobject_const.count("foo") == 0); + +#ifdef JSON_HAS_CPP_17 + CHECK(j.count(std::string_view("foo")) == 0); + CHECK(j_const.count(std::string_view("foo")) == 0); +#endif + } + + SECTION("number (integer)") + { + Json j_nonobject(Json::value_t::number_integer); + const Json j_nonobject_const(Json::value_t::number_integer); + + CHECK(j_nonobject.count("foo") == 0); + CHECK(j_nonobject_const.count("foo") == 0); + +#ifdef JSON_HAS_CPP_17 + CHECK(j.count(std::string_view("foo")) == 0); + CHECK(j_const.count(std::string_view("foo")) == 0); +#endif + } + + SECTION("number (unsigned)") + { + Json j_nonobject(Json::value_t::number_unsigned); + const Json j_nonobject_const(Json::value_t::number_unsigned); + + CHECK(j_nonobject.count("foo") == 0); + CHECK(j_nonobject_const.count("foo") == 0); + +#ifdef JSON_HAS_CPP_17 + CHECK(j.count(std::string_view("foo")) == 0); + CHECK(j_const.count(std::string_view("foo")) == 0); +#endif + } + + SECTION("number (floating-point)") + { + Json j_nonobject(Json::value_t::number_float); + const Json j_nonobject_const(Json::value_t::number_float); + + CHECK(j_nonobject.count("foo") == 0); + CHECK(j_nonobject_const.count("foo") == 0); + +#ifdef JSON_HAS_CPP_17 + CHECK(j.count(std::string_view("foo")) == 0); + CHECK(j_const.count(std::string_view("foo")) == 0); +#endif + } + } +} + +SECTION("check existence of key in an object") +{ + SECTION("existing element") + { + for (const auto* key : + {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"}) + { + CHECK(j.contains(key) == true); + CHECK(j_const.contains(key) == true); + } + +#ifdef JSON_HAS_CPP_17 + for (const std::string_view key : + {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"}) + { + CHECK(j.contains(key) == true); + CHECK(j_const.contains(key) == true); + } +#endif + } + + SECTION("nonexisting element") + { + CHECK(j.contains("foo") == false); + CHECK(j_const.contains("foo") == false); + +#ifdef JSON_HAS_CPP_17 + CHECK(j.contains(std::string_view("foo")) == false); + CHECK(j_const.contains(std::string_view("foo")) == false); +#endif + } + + SECTION("all types") + { + SECTION("null") + { + Json j_nonobject(Json::value_t::null); + const Json j_nonobject_const(Json::value_t::null); + + CHECK(j_nonobject.contains("foo") == false); + CHECK(j_nonobject_const.contains("foo") == false); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonobject.contains(std::string_view("foo")) == false); + CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); +#endif + } + + SECTION("string") + { + Json j_nonobject(Json::value_t::string); + const Json j_nonobject_const(Json::value_t::string); + + CHECK(j_nonobject.contains("foo") == false); + CHECK(j_nonobject_const.contains("foo") == false); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonobject.contains(std::string_view("foo")) == false); + CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); +#endif + } + + SECTION("object") + { + Json j_nonobject(Json::value_t::object); + const Json j_nonobject_const(Json::value_t::object); + + CHECK(j_nonobject.contains("foo") == false); + CHECK(j_nonobject_const.contains("foo") == false); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonobject.contains(std::string_view("foo")) == false); + CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); +#endif + } + + SECTION("array") + { + Json j_nonobject(Json::value_t::array); + const Json j_nonobject_const(Json::value_t::array); + + CHECK(j_nonobject.contains("foo") == false); + CHECK(j_nonobject_const.contains("foo") == false); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonobject.contains(std::string_view("foo")) == false); + CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); +#endif + } + + SECTION("boolean") + { + Json j_nonobject(Json::value_t::boolean); + const Json j_nonobject_const(Json::value_t::boolean); + + CHECK(j_nonobject.contains("foo") == false); + CHECK(j_nonobject_const.contains("foo") == false); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonobject.contains(std::string_view("foo")) == false); + CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); +#endif + } + + SECTION("number (integer)") + { + Json j_nonobject(Json::value_t::number_integer); + const Json j_nonobject_const(Json::value_t::number_integer); + + CHECK(j_nonobject.contains("foo") == false); + CHECK(j_nonobject_const.contains("foo") == false); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonobject.contains(std::string_view("foo")) == false); + CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); +#endif + } + + SECTION("number (unsigned)") + { + Json j_nonobject(Json::value_t::number_unsigned); + const Json j_nonobject_const(Json::value_t::number_unsigned); + + CHECK(j_nonobject.contains("foo") == false); + CHECK(j_nonobject_const.contains("foo") == false); + +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonobject.contains(std::string_view("foo")) == false); + CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); +#endif + } + + SECTION("number (floating-point)") + { + Json j_nonobject(Json::value_t::number_float); + const Json j_nonobject_const(Json::value_t::number_float); + CHECK(j_nonobject.contains("foo") == false); + CHECK(j_nonobject_const.contains("foo") == false); +#ifdef JSON_HAS_CPP_17 + CHECK(j_nonobject.contains(std::string_view("foo")) == false); + CHECK(j_nonobject_const.contains(std::string_view("foo")) == false); +#endif + } + } +} +} } #if !defined(JSON_NOEXCEPTION) @@ -1500,294 +1523,290 @@ // test assumes string_t and object_t::key_type are the same REQUIRE(std::is_same<string_t, typename Json::object_t::key_type>::value); - Json j - { + Json j{ {"foo", "bar"}, - {"baz", 42} - }; + {"baz", 42}}; const char* cpstr = "default"; - const char castr[] = "default"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + const char castr[] = "default"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) string_t const str = "default"; number_integer_t integer = 69; std::size_t size = 69; - SECTION("deduced ValueType") - { - SECTION("literal key") - { + SECTION("deduced ValueType"){ + SECTION("literal key"){ CHECK(j.value("foo", "default") == "bar"); - CHECK(j.value("foo", cpstr) == "bar"); - CHECK(j.value("foo", castr) == "bar"); - CHECK(j.value("foo", str) == "bar"); - // this test is in fact different from the one below, - // because of 0 considering const char * overloads - // whereas any other number does not - CHECK(j.value("baz", 0) == 42); - CHECK(j.value("baz", 47) == 42); - CHECK(j.value("baz", integer) == 42); - CHECK(j.value("baz", size) == 42); + CHECK(j.value("foo", cpstr) == "bar"); + CHECK(j.value("foo", castr) == "bar"); + CHECK(j.value("foo", str) == "bar"); + // this test is in fact different from the one below, + // because of 0 considering const char * overloads + // whereas any other number does not + CHECK(j.value("baz", 0) == 42); + CHECK(j.value("baz", 47) == 42); + CHECK(j.value("baz", integer) == 42); + CHECK(j.value("baz", size) == 42); - CHECK(j.value("bar", "default") == "default"); - CHECK(j.value("bar", 0) == 0); - CHECK(j.value("bar", 47) == 47); - CHECK(j.value("bar", integer) == integer); - CHECK(j.value("bar", size) == size); + CHECK(j.value("bar", "default") == "default"); + CHECK(j.value("bar", 0) == 0); + CHECK(j.value("bar", 47) == 47); + CHECK(j.value("bar", integer) == integer); + CHECK(j.value("bar", size) == size); - CHECK_THROWS_WITH_AS(Json().value("foo", "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - CHECK_THROWS_WITH_AS(Json().value("foo", str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - } + CHECK_THROWS_WITH_AS(Json().value("foo", "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().value("foo", str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); +} - SECTION("const char * key") - { - const char* key = "foo"; - const char* key2 = "baz"; - const char* key_notfound = "bar"; +SECTION("const char * key") +{ + const char* key = "foo"; + const char* key2 = "baz"; + const char* key_notfound = "bar"; - CHECK(j.value(key, "default") == "bar"); - CHECK(j.value(key, cpstr) == "bar"); - CHECK(j.value(key, castr) == "bar"); - CHECK(j.value(key, str) == "bar"); - CHECK(j.value(key2, 0) == 42); - CHECK(j.value(key2, 47) == 42); - CHECK(j.value(key2, integer) == 42); - CHECK(j.value(key2, size) == 42); + CHECK(j.value(key, "default") == "bar"); + CHECK(j.value(key, cpstr) == "bar"); + CHECK(j.value(key, castr) == "bar"); + CHECK(j.value(key, str) == "bar"); + CHECK(j.value(key2, 0) == 42); + CHECK(j.value(key2, 47) == 42); + CHECK(j.value(key2, integer) == 42); + CHECK(j.value(key2, size) == 42); - CHECK(j.value(key_notfound, "default") == "default"); - CHECK(j.value(key_notfound, 0) == 0); - CHECK(j.value(key_notfound, 47) == 47); - CHECK(j.value(key_notfound, integer) == integer); - CHECK(j.value(key_notfound, size) == size); + CHECK(j.value(key_notfound, "default") == "default"); + CHECK(j.value(key_notfound, 0) == 0); + CHECK(j.value(key_notfound, 47) == 47); + CHECK(j.value(key_notfound, integer) == integer); + CHECK(j.value(key_notfound, size) == size); - CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - } + CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); +} - SECTION("const char(&)[] key") - { - const char key[] = "foo"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) - const char key2[] = "baz"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) - const char key_notfound[] = "bar"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) +SECTION("const char(&)[] key") +{ + const char key[] = "foo"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + const char key2[] = "baz"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + const char key_notfound[] = "bar"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) - CHECK(j.value(key, "default") == "bar"); - CHECK(j.value(key, cpstr) == "bar"); - CHECK(j.value(key, castr) == "bar"); - CHECK(j.value(key, str) == "bar"); - CHECK(j.value(key2, 0) == 42); - CHECK(j.value(key2, 47) == 42); - CHECK(j.value(key2, integer) == 42); - CHECK(j.value(key2, size) == 42); + CHECK(j.value(key, "default") == "bar"); + CHECK(j.value(key, cpstr) == "bar"); + CHECK(j.value(key, castr) == "bar"); + CHECK(j.value(key, str) == "bar"); + CHECK(j.value(key2, 0) == 42); + CHECK(j.value(key2, 47) == 42); + CHECK(j.value(key2, integer) == 42); + CHECK(j.value(key2, size) == 42); - CHECK(j.value(key_notfound, "default") == "default"); - CHECK(j.value(key_notfound, 0) == 0); - CHECK(j.value(key_notfound, 47) == 47); - CHECK(j.value(key_notfound, integer) == integer); - CHECK(j.value(key_notfound, size) == size); + CHECK(j.value(key_notfound, "default") == "default"); + CHECK(j.value(key_notfound, 0) == 0); + CHECK(j.value(key_notfound, 47) == 47); + CHECK(j.value(key_notfound, integer) == integer); + CHECK(j.value(key_notfound, size) == size); - CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - } + CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); +} - SECTION("string_t/object_t::key_type key") - { - string_t const key = "foo"; - string_t const key2 = "baz"; - string_t const key_notfound = "bar"; +SECTION("string_t/object_t::key_type key") +{ + string_t const key = "foo"; + string_t const key2 = "baz"; + string_t const key_notfound = "bar"; - CHECK(j.value(key, "default") == "bar"); - CHECK(j.value(key, cpstr) == "bar"); - CHECK(j.value(key, castr) == "bar"); - CHECK(j.value(key, str) == "bar"); - CHECK(j.value(key2, 0) == 42); - CHECK(j.value(key2, 47) == 42); - CHECK(j.value(key2, integer) == 42); - CHECK(j.value(key2, size) == 42); + CHECK(j.value(key, "default") == "bar"); + CHECK(j.value(key, cpstr) == "bar"); + CHECK(j.value(key, castr) == "bar"); + CHECK(j.value(key, str) == "bar"); + CHECK(j.value(key2, 0) == 42); + CHECK(j.value(key2, 47) == 42); + CHECK(j.value(key2, integer) == 42); + CHECK(j.value(key2, size) == 42); - CHECK(j.value(key_notfound, "default") == "default"); - CHECK(j.value(key_notfound, 0) == 0); - CHECK(j.value(key_notfound, 47) == 47); - CHECK(j.value(key_notfound, integer) == integer); - CHECK(j.value(key_notfound, size) == size); + CHECK(j.value(key_notfound, "default") == "default"); + CHECK(j.value(key_notfound, 0) == 0); + CHECK(j.value(key_notfound, 47) == 47); + CHECK(j.value(key_notfound, integer) == integer); + CHECK(j.value(key_notfound, size) == size); - CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - } + CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); +} #ifdef JSON_HAS_CPP_17 - SECTION("std::string_view key") - { - std::string_view const key = "foo"; - std::string_view const key2 = "baz"; - std::string_view const key_notfound = "bar"; +SECTION("std::string_view key") +{ + std::string_view const key = "foo"; + std::string_view const key2 = "baz"; + std::string_view const key_notfound = "bar"; - CHECK(j.value(key, "default") == "bar"); - CHECK(j.value(key, cpstr) == "bar"); - CHECK(j.value(key, castr) == "bar"); - CHECK(j.value(key, str) == "bar"); - CHECK(j.value(key2, 0) == 42); - CHECK(j.value(key2, 47) == 42); - CHECK(j.value(key2, integer) == 42); - CHECK(j.value(key2, size) == 42); + CHECK(j.value(key, "default") == "bar"); + CHECK(j.value(key, cpstr) == "bar"); + CHECK(j.value(key, castr) == "bar"); + CHECK(j.value(key, str) == "bar"); + CHECK(j.value(key2, 0) == 42); + CHECK(j.value(key2, 47) == 42); + CHECK(j.value(key2, integer) == 42); + CHECK(j.value(key2, size) == 42); - CHECK(j.value(key_notfound, "default") == "default"); - CHECK(j.value(key_notfound, 0) == 0); - CHECK(j.value(key_notfound, 47) == 47); - CHECK(j.value(key_notfound, integer) == integer); - CHECK(j.value(key_notfound, size) == size); + CHECK(j.value(key_notfound, "default") == "default"); + CHECK(j.value(key_notfound, 0) == 0); + CHECK(j.value(key_notfound, 47) == 47); + CHECK(j.value(key_notfound, integer) == integer); + CHECK(j.value(key_notfound, size) == size); - CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - } + CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); +} #endif - } +} - SECTION("explicit ValueType") +SECTION("explicit ValueType") +{ + SECTION("literal key") { - SECTION("literal key") - { - CHECK(j.template value<string_t>("foo", "default") == "bar"); - CHECK(j.template value<string_t>("foo", cpstr) == "bar"); - CHECK(j.template value<string_t>("foo", castr) == "bar"); - CHECK(j.template value<string_t>("foo", str) == "bar"); - CHECK(j.template value<number_integer_t>("baz", 0) == 42); - CHECK(j.template value<number_integer_t>("baz", 47) == 42); - CHECK(j.template value<number_integer_t>("baz", integer) == 42); - CHECK(j.template value<std::size_t>("baz", 0) == 42); - CHECK(j.template value<std::size_t>("baz", 47) == 42); - CHECK(j.template value<std::size_t>("baz", size) == 42); + CHECK(j.template value<string_t>("foo", "default") == "bar"); + CHECK(j.template value<string_t>("foo", cpstr) == "bar"); + CHECK(j.template value<string_t>("foo", castr) == "bar"); + CHECK(j.template value<string_t>("foo", str) == "bar"); + CHECK(j.template value<number_integer_t>("baz", 0) == 42); + CHECK(j.template value<number_integer_t>("baz", 47) == 42); + CHECK(j.template value<number_integer_t>("baz", integer) == 42); + CHECK(j.template value<std::size_t>("baz", 0) == 42); + CHECK(j.template value<std::size_t>("baz", 47) == 42); + CHECK(j.template value<std::size_t>("baz", size) == 42); - CHECK(j.template value<string_t>("bar", "default") == "default"); - CHECK(j.template value<number_integer_t>("bar", 0) == 0); - CHECK(j.template value<number_integer_t>("bar", 47) == 47); - CHECK(j.template value<number_integer_t>("bar", integer) == integer); - CHECK(j.template value<std::size_t>("bar", 0) == 0); - CHECK(j.template value<std::size_t>("bar", 47) == 47); - CHECK(j.template value<std::size_t>("bar", size) == size); + CHECK(j.template value<string_t>("bar", "default") == "default"); + CHECK(j.template value<number_integer_t>("bar", 0) == 0); + CHECK(j.template value<number_integer_t>("bar", 47) == 47); + CHECK(j.template value<number_integer_t>("bar", integer) == integer); + CHECK(j.template value<std::size_t>("bar", 0) == 0); + CHECK(j.template value<std::size_t>("bar", 47) == 47); + CHECK(j.template value<std::size_t>("bar", size) == size); - CHECK_THROWS_WITH_AS(Json().template value<string_t>("foo", "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - CHECK_THROWS_WITH_AS(Json().template value<string_t>("foo", str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - } + CHECK_THROWS_WITH_AS(Json().template value<string_t>("foo", "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().template value<string_t>("foo", str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } - SECTION("const char * key") - { - const char* key = "foo"; - const char* key2 = "baz"; - const char* key_notfound = "bar"; + SECTION("const char * key") + { + const char* key = "foo"; + const char* key2 = "baz"; + const char* key_notfound = "bar"; - CHECK(j.template value<string_t>(key, "default") == "bar"); - CHECK(j.template value<string_t>(key, cpstr) == "bar"); - CHECK(j.template value<string_t>(key, castr) == "bar"); - CHECK(j.template value<string_t>(key, str) == "bar"); - CHECK(j.template value<number_integer_t>(key2, 0) == 42); - CHECK(j.template value<number_integer_t>(key2, 47) == 42); - CHECK(j.template value<number_integer_t>(key2, integer) == 42); - CHECK(j.template value<std::size_t>(key2, 0) == 42); - CHECK(j.template value<std::size_t>(key2, 47) == 42); - CHECK(j.template value<std::size_t>(key2, size) == 42); + CHECK(j.template value<string_t>(key, "default") == "bar"); + CHECK(j.template value<string_t>(key, cpstr) == "bar"); + CHECK(j.template value<string_t>(key, castr) == "bar"); + CHECK(j.template value<string_t>(key, str) == "bar"); + CHECK(j.template value<number_integer_t>(key2, 0) == 42); + CHECK(j.template value<number_integer_t>(key2, 47) == 42); + CHECK(j.template value<number_integer_t>(key2, integer) == 42); + CHECK(j.template value<std::size_t>(key2, 0) == 42); + CHECK(j.template value<std::size_t>(key2, 47) == 42); + CHECK(j.template value<std::size_t>(key2, size) == 42); - CHECK(j.template value<string_t>(key_notfound, "default") == "default"); - CHECK(j.template value<number_integer_t>(key_notfound, 0) == 0); - CHECK(j.template value<number_integer_t>(key_notfound, 47) == 47); - CHECK(j.template value<number_integer_t>(key_notfound, integer) == integer); - CHECK(j.template value<std::size_t>(key_notfound, 0) == 0); - CHECK(j.template value<std::size_t>(key_notfound, 47) == 47); - CHECK(j.template value<std::size_t>(key_notfound, size) == size); + CHECK(j.template value<string_t>(key_notfound, "default") == "default"); + CHECK(j.template value<number_integer_t>(key_notfound, 0) == 0); + CHECK(j.template value<number_integer_t>(key_notfound, 47) == 47); + CHECK(j.template value<number_integer_t>(key_notfound, integer) == integer); + CHECK(j.template value<std::size_t>(key_notfound, 0) == 0); + CHECK(j.template value<std::size_t>(key_notfound, 47) == 47); + CHECK(j.template value<std::size_t>(key_notfound, size) == size); - CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - } + CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } - SECTION("const char(&)[] key") - { - const char key[] = "foo"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) - const char key2[] = "baz"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) - const char key_notfound[] = "bar"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + SECTION("const char(&)[] key") + { + const char key[] = "foo"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + const char key2[] = "baz"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + const char key_notfound[] = "bar"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) - CHECK(j.template value<string_t>(key, "default") == "bar"); - CHECK(j.template value<string_t>(key, cpstr) == "bar"); - CHECK(j.template value<string_t>(key, castr) == "bar"); - CHECK(j.template value<string_t>(key, str) == "bar"); - CHECK(j.template value<number_integer_t>(key2, 0) == 42); - CHECK(j.template value<number_integer_t>(key2, 47) == 42); - CHECK(j.template value<number_integer_t>(key2, integer) == 42); - CHECK(j.template value<std::size_t>(key2, 0) == 42); - CHECK(j.template value<std::size_t>(key2, 47) == 42); - CHECK(j.template value<std::size_t>(key2, size) == 42); + CHECK(j.template value<string_t>(key, "default") == "bar"); + CHECK(j.template value<string_t>(key, cpstr) == "bar"); + CHECK(j.template value<string_t>(key, castr) == "bar"); + CHECK(j.template value<string_t>(key, str) == "bar"); + CHECK(j.template value<number_integer_t>(key2, 0) == 42); + CHECK(j.template value<number_integer_t>(key2, 47) == 42); + CHECK(j.template value<number_integer_t>(key2, integer) == 42); + CHECK(j.template value<std::size_t>(key2, 0) == 42); + CHECK(j.template value<std::size_t>(key2, 47) == 42); + CHECK(j.template value<std::size_t>(key2, size) == 42); - CHECK(j.template value<string_t>(key_notfound, "default") == "default"); - CHECK(j.template value<number_integer_t>(key_notfound, 0) == 0); - CHECK(j.template value<number_integer_t>(key_notfound, 47) == 47); - CHECK(j.template value<number_integer_t>(key_notfound, integer) == integer); - CHECK(j.template value<std::size_t>(key_notfound, 0) == 0); - CHECK(j.template value<std::size_t>(key_notfound, 47) == 47); - CHECK(j.template value<std::size_t>(key_notfound, size) == size); + CHECK(j.template value<string_t>(key_notfound, "default") == "default"); + CHECK(j.template value<number_integer_t>(key_notfound, 0) == 0); + CHECK(j.template value<number_integer_t>(key_notfound, 47) == 47); + CHECK(j.template value<number_integer_t>(key_notfound, integer) == integer); + CHECK(j.template value<std::size_t>(key_notfound, 0) == 0); + CHECK(j.template value<std::size_t>(key_notfound, 47) == 47); + CHECK(j.template value<std::size_t>(key_notfound, size) == size); - CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - } + CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } - SECTION("string_t/object_t::key_type key") - { - string_t const key = "foo"; - string_t const key2 = "baz"; - string_t const key_notfound = "bar"; + SECTION("string_t/object_t::key_type key") + { + string_t const key = "foo"; + string_t const key2 = "baz"; + string_t const key_notfound = "bar"; - CHECK(j.template value<string_t>(key, "default") == "bar"); - CHECK(j.template value<string_t>(key, cpstr) == "bar"); - CHECK(j.template value<string_t>(key, castr) == "bar"); - CHECK(j.template value<string_t>(key, str) == "bar"); - CHECK(j.template value<number_integer_t>(key2, 0) == 42); - CHECK(j.template value<number_integer_t>(key2, 47) == 42); - CHECK(j.template value<std::size_t>(key2, 0) == 42); - CHECK(j.template value<std::size_t>(key2, 47) == 42); + CHECK(j.template value<string_t>(key, "default") == "bar"); + CHECK(j.template value<string_t>(key, cpstr) == "bar"); + CHECK(j.template value<string_t>(key, castr) == "bar"); + CHECK(j.template value<string_t>(key, str) == "bar"); + CHECK(j.template value<number_integer_t>(key2, 0) == 42); + CHECK(j.template value<number_integer_t>(key2, 47) == 42); + CHECK(j.template value<std::size_t>(key2, 0) == 42); + CHECK(j.template value<std::size_t>(key2, 47) == 42); - CHECK(j.template value<string_t>(key_notfound, "default") == "default"); - CHECK(j.template value<number_integer_t>(key_notfound, 0) == 0); - CHECK(j.template value<number_integer_t>(key_notfound, 47) == 47); - CHECK(j.template value<std::size_t>(key_notfound, 0) == 0); - CHECK(j.template value<std::size_t>(key_notfound, 47) == 47); + CHECK(j.template value<string_t>(key_notfound, "default") == "default"); + CHECK(j.template value<number_integer_t>(key_notfound, 0) == 0); + CHECK(j.template value<number_integer_t>(key_notfound, 47) == 47); + CHECK(j.template value<std::size_t>(key_notfound, 0) == 0); + CHECK(j.template value<std::size_t>(key_notfound, 47) == 47); - CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - } + CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } #ifdef JSON_HAS_CPP_17 - SECTION("std::string_view key") - { - std::string_view const key = "foo"; - std::string_view const key2 = "baz"; - std::string_view const key_notfound = "bar"; + SECTION("std::string_view key") + { + std::string_view const key = "foo"; + std::string_view const key2 = "baz"; + std::string_view const key_notfound = "bar"; - CHECK(j.template value<string_t>(key, "default") == "bar"); - CHECK(j.template value<string_t>(key, cpstr) == "bar"); - CHECK(j.template value<string_t>(key, castr) == "bar"); - CHECK(j.template value<string_t>(key, str) == "bar"); - CHECK(j.template value<number_integer_t>(key2, 0) == 42); - CHECK(j.template value<number_integer_t>(key2, 47) == 42); - CHECK(j.template value<number_integer_t>(key2, integer) == 42); - CHECK(j.template value<std::size_t>(key2, 0) == 42); - CHECK(j.template value<std::size_t>(key2, 47) == 42); - CHECK(j.template value<std::size_t>(key2, size) == 42); + CHECK(j.template value<string_t>(key, "default") == "bar"); + CHECK(j.template value<string_t>(key, cpstr) == "bar"); + CHECK(j.template value<string_t>(key, castr) == "bar"); + CHECK(j.template value<string_t>(key, str) == "bar"); + CHECK(j.template value<number_integer_t>(key2, 0) == 42); + CHECK(j.template value<number_integer_t>(key2, 47) == 42); + CHECK(j.template value<number_integer_t>(key2, integer) == 42); + CHECK(j.template value<std::size_t>(key2, 0) == 42); + CHECK(j.template value<std::size_t>(key2, 47) == 42); + CHECK(j.template value<std::size_t>(key2, size) == 42); - CHECK(j.template value<string_t>(key_notfound, "default") == "default"); - CHECK(j.template value<number_integer_t>(key_notfound, 0) == 0); - CHECK(j.template value<number_integer_t>(key_notfound, 47) == 47); - CHECK(j.template value<number_integer_t>(key_notfound, integer) == integer); - CHECK(j.template value<std::size_t>(key_notfound, 0) == 0); - CHECK(j.template value<std::size_t>(key_notfound, 47) == 47); - CHECK(j.template value<std::size_t>(key_notfound, size) == size); + CHECK(j.template value<string_t>(key_notfound, "default") == "default"); + CHECK(j.template value<number_integer_t>(key_notfound, 0) == 0); + CHECK(j.template value<number_integer_t>(key_notfound, 47) == 47); + CHECK(j.template value<number_integer_t>(key_notfound, integer) == integer); + CHECK(j.template value<std::size_t>(key_notfound, 0) == 0); + CHECK(j.template value<std::size_t>(key_notfound, 47) == 47); + CHECK(j.template value<std::size_t>(key_notfound, size) == size); - CHECK(j.template value<std::string_view>(key, "default") == "bar"); - CHECK(j.template value<std::string_view>(key, cpstr) == "bar"); - CHECK(j.template value<std::string_view>(key, castr) == "bar"); - CHECK(j.template value<std::string_view>(key, str) == "bar"); + CHECK(j.template value<std::string_view>(key, "default") == "bar"); + CHECK(j.template value<std::string_view>(key, cpstr) == "bar"); + CHECK(j.template value<std::string_view>(key, castr) == "bar"); + CHECK(j.template value<std::string_view>(key, str) == "bar"); - CHECK(j.template value<std::string_view>(key_notfound, "default") == "default"); + CHECK(j.template value<std::string_view>(key_notfound, "default") == "default"); - CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); - } -#endif + CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); } +#endif +} }
diff --git a/tests/src/unit-hash.cpp b/tests/src/unit-hash.cpp index 7c98a27..65d86bf 100644 --- a/tests/src/unit-hash.cpp +++ b/tests/src/unit-hash.cpp
@@ -23,42 +23,42 @@ std::set<std::size_t> hashes; // null - hashes.insert(std::hash<json> {}(json(nullptr))); + hashes.insert(std::hash<json>{}(json(nullptr))); // boolean - hashes.insert(std::hash<json> {}(json(true))); - hashes.insert(std::hash<json> {}(json(false))); + hashes.insert(std::hash<json>{}(json(true))); + hashes.insert(std::hash<json>{}(json(false))); // string - hashes.insert(std::hash<json> {}(json(""))); - hashes.insert(std::hash<json> {}(json("foo"))); + hashes.insert(std::hash<json>{}(json(""))); + hashes.insert(std::hash<json>{}(json("foo"))); // number - hashes.insert(std::hash<json> {}(json(0))); - hashes.insert(std::hash<json> {}(json(static_cast<unsigned>(0)))); + hashes.insert(std::hash<json>{}(json(0))); + hashes.insert(std::hash<json>{}(json(static_cast<unsigned>(0)))); - hashes.insert(std::hash<json> {}(json(-1))); - hashes.insert(std::hash<json> {}(json(0.0))); - hashes.insert(std::hash<json> {}(json(42.23))); + hashes.insert(std::hash<json>{}(json(-1))); + hashes.insert(std::hash<json>{}(json(0.0))); + hashes.insert(std::hash<json>{}(json(42.23))); // array - hashes.insert(std::hash<json> {}(json::array())); - hashes.insert(std::hash<json> {}(json::array({1, 2, 3}))); + hashes.insert(std::hash<json>{}(json::array())); + hashes.insert(std::hash<json>{}(json::array({1, 2, 3}))); // object - hashes.insert(std::hash<json> {}(json::object())); - hashes.insert(std::hash<json> {}(json::object({{"foo", "bar"}}))); + hashes.insert(std::hash<json>{}(json::object())); + hashes.insert(std::hash<json>{}(json::object({{"foo", "bar"}}))); // binary - hashes.insert(std::hash<json> {}(json::binary({}))); - hashes.insert(std::hash<json> {}(json::binary({}, 0))); - hashes.insert(std::hash<json> {}(json::binary({}, 42))); - hashes.insert(std::hash<json> {}(json::binary({1, 2, 3}))); - hashes.insert(std::hash<json> {}(json::binary({1, 2, 3}, 0))); - hashes.insert(std::hash<json> {}(json::binary({1, 2, 3}, 42))); + hashes.insert(std::hash<json>{}(json::binary({}))); + hashes.insert(std::hash<json>{}(json::binary({}, 0))); + hashes.insert(std::hash<json>{}(json::binary({}, 42))); + hashes.insert(std::hash<json>{}(json::binary({1, 2, 3}))); + hashes.insert(std::hash<json>{}(json::binary({1, 2, 3}, 0))); + hashes.insert(std::hash<json>{}(json::binary({1, 2, 3}, 42))); // discarded - hashes.insert(std::hash<json> {}(json(json::value_t::discarded))); + hashes.insert(std::hash<json>{}(json(json::value_t::discarded))); CHECK(hashes.size() == 21); } @@ -72,42 +72,42 @@ std::set<std::size_t> hashes; // null - hashes.insert(std::hash<ordered_json> {}(ordered_json(nullptr))); + hashes.insert(std::hash<ordered_json>{}(ordered_json(nullptr))); // boolean - hashes.insert(std::hash<ordered_json> {}(ordered_json(true))); - hashes.insert(std::hash<ordered_json> {}(ordered_json(false))); + hashes.insert(std::hash<ordered_json>{}(ordered_json(true))); + hashes.insert(std::hash<ordered_json>{}(ordered_json(false))); // string - hashes.insert(std::hash<ordered_json> {}(ordered_json(""))); - hashes.insert(std::hash<ordered_json> {}(ordered_json("foo"))); + hashes.insert(std::hash<ordered_json>{}(ordered_json(""))); + hashes.insert(std::hash<ordered_json>{}(ordered_json("foo"))); // number - hashes.insert(std::hash<ordered_json> {}(ordered_json(0))); - hashes.insert(std::hash<ordered_json> {}(ordered_json(static_cast<unsigned>(0)))); + hashes.insert(std::hash<ordered_json>{}(ordered_json(0))); + hashes.insert(std::hash<ordered_json>{}(ordered_json(static_cast<unsigned>(0)))); - hashes.insert(std::hash<ordered_json> {}(ordered_json(-1))); - hashes.insert(std::hash<ordered_json> {}(ordered_json(0.0))); - hashes.insert(std::hash<ordered_json> {}(ordered_json(42.23))); + hashes.insert(std::hash<ordered_json>{}(ordered_json(-1))); + hashes.insert(std::hash<ordered_json>{}(ordered_json(0.0))); + hashes.insert(std::hash<ordered_json>{}(ordered_json(42.23))); // array - hashes.insert(std::hash<ordered_json> {}(ordered_json::array())); - hashes.insert(std::hash<ordered_json> {}(ordered_json::array({1, 2, 3}))); + hashes.insert(std::hash<ordered_json>{}(ordered_json::array())); + hashes.insert(std::hash<ordered_json>{}(ordered_json::array({1, 2, 3}))); // object - hashes.insert(std::hash<ordered_json> {}(ordered_json::object())); - hashes.insert(std::hash<ordered_json> {}(ordered_json::object({{"foo", "bar"}}))); + hashes.insert(std::hash<ordered_json>{}(ordered_json::object())); + hashes.insert(std::hash<ordered_json>{}(ordered_json::object({{"foo", "bar"}}))); // binary - hashes.insert(std::hash<ordered_json> {}(ordered_json::binary({}))); - hashes.insert(std::hash<ordered_json> {}(ordered_json::binary({}, 0))); - hashes.insert(std::hash<ordered_json> {}(ordered_json::binary({}, 42))); - hashes.insert(std::hash<ordered_json> {}(ordered_json::binary({1, 2, 3}))); - hashes.insert(std::hash<ordered_json> {}(ordered_json::binary({1, 2, 3}, 0))); - hashes.insert(std::hash<ordered_json> {}(ordered_json::binary({1, 2, 3}, 42))); + hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({}))); + hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({}, 0))); + hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({}, 42))); + hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({1, 2, 3}))); + hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({1, 2, 3}, 0))); + hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({1, 2, 3}, 42))); // discarded - hashes.insert(std::hash<ordered_json> {}(ordered_json(ordered_json::value_t::discarded))); + hashes.insert(std::hash<ordered_json>{}(ordered_json(ordered_json::value_t::discarded))); CHECK(hashes.size() == 21); }
diff --git a/tests/src/unit-inspection.cpp b/tests/src/unit-inspection.cpp index 0574094..f4eb322 100644 --- a/tests/src/unit-inspection.cpp +++ b/tests/src/unit-inspection.cpp
@@ -11,9 +11,9 @@ #include <nlohmann/json.hpp> using nlohmann::json; +#include "make_test_data_available.hpp" #include <fstream> #include <sstream> -#include "make_test_data_available.hpp" TEST_CASE("object inspection") { @@ -21,7 +21,7 @@ { SECTION("object") { - json const j {{"foo", 1}, {"bar", false}}; + json const j{{"foo", 1}, {"bar", false}}; CHECK(!j.is_null()); CHECK(!j.is_boolean()); CHECK(!j.is_number()); @@ -39,7 +39,7 @@ SECTION("array") { - json const j {"foo", 1, 1u, 42.23, false}; + json const j{"foo", 1, 1u, 42.23, false}; CHECK(!j.is_null()); CHECK(!j.is_boolean()); CHECK(!j.is_number()); @@ -202,7 +202,7 @@ SECTION("serialization") { - json const j {{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"} }; + json const j{{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"}}; SECTION("no indent / indent=-1") { @@ -329,8 +329,7 @@ SECTION("round trips") { for (const auto& s : - {"3.141592653589793", "1000000000000000010E5" - }) + {"3.141592653589793", "1000000000000000010E5"}) { json const j1 = json::parse(s); std::string s1 = j1.dump();
diff --git a/tests/src/unit-items.cpp b/tests/src/unit-items.cpp index ef2dd74..40cf5c8 100644 --- a/tests/src/unit-items.cpp +++ b/tests/src/unit-items.cpp
@@ -14,7 +14,7 @@ // This test suite uses range for loops where values are copied. This is inefficient in usual code, but required to achieve 100% coverage. DOCTEST_GCC_SUPPRESS_WARNING_PUSH #if DOCTEST_GCC >= DOCTEST_COMPILER(11, 0, 0) - DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct") +DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct") #endif DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING("-Wrange-loop-construct") @@ -25,10 +25,10 @@ { SECTION("value") { - json j = { {"A", 1}, {"B", 2} }; + json j = {{"A", 1}, {"B", 2}}; int counter = 1; - for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { switch (counter++) { @@ -58,10 +58,10 @@ SECTION("reference") { - json j = { {"A", 1}, {"B", 2} }; + json j = {{"A", 1}, {"B", 2}}; int counter = 1; - for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) + for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) { switch (counter++) { @@ -97,15 +97,15 @@ CHECK(counter == 3); // check if values where changed - CHECK(j == json({ {"A", 11}, {"B", 22} })); + CHECK(j == json({{"A", 11}, {"B", 22}})); } SECTION("const value") { - json j = { {"A", 1}, {"B", 2} }; + json j = {{"A", 1}, {"B", 2}}; int counter = 1; - for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { switch (counter++) { @@ -135,7 +135,7 @@ SECTION("const reference") { - json j = { {"A", 1}, {"B", 2} }; + json j = {{"A", 1}, {"B", 2}}; int counter = 1; for (const auto& i : json::iterator_wrapper(j)) @@ -171,10 +171,10 @@ { SECTION("value") { - const json j = { {"A", 1}, {"B", 2} }; + const json j = {{"A", 1}, {"B", 2}}; int counter = 1; - for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { switch (counter++) { @@ -204,10 +204,10 @@ SECTION("reference") { - const json j = { {"A", 1}, {"B", 2} }; + const json j = {{"A", 1}, {"B", 2}}; int counter = 1; - for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) + for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) { switch (counter++) { @@ -237,10 +237,10 @@ SECTION("const value") { - const json j = { {"A", 1}, {"B", 2} }; + const json j = {{"A", 1}, {"B", 2}}; int counter = 1; - for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { switch (counter++) { @@ -270,7 +270,7 @@ SECTION("const reference") { - const json j = { {"A", 1}, {"B", 2} }; + const json j = {{"A", 1}, {"B", 2}}; int counter = 1; for (const auto& i : json::iterator_wrapper(j)) @@ -306,10 +306,10 @@ { SECTION("value") { - json j = { "A", "B" }; + json j = {"A", "B"}; int counter = 1; - for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { switch (counter++) { @@ -339,10 +339,10 @@ SECTION("reference") { - json j = { "A", "B" }; + json j = {"A", "B"}; int counter = 1; - for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) + for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) { switch (counter++) { @@ -378,15 +378,15 @@ CHECK(counter == 3); // check if values where changed - CHECK(j == json({ "AA", "BB" })); + CHECK(j == json({"AA", "BB"})); } SECTION("const value") { - json j = { "A", "B" }; + json j = {"A", "B"}; int counter = 1; - for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { switch (counter++) { @@ -416,7 +416,7 @@ SECTION("const reference") { - json j = { "A", "B" }; + json j = {"A", "B"}; int counter = 1; for (const auto& i : json::iterator_wrapper(j)) @@ -452,10 +452,10 @@ { SECTION("value") { - const json j = { "A", "B" }; + const json j = {"A", "B"}; int counter = 1; - for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { switch (counter++) { @@ -485,10 +485,10 @@ SECTION("reference") { - const json j = { "A", "B" }; + const json j = {"A", "B"}; int counter = 1; - for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) + for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) { switch (counter++) { @@ -518,10 +518,10 @@ SECTION("const value") { - const json j = { "A", "B" }; + const json j = {"A", "B"}; int counter = 1; - for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { switch (counter++) { @@ -551,7 +551,7 @@ SECTION("const reference") { - const json j = { "A", "B" }; + const json j = {"A", "B"}; int counter = 1; for (const auto& i : json::iterator_wrapper(j)) @@ -590,7 +590,7 @@ json j = 1; int counter = 1; - for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { ++counter; CHECK(i.key() == ""); @@ -605,7 +605,7 @@ json j = 1; int counter = 1; - for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) + for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) { ++counter; CHECK(i.key() == ""); @@ -626,7 +626,7 @@ json j = 1; int counter = 1; - for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { ++counter; CHECK(i.key() == ""); @@ -659,7 +659,7 @@ const json j = 1; int counter = 1; - for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { ++counter; CHECK(i.key() == ""); @@ -674,7 +674,7 @@ const json j = 1; int counter = 1; - for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) + for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto) { ++counter; CHECK(i.key() == ""); @@ -689,7 +689,7 @@ const json j = 1; int counter = 1; - for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) + for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy) { ++counter; CHECK(i.key() == ""); @@ -718,715 +718,713 @@ TEST_CASE("items()") { - SECTION("object") + SECTION("object"){ + SECTION("value"){ + json j = {{"A", 1}, {"B", 2}}; + int counter = 1; + + for (auto i : j.items()) // NOLINT(performance-for-range-copy) { - SECTION("value") + switch (counter++) { - json j = { {"A", 1}, {"B", 2} }; - int counter = 1; - - for (auto i : j.items()) // NOLINT(performance-for-range-copy) + case 1: { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "A"); - CHECK(i.value() == json(1)); - break; - } - - case 2: - { - CHECK(i.key() == "B"); - CHECK(i.value() == json(2)); - break; - } - - default: - { - break; - } - } + CHECK(i.key() == "A"); + CHECK(i.value() == json(1)); + break; } - CHECK(counter == 3); - } - - SECTION("reference") - { - json j = { {"A", 1}, {"B", 2} }; - int counter = 1; - - for (auto& i : j.items()) // NOLINT(readability-qualified-auto) + case 2: { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "A"); - CHECK(i.value() == json(1)); - - // change the value - i.value() = json(11); - CHECK(i.value() == json(11)); - break; - } - - case 2: - { - CHECK(i.key() == "B"); - CHECK(i.value() == json(2)); - - // change the value - i.value() = json(22); - CHECK(i.value() == json(22)); - break; - } - - default: - { - break; - } - } + CHECK(i.key() == "B"); + CHECK(i.value() == json(2)); + break; } - CHECK(counter == 3); - - // check if values where changed - CHECK(j == json({ {"A", 11}, {"B", 22} })); - } - - SECTION("const value") - { - json j = { {"A", 1}, {"B", 2} }; - int counter = 1; - - for (const auto i : j.items()) // NOLINT(performance-for-range-copy) + default: { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "A"); - CHECK(i.value() == json(1)); - break; - } + break; + } + } + } - case 2: - { - CHECK(i.key() == "B"); - CHECK(i.value() == json(2)); - break; - } + CHECK(counter == 3); +} - default: - { - break; - } - } +SECTION("reference") +{ + json j = {{"A", 1}, {"B", 2}}; + int counter = 1; + + for (auto& i : j.items()) // NOLINT(readability-qualified-auto) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "A"); + CHECK(i.value() == json(1)); + + // change the value + i.value() = json(11); + CHECK(i.value() == json(11)); + break; } - CHECK(counter == 3); - } - - SECTION("const reference") - { - json j = { {"A", 1}, {"B", 2} }; - int counter = 1; - - for (const auto& i : j.items()) + case 2: { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "A"); - CHECK(i.value() == json(1)); - break; - } + CHECK(i.key() == "B"); + CHECK(i.value() == json(2)); - case 2: - { - CHECK(i.key() == "B"); - CHECK(i.value() == json(2)); - break; - } - - default: - { - break; - } - } + // change the value + i.value() = json(22); + CHECK(i.value() == json(22)); + break; } - CHECK(counter == 3); + default: + { + break; + } } + } + + CHECK(counter == 3); + + // check if values where changed + CHECK(j == json({{"A", 11}, {"B", 22}})); +} + +SECTION("const value") +{ + json j = {{"A", 1}, {"B", 2}}; + int counter = 1; + + for (const auto i : j.items()) // NOLINT(performance-for-range-copy) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "A"); + CHECK(i.value() == json(1)); + break; + } + + case 2: + { + CHECK(i.key() == "B"); + CHECK(i.value() == json(2)); + break; + } + + default: + { + break; + } + } + } + + CHECK(counter == 3); +} + +SECTION("const reference") +{ + json j = {{"A", 1}, {"B", 2}}; + int counter = 1; + + for (const auto& i : j.items()) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "A"); + CHECK(i.value() == json(1)); + break; + } + + case 2: + { + CHECK(i.key() == "B"); + CHECK(i.value() == json(2)); + break; + } + + default: + { + break; + } + } + } + + CHECK(counter == 3); +} #ifdef JSON_HAS_CPP_17 - SECTION("structured bindings") - { - json j = { {"A", 1}, {"B", 2} }; +SECTION("structured bindings") +{ + json j = {{"A", 1}, {"B", 2}}; - std::map<std::string, int> m; + std::map<std::string, int> m; - for (auto const&[key, value] : j.items()) - { - m.emplace(key, value); - } + for (auto const& [key, value] : j.items()) + { + m.emplace(key, value); + } - CHECK(j.get<decltype(m)>() == m); - } + CHECK(j.get<decltype(m)>() == m); +} #endif - } +} - SECTION("const object") +SECTION("const object") +{ + SECTION("value") { - SECTION("value") + const json j = {{"A", 1}, {"B", 2}}; + int counter = 1; + + for (auto i : j.items()) // NOLINT(performance-for-range-copy) { - const json j = { {"A", 1}, {"B", 2} }; - int counter = 1; - - for (auto i : j.items()) // NOLINT(performance-for-range-copy) + switch (counter++) { - switch (counter++) + case 1: { - case 1: - { - CHECK(i.key() == "A"); - CHECK(i.value() == json(1)); - break; - } + CHECK(i.key() == "A"); + CHECK(i.value() == json(1)); + break; + } - case 2: - { - CHECK(i.key() == "B"); - CHECK(i.value() == json(2)); - break; - } + case 2: + { + CHECK(i.key() == "B"); + CHECK(i.value() == json(2)); + break; + } - default: - { - break; - } + default: + { + break; } } - - CHECK(counter == 3); } - SECTION("reference") - { - const json j = { {"A", 1}, {"B", 2} }; - int counter = 1; - - for (auto& i : j.items()) // NOLINT(readability-qualified-auto) - { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "A"); - CHECK(i.value() == json(1)); - break; - } - - case 2: - { - CHECK(i.key() == "B"); - CHECK(i.value() == json(2)); - break; - } - - default: - { - break; - } - } - } - - CHECK(counter == 3); - } - - SECTION("const value") - { - const json j = { {"A", 1}, {"B", 2} }; - int counter = 1; - - for (const auto i : j.items()) // NOLINT(performance-for-range-copy) - { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "A"); - CHECK(i.value() == json(1)); - break; - } - - case 2: - { - CHECK(i.key() == "B"); - CHECK(i.value() == json(2)); - break; - } - - default: - { - break; - } - } - } - - CHECK(counter == 3); - } - - SECTION("const reference") - { - const json j = { {"A", 1}, {"B", 2} }; - int counter = 1; - - for (const auto& i : j.items()) - { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "A"); - CHECK(i.value() == json(1)); - break; - } - - case 2: - { - CHECK(i.key() == "B"); - CHECK(i.value() == json(2)); - break; - } - - default: - { - break; - } - } - } - - CHECK(counter == 3); - } + CHECK(counter == 3); } - SECTION("array") + SECTION("reference") { - SECTION("value") + const json j = {{"A", 1}, {"B", 2}}; + int counter = 1; + + for (auto& i : j.items()) // NOLINT(readability-qualified-auto) { - json j = { "A", "B" }; - int counter = 1; - - for (auto i : j.items()) // NOLINT(performance-for-range-copy) + switch (counter++) { - switch (counter++) + case 1: { - case 1: - { - CHECK(i.key() == "0"); - CHECK(i.value() == "A"); - break; - } + CHECK(i.key() == "A"); + CHECK(i.value() == json(1)); + break; + } - case 2: - { - CHECK(i.key() == "1"); - CHECK(i.value() == "B"); - break; - } + case 2: + { + CHECK(i.key() == "B"); + CHECK(i.value() == json(2)); + break; + } - default: - { - break; - } + default: + { + break; } } - - CHECK(counter == 3); } - SECTION("reference") - { - json j = { "A", "B" }; - int counter = 1; - - for (auto& i : j.items()) // NOLINT(readability-qualified-auto) - { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "0"); - CHECK(i.value() == "A"); - - // change the value - i.value() = "AA"; - CHECK(i.value() == "AA"); - break; - } - - case 2: - { - CHECK(i.key() == "1"); - CHECK(i.value() == "B"); - - // change the value - i.value() = "BB"; - CHECK(i.value() == "BB"); - break; - } - - default: - { - break; - } - } - } - - CHECK(counter == 3); - - // check if values where changed - CHECK(j == json({ "AA", "BB" })); - } - - SECTION("const value") - { - json j = { "A", "B" }; - int counter = 1; - - for (const auto i : j.items()) // NOLINT(performance-for-range-copy) - { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "0"); - CHECK(i.value() == "A"); - break; - } - - case 2: - { - CHECK(i.key() == "1"); - CHECK(i.value() == "B"); - break; - } - - default: - { - break; - } - } - } - - CHECK(counter == 3); - } - - SECTION("const reference") - { - json j = { "A", "B" }; - int counter = 1; - - for (const auto& i : j.items()) - { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "0"); - CHECK(i.value() == "A"); - break; - } - - case 2: - { - CHECK(i.key() == "1"); - CHECK(i.value() == "B"); - break; - } - - default: - { - break; - } - } - } - - CHECK(counter == 3); - } + CHECK(counter == 3); } - SECTION("const array") + SECTION("const value") { - SECTION("value") + const json j = {{"A", 1}, {"B", 2}}; + int counter = 1; + + for (const auto i : j.items()) // NOLINT(performance-for-range-copy) { - const json j = { "A", "B" }; - int counter = 1; - - for (auto i : j.items()) // NOLINT(performance-for-range-copy) + switch (counter++) { - switch (counter++) + case 1: { - case 1: - { - CHECK(i.key() == "0"); - CHECK(i.value() == "A"); - break; - } + CHECK(i.key() == "A"); + CHECK(i.value() == json(1)); + break; + } - case 2: - { - CHECK(i.key() == "1"); - CHECK(i.value() == "B"); - break; - } + case 2: + { + CHECK(i.key() == "B"); + CHECK(i.value() == json(2)); + break; + } - default: - { - break; - } + default: + { + break; } } - - CHECK(counter == 3); } - SECTION("reference") - { - const json j = { "A", "B" }; - int counter = 1; - - for (auto& i : j.items()) // NOLINT(readability-qualified-auto) - { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "0"); - CHECK(i.value() == "A"); - break; - } - - case 2: - { - CHECK(i.key() == "1"); - CHECK(i.value() == "B"); - break; - } - - default: - { - break; - } - } - } - - CHECK(counter == 3); - } - - SECTION("const value") - { - const json j = { "A", "B" }; - int counter = 1; - - for (const auto i : j.items()) // NOLINT(performance-for-range-copy) - { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "0"); - CHECK(i.value() == "A"); - break; - } - - case 2: - { - CHECK(i.key() == "1"); - CHECK(i.value() == "B"); - break; - } - - default: - { - break; - } - } - } - - CHECK(counter == 3); - } - - SECTION("const reference") - { - const json j = { "A", "B" }; - int counter = 1; - - for (const auto& i : j.items()) - { - switch (counter++) - { - case 1: - { - CHECK(i.key() == "0"); - CHECK(i.value() == "A"); - break; - } - - case 2: - { - CHECK(i.key() == "1"); - CHECK(i.value() == "B"); - break; - } - - default: - { - break; - } - } - } - - CHECK(counter == 3); - } + CHECK(counter == 3); } - SECTION("primitive") + SECTION("const reference") { - SECTION("value") + const json j = {{"A", 1}, {"B", 2}}; + int counter = 1; + + for (const auto& i : j.items()) { - json j = 1; - int counter = 1; - - for (auto i : j.items()) // NOLINT(performance-for-range-copy) + switch (counter++) { - ++counter; - CHECK(i.key() == ""); - CHECK(i.value() == json(1)); - } + case 1: + { + CHECK(i.key() == "A"); + CHECK(i.value() == json(1)); + break; + } - CHECK(counter == 2); + case 2: + { + CHECK(i.key() == "B"); + CHECK(i.value() == json(2)); + break; + } + + default: + { + break; + } + } } - SECTION("reference") - { - json j = 1; - int counter = 1; - - for (auto& i : j.items()) // NOLINT(readability-qualified-auto) - { - ++counter; - CHECK(i.key() == ""); - CHECK(i.value() == json(1)); - - // change value - i.value() = json(2); - } - - CHECK(counter == 2); - - // check if value has changed - CHECK(j == json(2)); - } - - SECTION("const value") - { - json j = 1; - int counter = 1; - - for (const auto i : j.items()) // NOLINT(performance-for-range-copy) - { - ++counter; - CHECK(i.key() == ""); - CHECK(i.value() == json(1)); - } - - CHECK(counter == 2); - } - - SECTION("const reference") - { - json j = 1; - int counter = 1; - - for (const auto& i : j.items()) - { - ++counter; - CHECK(i.key() == ""); - CHECK(i.value() == json(1)); - } - - CHECK(counter == 2); - } + CHECK(counter == 3); } +} - SECTION("const primitive") +SECTION("array") +{ + SECTION("value") { - SECTION("value") + json j = {"A", "B"}; + int counter = 1; + + for (auto i : j.items()) // NOLINT(performance-for-range-copy) { - const json j = 1; - int counter = 1; - - for (auto i : j.items()) // NOLINT(performance-for-range-copy) + switch (counter++) { - ++counter; - CHECK(i.key() == ""); - CHECK(i.value() == json(1)); - } + case 1: + { + CHECK(i.key() == "0"); + CHECK(i.value() == "A"); + break; + } - CHECK(counter == 2); + case 2: + { + CHECK(i.key() == "1"); + CHECK(i.value() == "B"); + break; + } + + default: + { + break; + } + } } - SECTION("reference") - { - const json j = 1; - int counter = 1; - - for (auto& i : j.items()) // NOLINT(readability-qualified-auto) - { - ++counter; - CHECK(i.key() == ""); - CHECK(i.value() == json(1)); - } - - CHECK(counter == 2); - } - - SECTION("const value") - { - const json j = 1; - int counter = 1; - - for (const auto i : j.items()) // NOLINT(performance-for-range-copy) - { - ++counter; - CHECK(i.key() == ""); - CHECK(i.value() == json(1)); - } - - CHECK(counter == 2); - } - - SECTION("const reference") - { - const json j = 1; - int counter = 1; - - for (const auto& i : j.items()) - { - ++counter; - CHECK(i.key() == ""); - CHECK(i.value() == json(1)); - } - - CHECK(counter == 2); - } + CHECK(counter == 3); } + + SECTION("reference") + { + json j = {"A", "B"}; + int counter = 1; + + for (auto& i : j.items()) // NOLINT(readability-qualified-auto) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "0"); + CHECK(i.value() == "A"); + + // change the value + i.value() = "AA"; + CHECK(i.value() == "AA"); + break; + } + + case 2: + { + CHECK(i.key() == "1"); + CHECK(i.value() == "B"); + + // change the value + i.value() = "BB"; + CHECK(i.value() == "BB"); + break; + } + + default: + { + break; + } + } + } + + CHECK(counter == 3); + + // check if values where changed + CHECK(j == json({"AA", "BB"})); + } + + SECTION("const value") + { + json j = {"A", "B"}; + int counter = 1; + + for (const auto i : j.items()) // NOLINT(performance-for-range-copy) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "0"); + CHECK(i.value() == "A"); + break; + } + + case 2: + { + CHECK(i.key() == "1"); + CHECK(i.value() == "B"); + break; + } + + default: + { + break; + } + } + } + + CHECK(counter == 3); + } + + SECTION("const reference") + { + json j = {"A", "B"}; + int counter = 1; + + for (const auto& i : j.items()) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "0"); + CHECK(i.value() == "A"); + break; + } + + case 2: + { + CHECK(i.key() == "1"); + CHECK(i.value() == "B"); + break; + } + + default: + { + break; + } + } + } + + CHECK(counter == 3); + } +} + +SECTION("const array") +{ + SECTION("value") + { + const json j = {"A", "B"}; + int counter = 1; + + for (auto i : j.items()) // NOLINT(performance-for-range-copy) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "0"); + CHECK(i.value() == "A"); + break; + } + + case 2: + { + CHECK(i.key() == "1"); + CHECK(i.value() == "B"); + break; + } + + default: + { + break; + } + } + } + + CHECK(counter == 3); + } + + SECTION("reference") + { + const json j = {"A", "B"}; + int counter = 1; + + for (auto& i : j.items()) // NOLINT(readability-qualified-auto) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "0"); + CHECK(i.value() == "A"); + break; + } + + case 2: + { + CHECK(i.key() == "1"); + CHECK(i.value() == "B"); + break; + } + + default: + { + break; + } + } + } + + CHECK(counter == 3); + } + + SECTION("const value") + { + const json j = {"A", "B"}; + int counter = 1; + + for (const auto i : j.items()) // NOLINT(performance-for-range-copy) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "0"); + CHECK(i.value() == "A"); + break; + } + + case 2: + { + CHECK(i.key() == "1"); + CHECK(i.value() == "B"); + break; + } + + default: + { + break; + } + } + } + + CHECK(counter == 3); + } + + SECTION("const reference") + { + const json j = {"A", "B"}; + int counter = 1; + + for (const auto& i : j.items()) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "0"); + CHECK(i.value() == "A"); + break; + } + + case 2: + { + CHECK(i.key() == "1"); + CHECK(i.value() == "B"); + break; + } + + default: + { + break; + } + } + } + + CHECK(counter == 3); + } +} + +SECTION("primitive") +{ + SECTION("value") + { + json j = 1; + int counter = 1; + + for (auto i : j.items()) // NOLINT(performance-for-range-copy) + { + ++counter; + CHECK(i.key() == ""); + CHECK(i.value() == json(1)); + } + + CHECK(counter == 2); + } + + SECTION("reference") + { + json j = 1; + int counter = 1; + + for (auto& i : j.items()) // NOLINT(readability-qualified-auto) + { + ++counter; + CHECK(i.key() == ""); + CHECK(i.value() == json(1)); + + // change value + i.value() = json(2); + } + + CHECK(counter == 2); + + // check if value has changed + CHECK(j == json(2)); + } + + SECTION("const value") + { + json j = 1; + int counter = 1; + + for (const auto i : j.items()) // NOLINT(performance-for-range-copy) + { + ++counter; + CHECK(i.key() == ""); + CHECK(i.value() == json(1)); + } + + CHECK(counter == 2); + } + + SECTION("const reference") + { + json j = 1; + int counter = 1; + + for (const auto& i : j.items()) + { + ++counter; + CHECK(i.key() == ""); + CHECK(i.value() == json(1)); + } + + CHECK(counter == 2); + } +} + +SECTION("const primitive") +{ + SECTION("value") + { + const json j = 1; + int counter = 1; + + for (auto i : j.items()) // NOLINT(performance-for-range-copy) + { + ++counter; + CHECK(i.key() == ""); + CHECK(i.value() == json(1)); + } + + CHECK(counter == 2); + } + + SECTION("reference") + { + const json j = 1; + int counter = 1; + + for (auto& i : j.items()) // NOLINT(readability-qualified-auto) + { + ++counter; + CHECK(i.key() == ""); + CHECK(i.value() == json(1)); + } + + CHECK(counter == 2); + } + + SECTION("const value") + { + const json j = 1; + int counter = 1; + + for (const auto i : j.items()) // NOLINT(performance-for-range-copy) + { + ++counter; + CHECK(i.key() == ""); + CHECK(i.value() == json(1)); + } + + CHECK(counter == 2); + } + + SECTION("const reference") + { + const json j = 1; + int counter = 1; + + for (const auto& i : j.items()) + { + ++counter; + CHECK(i.key() == ""); + CHECK(i.value() == json(1)); + } + + CHECK(counter == 2); + } +} } DOCTEST_GCC_SUPPRESS_WARNING_POP
diff --git a/tests/src/unit-iterators2.cpp b/tests/src/unit-iterators2.cpp index ce8c95b..116d231 100644 --- a/tests/src/unit-iterators2.cpp +++ b/tests/src/unit-iterators2.cpp
@@ -59,14 +59,14 @@ // comparison: not equal { // check definition - CHECK( (it1 != it1) == !(it1 == it1) ); - CHECK( (it1 != it2) == !(it1 == it2) ); - CHECK( (it1 != it3) == !(it1 == it3) ); - CHECK( (it2 != it3) == !(it2 == it3) ); - CHECK( (it1_c != it1_c) == !(it1_c == it1_c) ); - CHECK( (it1_c != it2_c) == !(it1_c == it2_c) ); - CHECK( (it1_c != it3_c) == !(it1_c == it3_c) ); - CHECK( (it2_c != it3_c) == !(it2_c == it3_c) ); + CHECK((it1 != it1) == !(it1 == it1)); + CHECK((it1 != it2) == !(it1 == it2)); + CHECK((it1 != it3) == !(it1 == it3)); + CHECK((it2 != it3) == !(it2 == it3)); + CHECK((it1_c != it1_c) == !(it1_c == it1_c)); + CHECK((it1_c != it2_c) == !(it1_c == it2_c)); + CHECK((it1_c != it3_c) == !(it1_c == it3_c)); + CHECK((it2_c != it3_c) == !(it2_c == it3_c)); } // comparison: smaller @@ -133,14 +133,14 @@ else { // check definition - CHECK( (it1 <= it1) == !(it1 < it1) ); - CHECK( (it1 <= it2) == !(it2 < it1) ); - CHECK( (it1 <= it3) == !(it3 < it1) ); - CHECK( (it2 <= it3) == !(it3 < it2) ); - CHECK( (it1_c <= it1_c) == !(it1_c < it1_c) ); - CHECK( (it1_c <= it2_c) == !(it2_c < it1_c) ); - CHECK( (it1_c <= it3_c) == !(it3_c < it1_c) ); - CHECK( (it2_c <= it3_c) == !(it3_c < it2_c) ); + CHECK((it1 <= it1) == !(it1 < it1)); + CHECK((it1 <= it2) == !(it2 < it1)); + CHECK((it1 <= it3) == !(it3 < it1)); + CHECK((it2 <= it3) == !(it3 < it2)); + CHECK((it1_c <= it1_c) == !(it1_c < it1_c)); + CHECK((it1_c <= it2_c) == !(it2_c < it1_c)); + CHECK((it1_c <= it3_c) == !(it3_c < it1_c)); + CHECK((it2_c <= it3_c) == !(it3_c < it2_c)); } } @@ -171,14 +171,14 @@ else { // check definition - CHECK( (it1 > it1) == (it1 < it1) ); - CHECK( (it1 > it2) == (it2 < it1) ); - CHECK( (it1 > it3) == (it3 < it1) ); - CHECK( (it2 > it3) == (it3 < it2) ); - CHECK( (it1_c > it1_c) == (it1_c < it1_c) ); - CHECK( (it1_c > it2_c) == (it2_c < it1_c) ); - CHECK( (it1_c > it3_c) == (it3_c < it1_c) ); - CHECK( (it2_c > it3_c) == (it3_c < it2_c) ); + CHECK((it1 > it1) == (it1 < it1)); + CHECK((it1 > it2) == (it2 < it1)); + CHECK((it1 > it3) == (it3 < it1)); + CHECK((it2 > it3) == (it3 < it2)); + CHECK((it1_c > it1_c) == (it1_c < it1_c)); + CHECK((it1_c > it2_c) == (it2_c < it1_c)); + CHECK((it1_c > it3_c) == (it3_c < it1_c)); + CHECK((it2_c > it3_c) == (it3_c < it2_c)); } } @@ -209,14 +209,14 @@ else { // check definition - CHECK( (it1 >= it1) == !(it1 < it1) ); - CHECK( (it1 >= it2) == !(it1 < it2) ); - CHECK( (it1 >= it3) == !(it1 < it3) ); - CHECK( (it2 >= it3) == !(it2 < it3) ); - CHECK( (it1_c >= it1_c) == !(it1_c < it1_c) ); - CHECK( (it1_c >= it2_c) == !(it1_c < it2_c) ); - CHECK( (it1_c >= it3_c) == !(it1_c < it3_c) ); - CHECK( (it2_c >= it3_c) == !(it2_c < it3_c) ); + CHECK((it1 >= it1) == !(it1 < it1)); + CHECK((it1 >= it2) == !(it1 < it2)); + CHECK((it1 >= it3) == !(it1 < it3)); + CHECK((it2 >= it3) == !(it2 < it3)); + CHECK((it1_c >= it1_c) == !(it1_c < it1_c)); + CHECK((it1_c >= it2_c) == !(it1_c < it2_c)); + CHECK((it1_c >= it3_c) == !(it1_c < it3_c)); + CHECK((it2_c >= it3_c) == !(it2_c < it3_c)); } } } @@ -483,14 +483,14 @@ // comparison: not equal { // check definition - CHECK( (it1 != it1) == !(it1 == it1) ); - CHECK( (it1 != it2) == !(it1 == it2) ); - CHECK( (it1 != it3) == !(it1 == it3) ); - CHECK( (it2 != it3) == !(it2 == it3) ); - CHECK( (it1_c != it1_c) == !(it1_c == it1_c) ); - CHECK( (it1_c != it2_c) == !(it1_c == it2_c) ); - CHECK( (it1_c != it3_c) == !(it1_c == it3_c) ); - CHECK( (it2_c != it3_c) == !(it2_c == it3_c) ); + CHECK((it1 != it1) == !(it1 == it1)); + CHECK((it1 != it2) == !(it1 == it2)); + CHECK((it1 != it3) == !(it1 == it3)); + CHECK((it2 != it3) == !(it2 == it3)); + CHECK((it1_c != it1_c) == !(it1_c == it1_c)); + CHECK((it1_c != it2_c) == !(it1_c == it2_c)); + CHECK((it1_c != it3_c) == !(it1_c == it3_c)); + CHECK((it2_c != it3_c) == !(it2_c == it3_c)); } // comparison: smaller @@ -557,14 +557,14 @@ else { // check definition - CHECK( (it1 <= it1) == !(it1 < it1) ); - CHECK( (it1 <= it2) == !(it2 < it1) ); - CHECK( (it1 <= it3) == !(it3 < it1) ); - CHECK( (it2 <= it3) == !(it3 < it2) ); - CHECK( (it1_c <= it1_c) == !(it1_c < it1_c) ); - CHECK( (it1_c <= it2_c) == !(it2_c < it1_c) ); - CHECK( (it1_c <= it3_c) == !(it3_c < it1_c) ); - CHECK( (it2_c <= it3_c) == !(it3_c < it2_c) ); + CHECK((it1 <= it1) == !(it1 < it1)); + CHECK((it1 <= it2) == !(it2 < it1)); + CHECK((it1 <= it3) == !(it3 < it1)); + CHECK((it2 <= it3) == !(it3 < it2)); + CHECK((it1_c <= it1_c) == !(it1_c < it1_c)); + CHECK((it1_c <= it2_c) == !(it2_c < it1_c)); + CHECK((it1_c <= it3_c) == !(it3_c < it1_c)); + CHECK((it2_c <= it3_c) == !(it3_c < it2_c)); } } @@ -595,14 +595,14 @@ else { // check definition - CHECK( (it1 > it1) == (it1 < it1) ); - CHECK( (it1 > it2) == (it2 < it1) ); - CHECK( (it1 > it3) == (it3 < it1) ); - CHECK( (it2 > it3) == (it3 < it2) ); - CHECK( (it1_c > it1_c) == (it1_c < it1_c) ); - CHECK( (it1_c > it2_c) == (it2_c < it1_c) ); - CHECK( (it1_c > it3_c) == (it3_c < it1_c) ); - CHECK( (it2_c > it3_c) == (it3_c < it2_c) ); + CHECK((it1 > it1) == (it1 < it1)); + CHECK((it1 > it2) == (it2 < it1)); + CHECK((it1 > it3) == (it3 < it1)); + CHECK((it2 > it3) == (it3 < it2)); + CHECK((it1_c > it1_c) == (it1_c < it1_c)); + CHECK((it1_c > it2_c) == (it2_c < it1_c)); + CHECK((it1_c > it3_c) == (it3_c < it1_c)); + CHECK((it2_c > it3_c) == (it3_c < it2_c)); } } @@ -633,14 +633,14 @@ else { // check definition - CHECK( (it1 >= it1) == !(it1 < it1) ); - CHECK( (it1 >= it2) == !(it1 < it2) ); - CHECK( (it1 >= it3) == !(it1 < it3) ); - CHECK( (it2 >= it3) == !(it2 < it3) ); - CHECK( (it1_c >= it1_c) == !(it1_c < it1_c) ); - CHECK( (it1_c >= it2_c) == !(it1_c < it2_c) ); - CHECK( (it1_c >= it3_c) == !(it1_c < it3_c) ); - CHECK( (it2_c >= it3_c) == !(it2_c < it3_c) ); + CHECK((it1 >= it1) == !(it1 < it1)); + CHECK((it1 >= it2) == !(it1 < it2)); + CHECK((it1 >= it3) == !(it1 < it3)); + CHECK((it2 >= it3) == !(it2 < it3)); + CHECK((it1_c >= it1_c) == !(it1_c < it1_c)); + CHECK((it1_c >= it2_c) == !(it1_c < it2_c)); + CHECK((it1_c >= it3_c) == !(it1_c < it3_c)); + CHECK((it2_c >= it3_c) == !(it2_c < it3_c)); } } } @@ -894,7 +894,7 @@ } // libstdc++ algorithms don't work with Clang 15 (04/2022) -#if !DOCTEST_CLANG || (DOCTEST_CLANG && defined(__GLIBCXX__)) + #if !DOCTEST_CLANG || (DOCTEST_CLANG && defined(__GLIBCXX__)) SECTION("algorithms") { SECTION("copy") @@ -912,28 +912,26 @@ json j{1, 3, 2, 4}; auto j_even = json::array(); -#if JSON_USE_IMPLICIT_CONVERSIONS - auto it = std::ranges::find_if(j, [](int v) noexcept - { + #if JSON_USE_IMPLICIT_CONVERSIONS + auto it = std::ranges::find_if(j, [](int v) noexcept { return (v % 2) == 0; }); -#else - auto it = std::ranges::find_if(j, [](const json & j) noexcept - { + #else + auto it = std::ranges::find_if(j, [](const json& j) noexcept { int v; j.get_to(v); return (v % 2) == 0; }); -#endif + #endif CHECK(*it == 2); } } -#endif + #endif // libstdc++ views don't work with Clang 15 (04/2022) // libc++ hides limited ranges implementation behind guard macro -#if !(DOCTEST_CLANG && (defined(__GLIBCXX__) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES))) + #if !(DOCTEST_CLANG && (defined(__GLIBCXX__) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES))) SECTION("views") { SECTION("reverse") @@ -947,25 +945,23 @@ SECTION("transform") { - json j - { - { "a_key", "a_value"}, - { "b_key", "b_value"}, - { "c_key", "c_value"}, + json j{ + {"a_key", "a_value"}, + {"b_key", "b_value"}, + {"c_key", "c_value"}, }; json j_expected{"a_key", "b_key", "c_key"}; - auto transformed = j.items() | std::views::transform([](const auto & item) - { - return item.key(); - }); + auto transformed = j.items() | std::views::transform([](const auto& item) { + return item.key(); + }); auto j_transformed = json::array(); std::ranges::copy(transformed, std::back_inserter(j_transformed)); CHECK(j_transformed == j_expected); } } -#endif + #endif } #endif }
diff --git a/tests/src/unit-json_patch.cpp b/tests/src/unit-json_patch.cpp index 0999393..28ae39f 100644 --- a/tests/src/unit-json_patch.cpp +++ b/tests/src/unit-json_patch.cpp
@@ -11,11 +11,11 @@ #include <nlohmann/json.hpp> using nlohmann::json; #ifdef JSON_TEST_NO_GLOBAL_UDLS - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) +using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif -#include <fstream> #include "make_test_data_available.hpp" +#include <fstream> TEST_CASE("JSON patch") { @@ -634,7 +634,7 @@ CHECK(target == R"({ "D": "Berlin", "F": "Paris", "GB": "London" })"_json); // create a diff from two JSONs - json p2 = json::diff(target, source); // NOLINT(readability-suspicious-call-argument) + json p2 = json::diff(target, source); // NOLINT(readability-suspicious-call-argument) // p2 = [{"op": "delete", "path": "/GB"}] CHECK(p2 == R"([{"op":"remove","path":"/GB"}])"_json); } @@ -1217,76 +1217,64 @@ SECTION("add") { CHECK(R"( {} )"_json.patch( - R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json - ) == R"( {"foo": "bar"} )"_json); + R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json) == R"( {"foo": "bar"} )"_json); CHECK(R"( {"foo": [1, 3]} )"_json.patch( - R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json - ) == R"( {"foo": "bar"} )"_json); + R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json) == R"( {"foo": "bar"} )"_json); CHECK(R"( {"foo": [{}]} )"_json.patch( - R"( [{"op": "add", "path": "/foo/0/bar", "value": "baz"}] )"_json - ) == R"( {"foo": [{"bar": "baz"}]} )"_json); + R"( [{"op": "add", "path": "/foo/0/bar", "value": "baz"}] )"_json) == R"( {"foo": [{"bar": "baz"}]} )"_json); } SECTION("remove") { CHECK(R"( {"foo": "bar"} )"_json.patch( - R"( [{"op": "remove", "path": "/foo"}] )"_json - ) == R"( {} )"_json); + R"( [{"op": "remove", "path": "/foo"}] )"_json) == R"( {} )"_json); CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch( - R"( [{"op": "remove", "path": "/foo/1"}] )"_json - ) == R"( {"foo": [1, 3]} )"_json); + R"( [{"op": "remove", "path": "/foo/1"}] )"_json) == R"( {"foo": [1, 3]} )"_json); CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch( - R"( [{"op": "remove", "path": "/foo/0/bar"}] )"_json - ) == R"( {"foo": [{}]} )"_json); + R"( [{"op": "remove", "path": "/foo/0/bar"}] )"_json) == R"( {"foo": [{}]} )"_json); } SECTION("replace") { CHECK(R"( {"foo": "bar"} )"_json.patch( - R"( [{"op": "replace", "path": "/foo", "value": 1}] )"_json - ) == R"( {"foo": 1} )"_json); + R"( [{"op": "replace", "path": "/foo", "value": 1}] )"_json) == R"( {"foo": 1} )"_json); CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch( - R"( [{"op": "replace", "path": "/foo/1", "value": 4}] )"_json - ) == R"( {"foo": [1, 4, 3]} )"_json); + R"( [{"op": "replace", "path": "/foo/1", "value": 4}] )"_json) == R"( {"foo": [1, 4, 3]} )"_json); CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch( - R"( [{"op": "replace", "path": "/foo/0/bar", "value": 1}] )"_json - ) == R"( {"foo": [{"bar": 1}]} )"_json); + R"( [{"op": "replace", "path": "/foo/0/bar", "value": 1}] )"_json) == R"( {"foo": [{"bar": 1}]} )"_json); } SECTION("move") { CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch( - R"( [{"op": "move", "from": "/foo", "path": "/bar"}] )"_json - ) == R"( {"bar": [1, 2, 3]} )"_json); + R"( [{"op": "move", "from": "/foo", "path": "/bar"}] )"_json) == R"( {"bar": [1, 2, 3]} )"_json); } SECTION("copy") { CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch( - R"( [{"op": "copy", "from": "/foo/1", "path": "/bar"}] )"_json - ) == R"( {"foo": [1, 2, 3], "bar": 2} )"_json); + R"( [{"op": "copy", "from": "/foo/1", "path": "/bar"}] )"_json) == R"( {"foo": [1, 2, 3], "bar": 2} )"_json); } SECTION("copy") { CHECK_NOTHROW(R"( {"foo": "bar"} )"_json.patch( - R"( [{"op": "test", "path": "/foo", "value": "bar"}] )"_json)); + R"( [{"op": "test", "path": "/foo", "value": "bar"}] )"_json)); } } SECTION("Tests from github.com/json-patch/json-patch-tests") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json", - TEST_DATA_DIRECTORY "/json-patch-tests/tests.json" - }) + { + TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json", + TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"}) { CAPTURE(filename) std::ifstream f(filename);
diff --git a/tests/src/unit-json_pointer.cpp b/tests/src/unit-json_pointer.cpp index 79c67f9..b161adc 100644 --- a/tests/src/unit-json_pointer.cpp +++ b/tests/src/unit-json_pointer.cpp
@@ -12,7 +12,7 @@ #include <nlohmann/json.hpp> using nlohmann::json; #ifdef JSON_TEST_NO_GLOBAL_UDLS - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) +using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif #include <map> @@ -23,26 +23,32 @@ SECTION("errors") { CHECK_THROWS_WITH_AS(json::json_pointer("foo"), - "[json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo'", json::parse_error&); + "[json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo'", + json::parse_error&); CHECK_THROWS_WITH_AS(json::json_pointer("/~~"), - "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'", json::parse_error&); + "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'", + json::parse_error&); CHECK_THROWS_WITH_AS(json::json_pointer("/~"), - "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'", json::parse_error&); + "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'", + json::parse_error&); json::json_pointer p; CHECK_THROWS_WITH_AS(p.top(), - "[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&); + "[json.exception.out_of_range.405] JSON pointer has no parent", + json::out_of_range&); CHECK_THROWS_WITH_AS(p.pop_back(), - "[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&); + "[json.exception.out_of_range.405] JSON pointer has no parent", + json::out_of_range&); SECTION("array index error") { json v = {1, 2, 3, 4}; json::json_pointer const ptr("/10e"); CHECK_THROWS_WITH_AS(v[ptr], - "[json.exception.out_of_range.404] unresolved reference token '10e'", json::out_of_range&); + "[json.exception.out_of_range.404] unresolved reference token '10e'", + json::out_of_range&); } } @@ -144,9 +150,11 @@ // unresolved access json j_primitive = 1; CHECK_THROWS_WITH_AS(j_primitive["/foo"_json_pointer], - "[json.exception.out_of_range.404] unresolved reference token 'foo'", json::out_of_range&); + "[json.exception.out_of_range.404] unresolved reference token 'foo'", + json::out_of_range&); CHECK_THROWS_WITH_AS(j_primitive.at("/foo"_json_pointer), - "[json.exception.out_of_range.404] unresolved reference token 'foo'", json::out_of_range&); + "[json.exception.out_of_range.404] unresolved reference token 'foo'", + json::out_of_range&); CHECK(!j_primitive.contains(json::json_pointer("/foo"))); } @@ -206,14 +214,17 @@ // unescaped access CHECK_THROWS_WITH_AS(j.at(json::json_pointer("/a/b")), - "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&); + "[json.exception.out_of_range.403] key 'a' not found", + json::out_of_range&); // unresolved access const json j_primitive = 1; CHECK_THROWS_WITH_AS(j_primitive["/foo"_json_pointer], - "[json.exception.out_of_range.404] unresolved reference token 'foo'", json::out_of_range&); + "[json.exception.out_of_range.404] unresolved reference token 'foo'", + json::out_of_range&); CHECK_THROWS_WITH_AS(j_primitive.at("/foo"_json_pointer), - "[json.exception.out_of_range.404] unresolved reference token 'foo'", json::out_of_range&); + "[json.exception.out_of_range.404] unresolved reference token 'foo'", + json::out_of_range&); } SECTION("user-defined string literal") @@ -274,13 +285,17 @@ // error with leading 0 CHECK_THROWS_WITH_AS(j["/01"_json_pointer], - "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'", json::parse_error&); + "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'", + json::parse_error&); CHECK_THROWS_WITH_AS(j_const["/01"_json_pointer], - "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'", json::parse_error&); + "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'", + json::parse_error&); CHECK_THROWS_WITH_AS(j.at("/01"_json_pointer), - "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'", json::parse_error&); + "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'", + json::parse_error&); CHECK_THROWS_WITH_AS(j_const.at("/01"_json_pointer), - "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'", json::parse_error&); + "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'", + json::parse_error&); CHECK(!j.contains("/01"_json_pointer)); CHECK(!j.contains("/01"_json_pointer)); @@ -289,24 +304,32 @@ // error with incorrect numbers CHECK_THROWS_WITH_AS(j["/one"_json_pointer] = 1, - "[json.exception.parse_error.109] parse error: array index 'one' is not a number", json::parse_error&); + "[json.exception.parse_error.109] parse error: array index 'one' is not a number", + json::parse_error&); CHECK_THROWS_WITH_AS(j_const["/one"_json_pointer] == 1, - "[json.exception.parse_error.109] parse error: array index 'one' is not a number", json::parse_error&); + "[json.exception.parse_error.109] parse error: array index 'one' is not a number", + json::parse_error&); CHECK_THROWS_WITH_AS(j.at("/one"_json_pointer) = 1, - "[json.exception.parse_error.109] parse error: array index 'one' is not a number", json::parse_error&); + "[json.exception.parse_error.109] parse error: array index 'one' is not a number", + json::parse_error&); CHECK_THROWS_WITH_AS(j_const.at("/one"_json_pointer) == 1, - "[json.exception.parse_error.109] parse error: array index 'one' is not a number", json::parse_error&); + "[json.exception.parse_error.109] parse error: array index 'one' is not a number", + json::parse_error&); CHECK_THROWS_WITH_AS(j["/+1"_json_pointer] = 1, - "[json.exception.parse_error.109] parse error: array index '+1' is not a number", json::parse_error&); + "[json.exception.parse_error.109] parse error: array index '+1' is not a number", + json::parse_error&); CHECK_THROWS_WITH_AS(j_const["/+1"_json_pointer] == 1, - "[json.exception.parse_error.109] parse error: array index '+1' is not a number", json::parse_error&); + "[json.exception.parse_error.109] parse error: array index '+1' is not a number", + json::parse_error&); CHECK_THROWS_WITH_AS(j["/1+1"_json_pointer] = 1, - "[json.exception.out_of_range.404] unresolved reference token '1+1'", json::out_of_range&); + "[json.exception.out_of_range.404] unresolved reference token '1+1'", + json::out_of_range&); CHECK_THROWS_WITH_AS(j_const["/1+1"_json_pointer] == 1, - "[json.exception.out_of_range.404] unresolved reference token '1+1'", json::out_of_range&); + "[json.exception.out_of_range.404] unresolved reference token '1+1'", + json::out_of_range&); { auto too_large_index = std::to_string((std::numeric_limits<unsigned long long>::max)()) + "1"; @@ -335,9 +358,11 @@ DOCTEST_MSVC_SUPPRESS_WARNING_POP CHECK_THROWS_WITH_AS(j.at("/one"_json_pointer) = 1, - "[json.exception.parse_error.109] parse error: array index 'one' is not a number", json::parse_error&); + "[json.exception.parse_error.109] parse error: array index 'one' is not a number", + json::parse_error&); CHECK_THROWS_WITH_AS(j_const.at("/one"_json_pointer) == 1, - "[json.exception.parse_error.109] parse error: array index 'one' is not a number", json::parse_error&); + "[json.exception.parse_error.109] parse error: array index 'one' is not a number", + json::parse_error&); CHECK(!j.contains("/one"_json_pointer)); CHECK(!j.contains("/one"_json_pointer)); @@ -345,7 +370,8 @@ CHECK(!j_const.contains("/one"_json_pointer)); CHECK_THROWS_WITH_AS(json({{"/list/0", 1}, {"/list/1", 2}, {"/list/three", 3}}).unflatten(), - "[json.exception.parse_error.109] parse error: array index 'three' is not a number", json::parse_error&); + "[json.exception.parse_error.109] parse error: array index 'three' is not a number", + json::parse_error&); // assign to "-" j["/-"_json_pointer] = 99; @@ -353,14 +379,17 @@ // error when using "-" in const object CHECK_THROWS_WITH_AS(j_const["/-"_json_pointer], - "[json.exception.out_of_range.402] array index '-' (3) is out of range", json::out_of_range&); + "[json.exception.out_of_range.402] array index '-' (3) is out of range", + json::out_of_range&); CHECK(!j_const.contains("/-"_json_pointer)); // error when using "-" with at CHECK_THROWS_WITH_AS(j.at("/-"_json_pointer), - "[json.exception.out_of_range.402] array index '-' (7) is out of range", json::out_of_range&); + "[json.exception.out_of_range.402] array index '-' (7) is out of range", + json::out_of_range&); CHECK_THROWS_WITH_AS(j_const.at("/-"_json_pointer), - "[json.exception.out_of_range.402] array index '-' (3) is out of range", json::out_of_range&); + "[json.exception.out_of_range.402] array index '-' (3) is out of range", + json::out_of_range&); CHECK(!j_const.contains("/-"_json_pointer)); } @@ -375,19 +404,23 @@ // assign to nonexisting index CHECK_THROWS_WITH_AS(j.at("/3"_json_pointer), - "[json.exception.out_of_range.401] array index 3 is out of range", json::out_of_range&); + "[json.exception.out_of_range.401] array index 3 is out of range", + json::out_of_range&); CHECK(!j.contains("/3"_json_pointer)); // assign to nonexisting index (with gap) CHECK_THROWS_WITH_AS(j.at("/5"_json_pointer), - "[json.exception.out_of_range.401] array index 5 is out of range", json::out_of_range&); + "[json.exception.out_of_range.401] array index 5 is out of range", + json::out_of_range&); CHECK(!j.contains("/5"_json_pointer)); // assign to "-" CHECK_THROWS_WITH_AS(j["/-"_json_pointer], - "[json.exception.out_of_range.402] array index '-' (3) is out of range", json::out_of_range&); + "[json.exception.out_of_range.402] array index '-' (3) is out of range", + json::out_of_range&); CHECK_THROWS_WITH_AS(j.at("/-"_json_pointer), - "[json.exception.out_of_range.402] array index '-' (3) is out of range", json::out_of_range&); + "[json.exception.out_of_range.402] array index '-' (3) is out of range", + json::out_of_range&); CHECK(!j.contains("/-"_json_pointer)); } } @@ -395,46 +428,31 @@ SECTION("flatten") { json j = - { - {"pi", 3.141}, - {"happy", true}, - {"name", "Niels"}, - {"nothing", nullptr}, { - "answer", { - {"everything", 42} - } - }, - {"list", {1, 0, 2}}, - { - "object", { - {"currency", "USD"}, - {"value", 42.99}, - {"", "empty string"}, - {"/", "slash"}, - {"~", "tilde"}, - {"~1", "tilde1"} - } - } - }; + {"pi", 3.141}, + {"happy", true}, + {"name", "Niels"}, + {"nothing", nullptr}, + {"answer", {{"everything", 42}}}, + {"list", {1, 0, 2}}, + {"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}}; json j_flatten = - { - {"/pi", 3.141}, - {"/happy", true}, - {"/name", "Niels"}, - {"/nothing", nullptr}, - {"/answer/everything", 42}, - {"/list/0", 1}, - {"/list/1", 0}, - {"/list/2", 2}, - {"/object/currency", "USD"}, - {"/object/value", 42.99}, - {"/object/", "empty string"}, - {"/object/~1", "slash"}, - {"/object/~0", "tilde"}, - {"/object/~01", "tilde1"} - }; + { + {"/pi", 3.141}, + {"/happy", true}, + {"/name", "Niels"}, + {"/nothing", nullptr}, + {"/answer/everything", 42}, + {"/list/0", 1}, + {"/list/1", 0}, + {"/list/2", 2}, + {"/object/currency", "USD"}, + {"/object/value", 42.99}, + {"/object/", "empty string"}, + {"/object/~1", "slash"}, + {"/object/~0", "tilde"}, + {"/object/~01", "tilde1"}}; // check if flattened result is as expected CHECK(j.flatten() == j_flatten); @@ -444,7 +462,8 @@ // error for nonobjects CHECK_THROWS_WITH_AS(json(1).unflatten(), - "[json.exception.type_error.314] only objects can be unflattened", json::type_error&); + "[json.exception.type_error.314] only objects can be unflattened", + json::type_error&); // error for nonprimitve values #if JSON_DIAGNOSTICS @@ -456,7 +475,8 @@ // error for conflicting values json const j_error = {{"", 42}, {"/foo", 17}}; CHECK_THROWS_WITH_AS(j_error.unflatten(), - "[json.exception.type_error.313] invalid value to unflatten", json::type_error&); + "[json.exception.type_error.313] invalid value to unflatten", + json::type_error&); // explicit roundtrip check CHECK(j.flatten().unflatten() == j); @@ -481,8 +501,7 @@ SECTION("string representation") { for (const auto* ptr_str : - {"", "/foo", "/foo/0", "/", "/a~1b", "/c%d", "/e^f", "/g|h", "/i\\j", "/k\"l", "/ ", "/m~0n" - }) + {"", "/foo", "/foo/0", "/", "/a~1b", "/c%d", "/e^f", "/g|h", "/i\\j", "/k\"l", "/ ", "/m~0n"}) { json::json_pointer const ptr(ptr_str); std::stringstream ss; @@ -515,29 +534,15 @@ SECTION("empty, push, pop and parent") { const json j = - { - {"", "Hello"}, - {"pi", 3.141}, - {"happy", true}, - {"name", "Niels"}, - {"nothing", nullptr}, { - "answer", { - {"everything", 42} - } - }, - {"list", {1, 0, 2}}, - { - "object", { - {"currency", "USD"}, - {"value", 42.99}, - {"", "empty string"}, - {"/", "slash"}, - {"~", "tilde"}, - {"~1", "tilde1"} - } - } - }; + {"", "Hello"}, + {"pi", 3.141}, + {"happy", true}, + {"name", "Niels"}, + {"nothing", nullptr}, + {"answer", {{"everything", 42}}}, + {"list", {1, 0, 2}}, + {"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}}; // empty json_pointer returns the root JSON-object auto ptr = ""_json_pointer; @@ -591,29 +596,15 @@ SECTION("operators") { const json j = - { - {"", "Hello"}, - {"pi", 3.141}, - {"happy", true}, - {"name", "Niels"}, - {"nothing", nullptr}, { - "answer", { - {"everything", 42} - } - }, - {"list", {1, 0, 2}}, - { - "object", { - {"currency", "USD"}, - {"value", 42.99}, - {"", "empty string"}, - {"/", "slash"}, - {"~", "tilde"}, - {"~1", "tilde1"} - } - } - }; + {"", "Hello"}, + {"pi", 3.141}, + {"happy", true}, + {"name", "Niels"}, + {"nothing", nullptr}, + {"answer", {{"everything", 42}}}, + {"list", {1, 0, 2}}, + {"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}}; // empty json_pointer returns the root JSON-object auto ptr = ""_json_pointer; @@ -652,7 +643,7 @@ SECTION("equality comparison") { const char* ptr_cpstring = "/foo/bar"; - const char ptr_castring[] = "/foo/bar"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + const char ptr_castring[] = "/foo/bar"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) std::string ptr_string{"/foo/bar"}; auto ptr1 = json::json_pointer(ptr_string); auto ptr2 = json::json_pointer(ptr_string); @@ -687,13 +678,17 @@ SECTION("exceptions") { CHECK_THROWS_WITH_AS(ptr1 == "foo", - "[json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo'", json::parse_error&); + "[json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo'", + json::parse_error&); CHECK_THROWS_WITH_AS("foo" == ptr1, - "[json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo'", json::parse_error&); + "[json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo'", + json::parse_error&); CHECK_THROWS_WITH_AS(ptr1 == "/~~", - "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'", json::parse_error&); + "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'", + json::parse_error&); CHECK_THROWS_WITH_AS("/~~" == ptr1, - "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'", json::parse_error&); + "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'", + json::parse_error&); } } @@ -708,7 +703,7 @@ // build with C++20 // JSON_HAS_CPP_20 #if JSON_HAS_THREE_WAY_COMPARISON - CHECK((ptr1 <=> ptr2) == std::strong_ordering::less); // *NOPAD* + CHECK((ptr1 <= > ptr2) == std::strong_ordering::less); // *NOPAD* CHECK(ptr2 > ptr1); #endif }
diff --git a/tests/src/unit-large_json.cpp b/tests/src/unit-large_json.cpp index 9703a54..3e37403 100644 --- a/tests/src/unit-large_json.cpp +++ b/tests/src/unit-large_json.cpp
@@ -26,4 +26,3 @@ CHECK_NOTHROW(_ = nlohmann::json::parse(s)); } } -
diff --git a/tests/src/unit-merge_patch.cpp b/tests/src/unit-merge_patch.cpp index 6a8bcfe..40b492d 100644 --- a/tests/src/unit-merge_patch.cpp +++ b/tests/src/unit-merge_patch.cpp
@@ -11,7 +11,7 @@ #include <nlohmann/json.hpp> using nlohmann::json; #ifdef JSON_TEST_NO_GLOBAL_UDLS - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) +using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif TEST_CASE("JSON Merge Patch")
diff --git a/tests/src/unit-meta.cpp b/tests/src/unit-meta.cpp index a522faa..ce23e22 100644 --- a/tests/src/unit-meta.cpp +++ b/tests/src/unit-meta.cpp
@@ -21,12 +21,10 @@ CHECK(j["copyright"] == "(C) 2013-2023 Niels Lohmann"); CHECK(j["url"] == "https://github.com/nlohmann/json"); CHECK(j["version"] == json( - { - {"string", "3.11.3"}, - {"major", 3}, - {"minor", 11}, - {"patch", 3} - })); + {{"string", "3.11.3"}, + {"major", 3}, + {"minor", 11}, + {"patch", 3}})); CHECK(j.find("platform") != j.end()); CHECK(j.at("compiler").find("family") != j.at("compiler").end());
diff --git a/tests/src/unit-modifiers.cpp b/tests/src/unit-modifiers.cpp index fb68678..1430776 100644 --- a/tests/src/unit-modifiers.cpp +++ b/tests/src/unit-modifiers.cpp
@@ -637,10 +637,8 @@ { json j_other_array2 = {"first", "second"}; - CHECK_THROWS_WITH_AS(j_array.insert(j_array.end(), j_array.begin(), j_array.end()), "[json.exception.invalid_iterator.211] passed iterators may not belong to container", - json::invalid_iterator&); - CHECK_THROWS_WITH_AS(j_array.insert(j_array.end(), j_other_array.begin(), j_other_array2.end()), "[json.exception.invalid_iterator.210] iterators do not fit", - json::invalid_iterator&); + CHECK_THROWS_WITH_AS(j_array.insert(j_array.end(), j_array.begin(), j_array.end()), "[json.exception.invalid_iterator.211] passed iterators may not belong to container", json::invalid_iterator&); + CHECK_THROWS_WITH_AS(j_array.insert(j_array.end(), j_other_array.begin(), j_other_array2.end()), "[json.exception.invalid_iterator.210] iterators do not fit", json::invalid_iterator&); } }
diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index 61162af..d8635a4 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp
@@ -11,23 +11,23 @@ #include <nlohmann/json.hpp> using nlohmann::json; #ifdef JSON_TEST_NO_GLOBAL_UDLS - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) +using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif +#include "make_test_data_available.hpp" +#include "test_utils.hpp" #include <fstream> -#include <sstream> #include <iomanip> #include <limits> #include <set> -#include "make_test_data_available.hpp" -#include "test_utils.hpp" +#include <sstream> -namespace -{ +namespace { class SaxCountdown { public: - explicit SaxCountdown(const int count) : events_left(count) + explicit SaxCountdown(const int count) + : events_left(count) {} bool null() @@ -90,7 +90,7 @@ return events_left-- > 0; } - bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static) + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static) { return false; } @@ -98,7 +98,7 @@ private: int events_left = 0; }; -} // namespace +} // namespace TEST_CASE("MessagePack") { @@ -168,10 +168,8 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { - static_cast<uint8_t>(i) - }; + std::vector<uint8_t> const expected{ + static_cast<uint8_t>(i)}; // compare result + size const auto result = json::to_msgpack(j); @@ -231,8 +229,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xcc, static_cast<uint8_t>(i), }; @@ -267,8 +264,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xcd, static_cast<uint8_t>((i >> 8) & 0xff), static_cast<uint8_t>(i & 0xff), @@ -293,9 +289,11 @@ SECTION("65536..4294967295 (int 32)") { for (uint32_t i : - { - 65536u, 77777u, 1048576u, 4294967295u - }) + { + 65536u, + 77777u, + 1048576u, + 4294967295u}) { CAPTURE(i) @@ -307,8 +305,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xce, static_cast<uint8_t>((i >> 24) & 0xff), static_cast<uint8_t>((i >> 16) & 0xff), @@ -338,9 +335,9 @@ SECTION("4294967296..9223372036854775807 (int 64)") { for (uint64_t i : - { - 4294967296LU, 9223372036854775807LU - }) + { + 4294967296LU, + 9223372036854775807LU}) { CAPTURE(i) @@ -352,8 +349,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xcf, static_cast<uint8_t>((i >> 070) & 0xff), static_cast<uint8_t>((i >> 060) & 0xff), @@ -401,8 +397,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xd0, static_cast<uint8_t>(i), }; @@ -451,8 +446,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xd1, static_cast<uint8_t>((i >> 8) & 0xff), static_cast<uint8_t>(i & 0xff), @@ -476,14 +470,13 @@ SECTION("-32769..-2147483648") { - std::vector<int32_t> const numbers - { + std::vector<int32_t> const numbers{ -32769, - -65536, - -77777, - -1048576, - -2147483648LL, - }; + -65536, + -77777, + -1048576, + -2147483648LL, + }; for (auto i : numbers) { CAPTURE(i) @@ -495,8 +488,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xd2, static_cast<uint8_t>((i >> 24) & 0xff), static_cast<uint8_t>((i >> 16) & 0xff), @@ -525,8 +517,7 @@ SECTION("-9223372036854775808..-2147483649 (int 64)") { - std::vector<int64_t> const numbers - { + std::vector<int64_t> const numbers{ (std::numeric_limits<int64_t>::min)(), -2147483649LL, }; @@ -541,8 +532,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xd3, static_cast<uint8_t>((i >> 070) & 0xff), static_cast<uint8_t>((i >> 060) & 0xff), @@ -622,8 +612,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xcc, static_cast<uint8_t>(i), }; @@ -657,8 +646,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xcd, static_cast<uint8_t>((i >> 8) & 0xff), static_cast<uint8_t>(i & 0xff), @@ -683,9 +671,11 @@ SECTION("65536..4294967295 (uint 32)") { for (const uint32_t i : - { - 65536u, 77777u, 1048576u, 4294967295u - }) + { + 65536u, + 77777u, + 1048576u, + 4294967295u}) { CAPTURE(i) @@ -696,8 +686,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xce, static_cast<uint8_t>((i >> 24) & 0xff), static_cast<uint8_t>((i >> 16) & 0xff), @@ -727,9 +716,9 @@ SECTION("4294967296..18446744073709551615 (uint 64)") { for (const uint64_t i : - { - 4294967296LU, 18446744073709551615LU - }) + { + 4294967296LU, + 18446744073709551615LU}) { CAPTURE(i) @@ -740,8 +729,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 0xcf, static_cast<uint8_t>((i >> 070) & 0xff), static_cast<uint8_t>((i >> 060) & 0xff), @@ -784,9 +772,16 @@ double const v = 3.1415925; json const j = v; std::vector<uint8_t> const expected = - { - 0xcb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc - }; + { + 0xcb, + 0x40, + 0x09, + 0x21, + 0xfb, + 0x3f, + 0xa6, + 0xde, + 0xfc}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -801,9 +796,12 @@ double const v = 1.0; json const j = v; std::vector<uint8_t> const expected = - { - 0xca, 0x3f, 0x80, 0x00, 0x00 - }; + { + 0xca, + 0x3f, + 0x80, + 0x00, + 0x00}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -818,9 +816,12 @@ double const v = 128.1280059814453125; json const j = v; std::vector<uint8_t> const expected = - { - 0xca, 0x43, 0x00, 0x20, 0xc5 - }; + { + 0xca, + 0x43, + 0x00, + 0x20, + 0xc5}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -838,12 +839,39 @@ { // explicitly enumerate the first byte for all 32 strings const std::vector<uint8_t> first_bytes = - { - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, - 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, - 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, - 0xbb, 0xbc, 0xbd, 0xbe, 0xbf - }; + { + 0xa0, + 0xa1, + 0xa2, + 0xa3, + 0xa4, + 0xa5, + 0xa6, + 0xa7, + 0xa8, + 0xa9, + 0xaa, + 0xab, + 0xac, + 0xad, + 0xae, + 0xaf, + 0xb0, + 0xb1, + 0xb2, + 0xb3, + 0xb4, + 0xb5, + 0xb6, + 0xb7, + 0xb8, + 0xb9, + 0xba, + 0xbb, + 0xbc, + 0xbd, + 0xbe, + 0xbf}; for (size_t N = 0; N < first_bytes.size(); ++N) { @@ -915,9 +943,13 @@ SECTION("N = 256..65535") { for (size_t N : - { - 256u, 999u, 1025u, 3333u, 2048u, 65535u - }) + { + 256u, + 999u, + 1025u, + 3333u, + 2048u, + 65535u}) { CAPTURE(N) @@ -948,9 +980,10 @@ SECTION("N = 65536..4294967295") { for (size_t N : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(N) @@ -1034,10 +1067,10 @@ SECTION("array 16") { json j(16, nullptr); - std::vector<uint8_t> expected(j.size() + 3, 0xc0); // all null - expected[0] = 0xdc; // array 16 - expected[1] = 0x00; // size (0x0010), byte 0 - expected[2] = 0x10; // size (0x0010), byte 1 + std::vector<uint8_t> expected(j.size() + 3, 0xc0); // all null + expected[0] = 0xdc; // array 16 + expected[1] = 0x00; // size (0x0010), byte 0 + expected[2] = 0x10; // size (0x0010), byte 1 const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -1049,12 +1082,12 @@ SECTION("array 32") { json j(65536, nullptr); - std::vector<uint8_t> expected(j.size() + 5, 0xc0); // all null - expected[0] = 0xdd; // array 32 - expected[1] = 0x00; // size (0x00100000), byte 0 - expected[2] = 0x01; // size (0x00100000), byte 1 - expected[3] = 0x00; // size (0x00100000), byte 2 - expected[4] = 0x00; // size (0x00100000), byte 3 + std::vector<uint8_t> expected(j.size() + 5, 0xc0); // all null + expected[0] = 0xdd; // array 32 + expected[1] = 0x00; // size (0x00100000), byte 0 + expected[2] = 0x01; // size (0x00100000), byte 1 + expected[3] = 0x00; // size (0x00100000), byte 2 + expected[4] = 0x00; // size (0x00100000), byte 3 const auto result = json::to_msgpack(j); //CHECK(result == expected); @@ -1101,9 +1134,17 @@ { json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); std::vector<uint8_t> const expected = - { - 0x81, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0x81, 0xa1, 0x63, 0x80 - }; + { + 0x81, + 0xa1, + 0x61, + 0x81, + 0xa1, + 0x62, + 0x81, + 0xa1, + 0x63, + 0x80}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -1126,10 +1167,10 @@ // pairs are made. We therefore only check the prefix (type and // size) and the overall size. The rest is then handled in the // roundtrip check. - CHECK(result.size() == 67); // 1 type, 2 size, 16*4 content - CHECK(result[0] == 0xde); // map 16 - CHECK(result[1] == 0x00); // byte 0 of size (0x0010) - CHECK(result[2] == 0x10); // byte 1 of size (0x0010) + CHECK(result.size() == 67); // 1 type, 2 size, 16*4 content + CHECK(result[0] == 0xde); // map 16 + CHECK(result[1] == 0x00); // byte 0 of size (0x0010) + CHECK(result[2] == 0x10); // byte 1 of size (0x0010) // roundtrip CHECK(json::from_msgpack(result) == j); @@ -1155,12 +1196,12 @@ // pairs are made. We therefore only check the prefix (type and // size) and the overall size. The rest is then handled in the // roundtrip check. - CHECK(result.size() == 458757); // 1 type, 4 size, 65536*7 content - CHECK(result[0] == 0xdf); // map 32 - CHECK(result[1] == 0x00); // byte 0 of size (0x00010000) - CHECK(result[2] == 0x01); // byte 1 of size (0x00010000) - CHECK(result[3] == 0x00); // byte 2 of size (0x00010000) - CHECK(result[4] == 0x00); // byte 3 of size (0x00010000) + CHECK(result.size() == 458757); // 1 type, 4 size, 65536*7 content + CHECK(result[0] == 0xdf); // map 32 + CHECK(result[1] == 0x00); // byte 0 of size (0x00010000) + CHECK(result[2] == 0x01); // byte 1 of size (0x00010000) + CHECK(result[3] == 0x00); // byte 2 of size (0x00010000) + CHECK(result[4] == 0x00); // byte 3 of size (0x00010000) // roundtrip CHECK(json::from_msgpack(result) == j); @@ -1245,9 +1286,13 @@ SECTION("N = 256..65535") { for (std::size_t N : - { - 256u, 999u, 1025u, 3333u, 2048u, 65535u - }) + { + 256u, + 999u, + 1025u, + 3333u, + 2048u, + 65535u}) { CAPTURE(N) @@ -1281,9 +1326,10 @@ SECTION("N = 65536..4294967295") { for (std::size_t N : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(N) @@ -1357,9 +1403,13 @@ SECTION("N = 256..65535") { for (std::size_t N : - { - 256u, 999u, 1025u, 3333u, 2048u, 65535u - }) + { + 256u, + 999u, + 1025u, + 3333u, + 2048u, + 65535u}) { CAPTURE(N) @@ -1390,9 +1440,10 @@ SECTION("N = 65536..4294967295") { for (std::size_t N : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(N) @@ -1445,45 +1496,65 @@ json _; CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x87})), - "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcc})), - "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcd})), - "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})), - "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce})), - "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00})), - "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00})), - "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00})), - "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf})), - "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00})), - "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00})), - "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00})), - "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00})), - "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})), - "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), - "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), - "[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing MessagePack number: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65})), - "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack string: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack string: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x92, 0x01})), - "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack value: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xa1, 0x61})), - "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack value: unexpected end of input", + json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xc4, 0x02})), - "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack binary: unexpected end of input", json::parse_error&); + "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack binary: unexpected end of input", + json::parse_error&); CHECK(json::from_msgpack(std::vector<uint8_t>({0x87}), true, false).is_discarded()); CHECK(json::from_msgpack(std::vector<uint8_t>({0xcc}), true, false).is_discarded()); @@ -1519,10 +1590,9 @@ SECTION("all unsupported bytes") { for (auto byte : - { - // never used - 0xc1 - }) + { + // never used + 0xc1}) { json _; CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&); @@ -1636,7 +1706,7 @@ exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/3.json"); exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/4.json"); exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/5.json"); - exclude_packed.insert(TEST_DATA_DIRECTORY "/json_testsuite/sample.json"); // kills AppVeyor + exclude_packed.insert(TEST_DATA_DIRECTORY "/json_testsuite/sample.json"); // kills AppVeyor exclude_packed.insert(TEST_DATA_DIRECTORY "/json_tests/pass1.json"); exclude_packed.insert(TEST_DATA_DIRECTORY "/regression/working_file.json"); exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json"); @@ -1647,153 +1717,152 @@ exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json"); for (std::string filename : - { - TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json", - TEST_DATA_DIRECTORY "/json.org/1.json", - TEST_DATA_DIRECTORY "/json.org/2.json", - TEST_DATA_DIRECTORY "/json.org/3.json", - TEST_DATA_DIRECTORY "/json.org/4.json", - TEST_DATA_DIRECTORY "/json.org/5.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json", - TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor - TEST_DATA_DIRECTORY "/json_tests/pass1.json", - TEST_DATA_DIRECTORY "/json_tests/pass2.json", - TEST_DATA_DIRECTORY "/json_tests/pass3.json", - TEST_DATA_DIRECTORY "/regression/floats.json", - TEST_DATA_DIRECTORY "/regression/signed_ints.json", - TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", - TEST_DATA_DIRECTORY "/regression/working_file.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json", - // TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json" - }) + { + TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json", + TEST_DATA_DIRECTORY "/json.org/1.json", + TEST_DATA_DIRECTORY "/json.org/2.json", + TEST_DATA_DIRECTORY "/json.org/3.json", + TEST_DATA_DIRECTORY "/json.org/4.json", + TEST_DATA_DIRECTORY "/json.org/5.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json", + TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor + TEST_DATA_DIRECTORY "/json_tests/pass1.json", + TEST_DATA_DIRECTORY "/json_tests/pass2.json", + TEST_DATA_DIRECTORY "/json_tests/pass3.json", + TEST_DATA_DIRECTORY "/regression/floats.json", + TEST_DATA_DIRECTORY "/regression/signed_ints.json", + TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", + TEST_DATA_DIRECTORY "/regression/working_file.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json", + // TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"}) { CAPTURE(filename)
diff --git a/tests/src/unit-no-mem-leak-on-adl-serialize.cpp b/tests/src/unit-no-mem-leak-on-adl-serialize.cpp index 37b10a9..3ca8b65 100644 --- a/tests/src/unit-no-mem-leak-on-adl-serialize.cpp +++ b/tests/src/unit-no-mem-leak-on-adl-serialize.cpp
@@ -8,9 +8,9 @@ #include "doctest_compatibility.h" -#include <nlohmann/json.hpp> #include <exception> #include <iostream> +#include <nlohmann/json.hpp> struct Foo { @@ -18,9 +18,8 @@ int b; }; -namespace nlohmann -{ -template <> +namespace nlohmann { +template<> struct adl_serializer<Foo> { static void to_json(json& j, Foo const& f) @@ -42,16 +41,16 @@ } } }; -} // namespace nlohmann +} // namespace nlohmann TEST_CASE("check_for_mem_leak_on_adl_to_json-1") { try { - const nlohmann::json j = Foo {1, 0}; + const nlohmann::json j = Foo{1, 0}; std::cout << j.dump() << "\n"; } - catch (...) // NOLINT(bugprone-empty-catch) + catch (...) // NOLINT(bugprone-empty-catch) { // just ignore the exception in this POC } @@ -61,10 +60,10 @@ { try { - const nlohmann::json j = Foo {1, 1}; + const nlohmann::json j = Foo{1, 1}; std::cout << j.dump() << "\n"; } - catch (...) // NOLINT(bugprone-empty-catch) + catch (...) // NOLINT(bugprone-empty-catch) { // just ignore the exception in this POC } @@ -74,13 +73,11 @@ { try { - const nlohmann::json j = Foo {1, 2}; + const nlohmann::json j = Foo{1, 2}; std::cout << j.dump() << "\n"; } - catch (...) // NOLINT(bugprone-empty-catch) + catch (...) // NOLINT(bugprone-empty-catch) { // just ignore the exception in this POC } } - -
diff --git a/tests/src/unit-noexcept.cpp b/tests/src/unit-noexcept.cpp index bba230d..7aa213f 100644 --- a/tests/src/unit-noexcept.cpp +++ b/tests/src/unit-noexcept.cpp
@@ -16,12 +16,15 @@ using nlohmann::json; -namespace +namespace { +enum test { -enum test {}; +}; -struct pod {}; -struct pod_bis {}; +struct pod +{}; +struct pod_bis +{}; void to_json(json& /*unused*/, pod /*unused*/) noexcept; void to_json(json& /*unused*/, pod_bis /*unused*/); @@ -45,15 +48,15 @@ static_assert(noexcept(std::declval<json>().get<pod>()), ""); static_assert(!noexcept(std::declval<json>().get<pod_bis>()), ""); static_assert(noexcept(json(pod{})), ""); -} // namespace +} // namespace TEST_CASE("noexcept") { // silence -Wunneeded-internal-declaration errors - static_cast<void>(static_cast<void(*)(json&, pod)>(&to_json)); - static_cast<void>(static_cast<void(*)(json&, pod_bis)>(&to_json)); - static_cast<void>(static_cast<void(*)(const json&, pod)>(&from_json)); - static_cast<void>(static_cast<void(*)(const json&, pod_bis)>(&from_json)); + static_cast<void>(static_cast<void (*)(json&, pod)>(&to_json)); + static_cast<void>(static_cast<void (*)(json&, pod_bis)>(&to_json)); + static_cast<void>(static_cast<void (*)(const json&, pod)>(&from_json)); + static_cast<void>(static_cast<void (*)(const json&, pod_bis)>(&from_json)); SECTION("nothrow-copy-constructible exceptions") {
diff --git a/tests/src/unit-ordered_json.cpp b/tests/src/unit-ordered_json.cpp index d77d904..930d8cf 100644 --- a/tests/src/unit-ordered_json.cpp +++ b/tests/src/unit-ordered_json.cpp
@@ -45,11 +45,11 @@ CHECK(oj.dump() == "{\"element3\":3,\"element2\":2}"); // There are no dup keys cause constructor calls emplace... - json const multi {{"z", 1}, {"m", 2}, {"m", 3}, {"y", 4}, {"m", 5}}; + json const multi{{"z", 1}, {"m", 2}, {"m", 3}, {"y", 4}, {"m", 5}}; CHECK(multi.size() == 3); CHECK(multi.dump() == "{\"m\":2,\"y\":4,\"z\":1}"); - ordered_json multi_ordered {{"z", 1}, {"m", 2}, {"m", 3}, {"y", 4}, {"m", 5}}; + ordered_json multi_ordered{{"z", 1}, {"m", 2}, {"m", 3}, {"y", 4}, {"m", 5}}; CHECK(multi_ordered.size() == 3); CHECK(multi_ordered.dump() == "{\"z\":1,\"m\":2,\"y\":4}"); CHECK(multi_ordered.erase("m") == 1); @@ -57,15 +57,15 @@ // Ranged insert test. // It seems that values shouldn't be overwritten. Only new values are added - json j1 {{"c", 1}, {"b", 2}, {"a", 3}}; - const json j2 {{"c", 77}, {"d", 42}, {"a", 4}}; - j1.insert( j2.cbegin(), j2.cend() ); + json j1{{"c", 1}, {"b", 2}, {"a", 3}}; + const json j2{{"c", 77}, {"d", 42}, {"a", 4}}; + j1.insert(j2.cbegin(), j2.cend()); CHECK(j1.size() == 4); CHECK(j1.dump() == "{\"a\":3,\"b\":2,\"c\":1,\"d\":42}"); - ordered_json oj1 {{"c", 1}, {"b", 2}, {"a", 3}}; - const ordered_json oj2 {{"c", 77}, {"d", 42}, {"a", 4}}; - oj1.insert( oj2.cbegin(), oj2.cend() ); + ordered_json oj1{{"c", 1}, {"b", 2}, {"a", 3}}; + const ordered_json oj2{{"c", 77}, {"d", 42}, {"a", 4}}; + oj1.insert(oj2.cbegin(), oj2.cend()); CHECK(oj1.size() == 4); CHECK(oj1.dump() == "{\"c\":1,\"b\":2,\"a\":3,\"d\":42}"); }
diff --git a/tests/src/unit-ordered_map.cpp b/tests/src/unit-ordered_map.cpp index ceafea1..f682a49 100644 --- a/tests/src/unit-ordered_map.cpp +++ b/tests/src/unit-ordered_map.cpp
@@ -17,24 +17,24 @@ { SECTION("constructor from iterator range") { - std::map<std::string, std::string> m {{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}}; + std::map<std::string, std::string> m{{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}}; ordered_map<std::string, std::string> const om(m.begin(), m.end()); CHECK(om.size() == 3); } SECTION("copy assignment") { - std::map<std::string, std::string> m {{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}}; + std::map<std::string, std::string> m{{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}}; ordered_map<std::string, std::string> om(m.begin(), m.end()); const auto com = om; - om.clear(); // silence a warning by forbidding having "const auto& com = om;" + om.clear(); // silence a warning by forbidding having "const auto& com = om;" CHECK(com.size() == 3); } } SECTION("at") { - std::map<std::string, std::string> m {{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}}; + std::map<std::string, std::string> m{{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}}; ordered_map<std::string, std::string> om(m.begin(), m.end()); const auto com = om; @@ -67,7 +67,7 @@ SECTION("operator[]") { - std::map<std::string, std::string> m {{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}}; + std::map<std::string, std::string> m{{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}}; ordered_map<std::string, std::string> om(m.begin(), m.end()); const auto com = om; @@ -280,8 +280,8 @@ SECTION("const value_type&") { - ordered_map<std::string, std::string>::value_type const vt1 {"eins", "1"}; - ordered_map<std::string, std::string>::value_type const vt4 {"vier", "four"}; + ordered_map<std::string, std::string>::value_type const vt1{"eins", "1"}; + ordered_map<std::string, std::string>::value_type const vt4{"vier", "four"}; auto res1 = om.insert(vt1); CHECK(res1.first == om.begin());
diff --git a/tests/src/unit-readme.cpp b/tests/src/unit-readme.cpp index f2a571a..d30a0af 100644 --- a/tests/src/unit-readme.cpp +++ b/tests/src/unit-readme.cpp
@@ -11,18 +11,18 @@ #include <nlohmann/json.hpp> using nlohmann::json; #ifdef JSON_TEST_NO_GLOBAL_UDLS - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) +using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif #include <deque> #include <forward_list> +#include <iomanip> +#include <iostream> #include <list> #include <set> +#include <sstream> #include <unordered_map> #include <unordered_set> -#include <iostream> -#include <sstream> -#include <iomanip> // local variable is initialized but not referenced DOCTEST_MSVC_SUPPRESS_WARNING_PUSH @@ -55,31 +55,21 @@ j["answer"]["everything"] = 42; // add an array that is stored as std::vector (using an initializer list) - j["list"] = { 1, 0, 2 }; + j["list"] = {1, 0, 2}; // add another object (using an initializer list of pairs) - j["object"] = { {"currency", "USD"}, {"value", 42.99} }; + j["object"] = {{"currency", "USD"}, {"value", 42.99}}; // instead, you could also write (which looks very similar to the JSON above) json const j2 = - { - {"pi", 3.141}, - {"happy", true}, - {"name", "Niels"}, - {"nothing", nullptr}, { - "answer", { - {"everything", 42} - } - }, - {"list", {1, 0, 2}}, - { - "object", { - {"currency", "USD"}, - {"value", 42.99} - } - } - }; + {"pi", 3.141}, + {"happy", true}, + {"name", "Niels"}, + {"nothing", nullptr}, + {"answer", {{"everything", 42}}}, + {"list", {1, 0, 2}}, + {"object", {{"currency", "USD"}, {"value", 42.99}}}}; } { @@ -94,7 +84,7 @@ CHECK(empty_object_explicit.is_object()); // a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]] - json array_not_object = json::array({ {"currency", "USD"}, {"value", 42.99} }); + json array_not_object = json::array({{"currency", "USD"}, {"value", 42.99}}); CHECK(array_not_object.is_array()); CHECK(array_not_object.size() == 2); CHECK(array_not_object[0].is_array()); @@ -103,7 +93,7 @@ { // create object from string literal - json const j = "{ \"happy\": true, \"pi\": 3.141 }"_json; // NOLINT(modernize-raw-string-literal) + json const j = "{ \"happy\": true, \"pi\": 3.141 }"_json; // NOLINT(modernize-raw-string-literal) // or even nicer with a raw string literal auto j2 = R"({ @@ -115,17 +105,17 @@ auto j3 = json::parse(R"({"happy": true, "pi": 3.141})"); // explicit conversion to string - std::string const s = j.dump(); // {\"happy\":true,\"pi\":3.141} + std::string const s = j.dump(); // {\"happy\":true,\"pi\":3.141} // serialization with pretty printing // pass in the amount of spaces to indent - std::cout << j.dump(4) << std::endl; // NOLINT(performance-avoid-endl) + std::cout << j.dump(4) << std::endl; // NOLINT(performance-avoid-endl) // { // "happy": true, // "pi": 3.141 // } - std::cout << std::setw(2) << j << std::endl; // NOLINT(performance-avoid-endl) + std::cout << std::setw(2) << j << std::endl; // NOLINT(performance-avoid-endl) } { @@ -140,7 +130,7 @@ CHECK(x == true); // iterate the array - for (json::iterator it = j.begin(); it != j.end(); ++it) // NOLINT(modernize-loop-convert) + for (json::iterator it = j.begin(); it != j.end(); ++it) // NOLINT(modernize-loop-convert) { std::cout << *it << '\n'; } @@ -178,58 +168,58 @@ } { - std::vector<int> const c_vector {1, 2, 3, 4}; + std::vector<int> const c_vector{1, 2, 3, 4}; json const j_vec(c_vector); // [1, 2, 3, 4] - std::deque<float> const c_deque {1.2f, 2.3f, 3.4f, 5.6f}; + std::deque<float> const c_deque{1.2f, 2.3f, 3.4f, 5.6f}; json const j_deque(c_deque); // [1.2, 2.3, 3.4, 5.6] - std::list<bool> const c_list {true, true, false, true}; + std::list<bool> const c_list{true, true, false, true}; json const j_list(c_list); // [true, true, false, true] - std::forward_list<int64_t> const c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543}; + std::forward_list<int64_t> const c_flist{12345678909876, 23456789098765, 34567890987654, 45678909876543}; json const j_flist(c_flist); // [12345678909876, 23456789098765, 34567890987654, 45678909876543] - std::array<unsigned long, 4> const c_array {{1, 2, 3, 4}}; + std::array<unsigned long, 4> const c_array{{1, 2, 3, 4}}; json const j_array(c_array); // [1, 2, 3, 4] - std::set<std::string> const c_set {"one", "two", "three", "four", "one"}; - json const j_set(c_set); // only one entry for "one" is used + std::set<std::string> const c_set{"one", "two", "three", "four", "one"}; + json const j_set(c_set); // only one entry for "one" is used // ["four", "one", "three", "two"] - std::unordered_set<std::string> const c_uset {"one", "two", "three", "four", "one"}; - json const j_uset(c_uset); // only one entry for "one" is used + std::unordered_set<std::string> const c_uset{"one", "two", "three", "four", "one"}; + json const j_uset(c_uset); // only one entry for "one" is used // maybe ["two", "three", "four", "one"] - std::multiset<std::string> const c_mset {"one", "two", "one", "four"}; - json const j_mset(c_mset); // both entries for "one" are used + std::multiset<std::string> const c_mset{"one", "two", "one", "four"}; + json const j_mset(c_mset); // both entries for "one" are used // maybe ["one", "two", "one", "four"] - std::unordered_multiset<std::string> const c_umset {"one", "two", "one", "four"}; - json const j_umset(c_umset); // both entries for "one" are used + std::unordered_multiset<std::string> const c_umset{"one", "two", "one", "four"}; + json const j_umset(c_umset); // both entries for "one" are used // maybe ["one", "two", "one", "four"] } { - std::map<std::string, int> const c_map { {"one", 1}, {"two", 2}, {"three", 3} }; + std::map<std::string, int> const c_map{{"one", 1}, {"two", 2}, {"three", 3}}; json const j_map(c_map); // {"one": 1, "two": 2, "three": 3} - std::unordered_map<const char*, float> const c_umap { {"one", 1.2f}, {"two", 2.3f}, {"three", 3.4f} }; + std::unordered_map<const char*, float> const c_umap{{"one", 1.2f}, {"two", 2.3f}, {"three", 3.4f}}; json const j_umap(c_umap); // {"one": 1.2, "two": 2.3, "three": 3.4} - std::multimap<std::string, bool> const c_mmap { {"one", true}, {"two", true}, {"three", false}, {"three", true} }; - json const j_mmap(c_mmap); // only one entry for key "three" is used + std::multimap<std::string, bool> const c_mmap{{"one", true}, {"two", true}, {"three", false}, {"three", true}}; + json const j_mmap(c_mmap); // only one entry for key "three" is used // maybe {"one": true, "two": true, "three": true} - std::unordered_multimap<std::string, bool> const c_ummap { {"one", true}, {"two", true}, {"three", false}, {"three", true} }; - json const j_ummap(c_ummap); // only one entry for key "three" is used + std::unordered_multimap<std::string, bool> const c_ummap{{"one", true}, {"two", true}, {"three", false}, {"three", true}}; + json const j_ummap(c_ummap); // only one entry for key "three" is used // maybe {"one": true, "two": true, "three": true} }
diff --git a/tests/src/unit-reference_access.cpp b/tests/src/unit-reference_access.cpp index 3b46fe8..024bc36 100644 --- a/tests/src/unit-reference_access.cpp +++ b/tests/src/unit-reference_access.cpp
@@ -15,18 +15,12 @@ { // create a JSON value with different types const json json_types = - { - {"boolean", true}, { - "number", { - {"integer", 42}, - {"floating-point", 17.23} - } - }, - {"string", "Hello, world!"}, - {"array", {1, 2, 3, 4, 5}}, - {"null", nullptr} - }; + {"boolean", true}, + {"number", {{"integer", 42}, {"floating-point", 17.23}}}, + {"string", "Hello, world!"}, + {"array", {1, 2, 3, 4, 5}}, + {"null", nullptr}}; SECTION("reference access to object_t") { @@ -45,17 +39,23 @@ // check if mismatching references throw correctly CHECK_NOTHROW(value.get_ref<json::object_t&>()); CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", + json::type_error&); } SECTION("const reference access to const object_t") @@ -88,18 +88,24 @@ // check if mismatching references throw correctly CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", + json::type_error&); CHECK_NOTHROW(value.get_ref<json::array_t&>()); CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", + json::type_error&); } SECTION("reference access to string_t") @@ -118,18 +124,24 @@ // check if mismatching references throw correctly CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", + json::type_error&); CHECK_NOTHROW(value.get_ref<json::string_t&>()); CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", + json::type_error&); } SECTION("reference access to boolean_t") @@ -148,18 +160,24 @@ // check if mismatching references throw correctly CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", + json::type_error&); CHECK_NOTHROW(value.get_ref<json::boolean_t&>()); CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", + json::type_error&); } SECTION("reference access to number_integer_t") @@ -178,18 +196,24 @@ // check if mismatching references throw correctly CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", + json::type_error&); CHECK_NOTHROW(value.get_ref<json::number_integer_t&>()); CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", + json::type_error&); } SECTION("reference access to number_unsigned_t") @@ -208,13 +232,17 @@ // check if mismatching references throw correctly CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", + json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", + json::type_error&); //CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(), // "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); CHECK_NOTHROW(value.get_ref<json::number_unsigned_t&>());
diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index f5ef5d8..a7a515d 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp
@@ -15,15 +15,15 @@ #include <nlohmann/json.hpp> using nlohmann::json; #ifdef JSON_TEST_NO_GLOBAL_UDLS - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) +using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif -#include <fstream> -#include <sstream> -#include <list> -#include <limits> -#include <cstdio> #include "make_test_data_available.hpp" +#include <cstdio> +#include <fstream> +#include <limits> +#include <list> +#include <sstream> #ifdef JSON_HAS_CPP_17 #include <variant> @@ -43,57 +43,54 @@ // for #977 ///////////////////////////////////////////////////////////////////// -namespace ns -{ +namespace ns { struct foo { int x; }; -template <typename, typename SFINAE = void> +template<typename, typename SFINAE = void> struct foo_serializer; template<typename T> struct foo_serializer<T, typename std::enable_if<std::is_same<foo, T>::value>::type> { - template <typename BasicJsonType> + template<typename BasicJsonType> static void to_json(BasicJsonType& j, const T& value) { j = BasicJsonType{{"x", value.x}}; } - template <typename BasicJsonType> - static void from_json(const BasicJsonType& j, T& value) // !!! + template<typename BasicJsonType> + static void from_json(const BasicJsonType& j, T& value) // !!! { nlohmann::from_json(j.at("x"), value.x); } }; template<typename T> -struct foo_serializer < T, typename std::enable_if < !std::is_same<foo, T>::value >::type > +struct foo_serializer<T, typename std::enable_if<!std::is_same<foo, T>::value>::type> { - template <typename BasicJsonType> - static void to_json(BasicJsonType& j, const T& value) noexcept // NOLINT(bugprone-exception-escape) + template<typename BasicJsonType> + static void to_json(BasicJsonType& j, const T& value) noexcept // NOLINT(bugprone-exception-escape) { ::nlohmann::to_json(j, value); } - template <typename BasicJsonType> - static void from_json(const BasicJsonType& j, T& value) //!!! + template<typename BasicJsonType> + static void from_json(const BasicJsonType& j, T& value) //!!! { ::nlohmann::from_json(j, value); } }; -} // namespace ns +} // namespace ns -using foo_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, - std::uint64_t, double, std::allocator, ns::foo_serializer, std::vector<std::uint8_t>>; +using foo_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, ns::foo_serializer, std::vector<std::uint8_t>>; ///////////////////////////////////////////////////////////////////// // for #805 ///////////////////////////////////////////////////////////////////// -namespace -{ -struct nocopy // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) +namespace { +struct nocopy // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) { nocopy() = default; nocopy(const nocopy&) = delete; @@ -108,7 +105,7 @@ j = {{"val", n.val}}; } }; -} // namespace +} // namespace TEST_CASE("regression tests 1") { @@ -171,7 +168,11 @@ SECTION("pull request #71 - handle enum type") { - enum { t = 0, u = 102}; + enum + { + t = 0, + u = 102 + }; json j = json::array(); j.push_back(t); @@ -187,9 +188,7 @@ static_assert(std::is_same<decltype(anon_enum_value), decltype(u)>::value, "types must be the same"); j.push_back(json::object( - { - {"game_type", t} - })); + {{"game_type", t}})); } SECTION("issue #76 - dump() / parse() not idempotent") @@ -258,22 +257,22 @@ // tests for correct handling of non-standard integers that overflow the type selected by the user // unsigned integer object creation - expected to wrap and still be stored as an integer - j = 4294967296U; // 2^32 + j = 4294967296U; // 2^32 CHECK(static_cast<int>(j.type()) == static_cast<int>(custom_json::value_t::number_unsigned)); CHECK(j.get<uint32_t>() == 0); // Wrap // unsigned integer parsing - expected to overflow and be stored as a float - j = custom_json::parse("4294967296"); // 2^32 + j = custom_json::parse("4294967296"); // 2^32 CHECK(static_cast<int>(j.type()) == static_cast<int>(custom_json::value_t::number_float)); CHECK(j.get<float>() == 4294967296.0f); // integer object creation - expected to wrap and still be stored as an integer - j = -2147483649LL; // -2^31-1 + j = -2147483649LL; // -2^31-1 CHECK(static_cast<int>(j.type()) == static_cast<int>(custom_json::value_t::number_integer)); CHECK(j.get<int32_t>() == 2147483647); // Wrap // integer parsing - expected to overflow and be stored as a float with rounding - j = custom_json::parse("-2147483649"); // -2^31 + j = custom_json::parse("-2147483649"); // -2^31 CHECK(static_cast<int>(j.type()) == static_cast<int>(custom_json::value_t::number_float)); CHECK(j.get<float>() == -2147483650.0f); } @@ -298,8 +297,7 @@ json::reverse_iterator rit = a.rbegin(); ++rit; json b = {0, 0, 0}; - std::transform(rit, a.rend(), b.rbegin(), [](json el) - { + std::transform(rit, a.rend(), b.rbegin(), [](json el) { return el; }); CHECK(b == json({0, 1, 2})); @@ -307,8 +305,7 @@ { json a = {1, 2, 3}; json b = {0, 0, 0}; - std::transform(++a.rbegin(), a.rend(), b.rbegin(), [](json el) - { + std::transform(++a.rbegin(), a.rend(), b.rbegin(), [](json el) { return el; }); CHECK(b == json({0, 1, 2})); @@ -318,11 +315,10 @@ SECTION("issue #100 - failed to iterator json object with reverse_iterator") { json config = - { - { "111", 111 }, - { "112", 112 }, - { "113", 113 } - }; + { + {"111", 111}, + {"112", 112}, + {"113", 113}}; std::stringstream ss; @@ -342,7 +338,9 @@ SECTION("issue #101 - binary string causes numbers to be dumped as hex") { int64_t const number = 10; - std::string const bytes{"\x00" "asdf\n", 6}; + std::string const bytes{"\x00" + "asdf\n", + 6}; json j; j["int64"] = number; j["binary string"] = bytes; @@ -374,11 +372,11 @@ // improve coverage o["int"] = 1; -#if JSON_DIAGNOSTICS + #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(s2 = o["int"], "[json.exception.type_error.302] (/int) type must be string, but is number", json::type_error); -#else + #else CHECK_THROWS_WITH_AS(s2 = o["int"], "[json.exception.type_error.302] type must be string, but is number", json::type_error); -#endif + #endif } #endif @@ -392,18 +390,18 @@ json j; // Non-const access with key as "char []" - char array_key[] = "Key1"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + char array_key[] = "Key1"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) CHECK_NOTHROW(j[array_key] = 1); CHECK(j[array_key] == json(1)); // Non-const access with key as "const char[]" - const char const_array_key[] = "Key2"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + const char const_array_key[] = "Key2"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) CHECK_NOTHROW(j[const_array_key] = 2); CHECK(j[const_array_key] == json(2)); // Non-const access with key as "char *" - char _ptr_key[] = "Key3"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - char* ptr_key = &_ptr_key[0]; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + char _ptr_key[] = "Key3"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + char* ptr_key = &_ptr_key[0]; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) CHECK_NOTHROW(j[ptr_key] = 3); CHECK(j[ptr_key] == json(3)); @@ -476,8 +474,7 @@ CHECK(j_double.get<double>() == 1.23e35); // long double - nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, long double> - const j_long_double = 1.23e45L; + nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, long double> const j_long_double = 1.23e45L; CHECK(j_long_double.get<long double>() == 1.23e45L); } @@ -596,9 +593,9 @@ SECTION("issue #283 - value() does not work with _json_pointer types") { json j = - { - {"object", {{"key1", 1}, {"key2", 2}}}, - }; + { + {"object", {{"key1", 1}, {"key2", 2}}}, + }; int at_integer{j.at("/object/key2"_json_pointer)}; int val_integer = j.value("/object/key2"_json_pointer, 0); @@ -618,10 +615,9 @@ SECTION("issue #306 - Parsing fails without space at end of file") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/regression/broken_file.json", - TEST_DATA_DIRECTORY "/regression/working_file.json" - }) + { + TEST_DATA_DIRECTORY "/regression/broken_file.json", + TEST_DATA_DIRECTORY "/regression/working_file.json"}) { CAPTURE(filename) json j; @@ -633,12 +629,11 @@ SECTION("issue #310 - make json_benchmarks no longer working in 2.0.4") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/regression/floats.json", - TEST_DATA_DIRECTORY "/regression/signed_ints.json", - TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", - TEST_DATA_DIRECTORY "/regression/small_signed_ints.json" - }) + { + TEST_DATA_DIRECTORY "/regression/floats.json", + TEST_DATA_DIRECTORY "/regression/signed_ints.json", + TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", + TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"}) { CAPTURE(filename) json j; @@ -662,8 +657,7 @@ SECTION("issue #360 - Loss of precision when serializing <double>") { - auto check_roundtrip = [](double number) - { + auto check_roundtrip = [](double number) { CAPTURE(number) json j = number; @@ -714,7 +708,7 @@ check_roundtrip(83623297654460.33); check_roundtrip(701466573254773.6); check_roundtrip(1369013370304513); - check_roundtrip(96963648023094720); // NOLINT(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions) + check_roundtrip(96963648023094720); // NOLINT(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions) check_roundtrip(3.478237409280108e+17); } @@ -754,7 +748,8 @@ ss << " "; json j; CHECK_THROWS_WITH_AS(ss >> j, - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", + json::parse_error&); } SECTION("one value") @@ -777,7 +772,8 @@ CHECK(j == 222); CHECK_THROWS_WITH_AS(ss >> j, - "[json.exception.parse_error.101] parse error at line 2, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error&); + "[json.exception.parse_error.101] parse error at line 2, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", + json::parse_error&); } SECTION("whitespace + one value") @@ -900,7 +896,7 @@ SECTION("issue #405 - Heap-buffer-overflow (OSS-Fuzz issue 342)") { // original test case - std::vector<uint8_t> const vec {0x65, 0xf5, 0x0a, 0x48, 0x21}; + std::vector<uint8_t> const vec{0x65, 0xf5, 0x0a, 0x48, 0x21}; json _; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); } @@ -910,23 +906,23 @@ json _; // original test case: incomplete float64 - std::vector<uint8_t> const vec1 {0xcb, 0x8f, 0x0a}; + std::vector<uint8_t> const vec1{0xcb, 0x8f, 0x0a}; CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec1), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); // related test case: incomplete float32 - std::vector<uint8_t> const vec2 {0xca, 0x8f, 0x0a}; + std::vector<uint8_t> const vec2{0xca, 0x8f, 0x0a}; CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec2), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); // related test case: incomplete Half-Precision Float (CBOR) - std::vector<uint8_t> const vec3 {0xf9, 0x8f}; + std::vector<uint8_t> const vec3{0xf9, 0x8f}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); // related test case: incomplete Single-Precision Float (CBOR) - std::vector<uint8_t> const vec4 {0xfa, 0x8f, 0x0a}; + std::vector<uint8_t> const vec4{0xfa, 0x8f, 0x0a}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec4), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); // related test case: incomplete Double-Precision Float (CBOR) - std::vector<uint8_t> const vec5 {0xfb, 0x8f, 0x0a}; + std::vector<uint8_t> const vec5{0xfb, 0x8f, 0x0a}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec5), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); } @@ -935,17 +931,73 @@ json _; // original test case - std::vector<uint8_t> const vec1 {0x87}; + std::vector<uint8_t> const vec1{0x87}; CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec1), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input", json::parse_error&); // more test cases for MessagePack for (auto b : - { - 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, // fixmap - 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, // fixarray - 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, // fixstr - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf - }) + { + 0x81, + 0x82, + 0x83, + 0x84, + 0x85, + 0x86, + 0x87, + 0x88, + 0x89, + 0x8a, + 0x8b, + 0x8c, + 0x8d, + 0x8e, + 0x8f, // fixmap + 0x91, + 0x92, + 0x93, + 0x94, + 0x95, + 0x96, + 0x97, + 0x98, + 0x99, + 0x9a, + 0x9b, + 0x9c, + 0x9d, + 0x9e, + 0x9f, // fixarray + 0xa1, + 0xa2, + 0xa3, + 0xa4, + 0xa5, + 0xa6, + 0xa7, + 0xa8, + 0xa9, + 0xaa, + 0xab, + 0xac, + 0xad, + 0xae, + 0xaf, // fixstr + 0xb0, + 0xb1, + 0xb2, + 0xb3, + 0xb4, + 0xb5, + 0xb6, + 0xb7, + 0xb8, + 0xb9, + 0xba, + 0xbb, + 0xbc, + 0xbd, + 0xbe, + 0xbf}) { std::vector<uint8_t> const vec(1, static_cast<uint8_t>(b)); CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error&); @@ -953,14 +1005,77 @@ // more test cases for CBOR for (auto b : - { - 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, // UTF-8 string - 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, // array - 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7 // map - }) + { + 0x61, + 0x62, + 0x63, + 0x64, + 0x65, + 0x66, + 0x67, + 0x68, + 0x69, + 0x6a, + 0x6b, + 0x6c, + 0x6d, + 0x6e, + 0x6f, + 0x70, + 0x71, + 0x72, + 0x73, + 0x74, + 0x75, + 0x76, + 0x77, // UTF-8 string + 0x81, + 0x82, + 0x83, + 0x84, + 0x85, + 0x86, + 0x87, + 0x88, + 0x89, + 0x8a, + 0x8b, + 0x8c, + 0x8d, + 0x8e, + 0x8f, + 0x90, + 0x91, + 0x92, + 0x93, + 0x94, + 0x95, + 0x96, + 0x97, // array + 0xa1, + 0xa2, + 0xa3, + 0xa4, + 0xa5, + 0xa6, + 0xa7, + 0xa8, + 0xa9, + 0xaa, + 0xab, + 0xac, + 0xad, + 0xae, + 0xaf, + 0xb0, + 0xb1, + 0xb2, + 0xb3, + 0xb4, + 0xb5, + 0xb6, + 0xb7 // map + }) { std::vector<uint8_t> const vec(1, static_cast<uint8_t>(b)); CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error&); @@ -977,64 +1092,181 @@ json _; // original test case: empty UTF-8 string (indefinite length) - std::vector<uint8_t> const vec1 {0x7f}; + std::vector<uint8_t> const vec1{0x7f}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); // related test case: empty array (indefinite length) - std::vector<uint8_t> const vec2 {0x9f}; + std::vector<uint8_t> const vec2{0x9f}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); // related test case: empty map (indefinite length) - std::vector<uint8_t> const vec3 {0xbf}; + std::vector<uint8_t> const vec3{0xbf}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); } SECTION("issue #412 - Heap-buffer-overflow (OSS-Fuzz issue 367)") { // original test case - std::vector<uint8_t> const vec - { - 0xab, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, - 0x98, 0x98, 0x98, 0x98, 0x98, 0x00, 0x00, 0x00, - 0x60, 0xab, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, - 0x98, 0x98, 0x98, 0x98, 0x98, 0x00, 0x00, 0x00, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0xa0, 0x9f, - 0x9f, 0x97, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60 - }; + std::vector<uint8_t> const vec{ + 0xab, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x00, + 0x00, + 0x00, + 0x60, + 0xab, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x98, + 0x00, + 0x00, + 0x00, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0xa0, + 0x9f, + 0x9f, + 0x97, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60, + 0x60}; json _; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x98", json::parse_error&); // related test case: nonempty UTF-8 string (indefinite length) - std::vector<uint8_t> const vec1 {0x7f, 0x61, 0x61}; + std::vector<uint8_t> const vec1{0x7f, 0x61, 0x61}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); // related test case: nonempty array (indefinite length) - std::vector<uint8_t> const vec2 {0x9f, 0x01}; + std::vector<uint8_t> const vec2{0x9f, 0x01}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); // related test case: nonempty map (indefinite length) - std::vector<uint8_t> const vec3 {0xbf, 0x61, 0x61, 0x01}; + std::vector<uint8_t> const vec3{0xbf, 0x61, 0x61, 0x01}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); } SECTION("issue #414 - compare with literal 0)") { -#define CHECK_TYPE(v) \ - CHECK((json(v) == (v)));\ - CHECK(((v) == json(v)));\ - CHECK_FALSE((json(v) != (v)));\ +#define CHECK_TYPE(v) \ + CHECK((json(v) == (v))); \ + CHECK(((v) == json(v))); \ + CHECK_FALSE((json(v) != (v))); \ CHECK_FALSE(((v) != json(v))); CHECK_TYPE(nullptr) @@ -1042,7 +1274,7 @@ CHECK_TYPE(0u) CHECK_TYPE(0L) CHECK_TYPE(0.0) - CHECK_TYPE("") // NOLINT(readability-container-size-empty) + CHECK_TYPE("") // NOLINT(readability-container-size-empty) #undef CHECK_TYPE } @@ -1050,29 +1282,109 @@ SECTION("issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)") { // original test case - std::vector<uint8_t> const vec1 - { - 0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, - 0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, - 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0x71, - 0xb4, 0xb4, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a, - 0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61, - 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfa - }; + std::vector<uint8_t> const vec1{ + 0x94, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0x3a, + 0x96, + 0x96, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0x71, + 0xb4, + 0xb4, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0x3a, + 0x96, + 0x96, + 0xb4, + 0xb4, + 0xfa, + 0x94, + 0x94, + 0x61, + 0x61, + 0x61, + 0x61, + 0x61, + 0x61, + 0x61, + 0x61, + 0xfa}; json _; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1), "[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4", json::parse_error&); // related test case: double-precision - std::vector<uint8_t> const vec2 - { - 0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, - 0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, - 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0x71, - 0xb4, 0xb4, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a, - 0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61, - 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfb - }; + std::vector<uint8_t> const vec2{ + 0x94, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0x3a, + 0x96, + 0x96, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0xb4, + 0x71, + 0xb4, + 0xb4, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0xfa, + 0x3a, + 0x96, + 0x96, + 0xb4, + 0xb4, + 0xfa, + 0x94, + 0x94, + 0x61, + 0x61, + 0x61, + 0x61, + 0x61, + 0x61, + 0x61, + 0x61, + 0xfb}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2), "[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4", json::parse_error&); } @@ -1117,8 +1429,7 @@ SECTION("std::vector") { - auto create = [](const json & j) - { + auto create = [](const json& j) { std::vector<int> const v = j; }; @@ -1129,8 +1440,7 @@ SECTION("std::list") { - auto create = [](const json & j) - { + auto create = [](const json& j) { std::list<int> const v = j; }; @@ -1141,8 +1451,7 @@ SECTION("std::forward_list") { - auto create = [](const json & j) - { + auto create = [](const json& j) { std::forward_list<int> const v = j; }; @@ -1156,7 +1465,7 @@ SECTION("issue #486 - json::value_t can't be a map's key type in VC++ 2015") { // the code below must compile with MSVC - std::map<json::value_t, std::string> jsonTypes ; + std::map<json::value_t, std::string> jsonTypes; jsonTypes[json::value_t::array] = "array"; } @@ -1199,28 +1508,28 @@ CHECK(j["a"] != 4); CHECK(j["a"] <= 7); - CHECK(j["a"] < 7); + CHECK(j["a"] < 7); CHECK(j["a"] >= 3); - CHECK(j["a"] > 3); + CHECK(j["a"] > 3); CHECK(!(j["a"] <= 4)); - CHECK(!(j["a"] < 4)); + CHECK(!(j["a"] < 4)); CHECK(!(j["a"] >= 6)); - CHECK(!(j["a"] > 6)); + CHECK(!(j["a"] > 6)); // scalar op json CHECK(5 == j["a"]); CHECK(4 != j["a"]); CHECK(7 >= j["a"]); - CHECK(7 > j["a"]); + CHECK(7 > j["a"]); CHECK(3 <= j["a"]); - CHECK(3 < j["a"]); + CHECK(3 < j["a"]); CHECK(!(4 >= j["a"])); - CHECK(!(4 > j["a"])); + CHECK(!(4 > j["a"])); CHECK(!(6 <= j["a"])); - CHECK(!(6 < j["a"])); + CHECK(!(6 < j["a"])); } SECTION("issue #575 - heap-buffer-overflow (OSS-Fuzz 1400)") @@ -1236,7 +1545,7 @@ SECTION("example 1") { // create a map - std::map<std::string, int> m1 {{"key", 1}}; + std::map<std::string, int> m1{{"key", 1}}; // create and print a JSON from the map json const j = m1; @@ -1251,7 +1560,7 @@ SECTION("example 2") { // create a map - std::map<std::string, std::string> m1 {{"key", "val"}}; + std::map<std::string, std::string> m1{{"key", "val"}}; // create and print a JSON from the map json const j = m1; @@ -1305,7 +1614,7 @@ { SECTION("example 1") { - std::istringstream i1_2_3( R"({"first": "one" }{"second": "two"}3)" ); + std::istringstream i1_2_3(R"({"first": "one" }{"second": "two"}3)"); json j1; json j2; json j3; @@ -1317,9 +1626,9 @@ auto m2 = j2.get<std::map<std::string, std::string>>(); int i3{j3}; - CHECK( m1 == ( std::map<std::string, std::string> {{ "first", "one" }} )); - CHECK( m2 == ( std::map<std::string, std::string> {{ "second", "two" }} )); - CHECK( i3 == 3 ); + CHECK(m1 == (std::map<std::string, std::string>{{"first", "one"}})); + CHECK(m2 == (std::map<std::string, std::string>{{"second", "two"}})); + CHECK(i3 == 3); } } @@ -1328,10 +1637,7 @@ { std::ifstream is; is.exceptions( - is.exceptions() - | std::ios_base::failbit - | std::ios_base::badbit - ); // handle different exceptions as 'file not found', 'permission denied' + is.exceptions() | std::ios_base::failbit | std::ios_base::badbit); // handle different exceptions as 'file not found', 'permission denied' is.open(TEST_DATA_DIRECTORY "/regression/working_file.json"); json _; @@ -1341,10 +1647,7 @@ { std::ifstream is; is.exceptions( - is.exceptions() - | std::ios_base::failbit - | std::ios_base::badbit - ); // handle different exceptions as 'file not found', 'permission denied' + is.exceptions() | std::ios_base::failbit | std::ios_base::badbit); // handle different exceptions as 'file not found', 'permission denied' is.open(TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json.cbor", std::ios_base::in | std::ios_base::binary); @@ -1363,7 +1666,7 @@ SECTION("issue #838 - incorrect parse error with binary data in keys") { - std::array<uint8_t, 28> key1 = {{ 103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92, 34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0 }}; + std::array<uint8_t, 28> key1 = {{103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92, 34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0}}; std::string const key1_str(reinterpret_cast<char*>(key1.data())); json const j = key1_str; CHECK_THROWS_WITH_AS(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 10: 0x7E", json::type_error&); @@ -1394,26 +1697,32 @@ "from": "/one/two/three", "path": "/a/b/c"}])"_json; CHECK_THROWS_WITH_AS(model.patch(p1), - "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&); + "[json.exception.out_of_range.403] key 'a' not found", + json::out_of_range&); auto p2 = R"([{"op": "copy", "from": "/one/two/three", "path": "/a/b/c"}])"_json; CHECK_THROWS_WITH_AS(model.patch(p2), - "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&); + "[json.exception.out_of_range.403] key 'a' not found", + json::out_of_range&); } SECTION("issue #961 - incorrect parsing of indefinite length CBOR strings") { std::vector<uint8_t> const v_cbor = - { - 0x7F, - 0x64, - 'a', 'b', 'c', 'd', - 0x63, - '1', '2', '3', - 0xFF - }; + { + 0x7F, + 0x64, + 'a', + 'b', + 'c', + 'd', + 0x63, + '1', + '2', + '3', + 0xFF}; json j = json::from_cbor(v_cbor); CHECK(j == "abcd123"); } @@ -1453,8 +1762,7 @@ )"; // define parser callback - json::parser_callback_t const cb = [](int /*depth*/, json::parse_event_t event, json & parsed) - { + json::parser_callback_t const cb = [](int /*depth*/, json::parse_event_t event, json& parsed) { // skip object elements with key "Thumbnail" return !(event == json::parse_event_t::key && parsed == json("Thumbnail")); }; @@ -1478,7 +1786,7 @@ CHECK(lj.size() == 1); CHECK(lj["x"] == 3); CHECK(ff.x == 3); - nlohmann::json const nj = lj; // This line works as expected + nlohmann::json const nj = lj; // This line works as expected } } @@ -1504,10 +1812,22 @@ // the code below fails with Clang on Windows, so we need to exclude it there #if DOCTEST_CLANG && (defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)) #else -template <typename T> class array {}; -template <typename T> class object {}; -template <typename T> class string {}; -template <typename T> class number_integer {}; -template <typename T> class number_unsigned {}; -template <typename T> class number_float {}; +template<typename T> +class array +{}; +template<typename T> +class object +{}; +template<typename T> +class string +{}; +template<typename T> +class number_integer +{}; +template<typename T> +class number_unsigned +{}; +template<typename T> +class number_float +{}; #endif
diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index fab9aae..9f345a5 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp
@@ -23,7 +23,7 @@ using json = nlohmann::json; using ordered_json = nlohmann::ordered_json; #ifdef JSON_TEST_NO_GLOBAL_UDLS - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) +using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif #include <cstdio> @@ -55,8 +55,7 @@ ///////////////////////////////////////////////////////////////////// // for #1647 ///////////////////////////////////////////////////////////////////// -namespace -{ +namespace { struct NonDefaultFromJsonStruct {}; @@ -73,10 +72,10 @@ // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays): this is a false positive NLOHMANN_JSON_SERIALIZE_ENUM(for_1647, -{ - {for_1647::one, "one"}, - {for_1647::two, "two"}, -}) + { + {for_1647::one, "one"}, + {for_1647::two, "two"}, + }) } // namespace ///////////////////////////////////////////////////////////////////// @@ -87,8 +86,8 @@ { Data() = default; Data(std::string a_, std::string b_) - : a(std::move(a_)) - , b(std::move(b_)) + : a(std::move(a_)) + , b(std::move(b_)) {} std::string a{}; std::string b{}; @@ -112,8 +111,7 @@ // return !(lhs == rhs); //} -namespace nlohmann -{ +namespace nlohmann { template<> struct adl_serializer<NonDefaultFromJsonStruct> { @@ -141,13 +139,12 @@ struct NonDefaultConstructible { explicit NonDefaultConstructible(int a) - : x(a) + : x(a) {} int x; }; -namespace nlohmann -{ +namespace nlohmann { template<> struct adl_serializer<NonDefaultConstructible> { @@ -166,7 +163,7 @@ { public: explicit sax_no_exception(json& j) - : nlohmann::detail::json_sax_dom_parser<json>(j, false) + : nlohmann::detail::json_sax_dom_parser<json>(j, false) {} static bool parse_error(std::size_t /*position*/, const std::string& /*last_token*/, const json::exception& ex) @@ -191,9 +188,11 @@ using std::allocator<T>::allocator; my_allocator() = default; - template<class U> my_allocator(const my_allocator<U>& /*unused*/) { } + template<class U> + my_allocator(const my_allocator<U>& /*unused*/) + {} - template <class U> + template<class U> struct rebind { using other = my_allocator<U>; @@ -230,7 +229,7 @@ // for #3171 ///////////////////////////////////////////////////////////////////// -struct for_3171_base // NOLINT(cppcoreguidelines-special-member-functions) +struct for_3171_base // NOLINT(cppcoreguidelines-special-member-functions) { for_3171_base(const std::string& /*unused*/ = {}) {} virtual ~for_3171_base() = default; @@ -246,7 +245,7 @@ struct for_3171_derived : public for_3171_base { for_3171_derived() = default; - explicit for_3171_derived(const std::string& /*unused*/) { } + explicit for_3171_derived(const std::string& /*unused*/) {} }; inline void from_json(const json& j, for_3171_base& tb) @@ -277,7 +276,7 @@ struct for_3204_foo { for_3204_foo() = default; - explicit for_3204_foo(std::string /*unused*/) {} // NOLINT(performance-unnecessary-value-param) + explicit for_3204_foo(std::string /*unused*/) {} // NOLINT(performance-unnecessary-value-param) }; struct for_3204_bar @@ -289,10 +288,12 @@ constructed_from_json = 2 }; - explicit for_3204_bar(std::function<void(for_3204_foo)> /*unused*/) noexcept // NOLINT(performance-unnecessary-value-param) - : constructed_from(constructed_from_foo) {} - explicit for_3204_bar(std::function<void(json)> /*unused*/) noexcept // NOLINT(performance-unnecessary-value-param) - : constructed_from(constructed_from_json) {} + explicit for_3204_bar(std::function<void(for_3204_foo)> /*unused*/) noexcept // NOLINT(performance-unnecessary-value-param) + : constructed_from(constructed_from_foo) + {} + explicit for_3204_bar(std::function<void(json)> /*unused*/) noexcept // NOLINT(performance-unnecessary-value-param) + : constructed_from(constructed_from_json) + {} constructed_from_t constructed_from = constructed_from_none; }; @@ -303,9 +304,12 @@ struct for_3333 final { - for_3333(int x_ = 0, int y_ = 0) : x(x_), y(y_) {} + for_3333(int x_ = 0, int y_ = 0) + : x(x_) + , y(y_) + {} - template <class T> + template<class T> for_3333(const T& /*unused*/) { CHECK(false); @@ -315,9 +319,9 @@ int y = 0; }; -template <> +template<> inline for_3333::for_3333(const json& j) - : for_3333(j.value("x", 0), j.value("y", 0)) + : for_3333(j.value("x", 0), j.value("y", 0)) {} TEST_CASE("regression tests 2") @@ -359,8 +363,7 @@ ] })"; - const json::parser_callback_t cb = [&](int /*level*/, json::parse_event_t event, json & parsed) noexcept - { + const json::parser_callback_t cb = [&](int /*level*/, json::parse_event_t event, json& parsed) noexcept { // skip uninteresting events if (event == json::parse_event_t::value && !parsed.is_primitive()) { @@ -432,11 +435,10 @@ p2.begin(), p2.end(), std::inserter(diffs, diffs.end()), - [&](const it_type & e1, const it_type & e2) -> bool - { - using comper_pair = std::pair<std::string, decltype(e1.value())>; // Trying to avoid unneeded copy - return comper_pair(e1.key(), e1.value()) < comper_pair(e2.key(), e2.value()); // Using pair comper - }); + [&](const it_type& e1, const it_type& e2) -> bool { + using comper_pair = std::pair<std::string, decltype(e1.value())>; // Trying to avoid unneeded copy + return comper_pair(e1.key(), e1.value()) < comper_pair(e2.key(), e2.value()); // Using pair comper + }); CHECK(diffs.size() == 1); // Note the change here, was 2 } @@ -452,14 +454,13 @@ "with std::pair") { const json j = - { - {"1", {{"a", "testa_1"}, {"b", "testb_1"}}}, - {"2", {{"a", "testa_2"}, {"b", "testb_2"}}}, - {"3", {{"a", "testa_3"}, {"b", "testb_3"}}}, - }; + { + {"1", {{"a", "testa_1"}, {"b", "testb_1"}}}, + {"2", {{"a", "testa_2"}, {"b", "testb_2"}}}, + {"3", {{"a", "testa_3"}, {"b", "testb_3"}}}, + }; - std::map<std::string, Data> expected - { + std::map<std::string, Data> expected{ {"1", {"testa_1", "testb_1"}}, {"2", {"testa_2", "testb_2"}}, {"3", {"testa_3", "testb_3"}}, @@ -508,9 +509,8 @@ { nlohmann::json dump_test; const std::array<int, 108> data = - { - {109, 108, 103, 125, -122, -53, 115, 18, 3, 0, 102, 19, 1, 15, -110, 13, -3, -1, -81, 32, 2, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -80, 2, 0, 0, 96, -118, 46, -116, 46, 109, -84, -87, 108, 14, 109, -24, -83, 13, -18, -51, -83, -52, -115, 14, 6, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 3, 0, 0, 0, 35, -74, -73, 55, 57, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, -96, -54, -28, -26} - }; + { + {109, 108, 103, 125, -122, -53, 115, 18, 3, 0, 102, 19, 1, 15, -110, 13, -3, -1, -81, 32, 2, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -80, 2, 0, 0, 96, -118, 46, -116, 46, 109, -84, -87, 108, 14, 109, -24, -83, 13, -18, -51, -83, -52, -115, 14, 6, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 3, 0, 0, 0, 35, -74, -73, 55, 57, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, -96, -54, -28, -26}}; std::string s; for (const int i : data) { @@ -614,7 +614,7 @@ ' ', // Indent char false, // Ensure ascii json::error_handler_t::strict // Error - )); + )); } SECTION("PR #2181 - regression bug with lvalue") @@ -629,18 +629,17 @@ SECTION("issue #2293 - eof doesn't cause parsing to stop") { const std::vector<uint8_t> data = - { - 0x7B, - 0x6F, - 0x62, - 0x6A, - 0x65, - 0x63, - 0x74, - 0x20, - 0x4F, - 0x42 - }; + { + 0x7B, + 0x6F, + 0x62, + 0x6A, + 0x65, + 0x63, + 0x74, + 0x20, + 0x4F, + 0x42}; const json result = json::from_cbor(data, true, false); CHECK(result.is_discarded()); } @@ -656,8 +655,7 @@ CHECK(jsonAnimals == jsonAnimals_parsed); const std::vector<std::pair<std::string, int64_t>> intData = {std::make_pair("aaaa", 11), - std::make_pair("bbb", 222) - }; + std::make_pair("bbb", 222)}; nlohmann::ordered_json jsonObj; for (const auto& data : intData) { @@ -675,15 +673,15 @@ } #ifdef JSON_HAS_CPP_20 -#if __has_include(<span>) + #if __has_include(<span>) SECTION("issue #2546 - parsing containers of std::byte") { - const char DATA[] = R"("Hello, world!")"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + const char DATA[] = R"("Hello, world!")"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) const auto s = std::as_bytes(std::span(DATA)); const json j = json::parse(s); CHECK(j.dump() == "\"Hello, world!\""); } -#endif + #endif #endif SECTION("issue #2574 - Deserialization to std::array, std::pair, and std::tuple with non-default constructable types fails") @@ -834,10 +832,10 @@ const auto j_path = j.get<nlohmann::detail::std_fs::path>(); CHECK(j_path == text_path); -#if DOCTEST_CLANG || DOCTEST_GCC >= DOCTEST_COMPILER(8, 4, 0) + #if DOCTEST_CLANG || DOCTEST_GCC >= DOCTEST_COMPILER(8, 4, 0) // only known to work on Clang and GCC >=8.4 CHECK_THROWS_WITH_AS(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number", json::type_error); -#endif + #endif } #endif @@ -858,17 +856,17 @@ CHECK(j.dump() == "[1,2,4]"); - j.erase(std::remove_if(j.begin(), j.end(), [](const ordered_json & val) - { - return val == 2; - }), j.end()); + j.erase(std::remove_if(j.begin(), j.end(), [](const ordered_json& val) { + return val == 2; + }), + j.end()); CHECK(j.dump() == "[1,4]"); } SECTION("issue #3343 - json and ordered_json are not interchangable") { - json::object_t jobj({ { "product", "one" } }); + json::object_t jobj({{"product", "one"}}); ordered_json::object_t ojobj({{"product", "one"}}); auto jit = jobj.begin(); @@ -880,7 +878,7 @@ SECTION("issue #3171 - if class is_constructible from std::string wrong from_json overload is being selected, compilation failed") { - const json j{{ "str", "value"}}; + const json j{{"str", "value"}}; // failed with: error: no match for ‘operator=’ (operand types are ‘for_3171_derived’ and ‘const nlohmann::basic_json<>::string_t’ // {aka ‘const std::__cxx11::basic_string<char>’}) @@ -917,8 +915,8 @@ SECTION("issue #3204 - ambiguous regression") { - for_3204_bar bar_from_foo([](for_3204_foo) noexcept {}); // NOLINT(performance-unnecessary-value-param) - for_3204_bar bar_from_json([](json) noexcept {}); // NOLINT(performance-unnecessary-value-param) + for_3204_bar bar_from_foo([](for_3204_foo) noexcept {}); // NOLINT(performance-unnecessary-value-param) + for_3204_bar bar_from_json([](json) noexcept {}); // NOLINT(performance-unnecessary-value-param) CHECK(bar_from_foo.constructed_from == for_3204_bar::constructed_from_foo); CHECK(bar_from_json.constructed_from == for_3204_bar::constructed_from_json); @@ -926,11 +924,9 @@ SECTION("issue #3333 - Ambiguous conversion from nlohmann::basic_json<> to custom class") { - const json j - { + const json j{ {"x", 1}, - {"y", 2} - }; + {"y", 2}}; for_3333 p = j; CHECK(p.x == 1);
diff --git a/tests/src/unit-serialization.cpp b/tests/src/unit-serialization.cpp index e8f0e7e..17fc733 100644 --- a/tests/src/unit-serialization.cpp +++ b/tests/src/unit-serialization.cpp
@@ -11,8 +11,8 @@ #include <nlohmann/json.hpp> using nlohmann::json; -#include <sstream> #include <iomanip> +#include <sstream> TEST_CASE("serialization") { @@ -118,41 +118,90 @@ // https://www.unicode.org/versions/Unicode11.0.0/ch03.pdf // Section 3.9 -- U+FFFD Substitution of Maximal Subparts - auto test = [&](std::string const & input, std::string const & expected) - { + auto test = [&](std::string const& input, std::string const& expected) { const json j = input; CHECK(j.dump(-1, ' ', true, json::error_handler_t::replace) == "\"" + expected + "\""); }; test("\xC2", "\\ufffd"); - test("\xC2\x41\x42", "\\ufffd" "\x41" "\x42"); - test("\xC2\xF4", "\\ufffd" "\\ufffd"); + test("\xC2\x41\x42", "\\ufffd" + "\x41" + "\x42"); + test("\xC2\xF4", "\\ufffd" + "\\ufffd"); - test("\xF0\x80\x80\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\x41"); - test("\xF1\x80\x80\x41", "\\ufffd" "\x41"); - test("\xF2\x80\x80\x41", "\\ufffd" "\x41"); - test("\xF3\x80\x80\x41", "\\ufffd" "\x41"); - test("\xF4\x80\x80\x41", "\\ufffd" "\x41"); - test("\xF5\x80\x80\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\x41"); + test("\xF0\x80\x80\x41", "\\ufffd" + "\\ufffd" + "\\ufffd" + "\x41"); + test("\xF1\x80\x80\x41", "\\ufffd" + "\x41"); + test("\xF2\x80\x80\x41", "\\ufffd" + "\x41"); + test("\xF3\x80\x80\x41", "\\ufffd" + "\x41"); + test("\xF4\x80\x80\x41", "\\ufffd" + "\x41"); + test("\xF5\x80\x80\x41", "\\ufffd" + "\\ufffd" + "\\ufffd" + "\x41"); - test("\xF0\x90\x80\x41", "\\ufffd" "\x41"); - test("\xF1\x90\x80\x41", "\\ufffd" "\x41"); - test("\xF2\x90\x80\x41", "\\ufffd" "\x41"); - test("\xF3\x90\x80\x41", "\\ufffd" "\x41"); - test("\xF4\x90\x80\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\x41"); - test("\xF5\x90\x80\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\x41"); + test("\xF0\x90\x80\x41", "\\ufffd" + "\x41"); + test("\xF1\x90\x80\x41", "\\ufffd" + "\x41"); + test("\xF2\x90\x80\x41", "\\ufffd" + "\x41"); + test("\xF3\x90\x80\x41", "\\ufffd" + "\x41"); + test("\xF4\x90\x80\x41", "\\ufffd" + "\\ufffd" + "\\ufffd" + "\x41"); + test("\xF5\x90\x80\x41", "\\ufffd" + "\\ufffd" + "\\ufffd" + "\x41"); - test("\xC0\xAF\xE0\x80\xBF\xF0\x81\x82\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\x41"); - test("\xED\xA0\x80\xED\xBF\xBF\xED\xAF\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\x41"); - test("\xF4\x91\x92\x93\xFF\x41\x80\xBF\x42", "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\x41" "\\ufffd""\\ufffd" "\x42"); - test("\xE1\x80\xE2\xF0\x91\x92\xF1\xBF\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\x41"); + test("\xC0\xAF\xE0\x80\xBF\xF0\x81\x82\x41", "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\x41"); + test("\xED\xA0\x80\xED\xBF\xBF\xED\xAF\x41", "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\x41"); + test("\xF4\x91\x92\x93\xFF\x41\x80\xBF\x42", "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\x41" + "\\ufffd" + "\\ufffd" + "\x42"); + test("\xE1\x80\xE2\xF0\x91\x92\xF1\xBF\x41", "\\ufffd" + "\\ufffd" + "\\ufffd" + "\\ufffd" + "\x41"); } } SECTION("to_string") { - auto test = [&](std::string const & input, std::string const & expected) - { + auto test = [&](std::string const& input, std::string const& expected) { using std::to_string; const json j = input; CHECK(to_string(j) == "\"" + expected + "\""); @@ -220,78 +269,78 @@ SECTION("pretty-printed") { CHECK(binary.dump(4) == "{\n" - " \"bytes\": [1, 2, 3, 4],\n" - " \"subtype\": null\n" - "}"); + " \"bytes\": [1, 2, 3, 4],\n" + " \"subtype\": null\n" + "}"); CHECK(binary_empty.dump(4) == "{\n" - " \"bytes\": [],\n" - " \"subtype\": null\n" - "}"); + " \"bytes\": [],\n" + " \"subtype\": null\n" + "}"); CHECK(binary_with_subtype.dump(4) == "{\n" - " \"bytes\": [1, 2, 3, 4],\n" - " \"subtype\": 128\n" - "}"); + " \"bytes\": [1, 2, 3, 4],\n" + " \"subtype\": 128\n" + "}"); CHECK(binary_empty_with_subtype.dump(4) == "{\n" - " \"bytes\": [],\n" - " \"subtype\": 128\n" - "}"); + " \"bytes\": [],\n" + " \"subtype\": 128\n" + "}"); CHECK(object.dump(4) == "{\n" - " \"key\": {\n" - " \"bytes\": [1, 2, 3, 4],\n" - " \"subtype\": null\n" - " }\n" - "}"); + " \"key\": {\n" + " \"bytes\": [1, 2, 3, 4],\n" + " \"subtype\": null\n" + " }\n" + "}"); CHECK(object_empty.dump(4) == "{\n" - " \"key\": {\n" - " \"bytes\": [],\n" - " \"subtype\": null\n" - " }\n" - "}"); + " \"key\": {\n" + " \"bytes\": [],\n" + " \"subtype\": null\n" + " }\n" + "}"); CHECK(object_with_subtype.dump(4) == "{\n" - " \"key\": {\n" - " \"bytes\": [1, 2, 3, 4],\n" - " \"subtype\": 128\n" - " }\n" - "}"); + " \"key\": {\n" + " \"bytes\": [1, 2, 3, 4],\n" + " \"subtype\": 128\n" + " }\n" + "}"); CHECK(object_empty_with_subtype.dump(4) == "{\n" - " \"key\": {\n" - " \"bytes\": [],\n" - " \"subtype\": 128\n" - " }\n" - "}"); + " \"key\": {\n" + " \"bytes\": [],\n" + " \"subtype\": 128\n" + " }\n" + "}"); CHECK(array.dump(4) == "[\n" - " \"value\",\n" - " 1,\n" - " {\n" - " \"bytes\": [1, 2, 3, 4],\n" - " \"subtype\": null\n" - " }\n" - "]"); + " \"value\",\n" + " 1,\n" + " {\n" + " \"bytes\": [1, 2, 3, 4],\n" + " \"subtype\": null\n" + " }\n" + "]"); CHECK(array_empty.dump(4) == "[\n" - " \"value\",\n" - " 1,\n" - " {\n" - " \"bytes\": [],\n" - " \"subtype\": null\n" - " }\n" - "]"); + " \"value\",\n" + " 1,\n" + " {\n" + " \"bytes\": [],\n" + " \"subtype\": null\n" + " }\n" + "]"); CHECK(array_with_subtype.dump(4) == "[\n" - " \"value\",\n" - " 1,\n" - " {\n" - " \"bytes\": [1, 2, 3, 4],\n" - " \"subtype\": 128\n" - " }\n" - "]"); + " \"value\",\n" + " 1,\n" + " {\n" + " \"bytes\": [1, 2, 3, 4],\n" + " \"subtype\": 128\n" + " }\n" + "]"); CHECK(array_empty_with_subtype.dump(4) == "[\n" - " \"value\",\n" - " 1,\n" - " {\n" - " \"bytes\": [],\n" - " \"subtype\": 128\n" - " }\n" - "]"); + " \"value\",\n" + " 1,\n" + " {\n" + " \"bytes\": [],\n" + " \"subtype\": 128\n" + " }\n" + "]"); } }
diff --git a/tests/src/unit-testsuites.cpp b/tests/src/unit-testsuites.cpp index 5807934..ddd9032 100644 --- a/tests/src/unit-testsuites.cpp +++ b/tests/src/unit-testsuites.cpp
@@ -11,8 +11,8 @@ #include <nlohmann/json.hpp> using nlohmann::json; -#include <fstream> #include "make_test_data_available.hpp" +#include <fstream> TEST_CASE("compliance tests from json.org") { @@ -21,41 +21,40 @@ SECTION("expected failures") { for (const auto* filename : - { - //TEST_DATA_DIRECTORY "/json_tests/fail1.json", - TEST_DATA_DIRECTORY "/json_tests/fail2.json", - TEST_DATA_DIRECTORY "/json_tests/fail3.json", - TEST_DATA_DIRECTORY "/json_tests/fail4.json", - TEST_DATA_DIRECTORY "/json_tests/fail5.json", - TEST_DATA_DIRECTORY "/json_tests/fail6.json", - TEST_DATA_DIRECTORY "/json_tests/fail7.json", - TEST_DATA_DIRECTORY "/json_tests/fail8.json", - TEST_DATA_DIRECTORY "/json_tests/fail9.json", - TEST_DATA_DIRECTORY "/json_tests/fail10.json", - TEST_DATA_DIRECTORY "/json_tests/fail11.json", - TEST_DATA_DIRECTORY "/json_tests/fail12.json", - TEST_DATA_DIRECTORY "/json_tests/fail13.json", - TEST_DATA_DIRECTORY "/json_tests/fail14.json", - TEST_DATA_DIRECTORY "/json_tests/fail15.json", - TEST_DATA_DIRECTORY "/json_tests/fail16.json", - TEST_DATA_DIRECTORY "/json_tests/fail17.json", - //TEST_DATA_DIRECTORY "/json_tests/fail18.json", - TEST_DATA_DIRECTORY "/json_tests/fail19.json", - TEST_DATA_DIRECTORY "/json_tests/fail20.json", - TEST_DATA_DIRECTORY "/json_tests/fail21.json", - TEST_DATA_DIRECTORY "/json_tests/fail22.json", - TEST_DATA_DIRECTORY "/json_tests/fail23.json", - TEST_DATA_DIRECTORY "/json_tests/fail24.json", - TEST_DATA_DIRECTORY "/json_tests/fail25.json", - TEST_DATA_DIRECTORY "/json_tests/fail26.json", - TEST_DATA_DIRECTORY "/json_tests/fail27.json", - TEST_DATA_DIRECTORY "/json_tests/fail28.json", - TEST_DATA_DIRECTORY "/json_tests/fail29.json", - TEST_DATA_DIRECTORY "/json_tests/fail30.json", - TEST_DATA_DIRECTORY "/json_tests/fail31.json", - TEST_DATA_DIRECTORY "/json_tests/fail32.json", - TEST_DATA_DIRECTORY "/json_tests/fail33.json" - }) + { + //TEST_DATA_DIRECTORY "/json_tests/fail1.json", + TEST_DATA_DIRECTORY "/json_tests/fail2.json", + TEST_DATA_DIRECTORY "/json_tests/fail3.json", + TEST_DATA_DIRECTORY "/json_tests/fail4.json", + TEST_DATA_DIRECTORY "/json_tests/fail5.json", + TEST_DATA_DIRECTORY "/json_tests/fail6.json", + TEST_DATA_DIRECTORY "/json_tests/fail7.json", + TEST_DATA_DIRECTORY "/json_tests/fail8.json", + TEST_DATA_DIRECTORY "/json_tests/fail9.json", + TEST_DATA_DIRECTORY "/json_tests/fail10.json", + TEST_DATA_DIRECTORY "/json_tests/fail11.json", + TEST_DATA_DIRECTORY "/json_tests/fail12.json", + TEST_DATA_DIRECTORY "/json_tests/fail13.json", + TEST_DATA_DIRECTORY "/json_tests/fail14.json", + TEST_DATA_DIRECTORY "/json_tests/fail15.json", + TEST_DATA_DIRECTORY "/json_tests/fail16.json", + TEST_DATA_DIRECTORY "/json_tests/fail17.json", + //TEST_DATA_DIRECTORY "/json_tests/fail18.json", + TEST_DATA_DIRECTORY "/json_tests/fail19.json", + TEST_DATA_DIRECTORY "/json_tests/fail20.json", + TEST_DATA_DIRECTORY "/json_tests/fail21.json", + TEST_DATA_DIRECTORY "/json_tests/fail22.json", + TEST_DATA_DIRECTORY "/json_tests/fail23.json", + TEST_DATA_DIRECTORY "/json_tests/fail24.json", + TEST_DATA_DIRECTORY "/json_tests/fail25.json", + TEST_DATA_DIRECTORY "/json_tests/fail26.json", + TEST_DATA_DIRECTORY "/json_tests/fail27.json", + TEST_DATA_DIRECTORY "/json_tests/fail28.json", + TEST_DATA_DIRECTORY "/json_tests/fail29.json", + TEST_DATA_DIRECTORY "/json_tests/fail30.json", + TEST_DATA_DIRECTORY "/json_tests/fail31.json", + TEST_DATA_DIRECTORY "/json_tests/fail32.json", + TEST_DATA_DIRECTORY "/json_tests/fail33.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -70,11 +69,11 @@ // they succeed when the operator>> is used, because it does not // have this constraint for (const auto* filename : - { - TEST_DATA_DIRECTORY "/json_tests/fail7.json", - TEST_DATA_DIRECTORY "/json_tests/fail8.json", - TEST_DATA_DIRECTORY "/json_tests/fail10.json", - }) + { + TEST_DATA_DIRECTORY "/json_tests/fail7.json", + TEST_DATA_DIRECTORY "/json_tests/fail8.json", + TEST_DATA_DIRECTORY "/json_tests/fail10.json", + }) { CAPTURE(filename) std::ifstream f(filename); @@ -86,11 +85,10 @@ SECTION("expected passes") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/json_tests/pass1.json", - TEST_DATA_DIRECTORY "/json_tests/pass2.json", - TEST_DATA_DIRECTORY "/json_tests/pass3.json" - }) + { + TEST_DATA_DIRECTORY "/json_tests/pass1.json", + TEST_DATA_DIRECTORY "/json_tests/pass2.json", + TEST_DATA_DIRECTORY "/json_tests/pass3.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -106,8 +104,7 @@ SECTION("doubles") { - auto TEST_DOUBLE = [](const std::string & json_string, const double expected) - { + auto TEST_DOUBLE = [](const std::string& json_string, const double expected) { CAPTURE(json_string) CAPTURE(expected) CHECK(json::parse(json_string)[0].get<double>() == Approx(expected)); @@ -134,18 +131,18 @@ TEST_DOUBLE("[2.22507e-308]", 2.22507e-308); TEST_DOUBLE("[-1.79769e+308]", -1.79769e+308); TEST_DOUBLE("[-2.22507e-308]", -2.22507e-308); - TEST_DOUBLE("[4.9406564584124654e-324]", 4.9406564584124654e-324); // minimum denormal - TEST_DOUBLE("[2.2250738585072009e-308]", 2.2250738585072009e-308); // Max subnormal double - TEST_DOUBLE("[2.2250738585072014e-308]", 2.2250738585072014e-308); // Min normal positive double - TEST_DOUBLE("[1.7976931348623157e+308]", 1.7976931348623157e+308); // Max double - TEST_DOUBLE("[1e-10000]", 0.0); // must underflow + TEST_DOUBLE("[4.9406564584124654e-324]", 4.9406564584124654e-324); // minimum denormal + TEST_DOUBLE("[2.2250738585072009e-308]", 2.2250738585072009e-308); // Max subnormal double + TEST_DOUBLE("[2.2250738585072014e-308]", 2.2250738585072014e-308); // Min normal positive double + TEST_DOUBLE("[1.7976931348623157e+308]", 1.7976931348623157e+308); // Max double + TEST_DOUBLE("[1e-10000]", 0.0); // must underflow TEST_DOUBLE("[18446744073709551616]", - 18446744073709551616.0); // 2^64 (max of uint64_t + 1, force to use double) + 18446744073709551616.0); // 2^64 (max of uint64_t + 1, force to use double) TEST_DOUBLE("[-9223372036854775809]", - -9223372036854775809.0); // -2^63 - 1(min of int64_t + 1, force to use double) + -9223372036854775809.0); // -2^63 - 1(min of int64_t + 1, force to use double) TEST_DOUBLE("[0.9868011474609375]", - 0.9868011474609375); // https://github.com/miloyip/rapidjson/issues/120 - TEST_DOUBLE("[123e34]", 123e34); // Fast Path Cases In Disguise + 0.9868011474609375); // https://github.com/miloyip/rapidjson/issues/120 + TEST_DOUBLE("[123e34]", 123e34); // Fast Path Cases In Disguise TEST_DOUBLE("[45913141877270640000.0]", 45913141877270640000.0); TEST_DOUBLE("[2.2250738585072011e-308]", 2.2250738585072011e-308); @@ -154,7 +151,7 @@ TEST_DOUBLE("[1e-214748363]", 0.0); TEST_DOUBLE("[1e-214748364]", 0.0); //TEST_DOUBLE("[1e-21474836311]", 0.0); - TEST_DOUBLE("[0.017976931348623157e+310]", 1.7976931348623157e+308); // Max double in another form + TEST_DOUBLE("[0.017976931348623157e+310]", 1.7976931348623157e+308); // Max double in another form // Since // abs((2^-1022 - 2^-1074) - 2.2250738585072012e-308) = 3.109754131239141401123495768877590405345064751974375599... ¡Á 10^-324 @@ -172,15 +169,15 @@ // 1.0 is in (1.0 - 2^-54, 1.0 + 2^-53) // 1.0 - 2^-54 = 0.999999999999999944488848768742172978818416595458984375 - TEST_DOUBLE("[0.999999999999999944488848768742172978818416595458984375]", 1.0); // round to even + TEST_DOUBLE("[0.999999999999999944488848768742172978818416595458984375]", 1.0); // round to even TEST_DOUBLE("[0.999999999999999944488848768742172978818416595458984374]", - 0.99999999999999989); // previous double - TEST_DOUBLE("[0.999999999999999944488848768742172978818416595458984376]", 1.0); // next double + 0.99999999999999989); // previous double + TEST_DOUBLE("[0.999999999999999944488848768742172978818416595458984376]", 1.0); // next double // 1.0 + 2^-53 = 1.00000000000000011102230246251565404236316680908203125 - TEST_DOUBLE("[1.00000000000000011102230246251565404236316680908203125]", 1.0); // round to even - TEST_DOUBLE("[1.00000000000000011102230246251565404236316680908203124]", 1.0); // previous double + TEST_DOUBLE("[1.00000000000000011102230246251565404236316680908203125]", 1.0); // round to even + TEST_DOUBLE("[1.00000000000000011102230246251565404236316680908203124]", 1.0); // previous double TEST_DOUBLE("[1.00000000000000011102230246251565404236316680908203126]", - 1.00000000000000022); // next double + 1.00000000000000022); // next double // Numbers from https://github.com/floitsch/double-conversion/blob/master/test/cctest/test-strtod.cc @@ -214,7 +211,7 @@ 5708990770823839524233143877797980545530986496.0); { - std::string n1e308(312, '0'); // '1' followed by 308 '0' + std::string n1e308(312, '0'); // '1' followed by 308 '0' n1e308[0] = '['; n1e308[1] = '1'; n1e308[310] = ']'; @@ -238,8 +235,7 @@ SECTION("strings") { - auto TEST_STRING = [](const std::string & json_string, const std::string & expected) - { + auto TEST_STRING = [](const std::string& json_string, const std::string& expected) { CAPTURE(json_string) CAPTURE(expected) CHECK(json::parse(json_string)[0].get<std::string>() == expected); @@ -250,9 +246,9 @@ TEST_STRING(R"(["Hello\nWorld"])", "Hello\nWorld"); //TEST_STRING("[\"Hello\\u0000World\"]", "Hello\0World"); TEST_STRING(R"(["\"\\/\b\f\n\r\t"])", "\"\\/\b\f\n\r\t"); - TEST_STRING(R"(["\u0024"])", "$"); // Dollar sign U+0024 - TEST_STRING(R"(["\u00A2"])", "\xC2\xA2"); // Cents sign U+00A2 - TEST_STRING(R"(["\u20AC"])", "\xE2\x82\xAC"); // Euro sign U+20AC + TEST_STRING(R"(["\u0024"])", "$"); // Dollar sign U+0024 + TEST_STRING(R"(["\u00A2"])", "\xC2\xA2"); // Cents sign U+00A2 + TEST_STRING(R"(["\u20AC"])", "\xE2\x82\xAC"); // Euro sign U+20AC TEST_STRING(R"(["\uD834\uDD1E"])", "\xF0\x9D\x84\x9E"); // G clef sign U+1D11E } @@ -261,45 +257,45 @@ // test cases are from https://github.com/miloyip/nativejson-benchmark/tree/master/test/data/roundtrip for (const auto* filename : - { - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json", - //TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json", // incompatible with roundtrip24 - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json" - //TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json" // same as roundtrip31 - }) + { + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json", + //TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json", // incompatible with roundtrip24 + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json" + //TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json" // same as roundtrip31 + }) { CAPTURE(filename) std::ifstream f(filename); - std::string json_string( (std::istreambuf_iterator<char>(f) ), - (std::istreambuf_iterator<char>()) ); + std::string json_string((std::istreambuf_iterator<char>(f)), + (std::istreambuf_iterator<char>())); CAPTURE(json_string) const json j = json::parse(json_string); @@ -476,105 +472,103 @@ SECTION("y") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json", - // TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json" - } - ) + { + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json", + // TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -586,204 +580,202 @@ SECTION("n") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_1_true_without_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_a_invalid_utf8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_colon_instead_of_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_after_close.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_and_number.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_double_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_double_extra_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_close.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_incomplete.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_incomplete_invalid_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_inner_array_no_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_invalid_utf8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_items_separated_by_semicolon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_just_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_just_minus.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_missing_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_newlines_unclosed.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_number_and_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_number_and_several_commas.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_spaces_vertical_tab_formfeed.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_star_inside.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed_trailing_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed_with_new_lines.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed_with_object_inside.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_incomplete_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_incomplete_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_incomplete_true.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_++.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_+1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_+Inf.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-01.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-1.0..json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-2..json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-NaN.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_.-1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_.2e-3.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.1.2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.3e+.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.3e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.e1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0_capital_E+.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0_capital_E.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0e+.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1.0e+.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1.0e-.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1.0e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1_000.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1eE2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_2.e+3.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_2.e-3.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_2.e3.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_9.e+.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_Inf.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_NaN.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_U+FF11_fullwidth_digit_one.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_expression.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_hex_1_digit.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_hex_2_digits.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_infinity.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid+-.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-negative-real.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-utf-8-in-bigger-int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-utf-8-in-exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-utf-8-in-int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_minus_infinity.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_minus_sign_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_minus_space_1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_neg_int_starting_with_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_neg_real_without_int_part.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_neg_with_garbage_at_end.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_real_garbage_after_e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_real_with_invalid_utf8_after_e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_real_without_fractional_part.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_starting_with_dot.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_then_00.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_with_alpha.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_with_alpha_char.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_with_leading_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_bad_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_bracket_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_comma_instead_of_colon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_double_colon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_emoji.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_garbage_at_end.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_key_with_single_quotes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_colon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_semicolon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_no-colon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_non_string_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_non_string_key_but_huge_number_instead.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_pi_in_key_and_trailing_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_repeated_null_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_several_trailing_commas.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_single_quote.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_open.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open_incomplete.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_two_commas_in_a_row.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_unquoted_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_unterminated-value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_with_single_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_single_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape u.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape u1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape u1x.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_UTF-16_incomplete_surrogate.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_UTF8_surrogate_U+D800.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_accentuated_char_no_quotes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_backslash_00.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escape_x.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escaped_backslash_bad.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escaped_ctrl_char_tab.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escaped_emoji.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_incomplete_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_incomplete_escaped_character.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_incomplete_surrogate_escape_invalid.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid-utf-8-in-escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_backslash_esc.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_unicode_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_utf8_after_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_iso_latin_1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_leading_uescaped_thinspace.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_lone_utf8_continuation_byte.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_no_quotes_with_bad_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_overlong_sequence_2_bytes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_overlong_sequence_6_bytes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_overlong_sequence_6_bytes_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_single_doublequote.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_single_quote.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_single_string_no_double_quotes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_start_escape_unclosed.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unescaped_crtl_char.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unescaped_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unescaped_tab.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unicode_CapitalU.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_with_trailing_garbage.json", - //!TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_100000_opening_arrays.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_3C.3E.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_3Cnull3E.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_U+2060_word_joined.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_UTF8_BOM_no_data.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_with_extra_array_close.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_with_unclosed_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_ascii-unicode-identifier.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_capitalized_True.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_close_unopened_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_comma_instead_of_closing_brace.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_double_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_end_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_incomplete_UTF8_BOM.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_lone-invalid-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_lone-open-bracket.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_no_data.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_null-byte-outside-string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_number_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_followed_by_closing_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_unclosed_no_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_with_comment.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_apostrophe.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_comma.json", - //!TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_open_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_open_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_close_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_open_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_open_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_string_with_apostrophes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_open.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_single_point.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_single_star.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_trailing_#.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_uescaped_LF_before_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array_partial_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array_unfinished_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array_unfinished_true.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unicode-identifier.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_whitespace_U+2060_word_joiner.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_whitespace_formfeed.json" - } - ) + { + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_1_true_without_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_a_invalid_utf8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_colon_instead_of_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_after_close.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_and_number.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_double_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_double_extra_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_close.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_incomplete.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_incomplete_invalid_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_inner_array_no_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_invalid_utf8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_items_separated_by_semicolon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_just_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_just_minus.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_missing_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_newlines_unclosed.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_number_and_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_number_and_several_commas.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_spaces_vertical_tab_formfeed.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_star_inside.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed_trailing_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed_with_new_lines.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed_with_object_inside.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_incomplete_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_incomplete_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_incomplete_true.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_++.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_+1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_+Inf.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-01.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-1.0..json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-2..json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-NaN.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_.-1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_.2e-3.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.1.2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.3e+.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.3e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.e1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0_capital_E+.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0_capital_E.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0e+.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1.0e+.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1.0e-.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1.0e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1_000.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1eE2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_2.e+3.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_2.e-3.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_2.e3.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_9.e+.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_Inf.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_NaN.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_U+FF11_fullwidth_digit_one.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_expression.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_hex_1_digit.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_hex_2_digits.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_infinity.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid+-.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-negative-real.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-utf-8-in-bigger-int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-utf-8-in-exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-utf-8-in-int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_minus_infinity.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_minus_sign_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_minus_space_1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_neg_int_starting_with_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_neg_real_without_int_part.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_neg_with_garbage_at_end.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_real_garbage_after_e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_real_with_invalid_utf8_after_e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_real_without_fractional_part.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_starting_with_dot.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_then_00.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_with_alpha.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_with_alpha_char.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_with_leading_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_bad_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_bracket_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_comma_instead_of_colon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_double_colon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_emoji.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_garbage_at_end.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_key_with_single_quotes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_colon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_semicolon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_no-colon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_non_string_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_non_string_key_but_huge_number_instead.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_pi_in_key_and_trailing_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_repeated_null_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_several_trailing_commas.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_single_quote.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_open.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open_incomplete.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_two_commas_in_a_row.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_unquoted_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_unterminated-value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_with_single_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_single_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape u.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape u1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape u1x.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_UTF-16_incomplete_surrogate.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_UTF8_surrogate_U+D800.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_accentuated_char_no_quotes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_backslash_00.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escape_x.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escaped_backslash_bad.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escaped_ctrl_char_tab.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escaped_emoji.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_incomplete_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_incomplete_escaped_character.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_incomplete_surrogate_escape_invalid.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid-utf-8-in-escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_backslash_esc.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_unicode_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_utf8_after_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_iso_latin_1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_leading_uescaped_thinspace.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_lone_utf8_continuation_byte.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_no_quotes_with_bad_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_overlong_sequence_2_bytes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_overlong_sequence_6_bytes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_overlong_sequence_6_bytes_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_single_doublequote.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_single_quote.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_single_string_no_double_quotes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_start_escape_unclosed.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unescaped_crtl_char.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unescaped_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unescaped_tab.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unicode_CapitalU.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_with_trailing_garbage.json", + //!TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_100000_opening_arrays.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_3C.3E.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_3Cnull3E.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_U+2060_word_joined.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_UTF8_BOM_no_data.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_with_extra_array_close.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_with_unclosed_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_ascii-unicode-identifier.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_capitalized_True.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_close_unopened_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_comma_instead_of_closing_brace.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_double_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_end_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_incomplete_UTF8_BOM.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_lone-invalid-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_lone-open-bracket.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_no_data.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_null-byte-outside-string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_number_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_followed_by_closing_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_unclosed_no_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_with_comment.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_apostrophe.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_comma.json", + //!TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_open_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_open_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_close_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_open_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_open_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_string_with_apostrophes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_open.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_single_point.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_single_star.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_trailing_#.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_uescaped_LF_before_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array_partial_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array_unfinished_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array_unfinished_true.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unicode-identifier.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_whitespace_U+2060_word_joiner.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_whitespace_formfeed.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -798,25 +790,23 @@ // they succeed when the operator>> is used, because it does not // have this constraint for (const auto* filename : - { - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_after_close.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_close.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_open.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open_incomplete.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_with_extra_array_close.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_close_unopened_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_double_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_number_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_followed_by_closing_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_trailing_#.json" - } - ) + { + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_after_close.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_close.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_open.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open_incomplete.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_with_extra_array_close.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_close_unopened_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_double_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_number_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_followed_by_closing_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_trailing_#.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -828,18 +818,16 @@ SECTION("i -> y") { for (const auto* filename : - { - // we do not pose a limit on nesting - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_structure_500_nested_arrays.json", - // we silently ignore BOMs - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_structure_UTF-8_BOM_empty_object.json", - // we accept and forward non-characters - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+10FFFE_nonchar.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+1FFFE_nonchar.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+FDD0_nonchar.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+FFFE_nonchar.json" - } - ) + { + // we do not pose a limit on nesting + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_structure_500_nested_arrays.json", + // we silently ignore BOMs + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_structure_UTF-8_BOM_empty_object.json", + // we accept and forward non-characters + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+10FFFE_nonchar.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+1FFFE_nonchar.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+FDD0_nonchar.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+FFFE_nonchar.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -852,14 +840,12 @@ SECTION("i/y -> n (out of range)") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_neg_int_huge_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_pos_double_huge_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json" - } - ) + { + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_neg_int_huge_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_pos_double_huge_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -871,22 +857,20 @@ SECTION("i -> n") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_object_key_lone_2nd_surrogate.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_1st_surrogate_but_2nd_missing.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_UTF-16_invalid_lonely_surrogate.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_UTF-16_invalid_surrogate.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_UTF-8_invalid_sequence.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_incomplete_surrogate_and_escape_valid.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_incomplete_surrogate_pair.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_incomplete_surrogates_escape_valid.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_inverted_surrogates_U+1D11E.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_lone_second_surrogate.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_not_in_unicode_range.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_truncated-utf-8.json" - } - ) + { + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_object_key_lone_2nd_surrogate.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_1st_surrogate_but_2nd_missing.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_UTF-16_invalid_lonely_surrogate.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_UTF-16_invalid_surrogate.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_UTF-8_invalid_sequence.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_incomplete_surrogate_and_escape_valid.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_incomplete_surrogate_pair.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_incomplete_surrogates_escape_valid.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_inverted_surrogates_U+1D11E.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_lone_second_surrogate.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_not_in_unicode_range.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_truncated-utf-8.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -904,104 +888,102 @@ SECTION("y") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_arraysWithSpaces.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_empty-string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_ending_with_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_heterogeneous.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_1_and_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_leading_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_several_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_trailing_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_0e+1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_0e1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_after_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_double_close_to_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_int_with_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_minus_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_negative_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_negative_one.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_negative_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_capital_e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_capital_e_neg_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_capital_e_pos_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_fraction_exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_neg_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_pos_exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_simple_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_simple_real.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_basic.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_duplicated_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_duplicated_key_and_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_empty_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_escaped_null_in_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_extreme_numbers.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_long_strings.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_simple.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_string_unicode.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_with_newlines.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_accepted_surrogate_pair.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_accepted_surrogate_pairs.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_allowed_escapes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_backslash_and_u_escaped_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_backslash_doublequotes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_comments.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_double_escape_a.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_double_escape_n.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_escaped_control_character.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_escaped_noncharacter.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_in_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_in_array_with_leading_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_last_surrogates_1_and_2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_nbsp_uescaped.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_null_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_one-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_pi.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_reservedCharacterInUTF-8_U+1BFFF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_simple_ascii.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_three-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_two-byte-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_u+2028_line_sep.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_u+2029_par_sep.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_uEscape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_uescaped_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unescaped_char_delete.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicodeEscapedBackslash.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+10FFFE_nonchar.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+1FFFE_nonchar.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+2064_invisible_plus.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+FDD0_nonchar.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+FFFE_nonchar.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_escaped_double_quote.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_utf8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_with_del_character.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_negative_real.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_true.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_string_empty.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_trailing_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_true_in_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_whitespace_array.json" - } - ) + { + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_arraysWithSpaces.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_empty-string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_ending_with_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_heterogeneous.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_1_and_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_leading_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_several_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_trailing_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_0e+1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_0e1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_after_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_double_close_to_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_int_with_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_minus_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_negative_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_negative_one.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_negative_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_capital_e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_capital_e_neg_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_capital_e_pos_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_fraction_exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_neg_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_pos_exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_simple_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_simple_real.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_basic.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_duplicated_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_duplicated_key_and_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_empty_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_escaped_null_in_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_extreme_numbers.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_long_strings.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_simple.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_string_unicode.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_with_newlines.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_accepted_surrogate_pair.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_accepted_surrogate_pairs.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_allowed_escapes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_backslash_and_u_escaped_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_backslash_doublequotes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_comments.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_double_escape_a.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_double_escape_n.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_escaped_control_character.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_escaped_noncharacter.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_in_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_in_array_with_leading_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_last_surrogates_1_and_2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_nbsp_uescaped.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_null_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_one-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_pi.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_reservedCharacterInUTF-8_U+1BFFF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_simple_ascii.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_three-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_two-byte-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_u+2028_line_sep.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_u+2029_par_sep.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_uEscape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_uescaped_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unescaped_char_delete.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicodeEscapedBackslash.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+10FFFE_nonchar.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+1FFFE_nonchar.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+2064_invisible_plus.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+FDD0_nonchar.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+FFFE_nonchar.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_escaped_double_quote.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_utf8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_with_del_character.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_negative_real.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_true.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_string_empty.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_trailing_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_true_in_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_whitespace_array.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -1015,195 +997,193 @@ SECTION("n") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_1_true_without_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_a_invalid_utf8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_colon_instead_of_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_comma_after_close.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_comma_and_number.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_double_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_double_extra_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_extra_close.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_extra_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_incomplete.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_incomplete_invalid_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_inner_array_no_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_invalid_utf8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_items_separated_by_semicolon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_just_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_just_minus.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_missing_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_newlines_unclosed.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_number_and_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_number_and_several_commas.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_spaces_vertical_tab_formfeed.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_star_inside.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed_trailing_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed_with_new_lines.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed_with_object_inside.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_incomplete_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_incomplete_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_incomplete_true.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_multidigit_number_then_00.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_++.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_+1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_+Inf.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-01.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-1.0..json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-2..json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-NaN.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_.-1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_.2e-3.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.1.2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.3e+.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.3e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.e1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0_capital_E+.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0_capital_E.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0e+.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1.0e+.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1.0e-.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1.0e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1_000.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1eE2.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_2.e+3.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_2.e-3.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_2.e3.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_9.e+.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_Inf.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_NaN.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_U+FF11_fullwidth_digit_one.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_expression.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_hex_1_digit.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_hex_2_digits.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_infinity.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid+-.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-negative-real.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-utf-8-in-bigger-int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-utf-8-in-exponent.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-utf-8-in-int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_minus_infinity.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_minus_sign_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_minus_space_1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_neg_int_starting_with_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_neg_real_without_int_part.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_neg_with_garbage_at_end.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_real_garbage_after_e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_real_with_invalid_utf8_after_e.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_real_without_fractional_part.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_starting_with_dot.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_with_alpha.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_with_alpha_char.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_with_leading_zero.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_bad_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_bracket_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_comma_instead_of_colon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_double_colon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_emoji.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_garbage_at_end.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_key_with_single_quotes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_lone_continuation_byte_in_key_and_trailing_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_colon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_semicolon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_no-colon.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_non_string_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_non_string_key_but_huge_number_instead.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_repeated_null_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_several_trailing_commas.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_single_quote.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment_open.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment_slash_open.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment_slash_open_incomplete.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_two_commas_in_a_row.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_unquoted_key.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_unterminated-value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_with_single_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_single_space.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape_u.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape_u1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape_u1x.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_accentuated_char_no_quotes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_backslash_00.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escape_x.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escaped_backslash_bad.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escaped_ctrl_char_tab.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escaped_emoji.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_escaped_character.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_surrogate.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_surrogate_escape_invalid.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid-utf-8-in-escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid_backslash_esc.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid_unicode_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid_utf8_after_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_leading_uescaped_thinspace.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_no_quotes_with_bad_escape.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_single_doublequote.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_single_quote.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_single_string_no_double_quotes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_start_escape_unclosed.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unescaped_crtl_char.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unescaped_newline.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unescaped_tab.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unicode_CapitalU.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_U+2060_word_joined.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_UTF8_BOM_no_data.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_angle_bracket_..json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_angle_bracket_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_array_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_array_with_extra_array_close.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_array_with_unclosed_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_ascii-unicode-identifier.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_capitalized_True.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_close_unopened_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_comma_instead_of_closing_brace.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_double_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_end_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_incomplete_UTF8_BOM.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_lone-invalid-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_lone-open-bracket.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_no_data.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_null-byte-outside-string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_number_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_followed_by_closing_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_unclosed_no_value.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_with_comment.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_with_trailing_garbage.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_apostrophe.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_open_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_open_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_close_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_comma.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_open_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_open_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_string_with_apostrophes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_open.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_single_eacute.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_single_star.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_trailing_#.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_uescaped_LF_before_string.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array_partial_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array_unfinished_false.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array_unfinished_true.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_object.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unicode-identifier.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_whitespace_U+2060_word_joiner.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_whitespace_formfeed.json" - } - ) + { + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_1_true_without_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_a_invalid_utf8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_colon_instead_of_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_comma_after_close.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_comma_and_number.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_double_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_double_extra_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_extra_close.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_extra_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_incomplete.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_incomplete_invalid_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_inner_array_no_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_invalid_utf8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_items_separated_by_semicolon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_just_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_just_minus.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_missing_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_newlines_unclosed.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_number_and_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_number_and_several_commas.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_spaces_vertical_tab_formfeed.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_star_inside.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed_trailing_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed_with_new_lines.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed_with_object_inside.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_incomplete_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_incomplete_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_incomplete_true.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_multidigit_number_then_00.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_++.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_+1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_+Inf.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-01.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-1.0..json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-2..json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-NaN.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_.-1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_.2e-3.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.1.2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.3e+.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.3e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.e1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0_capital_E+.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0_capital_E.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0e+.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1.0e+.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1.0e-.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1.0e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1_000.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1eE2.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_2.e+3.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_2.e-3.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_2.e3.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_9.e+.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_Inf.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_NaN.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_U+FF11_fullwidth_digit_one.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_expression.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_hex_1_digit.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_hex_2_digits.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_infinity.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid+-.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-negative-real.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-utf-8-in-bigger-int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-utf-8-in-exponent.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-utf-8-in-int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_minus_infinity.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_minus_sign_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_minus_space_1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_neg_int_starting_with_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_neg_real_without_int_part.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_neg_with_garbage_at_end.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_real_garbage_after_e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_real_with_invalid_utf8_after_e.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_real_without_fractional_part.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_starting_with_dot.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_with_alpha.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_with_alpha_char.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_with_leading_zero.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_bad_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_bracket_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_comma_instead_of_colon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_double_colon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_emoji.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_garbage_at_end.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_key_with_single_quotes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_lone_continuation_byte_in_key_and_trailing_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_colon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_semicolon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_no-colon.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_non_string_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_non_string_key_but_huge_number_instead.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_repeated_null_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_several_trailing_commas.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_single_quote.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment_open.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment_slash_open.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment_slash_open_incomplete.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_two_commas_in_a_row.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_unquoted_key.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_unterminated-value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_with_single_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_single_space.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape_u.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape_u1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape_u1x.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_accentuated_char_no_quotes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_backslash_00.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escape_x.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escaped_backslash_bad.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escaped_ctrl_char_tab.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escaped_emoji.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_escaped_character.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_surrogate.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_surrogate_escape_invalid.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid-utf-8-in-escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid_backslash_esc.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid_unicode_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid_utf8_after_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_leading_uescaped_thinspace.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_no_quotes_with_bad_escape.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_single_doublequote.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_single_quote.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_single_string_no_double_quotes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_start_escape_unclosed.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unescaped_crtl_char.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unescaped_newline.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unescaped_tab.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unicode_CapitalU.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_U+2060_word_joined.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_UTF8_BOM_no_data.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_angle_bracket_..json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_angle_bracket_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_array_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_array_with_extra_array_close.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_array_with_unclosed_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_ascii-unicode-identifier.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_capitalized_True.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_close_unopened_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_comma_instead_of_closing_brace.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_double_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_end_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_incomplete_UTF8_BOM.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_lone-invalid-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_lone-open-bracket.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_no_data.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_null-byte-outside-string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_number_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_followed_by_closing_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_unclosed_no_value.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_with_comment.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_with_trailing_garbage.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_apostrophe.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_open_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_open_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_close_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_comma.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_open_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_open_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_string_with_apostrophes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_open.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_single_eacute.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_single_star.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_trailing_#.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_uescaped_LF_before_string.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array_partial_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array_unfinished_false.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array_unfinished_true.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_object.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unicode-identifier.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_whitespace_U+2060_word_joiner.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_whitespace_formfeed.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -1217,11 +1197,9 @@ SECTION("n (previously overflowed)") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_100000_opening_arrays.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_object.json" - } - ) + { + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_100000_opening_arrays.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_object.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -1232,44 +1210,42 @@ SECTION("i -> y") { for (const auto* filename : - { - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_huge_exp.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_neg_int_huge_exp.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_pos_double_huge_exp.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_neg_overflow.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_pos_overflow.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_underflow.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_neg_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_pos_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_very_big_negative_int.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_object_key_lone_2nd_surrogate.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_surrogate_but_2nd_missing.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-16LE_with_BOM.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-8_invalid_sequence.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF8_surrogate_U+D800.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_and_escape_valid.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_pair.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogates_escape_valid.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_lonely_surrogate.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_surrogate.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_utf-8.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_inverted_surrogates_U+1D11E.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_iso_latin_1.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_second_surrogate.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_utf8_continuation_byte.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_not_in_unicode_range.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_2_bytes.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes_null.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_truncated-utf-8.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16BE_no_BOM.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16LE_no_BOM.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_500_nested_arrays.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_UTF-8_BOM_empty_object.json" - } - ) + { + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_huge_exp.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_neg_int_huge_exp.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_pos_double_huge_exp.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_neg_overflow.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_pos_overflow.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_underflow.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_neg_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_pos_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_very_big_negative_int.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_object_key_lone_2nd_surrogate.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_surrogate_but_2nd_missing.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-16LE_with_BOM.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-8_invalid_sequence.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF8_surrogate_U+D800.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_and_escape_valid.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_pair.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogates_escape_valid.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_lonely_surrogate.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_surrogate.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_utf-8.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_inverted_surrogates_U+1D11E.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_iso_latin_1.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_second_surrogate.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_utf8_continuation_byte.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_not_in_unicode_range.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_2_bytes.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes_null.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_truncated-utf-8.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16BE_no_BOM.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16LE_no_BOM.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_500_nested_arrays.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_UTF-8_BOM_empty_object.json"}) { CAPTURE(filename) std::ifstream f(filename); @@ -1283,49 +1259,48 @@ SECTION("i -> n") { for (const auto* filename : - { - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_huge_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_neg_int_huge_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_pos_double_huge_exp.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_neg_overflow.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_pos_overflow.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_underflow.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_neg_int.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_pos_int.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_very_big_negative_int.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_object_key_lone_2nd_surrogate.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_surrogate_but_2nd_missing.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-16LE_with_BOM.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-8_invalid_sequence.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF8_surrogate_U+D800.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_and_escape_valid.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_pair.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogates_escape_valid.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_lonely_surrogate.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_surrogate.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_inverted_surrogates_U+1D11E.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_iso_latin_1.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_second_surrogate.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_utf8_continuation_byte.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_not_in_unicode_range.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_2_bytes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes_null.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_truncated-utf-8.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16BE_no_BOM.json", - TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16LE_no_BOM.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_500_nested_arrays.json", - //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_UTF-8_BOM_empty_object.json" - } - ) + { + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_huge_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_neg_int_huge_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_pos_double_huge_exp.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_neg_overflow.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_pos_overflow.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_underflow.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_neg_int.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_pos_int.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_very_big_negative_int.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_object_key_lone_2nd_surrogate.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_surrogate_but_2nd_missing.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-16LE_with_BOM.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-8_invalid_sequence.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF8_surrogate_U+D800.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_and_escape_valid.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_pair.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogates_escape_valid.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_lonely_surrogate.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_surrogate.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_inverted_surrogates_U+1D11E.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_iso_latin_1.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_second_surrogate.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_utf8_continuation_byte.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_not_in_unicode_range.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_2_bytes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes_null.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_truncated-utf-8.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16BE_no_BOM.json", + TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16LE_no_BOM.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_500_nested_arrays.json", + //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_UTF-8_BOM_empty_object.json" + }) { CAPTURE(filename) std::ifstream f(filename); json _; - CHECK_THROWS_AS(_ = json::parse(f), json::exception&); // could be parse_error or out_of_range + CHECK_THROWS_AS(_ = json::parse(f), json::exception&); // could be parse_error or out_of_range std::ifstream f2(filename); CHECK(!json::accept(f2)); } @@ -1333,8 +1308,7 @@ } } -namespace -{ +namespace { std::string trim(const std::string& str); // from https://stackoverflow.com/a/25829178/266378 @@ -1348,7 +1322,7 @@ const size_t last = str.find_last_not_of(' '); return str.substr(first, (last - first + 1)); } -} // namespace +} // namespace TEST_CASE("Big List of Naughty Strings") {
diff --git a/tests/src/unit-to_chars.cpp b/tests/src/unit-to_chars.cpp index 6d32e06..258d690 100644 --- a/tests/src/unit-to_chars.cpp +++ b/tests/src/unit-to_chars.cpp
@@ -15,8 +15,7 @@ #include <nlohmann/json.hpp> using nlohmann::detail::dtoa_impl::reinterpret_bits; -namespace -{ +namespace { float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t significand) { assert(sign_bit == 0 || sign_bit == 1); @@ -35,12 +34,12 @@ // ldexp -- convert f * 2^e to IEEE single precision float make_float(uint64_t f, int e) { - constexpr uint64_t kHiddenBit = 0x00800000; - constexpr uint64_t kSignificandMask = 0x007FFFFF; - constexpr int kPhysicalSignificandSize = 23; // Excludes the hidden bit. - constexpr int kExponentBias = 0x7F + kPhysicalSignificandSize; - constexpr int kDenormalExponent = 1 - kExponentBias; - constexpr int kMaxExponent = 0xFF - kExponentBias; + constexpr uint64_t kHiddenBit = 0x00800000; + constexpr uint64_t kSignificandMask = 0x007FFFFF; + constexpr int kPhysicalSignificandSize = 23; // Excludes the hidden bit. + constexpr int kExponentBias = 0x7F + kPhysicalSignificandSize; + constexpr int kDenormalExponent = 1 - kExponentBias; + constexpr int kMaxExponent = 0xFF - kExponentBias; while (f > kHiddenBit + kSignificandMask) { @@ -62,8 +61,8 @@ } const uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0) - ? 0 - : static_cast<uint64_t>(e + kExponentBias); + ? 0 + : static_cast<uint64_t>(e + kExponentBias); const uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize); return reinterpret_bits<float>(static_cast<uint32_t>(bits)); @@ -87,12 +86,12 @@ // ldexp -- convert f * 2^e to IEEE double precision double make_double(uint64_t f, int e) { - constexpr uint64_t kHiddenBit = 0x0010000000000000; - constexpr uint64_t kSignificandMask = 0x000FFFFFFFFFFFFF; - constexpr int kPhysicalSignificandSize = 52; // Excludes the hidden bit. - constexpr int kExponentBias = 0x3FF + kPhysicalSignificandSize; - constexpr int kDenormalExponent = 1 - kExponentBias; - constexpr int kMaxExponent = 0x7FF - kExponentBias; + constexpr uint64_t kHiddenBit = 0x0010000000000000; + constexpr uint64_t kSignificandMask = 0x000FFFFFFFFFFFFF; + constexpr int kPhysicalSignificandSize = 52; // Excludes the hidden bit. + constexpr int kExponentBias = 0x3FF + kPhysicalSignificandSize; + constexpr int kDenormalExponent = 1 - kExponentBias; + constexpr int kMaxExponent = 0x7FF - kExponentBias; while (f > kHiddenBit + kSignificandMask) { @@ -114,20 +113,19 @@ } const uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0) - ? 0 - : static_cast<uint64_t>(e + kExponentBias); + ? 0 + : static_cast<uint64_t>(e + kExponentBias); const uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize); return reinterpret_bits<double>(bits); } -} // namespace +} // namespace TEST_CASE("digit gen") { SECTION("single precision") { - auto check_float = [](float number, const std::string & digits, int expected_exponent) - { + auto check_float = [](float number, const std::string& digits, int expected_exponent) { CAPTURE(number) CAPTURE(digits) CAPTURE(expected_exponent) @@ -141,57 +139,56 @@ CHECK(expected_exponent == exponent); }; - check_float(make_float(0, 0, 0x00000001), "1", -45); // min denormal - check_float(make_float(0, 0, 0x007FFFFF), "11754942", -45); // max denormal - check_float(make_float(0, 1, 0x00000000), "11754944", -45); // min normal - check_float(make_float(0, 1, 0x00000001), "11754945", -45); - check_float(make_float(0, 1, 0x007FFFFF), "23509886", -45); - check_float(make_float(0, 2, 0x00000000), "23509887", -45); - check_float(make_float(0, 2, 0x00000001), "2350989", -44); - check_float(make_float(0, 24, 0x00000000), "98607613", -39); // fail if no special case in normalized boundaries - check_float(make_float(0, 30, 0x00000000), "63108872", -37); // fail if no special case in normalized boundaries - check_float(make_float(0, 31, 0x00000000), "12621775", -36); // fail if no special case in normalized boundaries - check_float(make_float(0, 57, 0x00000000), "84703295", -29); // fail if no special case in normalized boundaries - check_float(make_float(0, 254, 0x007FFFFE), "34028233", 31); - check_float(make_float(0, 254, 0x007FFFFF), "34028235", 31); // max normal + check_float(make_float(0, 0, 0x00000001), "1", -45); // min denormal + check_float(make_float(0, 0, 0x007FFFFF), "11754942", -45); // max denormal + check_float(make_float(0, 1, 0x00000000), "11754944", -45); // min normal + check_float(make_float(0, 1, 0x00000001), "11754945", -45); + check_float(make_float(0, 1, 0x007FFFFF), "23509886", -45); + check_float(make_float(0, 2, 0x00000000), "23509887", -45); + check_float(make_float(0, 2, 0x00000001), "2350989", -44); + check_float(make_float(0, 24, 0x00000000), "98607613", -39); // fail if no special case in normalized boundaries + check_float(make_float(0, 30, 0x00000000), "63108872", -37); // fail if no special case in normalized boundaries + check_float(make_float(0, 31, 0x00000000), "12621775", -36); // fail if no special case in normalized boundaries + check_float(make_float(0, 57, 0x00000000), "84703295", -29); // fail if no special case in normalized boundaries + check_float(make_float(0, 254, 0x007FFFFE), "34028233", 31); + check_float(make_float(0, 254, 0x007FFFFF), "34028235", 31); // max normal // V. Paxson and W. Kahan, "A Program for Testing IEEE Binary-Decimal Conversion", manuscript, May 1991, // ftp://ftp.ee.lbl.gov/testbase-report.ps.Z (report) // ftp://ftp.ee.lbl.gov/testbase.tar.Z (program) // Table 16: Stress Inputs for Converting 24-bit Binary to Decimal, < 1/2 ULP - check_float(make_float(12676506, -102), "25", -25); - check_float(make_float(12676506, -103), "125", -26); - check_float(make_float(15445013, 86), "1195", 30); - check_float(make_float(13734123, -138), "39415", -39); - check_float(make_float(12428269, -130), "913085", -38); - check_float(make_float(15334037, -146), "1719005", -43); - check_float(make_float(11518287, -41), "52379105", -13); - check_float(make_float(12584953, -145), "2821644", -43); + check_float(make_float(12676506, -102), "25", -25); + check_float(make_float(12676506, -103), "125", -26); + check_float(make_float(15445013, 86), "1195", 30); + check_float(make_float(13734123, -138), "39415", -39); + check_float(make_float(12428269, -130), "913085", -38); + check_float(make_float(15334037, -146), "1719005", -43); + check_float(make_float(11518287, -41), "52379105", -13); + check_float(make_float(12584953, -145), "2821644", -43); check_float(make_float(15961084, -125), "37524328", -38); check_float(make_float(14915817, -146), "16721209", -44); check_float(make_float(10845484, -102), "21388946", -31); - check_float(make_float(16431059, -61), "7125836", -18); + check_float(make_float(16431059, -61), "7125836", -18); // Table 17: Stress Inputs for Converting 24-bit Binary to Decimal, > 1/2 ULP - check_float(make_float(16093626, 69), "95", 26); - check_float(make_float( 9983778, 25), "335", 12); - check_float(make_float(12745034, 104), "2585", 35); - check_float(make_float(12706553, 72), "60005", 24); - check_float(make_float(11005028, 45), "387205", 15); - check_float(make_float(15059547, 71), "3555835", 22); - check_float(make_float(16015691, -99), "25268305", -30); - check_float(make_float( 8667859, 56), "6245851", 17); - check_float(make_float(14855922, -82), "30721327", -25); - check_float(make_float(14855922, -83), "15360663", -25); - check_float(make_float(10144164, -110), "781478", -32); - check_float(make_float(13248074, 95), "52481028", 28); + check_float(make_float(16093626, 69), "95", 26); + check_float(make_float(9983778, 25), "335", 12); + check_float(make_float(12745034, 104), "2585", 35); + check_float(make_float(12706553, 72), "60005", 24); + check_float(make_float(11005028, 45), "387205", 15); + check_float(make_float(15059547, 71), "3555835", 22); + check_float(make_float(16015691, -99), "25268305", -30); + check_float(make_float(8667859, 56), "6245851", 17); + check_float(make_float(14855922, -82), "30721327", -25); + check_float(make_float(14855922, -83), "15360663", -25); + check_float(make_float(10144164, -110), "781478", -32); + check_float(make_float(13248074, 95), "52481028", 28); } SECTION("double precision") { - auto check_double = [](double number, const std::string & digits, int expected_exponent) - { + auto check_double = [](double number, const std::string& digits, int expected_exponent) { CAPTURE(number) CAPTURE(digits) CAPTURE(expected_exponent) @@ -205,130 +202,130 @@ CHECK(expected_exponent == exponent); }; - check_double(make_double(0, 0, 0x0000000000000001), "5", -324); // min denormal - check_double(make_double(0, 0, 0x000FFFFFFFFFFFFF), "2225073858507201", -323); // max denormal - check_double(make_double(0, 1, 0x0000000000000000), "22250738585072014", -324); // min normal - check_double(make_double(0, 1, 0x0000000000000001), "2225073858507202", -323); - check_double(make_double(0, 1, 0x000FFFFFFFFFFFFF), "44501477170144023", -324); - check_double(make_double(0, 2, 0x0000000000000000), "4450147717014403", -323); - check_double(make_double(0, 2, 0x0000000000000001), "4450147717014404", -323); - check_double(make_double(0, 4, 0x0000000000000000), "17800590868057611", -323); // fail if no special case in normalized boundaries - check_double(make_double(0, 5, 0x0000000000000000), "35601181736115222", -323); // fail if no special case in normalized boundaries - check_double(make_double(0, 6, 0x0000000000000000), "7120236347223045", -322); // fail if no special case in normalized boundaries - check_double(make_double(0, 10, 0x0000000000000000), "11392378155556871", -321); // fail if no special case in normalized boundaries - check_double(make_double(0, 2046, 0x000FFFFFFFFFFFFE), "17976931348623155", 292); - check_double(make_double(0, 2046, 0x000FFFFFFFFFFFFF), "17976931348623157", 292); // max normal + check_double(make_double(0, 0, 0x0000000000000001), "5", -324); // min denormal + check_double(make_double(0, 0, 0x000FFFFFFFFFFFFF), "2225073858507201", -323); // max denormal + check_double(make_double(0, 1, 0x0000000000000000), "22250738585072014", -324); // min normal + check_double(make_double(0, 1, 0x0000000000000001), "2225073858507202", -323); + check_double(make_double(0, 1, 0x000FFFFFFFFFFFFF), "44501477170144023", -324); + check_double(make_double(0, 2, 0x0000000000000000), "4450147717014403", -323); + check_double(make_double(0, 2, 0x0000000000000001), "4450147717014404", -323); + check_double(make_double(0, 4, 0x0000000000000000), "17800590868057611", -323); // fail if no special case in normalized boundaries + check_double(make_double(0, 5, 0x0000000000000000), "35601181736115222", -323); // fail if no special case in normalized boundaries + check_double(make_double(0, 6, 0x0000000000000000), "7120236347223045", -322); // fail if no special case in normalized boundaries + check_double(make_double(0, 10, 0x0000000000000000), "11392378155556871", -321); // fail if no special case in normalized boundaries + check_double(make_double(0, 2046, 0x000FFFFFFFFFFFFE), "17976931348623155", 292); + check_double(make_double(0, 2046, 0x000FFFFFFFFFFFFF), "17976931348623157", 292); // max normal // Test different paths in DigitGen - check_double( 10000, "1", 4); - check_double( 1200000, "12", 5); - check_double(4.9406564584124654e-324, "5", -324); // exit integral loop - check_double(2.2250738585072009e-308, "2225073858507201", -323); // exit fractional loop - check_double( 1.82877982605164e-99, "182877982605164", -113); - check_double( 1.1505466208671903e-09, "11505466208671903", -25); - check_double( 5.5645893133766722e+20, "5564589313376672", 5); - check_double( 53.034830388866226, "53034830388866226", -15); - check_double( 0.0021066531670178605, "21066531670178605", -19); + check_double(10000, "1", 4); + check_double(1200000, "12", 5); + check_double(4.9406564584124654e-324, "5", -324); // exit integral loop + check_double(2.2250738585072009e-308, "2225073858507201", -323); // exit fractional loop + check_double(1.82877982605164e-99, "182877982605164", -113); + check_double(1.1505466208671903e-09, "11505466208671903", -25); + check_double(5.5645893133766722e+20, "5564589313376672", 5); + check_double(53.034830388866226, "53034830388866226", -15); + check_double(0.0021066531670178605, "21066531670178605", -19); // V. Paxson and W. Kahan, "A Program for Testing IEEE Binary-Decimal Conversion", manuscript, May 1991, // ftp://ftp.ee.lbl.gov/testbase-report.ps.Z (report) // ftp://ftp.ee.lbl.gov/testbase.tar.Z (program) // Table 3: Stress Inputs for Converting 53-bit Binary to Decimal, < 1/2 ULP - check_double(make_double(8511030020275656, -342) /* 9.5e-088 */, "95", -89); - check_double(make_double(5201988407066741, -824) /* 4.65e-233 */, "465", -235); - check_double(make_double(6406892948269899, +237) /* 1.415e+087 */, "1415", 84); - check_double(make_double(8431154198732492, +72) /* 3.9815e+037 */, "39815", 33); - check_double(make_double(6475049196144587, +99) /* 4.10405e+045 */, "410405", 40); - check_double(make_double(8274307542972842, +726) /* 2.920845e+234 */, "2920845", 228); - check_double(make_double(5381065484265332, -456) /* 2.8919465e-122 */, "28919465", -129); - check_double(make_double(6761728585499734, -1057) /* 4.37877185e-303 */, "437877185", -311); - check_double(make_double(7976538478610756, +376) /* 1.227701635e+129 */, "1227701635", 120); - check_double(make_double(5982403858958067, +377) /* 1.8415524525e+129 */, "18415524525", 119); - check_double(make_double(5536995190630837, +93) /* 5.48357443505e+043 */, "548357443505", 32); - check_double(make_double(7225450889282194, +710) /* 3.891901811465e+229 */, "3891901811465", 217); - check_double(make_double(7225450889282194, +709) /* 1.9459509057325e+229 */, "19459509057325", 216); - check_double(make_double(8703372741147379, +117) /* 1.44609583816055e+051 */, "144609583816055", 37); - check_double(make_double(8944262675275217, -1001) /* 4.173677474585315e-286 */, "4173677474585315", -301); - check_double(make_double(7459803696087692, -707) /* 1.1079507728788885e-197 */, "11079507728788885", -213); - check_double(make_double(6080469016670379, -381) /* 1.234550136632744e-099 */, "1234550136632744", -114); - check_double(make_double(8385515147034757, +721) /* 9.2503171196036502e+232 */, "925031711960365", 218); - check_double(make_double(7514216811389786, -828) /* 4.1980471502848898e-234 */, "419804715028489", -248); - check_double(make_double(8397297803260511, -345) /* 1.1716315319786511e-088 */, "11716315319786511", -104); - check_double(make_double(6733459239310543, +202) /* 4.3281007284461249e+076 */, "4328100728446125", 61); - check_double(make_double(8091450587292794, -473) /* 3.3177101181600311e-127 */, "3317710118160031", -142); + check_double(make_double(8511030020275656, -342) /* 9.5e-088 */, "95", -89); + check_double(make_double(5201988407066741, -824) /* 4.65e-233 */, "465", -235); + check_double(make_double(6406892948269899, +237) /* 1.415e+087 */, "1415", 84); + check_double(make_double(8431154198732492, +72) /* 3.9815e+037 */, "39815", 33); + check_double(make_double(6475049196144587, +99) /* 4.10405e+045 */, "410405", 40); + check_double(make_double(8274307542972842, +726) /* 2.920845e+234 */, "2920845", 228); + check_double(make_double(5381065484265332, -456) /* 2.8919465e-122 */, "28919465", -129); + check_double(make_double(6761728585499734, -1057) /* 4.37877185e-303 */, "437877185", -311); + check_double(make_double(7976538478610756, +376) /* 1.227701635e+129 */, "1227701635", 120); + check_double(make_double(5982403858958067, +377) /* 1.8415524525e+129 */, "18415524525", 119); + check_double(make_double(5536995190630837, +93) /* 5.48357443505e+043 */, "548357443505", 32); + check_double(make_double(7225450889282194, +710) /* 3.891901811465e+229 */, "3891901811465", 217); + check_double(make_double(7225450889282194, +709) /* 1.9459509057325e+229 */, "19459509057325", 216); + check_double(make_double(8703372741147379, +117) /* 1.44609583816055e+051 */, "144609583816055", 37); + check_double(make_double(8944262675275217, -1001) /* 4.173677474585315e-286 */, "4173677474585315", -301); + check_double(make_double(7459803696087692, -707) /* 1.1079507728788885e-197 */, "11079507728788885", -213); + check_double(make_double(6080469016670379, -381) /* 1.234550136632744e-099 */, "1234550136632744", -114); + check_double(make_double(8385515147034757, +721) /* 9.2503171196036502e+232 */, "925031711960365", 218); + check_double(make_double(7514216811389786, -828) /* 4.1980471502848898e-234 */, "419804715028489", -248); + check_double(make_double(8397297803260511, -345) /* 1.1716315319786511e-088 */, "11716315319786511", -104); + check_double(make_double(6733459239310543, +202) /* 4.3281007284461249e+076 */, "4328100728446125", 61); + check_double(make_double(8091450587292794, -473) /* 3.3177101181600311e-127 */, "3317710118160031", -142); // Table 4: Stress Inputs for Converting 53-bit Binary to Decimal, > 1/2 ULP - check_double(make_double(6567258882077402, +952) /* 2.5e+302 */, "25", 301); - check_double(make_double(6712731423444934, +535) /* 7.55e+176 */, "755", 174); - check_double(make_double(6712731423444934, +534) /* 3.775e+176 */, "3775", 173); - check_double(make_double(5298405411573037, -957) /* 4.3495e-273 */, "43495", -277); - check_double(make_double(5137311167659507, -144) /* 2.30365e-028 */, "230365", -33); - check_double(make_double(6722280709661868, +363) /* 1.263005e+125 */, "1263005", 119); - check_double(make_double(5344436398034927, -169) /* 7.1422105e-036 */, "71422105", -43); - check_double(make_double(8369123604277281, -853) /* 1.39345735e-241 */, "139345735", -249); - check_double(make_double(8995822108487663, -780) /* 1.414634485e-219 */, "1414634485", -228); - check_double(make_double(8942832835564782, -383) /* 4.5392779195e-100 */, "45392779195", -110); - check_double(make_double(8942832835564782, -384) /* 2.26963895975e-100 */, "226963895975", -111); - check_double(make_double(8942832835564782, -385) /* 1.134819479875e-100 */, "1134819479875", -112); - check_double(make_double(6965949469487146, -249) /* 7.7003665618895e-060 */, "77003665618895", -73); - check_double(make_double(6965949469487146, -250) /* 3.85018328094475e-060 */, "385018328094475", -74); - check_double(make_double(6965949469487146, -251) /* 1.925091640472375e-060 */, "1925091640472375", -75); - check_double(make_double(7487252720986826, +548) /* 6.8985865317742005e+180 */, "68985865317742005", 164); - check_double(make_double(5592117679628511, +164) /* 1.3076622631878654e+065 */, "13076622631878654", 49); - check_double(make_double(8887055249355788, +665) /* 1.3605202075612124e+216 */, "13605202075612124", 200); - check_double(make_double(6994187472632449, +690) /* 3.5928102174759597e+223 */, "35928102174759597", 207); - check_double(make_double(8797576579012143, +588) /* 8.9125197712484552e+192 */, "8912519771248455", 177); - check_double(make_double(7363326733505337, +272) /* 5.5876975736230114e+097 */, "55876975736230114", 81); - check_double(make_double(8549497411294502, -448) /* 1.1762578307285404e-119 */, "11762578307285404", -135); + check_double(make_double(6567258882077402, +952) /* 2.5e+302 */, "25", 301); + check_double(make_double(6712731423444934, +535) /* 7.55e+176 */, "755", 174); + check_double(make_double(6712731423444934, +534) /* 3.775e+176 */, "3775", 173); + check_double(make_double(5298405411573037, -957) /* 4.3495e-273 */, "43495", -277); + check_double(make_double(5137311167659507, -144) /* 2.30365e-028 */, "230365", -33); + check_double(make_double(6722280709661868, +363) /* 1.263005e+125 */, "1263005", 119); + check_double(make_double(5344436398034927, -169) /* 7.1422105e-036 */, "71422105", -43); + check_double(make_double(8369123604277281, -853) /* 1.39345735e-241 */, "139345735", -249); + check_double(make_double(8995822108487663, -780) /* 1.414634485e-219 */, "1414634485", -228); + check_double(make_double(8942832835564782, -383) /* 4.5392779195e-100 */, "45392779195", -110); + check_double(make_double(8942832835564782, -384) /* 2.26963895975e-100 */, "226963895975", -111); + check_double(make_double(8942832835564782, -385) /* 1.134819479875e-100 */, "1134819479875", -112); + check_double(make_double(6965949469487146, -249) /* 7.7003665618895e-060 */, "77003665618895", -73); + check_double(make_double(6965949469487146, -250) /* 3.85018328094475e-060 */, "385018328094475", -74); + check_double(make_double(6965949469487146, -251) /* 1.925091640472375e-060 */, "1925091640472375", -75); + check_double(make_double(7487252720986826, +548) /* 6.8985865317742005e+180 */, "68985865317742005", 164); + check_double(make_double(5592117679628511, +164) /* 1.3076622631878654e+065 */, "13076622631878654", 49); + check_double(make_double(8887055249355788, +665) /* 1.3605202075612124e+216 */, "13605202075612124", 200); + check_double(make_double(6994187472632449, +690) /* 3.5928102174759597e+223 */, "35928102174759597", 207); + check_double(make_double(8797576579012143, +588) /* 8.9125197712484552e+192 */, "8912519771248455", 177); + check_double(make_double(7363326733505337, +272) /* 5.5876975736230114e+097 */, "55876975736230114", 81); + check_double(make_double(8549497411294502, -448) /* 1.1762578307285404e-119 */, "11762578307285404", -135); // Table 20: Stress Inputs for Converting 56-bit Binary to Decimal, < 1/2 ULP - check_double(make_double(50883641005312716, -172) /* 8.4999999999999993e-036 */, "8499999999999999", -51); - check_double(make_double(38162730753984537, -170) /* 2.5499999999999999e-035 */, "255", -37); - check_double(make_double(50832789069151999, -101) /* 2.0049999999999997e-014 */, "20049999999999997", -30); - check_double(make_double(51822367833714164, -109) /* 7.9844999999999994e-017 */, "7984499999999999", -32); - check_double(make_double(66840152193508133, -172) /* 1.1165499999999999e-035 */, "11165499999999999", -51); - check_double(make_double(55111239245584393, -138) /* 1.581615e-025 */, "1581615", -31); - check_double(make_double(71704866733321482, -112) /* 1.3809855e-017 */, "13809855", -24); - check_double(make_double(67160949328233173, -142) /* 1.2046404499999999e-026 */, "12046404499999999", -42); - check_double(make_double(53237141308040189, -152) /* 9.3251405449999991e-030 */, "9325140544999999", -45); - check_double(make_double(62785329394975786, -112) /* 1.2092014595e-017 */, "12092014595", -27); - check_double(make_double(48367680154689523, -77) /* 3.2007045838499998e-007 */, "320070458385", -18); - check_double(make_double(42552223180606797, -102) /* 8.391946324354999e-015 */, "8391946324354999", -30); - check_double(make_double(63626356173011241, -112) /* 1.2253990460585e-017 */, "12253990460585", -30); - check_double(make_double(43566388595783643, -99) /* 6.8735641489760495e-014 */, "687356414897605", -28); - check_double(make_double(54512669636675272, -159) /* 7.459816430480385e-032 */, "7459816430480385", -47); - check_double(make_double(52306490527514614, -167) /* 2.7960588398142552e-034 */, "2796058839814255", -49); - check_double(make_double(52306490527514614, -168) /* 1.3980294199071276e-034 */, "13980294199071276", -50); - check_double(make_double(41024721590449423, -89) /* 6.6279012373057359e-011 */, "6627901237305736", -26); - check_double(make_double(37664020415894738, -132) /* 6.9177880043968072e-024 */, "6917788004396807", -39); - check_double(make_double(37549883692866294, -93) /* 3.7915693108349708e-012 */, "3791569310834971", -27); - check_double(make_double(69124110374399839, -104) /* 3.4080817676591365e-015 */, "34080817676591365", -31); - check_double(make_double(69124110374399839, -105) /* 1.7040408838295683e-015 */, "17040408838295683", -31); + check_double(make_double(50883641005312716, -172) /* 8.4999999999999993e-036 */, "8499999999999999", -51); + check_double(make_double(38162730753984537, -170) /* 2.5499999999999999e-035 */, "255", -37); + check_double(make_double(50832789069151999, -101) /* 2.0049999999999997e-014 */, "20049999999999997", -30); + check_double(make_double(51822367833714164, -109) /* 7.9844999999999994e-017 */, "7984499999999999", -32); + check_double(make_double(66840152193508133, -172) /* 1.1165499999999999e-035 */, "11165499999999999", -51); + check_double(make_double(55111239245584393, -138) /* 1.581615e-025 */, "1581615", -31); + check_double(make_double(71704866733321482, -112) /* 1.3809855e-017 */, "13809855", -24); + check_double(make_double(67160949328233173, -142) /* 1.2046404499999999e-026 */, "12046404499999999", -42); + check_double(make_double(53237141308040189, -152) /* 9.3251405449999991e-030 */, "9325140544999999", -45); + check_double(make_double(62785329394975786, -112) /* 1.2092014595e-017 */, "12092014595", -27); + check_double(make_double(48367680154689523, -77) /* 3.2007045838499998e-007 */, "320070458385", -18); + check_double(make_double(42552223180606797, -102) /* 8.391946324354999e-015 */, "8391946324354999", -30); + check_double(make_double(63626356173011241, -112) /* 1.2253990460585e-017 */, "12253990460585", -30); + check_double(make_double(43566388595783643, -99) /* 6.8735641489760495e-014 */, "687356414897605", -28); + check_double(make_double(54512669636675272, -159) /* 7.459816430480385e-032 */, "7459816430480385", -47); + check_double(make_double(52306490527514614, -167) /* 2.7960588398142552e-034 */, "2796058839814255", -49); + check_double(make_double(52306490527514614, -168) /* 1.3980294199071276e-034 */, "13980294199071276", -50); + check_double(make_double(41024721590449423, -89) /* 6.6279012373057359e-011 */, "6627901237305736", -26); + check_double(make_double(37664020415894738, -132) /* 6.9177880043968072e-024 */, "6917788004396807", -39); + check_double(make_double(37549883692866294, -93) /* 3.7915693108349708e-012 */, "3791569310834971", -27); + check_double(make_double(69124110374399839, -104) /* 3.4080817676591365e-015 */, "34080817676591365", -31); + check_double(make_double(69124110374399839, -105) /* 1.7040408838295683e-015 */, "17040408838295683", -31); // Table 21: Stress Inputs for Converting 56-bit Binary to Decimal, > 1/2 ULP - check_double(make_double(49517601571415211, -94) /* 2.4999999999999998e-012 */, "25", -13); - check_double(make_double(49517601571415211, -95) /* 1.2499999999999999e-012 */, "125", -14); - check_double(make_double(54390733528642804, -133) /* 4.9949999999999996e-024 */, "49949999999999996", -40); // shortest: 4995e-27 - check_double(make_double(71805402319113924, -157) /* 3.9304999999999998e-031 */, "39304999999999998", -47); // shortest: 39305e-35 - check_double(make_double(40435277969631694, -179) /* 5.2770499999999992e-038 */, "5277049999999999", -53); - check_double(make_double(57241991568619049, -165) /* 1.223955e-033 */, "1223955", -39); - check_double(make_double(65224162876242886, +58) /* 1.8799584999999998e+034 */, "18799584999999998", 18); - check_double(make_double(70173376848895368, -138) /* 2.01387715e-025 */, "201387715", -33); - check_double(make_double(37072848117383207, -99) /* 5.8490641049999989e-014 */, "5849064104999999", -29); - check_double(make_double(56845051585389697, -176) /* 5.9349003054999999e-037 */, "59349003055", -47); - check_double(make_double(54791673366936431, -145) /* 1.2284718039499998e-027 */, "12284718039499998", -43); - check_double(make_double(66800318669106231, -169) /* 8.9270767180849991e-035 */, "8927076718084999", -50); - check_double(make_double(66800318669106231, -170) /* 4.4635383590424995e-035 */, "44635383590424995", -51); - check_double(make_double(66574323440112438, -119) /* 1.0016990862549499e-019 */, "10016990862549499", -35); - check_double(make_double(65645179969330963, -173) /* 5.4829412628024647e-036 */, "5482941262802465", -51); - check_double(make_double(61847254334681076, -109) /* 9.5290783281036439e-017 */, "9529078328103644", -32); - check_double(make_double(39990712921393606, -145) /* 8.9662279366405553e-028 */, "8966227936640555", -43); - check_double(make_double(59292318184400283, -149) /* 8.3086234418058538e-029 */, "8308623441805854", -44); - check_double(make_double(69116558615326153, -143) /* 6.1985873566126555e-027 */, "61985873566126555", -43); - check_double(make_double(69116558615326153, -144) /* 3.0992936783063277e-027 */, "30992936783063277", -43); - check_double(make_double(39462549494468513, -152) /* 6.9123512506176015e-030 */, "6912351250617602", -45); - check_double(make_double(39462549494468513, -153) /* 3.4561756253088008e-030 */, "3456175625308801", -45); + check_double(make_double(49517601571415211, -94) /* 2.4999999999999998e-012 */, "25", -13); + check_double(make_double(49517601571415211, -95) /* 1.2499999999999999e-012 */, "125", -14); + check_double(make_double(54390733528642804, -133) /* 4.9949999999999996e-024 */, "49949999999999996", -40); // shortest: 4995e-27 + check_double(make_double(71805402319113924, -157) /* 3.9304999999999998e-031 */, "39304999999999998", -47); // shortest: 39305e-35 + check_double(make_double(40435277969631694, -179) /* 5.2770499999999992e-038 */, "5277049999999999", -53); + check_double(make_double(57241991568619049, -165) /* 1.223955e-033 */, "1223955", -39); + check_double(make_double(65224162876242886, +58) /* 1.8799584999999998e+034 */, "18799584999999998", 18); + check_double(make_double(70173376848895368, -138) /* 2.01387715e-025 */, "201387715", -33); + check_double(make_double(37072848117383207, -99) /* 5.8490641049999989e-014 */, "5849064104999999", -29); + check_double(make_double(56845051585389697, -176) /* 5.9349003054999999e-037 */, "59349003055", -47); + check_double(make_double(54791673366936431, -145) /* 1.2284718039499998e-027 */, "12284718039499998", -43); + check_double(make_double(66800318669106231, -169) /* 8.9270767180849991e-035 */, "8927076718084999", -50); + check_double(make_double(66800318669106231, -170) /* 4.4635383590424995e-035 */, "44635383590424995", -51); + check_double(make_double(66574323440112438, -119) /* 1.0016990862549499e-019 */, "10016990862549499", -35); + check_double(make_double(65645179969330963, -173) /* 5.4829412628024647e-036 */, "5482941262802465", -51); + check_double(make_double(61847254334681076, -109) /* 9.5290783281036439e-017 */, "9529078328103644", -32); + check_double(make_double(39990712921393606, -145) /* 8.9662279366405553e-028 */, "8966227936640555", -43); + check_double(make_double(59292318184400283, -149) /* 8.3086234418058538e-029 */, "8308623441805854", -44); + check_double(make_double(69116558615326153, -143) /* 6.1985873566126555e-027 */, "61985873566126555", -43); + check_double(make_double(69116558615326153, -144) /* 3.0992936783063277e-027 */, "30992936783063277", -43); + check_double(make_double(39462549494468513, -152) /* 6.9123512506176015e-030 */, "6912351250617602", -45); + check_double(make_double(39462549494468513, -153) /* 3.4561756253088008e-030 */, "3456175625308801", -45); } } @@ -336,128 +333,125 @@ { SECTION("single precision") { - auto check_float = [](float number, const std::string & expected) - { + auto check_float = [](float number, const std::string& expected) { std::array<char, 33> buf{}; - char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) std::string actual(buf.data(), end); CHECK(actual == expected); }; // %.9g - check_float( -1.2345e-22f, "-1.2345e-22" ); // -1.23450004e-22 - check_float( -1.2345e-21f, "-1.2345e-21" ); // -1.23450002e-21 - check_float( -1.2345e-20f, "-1.2345e-20" ); // -1.23450002e-20 - check_float( -1.2345e-19f, "-1.2345e-19" ); // -1.23449999e-19 - check_float( -1.2345e-18f, "-1.2345e-18" ); // -1.23449996e-18 - check_float( -1.2345e-17f, "-1.2345e-17" ); // -1.23449998e-17 - check_float( -1.2345e-16f, "-1.2345e-16" ); // -1.23449996e-16 - check_float( -1.2345e-15f, "-1.2345e-15" ); // -1.23450002e-15 - check_float( -1.2345e-14f, "-1.2345e-14" ); // -1.23450004e-14 - check_float( -1.2345e-13f, "-1.2345e-13" ); // -1.23449997e-13 - check_float( -1.2345e-12f, "-1.2345e-12" ); // -1.23450002e-12 - check_float( -1.2345e-11f, "-1.2345e-11" ); // -1.2345e-11 - check_float( -1.2345e-10f, "-1.2345e-10" ); // -1.2345e-10 - check_float( -1.2345e-9f, "-1.2345e-09" ); // -1.23449995e-09 - check_float( -1.2345e-8f, "-1.2345e-08" ); // -1.23449997e-08 - check_float( -1.2345e-7f, "-1.2345e-07" ); // -1.23449993e-07 - check_float( -1.2345e-6f, "-1.2345e-06" ); // -1.23450002e-06 - check_float( -1.2345e-5f, "-1.2345e-05" ); // -1.2345e-05 - check_float( -1.2345e-4f, "-0.00012345" ); // -0.000123449994 - check_float( -1.2345e-3f, "-0.0012345" ); // -0.00123449997 - check_float( -1.2345e-2f, "-0.012345" ); // -0.0123450002 - check_float( -1.2345e-1f, "-0.12345" ); // -0.123450004 - check_float( -0.0f, "-0.0" ); // -0 - check_float( 0.0f, "0.0" ); // 0 - check_float( 1.2345e+0f, "1.2345" ); // 1.23450005 - check_float( 1.2345e+1f, "12.345" ); // 12.3450003 - check_float( 1.2345e+2f, "123.45" ); // 123.449997 - check_float( 1.2345e+3f, "1234.5" ); // 1234.5 - check_float( 1.2345e+4f, "12345.0" ); // 12345 - check_float( 1.2345e+5f, "123450.0" ); // 123450 - check_float( 1.2345e+6f, "1.2345e+06" ); // 1234500 - check_float( 1.2345e+7f, "1.2345e+07" ); // 12345000 - check_float( 1.2345e+8f, "1.2345e+08" ); // 123450000 - check_float( 1.2345e+9f, "1.2345e+09" ); // 1.23449997e+09 - check_float( 1.2345e+10f, "1.2345e+10" ); // 1.23449999e+10 - check_float( 1.2345e+11f, "1.2345e+11" ); // 1.23449999e+11 - check_float( 1.2345e+12f, "1.2345e+12" ); // 1.23450006e+12 - check_float( 1.2345e+13f, "1.2345e+13" ); // 1.23449995e+13 - check_float( 1.2345e+14f, "1.2345e+14" ); // 1.23450002e+14 - check_float( 1.2345e+15f, "1.2345e+15" ); // 1.23450003e+15 - check_float( 1.2345e+16f, "1.2345e+16" ); // 1.23449998e+16 - check_float( 1.2345e+17f, "1.2345e+17" ); // 1.23449996e+17 - check_float( 1.2345e+18f, "1.2345e+18" ); // 1.23450004e+18 - check_float( 1.2345e+19f, "1.2345e+19" ); // 1.23449999e+19 - check_float( 1.2345e+20f, "1.2345e+20" ); // 1.23449999e+20 - check_float( 1.2345e+21f, "1.2345e+21" ); // 1.23449999e+21 - check_float( 1.2345e+22f, "1.2345e+22" ); // 1.23450005e+22 + check_float(-1.2345e-22f, "-1.2345e-22"); // -1.23450004e-22 + check_float(-1.2345e-21f, "-1.2345e-21"); // -1.23450002e-21 + check_float(-1.2345e-20f, "-1.2345e-20"); // -1.23450002e-20 + check_float(-1.2345e-19f, "-1.2345e-19"); // -1.23449999e-19 + check_float(-1.2345e-18f, "-1.2345e-18"); // -1.23449996e-18 + check_float(-1.2345e-17f, "-1.2345e-17"); // -1.23449998e-17 + check_float(-1.2345e-16f, "-1.2345e-16"); // -1.23449996e-16 + check_float(-1.2345e-15f, "-1.2345e-15"); // -1.23450002e-15 + check_float(-1.2345e-14f, "-1.2345e-14"); // -1.23450004e-14 + check_float(-1.2345e-13f, "-1.2345e-13"); // -1.23449997e-13 + check_float(-1.2345e-12f, "-1.2345e-12"); // -1.23450002e-12 + check_float(-1.2345e-11f, "-1.2345e-11"); // -1.2345e-11 + check_float(-1.2345e-10f, "-1.2345e-10"); // -1.2345e-10 + check_float(-1.2345e-9f, "-1.2345e-09"); // -1.23449995e-09 + check_float(-1.2345e-8f, "-1.2345e-08"); // -1.23449997e-08 + check_float(-1.2345e-7f, "-1.2345e-07"); // -1.23449993e-07 + check_float(-1.2345e-6f, "-1.2345e-06"); // -1.23450002e-06 + check_float(-1.2345e-5f, "-1.2345e-05"); // -1.2345e-05 + check_float(-1.2345e-4f, "-0.00012345"); // -0.000123449994 + check_float(-1.2345e-3f, "-0.0012345"); // -0.00123449997 + check_float(-1.2345e-2f, "-0.012345"); // -0.0123450002 + check_float(-1.2345e-1f, "-0.12345"); // -0.123450004 + check_float(-0.0f, "-0.0"); // -0 + check_float(0.0f, "0.0"); // 0 + check_float(1.2345e+0f, "1.2345"); // 1.23450005 + check_float(1.2345e+1f, "12.345"); // 12.3450003 + check_float(1.2345e+2f, "123.45"); // 123.449997 + check_float(1.2345e+3f, "1234.5"); // 1234.5 + check_float(1.2345e+4f, "12345.0"); // 12345 + check_float(1.2345e+5f, "123450.0"); // 123450 + check_float(1.2345e+6f, "1.2345e+06"); // 1234500 + check_float(1.2345e+7f, "1.2345e+07"); // 12345000 + check_float(1.2345e+8f, "1.2345e+08"); // 123450000 + check_float(1.2345e+9f, "1.2345e+09"); // 1.23449997e+09 + check_float(1.2345e+10f, "1.2345e+10"); // 1.23449999e+10 + check_float(1.2345e+11f, "1.2345e+11"); // 1.23449999e+11 + check_float(1.2345e+12f, "1.2345e+12"); // 1.23450006e+12 + check_float(1.2345e+13f, "1.2345e+13"); // 1.23449995e+13 + check_float(1.2345e+14f, "1.2345e+14"); // 1.23450002e+14 + check_float(1.2345e+15f, "1.2345e+15"); // 1.23450003e+15 + check_float(1.2345e+16f, "1.2345e+16"); // 1.23449998e+16 + check_float(1.2345e+17f, "1.2345e+17"); // 1.23449996e+17 + check_float(1.2345e+18f, "1.2345e+18"); // 1.23450004e+18 + check_float(1.2345e+19f, "1.2345e+19"); // 1.23449999e+19 + check_float(1.2345e+20f, "1.2345e+20"); // 1.23449999e+20 + check_float(1.2345e+21f, "1.2345e+21"); // 1.23449999e+21 + check_float(1.2345e+22f, "1.2345e+22"); // 1.23450005e+22 } SECTION("double precision") { - auto check_double = [](double number, const std::string & expected) - { + auto check_double = [](double number, const std::string& expected) { std::array<char, 33> buf{}; - char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) std::string actual(buf.data(), end); CHECK(actual == expected); }; // dtoa %.15g %.17g shortest - check_double( -1.2345e-22, "-1.2345e-22" ); // -1.2345e-22 -1.2345000000000001e-22 -1.2345e-22 - check_double( -1.2345e-21, "-1.2345e-21" ); // -1.2345e-21 -1.2345000000000001e-21 -1.2345e-21 - check_double( -1.2345e-20, "-1.2345e-20" ); // -1.2345e-20 -1.2345e-20 -1.2345e-20 - check_double( -1.2345e-19, "-1.2345e-19" ); // -1.2345e-19 -1.2345000000000001e-19 -1.2345e-19 - check_double( -1.2345e-18, "-1.2345e-18" ); // -1.2345e-18 -1.2345000000000001e-18 -1.2345e-18 - check_double( -1.2345e-17, "-1.2345e-17" ); // -1.2345e-17 -1.2345e-17 -1.2345e-17 - check_double( -1.2345e-16, "-1.2345e-16" ); // -1.2345e-16 -1.2344999999999999e-16 -1.2345e-16 - check_double( -1.2345e-15, "-1.2345e-15" ); // -1.2345e-15 -1.2345e-15 -1.2345e-15 - check_double( -1.2345e-14, "-1.2345e-14" ); // -1.2345e-14 -1.2345e-14 -1.2345e-14 - check_double( -1.2345e-13, "-1.2345e-13" ); // -1.2345e-13 -1.2344999999999999e-13 -1.2345e-13 - check_double( -1.2345e-12, "-1.2345e-12" ); // -1.2345e-12 -1.2345e-12 -1.2345e-12 - check_double( -1.2345e-11, "-1.2345e-11" ); // -1.2345e-11 -1.2345e-11 -1.2345e-11 - check_double( -1.2345e-10, "-1.2345e-10" ); // -1.2345e-10 -1.2345e-10 -1.2345e-10 - check_double( -1.2345e-9, "-1.2345e-09" ); // -1.2345e-09 -1.2345e-09 -1.2345e-9 - check_double( -1.2345e-8, "-1.2345e-08" ); // -1.2345e-08 -1.2345000000000001e-08 -1.2345e-8 - check_double( -1.2345e-7, "-1.2345e-07" ); // -1.2345e-07 -1.2345000000000001e-07 -1.2345e-7 - check_double( -1.2345e-6, "-1.2345e-06" ); // -1.2345e-06 -1.2345e-06 -1.2345e-6 - check_double( -1.2345e-5, "-1.2345e-05" ); // -1.2345e-05 -1.2345e-05 -1.2345e-5 - check_double( -1.2345e-4, "-0.00012345" ); // -0.00012345 -0.00012344999999999999 -0.00012345 - check_double( -1.2345e-3, "-0.0012345" ); // -0.0012345 -0.0012344999999999999 -0.0012345 - check_double( -1.2345e-2, "-0.012345" ); // -0.012345 -0.012345 -0.012345 - check_double( -1.2345e-1, "-0.12345" ); // -0.12345 -0.12345 -0.12345 - check_double( -0.0, "-0.0" ); // -0 -0 -0 - check_double( 0.0, "0.0" ); // 0 0 0 - check_double( 1.2345e+0, "1.2345" ); // 1.2345 1.2344999999999999 1.2345 - check_double( 1.2345e+1, "12.345" ); // 12.345 12.345000000000001 12.345 - check_double( 1.2345e+2, "123.45" ); // 123.45 123.45 123.45 - check_double( 1.2345e+3, "1234.5" ); // 1234.5 1234.5 1234.5 - check_double( 1.2345e+4, "12345.0" ); // 12345 12345 12345 - check_double( 1.2345e+5, "123450.0" ); // 123450 123450 123450 - check_double( 1.2345e+6, "1234500.0" ); // 1234500 1234500 1234500 - check_double( 1.2345e+7, "12345000.0" ); // 12345000 12345000 12345000 - check_double( 1.2345e+8, "123450000.0" ); // 123450000 123450000 123450000 - check_double( 1.2345e+9, "1234500000.0" ); // 1234500000 1234500000 1234500000 - check_double( 1.2345e+10, "12345000000.0" ); // 12345000000 12345000000 12345000000 - check_double( 1.2345e+11, "123450000000.0" ); // 123450000000 123450000000 123450000000 - check_double( 1.2345e+12, "1234500000000.0" ); // 1234500000000 1234500000000 1234500000000 - check_double( 1.2345e+13, "12345000000000.0" ); // 12345000000000 12345000000000 12345000000000 - check_double( 1.2345e+14, "123450000000000.0" ); // 123450000000000 123450000000000 123450000000000 - check_double( 1.2345e+15, "1.2345e+15" ); // 1.2345e+15 1234500000000000 1.2345e15 - check_double( 1.2345e+16, "1.2345e+16" ); // 1.2345e+16 12345000000000000 1.2345e16 - check_double( 1.2345e+17, "1.2345e+17" ); // 1.2345e+17 1.2345e+17 1.2345e17 - check_double( 1.2345e+18, "1.2345e+18" ); // 1.2345e+18 1.2345e+18 1.2345e18 - check_double( 1.2345e+19, "1.2345e+19" ); // 1.2345e+19 1.2345e+19 1.2345e19 - check_double( 1.2345e+20, "1.2345e+20" ); // 1.2345e+20 1.2345e+20 1.2345e20 - check_double( 1.2345e+21, "1.2344999999999999e+21" ); // 1.2345e+21 1.2344999999999999e+21 1.2345e21 - check_double( 1.2345e+22, "1.2345e+22" ); // 1.2345e+22 1.2345e+22 1.2345e22 + check_double(-1.2345e-22, "-1.2345e-22"); // -1.2345e-22 -1.2345000000000001e-22 -1.2345e-22 + check_double(-1.2345e-21, "-1.2345e-21"); // -1.2345e-21 -1.2345000000000001e-21 -1.2345e-21 + check_double(-1.2345e-20, "-1.2345e-20"); // -1.2345e-20 -1.2345e-20 -1.2345e-20 + check_double(-1.2345e-19, "-1.2345e-19"); // -1.2345e-19 -1.2345000000000001e-19 -1.2345e-19 + check_double(-1.2345e-18, "-1.2345e-18"); // -1.2345e-18 -1.2345000000000001e-18 -1.2345e-18 + check_double(-1.2345e-17, "-1.2345e-17"); // -1.2345e-17 -1.2345e-17 -1.2345e-17 + check_double(-1.2345e-16, "-1.2345e-16"); // -1.2345e-16 -1.2344999999999999e-16 -1.2345e-16 + check_double(-1.2345e-15, "-1.2345e-15"); // -1.2345e-15 -1.2345e-15 -1.2345e-15 + check_double(-1.2345e-14, "-1.2345e-14"); // -1.2345e-14 -1.2345e-14 -1.2345e-14 + check_double(-1.2345e-13, "-1.2345e-13"); // -1.2345e-13 -1.2344999999999999e-13 -1.2345e-13 + check_double(-1.2345e-12, "-1.2345e-12"); // -1.2345e-12 -1.2345e-12 -1.2345e-12 + check_double(-1.2345e-11, "-1.2345e-11"); // -1.2345e-11 -1.2345e-11 -1.2345e-11 + check_double(-1.2345e-10, "-1.2345e-10"); // -1.2345e-10 -1.2345e-10 -1.2345e-10 + check_double(-1.2345e-9, "-1.2345e-09"); // -1.2345e-09 -1.2345e-09 -1.2345e-9 + check_double(-1.2345e-8, "-1.2345e-08"); // -1.2345e-08 -1.2345000000000001e-08 -1.2345e-8 + check_double(-1.2345e-7, "-1.2345e-07"); // -1.2345e-07 -1.2345000000000001e-07 -1.2345e-7 + check_double(-1.2345e-6, "-1.2345e-06"); // -1.2345e-06 -1.2345e-06 -1.2345e-6 + check_double(-1.2345e-5, "-1.2345e-05"); // -1.2345e-05 -1.2345e-05 -1.2345e-5 + check_double(-1.2345e-4, "-0.00012345"); // -0.00012345 -0.00012344999999999999 -0.00012345 + check_double(-1.2345e-3, "-0.0012345"); // -0.0012345 -0.0012344999999999999 -0.0012345 + check_double(-1.2345e-2, "-0.012345"); // -0.012345 -0.012345 -0.012345 + check_double(-1.2345e-1, "-0.12345"); // -0.12345 -0.12345 -0.12345 + check_double(-0.0, "-0.0"); // -0 -0 -0 + check_double(0.0, "0.0"); // 0 0 0 + check_double(1.2345e+0, "1.2345"); // 1.2345 1.2344999999999999 1.2345 + check_double(1.2345e+1, "12.345"); // 12.345 12.345000000000001 12.345 + check_double(1.2345e+2, "123.45"); // 123.45 123.45 123.45 + check_double(1.2345e+3, "1234.5"); // 1234.5 1234.5 1234.5 + check_double(1.2345e+4, "12345.0"); // 12345 12345 12345 + check_double(1.2345e+5, "123450.0"); // 123450 123450 123450 + check_double(1.2345e+6, "1234500.0"); // 1234500 1234500 1234500 + check_double(1.2345e+7, "12345000.0"); // 12345000 12345000 12345000 + check_double(1.2345e+8, "123450000.0"); // 123450000 123450000 123450000 + check_double(1.2345e+9, "1234500000.0"); // 1234500000 1234500000 1234500000 + check_double(1.2345e+10, "12345000000.0"); // 12345000000 12345000000 12345000000 + check_double(1.2345e+11, "123450000000.0"); // 123450000000 123450000000 123450000000 + check_double(1.2345e+12, "1234500000000.0"); // 1234500000000 1234500000000 1234500000000 + check_double(1.2345e+13, "12345000000000.0"); // 12345000000000 12345000000000 12345000000000 + check_double(1.2345e+14, "123450000000000.0"); // 123450000000000 123450000000000 123450000000000 + check_double(1.2345e+15, "1.2345e+15"); // 1.2345e+15 1234500000000000 1.2345e15 + check_double(1.2345e+16, "1.2345e+16"); // 1.2345e+16 12345000000000000 1.2345e16 + check_double(1.2345e+17, "1.2345e+17"); // 1.2345e+17 1.2345e+17 1.2345e17 + check_double(1.2345e+18, "1.2345e+18"); // 1.2345e+18 1.2345e+18 1.2345e18 + check_double(1.2345e+19, "1.2345e+19"); // 1.2345e+19 1.2345e+19 1.2345e19 + check_double(1.2345e+20, "1.2345e+20"); // 1.2345e+20 1.2345e+20 1.2345e20 + check_double(1.2345e+21, "1.2344999999999999e+21"); // 1.2345e+21 1.2344999999999999e+21 1.2345e21 + check_double(1.2345e+22, "1.2345e+22"); // 1.2345e+22 1.2345e+22 1.2345e22 } SECTION("integer") { - auto check_integer = [](std::int64_t number, const std::string & expected) - { + auto check_integer = [](std::int64_t number, const std::string& expected) { const nlohmann::json j = number; CHECK(j.dump() == expected); };
diff --git a/tests/src/unit-ubjson.cpp b/tests/src/unit-ubjson.cpp index 06611c5..3d3ad6c 100644 --- a/tests/src/unit-ubjson.cpp +++ b/tests/src/unit-ubjson.cpp
@@ -11,18 +11,18 @@ #include <nlohmann/json.hpp> using nlohmann::json; -#include <iostream> -#include <fstream> -#include <set> #include "make_test_data_available.hpp" #include "test_utils.hpp" +#include <fstream> +#include <iostream> +#include <set> -namespace -{ +namespace { class SaxCountdown { public: - explicit SaxCountdown(const int count) : events_left(count) + explicit SaxCountdown(const int count) + : events_left(count) {} bool null() @@ -85,7 +85,7 @@ return events_left-- > 0; } - bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static) + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static) { return false; } @@ -93,7 +93,7 @@ private: int events_left = 0; }; -} // namespace +} // namespace TEST_CASE("UBJSON") { @@ -152,8 +152,7 @@ { SECTION("-9223372036854775808..-2147483649 (int64)") { - std::vector<int64_t> const numbers - { + std::vector<int64_t> const numbers{ (std::numeric_limits<int64_t>::min)(), -1000000000000000000LL, -100000000000000000LL, @@ -177,8 +176,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('L'), static_cast<uint8_t>((i >> 56) & 0xff), static_cast<uint8_t>((i >> 48) & 0xff), @@ -222,7 +220,7 @@ numbers.push_back(-10000000); numbers.push_back(-100000000); numbers.push_back(-1000000000); - numbers.push_back(-2147483647 - 1); // https://stackoverflow.com/a/29356002/266378 + numbers.push_back(-2147483647 - 1); // https://stackoverflow.com/a/29356002/266378 for (auto i : numbers) { CAPTURE(i) @@ -234,8 +232,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('l'), static_cast<uint8_t>((i >> 24) & 0xff), static_cast<uint8_t>((i >> 16) & 0xff), @@ -275,8 +272,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('I'), static_cast<uint8_t>((i >> 8) & 0xff), static_cast<uint8_t>(i & 0xff), @@ -331,8 +327,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'i', static_cast<uint8_t>(i), }; @@ -366,8 +361,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('i'), static_cast<uint8_t>(i), }; @@ -401,8 +395,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('U'), static_cast<uint8_t>(i), }; @@ -436,8 +429,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ static_cast<uint8_t>('I'), static_cast<uint8_t>((i >> 8) & 0xff), static_cast<uint8_t>(i & 0xff), @@ -462,9 +454,10 @@ SECTION("65536..2147483647 (int32)") { for (uint32_t i : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(i) @@ -476,8 +469,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'l', static_cast<uint8_t>((i >> 24) & 0xff), static_cast<uint8_t>((i >> 16) & 0xff), @@ -519,8 +511,7 @@ CHECK(j.is_number_integer()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'L', static_cast<uint8_t>((i >> 070) & 0xff), static_cast<uint8_t>((i >> 060) & 0xff), @@ -571,8 +562,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'i', static_cast<uint8_t>(i), }; @@ -606,8 +596,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'U', static_cast<uint8_t>(i), }; @@ -641,8 +630,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'I', static_cast<uint8_t>((i >> 8) & 0xff), static_cast<uint8_t>(i & 0xff), @@ -667,9 +655,10 @@ SECTION("65536..2147483647 (int32)") { for (uint32_t i : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(i) @@ -680,8 +669,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'l', static_cast<uint8_t>((i >> 24) & 0xff), static_cast<uint8_t>((i >> 16) & 0xff), @@ -722,8 +710,7 @@ CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector<uint8_t> const expected - { + std::vector<uint8_t> const expected{ 'L', static_cast<uint8_t>((i >> 070) & 0xff), static_cast<uint8_t>((i >> 060) & 0xff), @@ -766,9 +753,16 @@ double v = 3.1415925; json const j = v; std::vector<uint8_t> expected = - { - 'D', 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc - }; + { + 'D', + 0x40, + 0x09, + 0x21, + 0xfb, + 0x3f, + 0xa6, + 0xde, + 0xfc}; const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -799,7 +793,7 @@ SECTION("floating-point number") { - std::vector<uint8_t> const vec = {'H', 'i', 0x16, '3', '.', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5', '8', '9', '7', '9', '3', '2', '3', '8', '4', '6'}; + std::vector<uint8_t> const vec = {'H', 'i', 0x16, '3', '.', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5', '8', '9', '7', '9', '3', '2', '3', '8', '4', '6'}; const auto j = json::from_ubjson(vec); CHECK(j.is_number_float()); CHECK(j.dump() == "3.141592653589793"); @@ -831,7 +825,7 @@ // number will be serialized to high-precision number const auto vec = json::to_ubjson(j); - std::vector<uint8_t> expected = {'H', 'i', 0x14, '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'}; + std::vector<uint8_t> expected = {'H', 'i', 0x14, '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'}; CHECK(vec == expected); // roundtrip @@ -914,9 +908,13 @@ SECTION("N = 256..32767") { for (size_t N : - { - 256u, 999u, 1025u, 3333u, 2048u, 32767u - }) + { + 256u, + 999u, + 1025u, + 3333u, + 2048u, + 32767u}) { CAPTURE(N) @@ -948,9 +946,10 @@ SECTION("N = 65536..2147483647") { for (size_t N : - { - 65536u, 77777u, 1048576u - }) + { + 65536u, + 77777u, + 1048576u}) { CAPTURE(N) @@ -1075,9 +1074,13 @@ SECTION("N = 256..32767") { for (std::size_t N : - { - 256u, 999u, 1025u, 3333u, 2048u, 32767u - }) + { + 256u, + 999u, + 1025u, + 3333u, + 2048u, + 32767u}) { CAPTURE(N) @@ -1112,9 +1115,10 @@ SECTION("N = 32768..2147483647") { for (std::size_t N : - { - 32768u, 77777u, 1048576u - }) + { + 32768u, + 77777u, + 1048576u}) { CAPTURE(N) @@ -1370,9 +1374,9 @@ SECTION("size=false type=false") { json j(257, nullptr); - std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null - expected[0] = '['; // opening array - expected[258] = ']'; // closing array + std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null + expected[0] = '['; // opening array + expected[258] = ']'; // closing array const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -1384,12 +1388,12 @@ SECTION("size=true type=false") { json j(257, nullptr); - std::vector<uint8_t> expected(j.size() + 5, 'Z'); // all null - expected[0] = '['; // opening array - expected[1] = '#'; // array size - expected[2] = 'I'; // int16 - expected[3] = 0x01; // 0x0101, first byte - expected[4] = 0x01; // 0x0101, second byte + std::vector<uint8_t> expected(j.size() + 5, 'Z'); // all null + expected[0] = '['; // opening array + expected[1] = '#'; // array size + expected[2] = 'I'; // int16 + expected[3] = 0x01; // 0x0101, first byte + expected[4] = 0x01; // 0x0101, second byte const auto result = json::to_ubjson(j, true); CHECK(result == expected); @@ -1416,9 +1420,9 @@ SECTION("size=false type=false") { json j(65793, nullptr); - std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null - expected[0] = '['; // opening array - expected[65794] = ']'; // closing array + std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null + expected[0] = '['; // opening array + expected[65794] = ']'; // closing array const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -1430,14 +1434,14 @@ SECTION("size=true type=false") { json j(65793, nullptr); - std::vector<uint8_t> expected(j.size() + 7, 'Z'); // all null - expected[0] = '['; // opening array - expected[1] = '#'; // array size - expected[2] = 'l'; // int32 - expected[3] = 0x00; // 0x00010101, first byte - expected[4] = 0x01; // 0x00010101, second byte - expected[5] = 0x01; // 0x00010101, third byte - expected[6] = 0x01; // 0x00010101, fourth byte + std::vector<uint8_t> expected(j.size() + 7, 'Z'); // all null + expected[0] = '['; // opening array + expected[1] = '#'; // array size + expected[2] = 'l'; // int32 + expected[3] = 0x00; // 0x00010101, first byte + expected[4] = 0x01; // 0x00010101, second byte + expected[5] = 0x01; // 0x00010101, third byte + expected[6] = 0x01; // 0x00010101, fourth byte const auto result = json::to_ubjson(j, true); CHECK(result == expected); @@ -1546,9 +1550,24 @@ { json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); std::vector<uint8_t> expected = - { - '{', 'i', 1, 'a', '{', 'i', 1, 'b', '{', 'i', 1, 'c', '{', '}', '}', '}', '}' - }; + { + '{', + 'i', + 1, + 'a', + '{', + 'i', + 1, + 'b', + '{', + 'i', + 1, + 'c', + '{', + '}', + '}', + '}', + '}'}; const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -1561,9 +1580,32 @@ { json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); std::vector<uint8_t> expected = - { - '{', '#', 'i', 1, 'i', 1, 'a', '{', '#', 'i', 1, 'i', 1, 'b', '{', '#', 'i', 1, 'i', 1, 'c', '{', '#', 'i', 0 - }; + { + '{', + '#', + 'i', + 1, + 'i', + 1, + 'a', + '{', + '#', + 'i', + 1, + 'i', + 1, + 'b', + '{', + '#', + 'i', + 1, + 'i', + 1, + 'c', + '{', + '#', + 'i', + 0}; const auto result = json::to_ubjson(j, true); CHECK(result == expected); @@ -1576,9 +1618,35 @@ { json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); std::vector<uint8_t> expected = - { - '{', '$', '{', '#', 'i', 1, 'i', 1, 'a', '$', '{', '#', 'i', 1, 'i', 1, 'b', '$', '{', '#', 'i', 1, 'i', 1, 'c', '#', 'i', 0 - }; + { + '{', + '$', + '{', + '#', + 'i', + 1, + 'i', + 1, + 'a', + '$', + '{', + '#', + 'i', + 1, + 'i', + 1, + 'b', + '$', + '{', + '#', + 'i', + 1, + 'i', + 1, + 'c', + '#', + 'i', + 0}; const auto result = json::to_ubjson(j, true, true); CHECK(result == expected); @@ -1617,8 +1685,7 @@ CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&); json j; - nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept - { + nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return true; }); CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&); @@ -1631,8 +1698,7 @@ CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&); json j; - nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept - { + nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return true; }); CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&); @@ -1771,7 +1837,7 @@ CHECK(json::to_ubjson(json::from_ubjson(v_L), true) == v_L); CHECK(json::to_ubjson(json::from_ubjson(v_D), true) == v_D); CHECK(json::to_ubjson(json::from_ubjson(v_S), true) == v_S); - CHECK(json::to_ubjson(json::from_ubjson(v_C), true) == v_S); // char is serialized to string + CHECK(json::to_ubjson(json::from_ubjson(v_C), true) == v_S); // char is serialized to string } SECTION("optimized version (type and length)") @@ -1817,7 +1883,7 @@ CHECK(json::to_ubjson(json::from_ubjson(v_L), true, true) == v_L); CHECK(json::to_ubjson(json::from_ubjson(v_D), true, true) == v_D); CHECK(json::to_ubjson(json::from_ubjson(v_S), true, true) == v_S); - CHECK(json::to_ubjson(json::from_ubjson(v_C), true, true) == v_S); // char is serialized to string + CHECK(json::to_ubjson(json::from_ubjson(v_C), true, true) == v_S); // char is serialized to string } } } @@ -2097,14 +2163,8 @@ SECTION("No-Op Value") { json const j = {"foo", "bar", "baz"}; - std::vector<uint8_t> const v = {'[', 'S', 'i', 3, 'f', 'o', 'o', - 'S', 'i', 3, 'b', 'a', 'r', - 'S', 'i', 3, 'b', 'a', 'z', ']' - }; - std::vector<uint8_t> const v2 = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'N', - 'S', 'i', 3, 'b', 'a', 'r', 'N', 'N', 'N', - 'S', 'i', 3, 'b', 'a', 'z', 'N', 'N', ']' - }; + std::vector<uint8_t> const v = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'S', 'i', 3, 'b', 'a', 'r', 'S', 'i', 3, 'b', 'a', 'z', ']'}; + std::vector<uint8_t> const v2 = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'N', 'S', 'i', 3, 'b', 'a', 'r', 'N', 'N', 'N', 'S', 'i', 3, 'b', 'a', 'z', 'N', 'N', ']'}; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); CHECK(json::from_ubjson(v2) == j); @@ -2113,9 +2173,7 @@ SECTION("Boolean Types") { json const j = {{"authorized", true}, {"verified", false}}; - std::vector<uint8_t> const v = {'{', 'i', 10, 'a', 'u', 't', 'h', 'o', 'r', 'i', 'z', 'e', 'd', 'T', - 'i', 8, 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'F', '}' - }; + std::vector<uint8_t> const v = {'{', 'i', 10, 'a', 'u', 't', 'h', 'o', 'r', 'i', 'z', 'e', 'd', 'T', 'i', 8, 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'F', '}'}; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } @@ -2123,23 +2181,88 @@ SECTION("Numeric Types") { json const j = - { - {"int8", 16}, - {"uint8", 255}, - {"int16", 32767}, - {"int32", 2147483647}, - {"int64", 9223372036854775807}, - {"float64", 113243.7863123} - }; + { + {"int8", 16}, + {"uint8", 255}, + {"int16", 32767}, + {"int32", 2147483647}, + {"int64", 9223372036854775807}, + {"float64", 113243.7863123}}; std::vector<uint8_t> const v = {'{', - 'i', 7, 'f', 'l', 'o', 'a', 't', '6', '4', 'D', 0x40, 0xfb, 0xa5, 0xbc, 0x94, 0xbc, 0x34, 0xcf, - 'i', 5, 'i', 'n', 't', '1', '6', 'I', 0x7f, 0xff, - 'i', 5, 'i', 'n', 't', '3', '2', 'l', 0x7f, 0xff, 0xff, 0xff, - 'i', 5, 'i', 'n', 't', '6', '4', 'L', 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 'i', 4, 'i', 'n', 't', '8', 'i', 16, - 'i', 5, 'u', 'i', 'n', 't', '8', 'U', 0xff, - '}' - }; + 'i', + 7, + 'f', + 'l', + 'o', + 'a', + 't', + '6', + '4', + 'D', + 0x40, + 0xfb, + 0xa5, + 0xbc, + 0x94, + 0xbc, + 0x34, + 0xcf, + 'i', + 5, + 'i', + 'n', + 't', + '1', + '6', + 'I', + 0x7f, + 0xff, + 'i', + 5, + 'i', + 'n', + 't', + '3', + '2', + 'l', + 0x7f, + 0xff, + 0xff, + 0xff, + 'i', + 5, + 'i', + 'n', + 't', + '6', + '4', + 'L', + 0x7f, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 'i', + 4, + 'i', + 'n', + 't', + '8', + 'i', + 16, + 'i', + 5, + 'u', + 'i', + 'n', + 't', + '8', + 'U', + 0xff, + '}'}; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } @@ -2214,23 +2337,9 @@ SECTION("size=false type=false") { json const j = - { { - "post", { - {"id", 1137}, - {"author", "rkalla"}, - {"timestamp", 1364482090592}, - {"body", "I totally agree!"} - } - } - }; - std::vector<uint8_t> const v = {'{', 'i', 4, 'p', 'o', 's', 't', '{', - 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', - 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', - 'i', 2, 'i', 'd', 'I', 0x04, 0x71, - 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60, - '}', '}' - }; + {"post", {{"id", 1137}, {"author", "rkalla"}, {"timestamp", 1364482090592}, {"body", "I totally agree!"}}}}; + std::vector<uint8_t> const v = {'{', 'i', 4, 'p', 'o', 's', 't', '{', 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', 'i', 2, 'i', 'd', 'I', 0x04, 0x71, 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60, '}', '}'}; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } @@ -2238,22 +2347,9 @@ SECTION("size=true type=false") { json const j = - { { - "post", { - {"id", 1137}, - {"author", "rkalla"}, - {"timestamp", 1364482090592}, - {"body", "I totally agree!"} - } - } - }; - std::vector<uint8_t> const v = {'{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '{', '#', 'i', 4, - 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', - 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', - 'i', 2, 'i', 'd', 'I', 0x04, 0x71, - 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60 - }; + {"post", {{"id", 1137}, {"author", "rkalla"}, {"timestamp", 1364482090592}, {"body", "I totally agree!"}}}}; + std::vector<uint8_t> const v = {'{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '{', '#', 'i', 4, 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', 'i', 2, 'i', 'd', 'I', 0x04, 0x71, 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60}; CHECK(json::to_ubjson(j, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2261,22 +2357,9 @@ SECTION("size=true type=true") { json const j = - { { - "post", { - {"id", 1137}, - {"author", "rkalla"}, - {"timestamp", 1364482090592}, - {"body", "I totally agree!"} - } - } - }; - std::vector<uint8_t> const v = {'{', '$', '{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '#', 'i', 4, - 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', - 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', - 'i', 2, 'i', 'd', 'I', 0x04, 0x71, - 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60 - }; + {"post", {{"id", 1137}, {"author", "rkalla"}, {"timestamp", 1364482090592}, {"body", "I totally agree!"}}}}; + std::vector<uint8_t> const v = {'{', '$', '{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '#', 'i', 4, 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', 'i', 2, 'i', 'd', 'I', 0x04, 0x71, 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60}; CHECK(json::to_ubjson(j, true, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2291,13 +2374,52 @@ // note the floats have been replaced by doubles json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; std::vector<uint8_t> const v = {'[', - 'D', 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8, - 'D', 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1, - 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 'D', 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81, - 'D', 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17, - ']' - }; + 'D', + 0x40, + 0x3d, + 0xf8, + 0x51, + 0xeb, + 0x85, + 0x1e, + 0xb8, + 'D', + 0x40, + 0x3f, + 0x21, + 0x47, + 0xae, + 0x14, + 0x7a, + 0xe1, + 'D', + 0x40, + 0x50, + 0xc0, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 'D', + 0x40, + 0x00, + 0xe7, + 0x6c, + 0x8b, + 0x43, + 0x95, + 0x81, + 'D', + 0x40, + 0x37, + 0xe3, + 0x53, + 0xf7, + 0xce, + 0xd9, + 0x17, + ']'}; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } @@ -2306,13 +2428,7 @@ { // note the floats have been replaced by doubles json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; - std::vector<uint8_t> const v = {'[', '#', 'i', 5, - 'D', 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8, - 'D', 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1, - 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 'D', 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81, - 'D', 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17 - }; + std::vector<uint8_t> const v = {'[', '#', 'i', 5, 'D', 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8, 'D', 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1, 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 'D', 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81, 'D', 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17}; CHECK(json::to_ubjson(j, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2321,13 +2437,7 @@ { // note the floats have been replaced by doubles json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; - std::vector<uint8_t> const v = {'[', '$', 'D', '#', 'i', 5, - 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8, - 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1, - 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81, - 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17 - }; + std::vector<uint8_t> const v = {'[', '$', 'D', '#', 'i', 5, 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8, 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1, 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81, 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17}; CHECK(json::to_ubjson(j, true, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2338,13 +2448,52 @@ SECTION("No Optimization") { // note the floats have been replaced by doubles - json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; + json const j = {{"lat", 29.976}, {"long", 31.131}, {"alt", 67.0}}; std::vector<uint8_t> const v = {'{', - 'i', 3, 'a', 'l', 't', 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 'i', 3, 'l', 'a', 't', 'D', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60, - 'i', 4, 'l', 'o', 'n', 'g', 'D', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8, - '}' - }; + 'i', + 3, + 'a', + 'l', + 't', + 'D', + 0x40, + 0x50, + 0xc0, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 'i', + 3, + 'l', + 'a', + 't', + 'D', + 0x40, + 0x3d, + 0xf9, + 0xdb, + 0x22, + 0xd0, + 0xe5, + 0x60, + 'i', + 4, + 'l', + 'o', + 'n', + 'g', + 'D', + 0x40, + 0x3f, + 0x21, + 0x89, + 0x37, + 0x4b, + 0xc6, + 0xa8, + '}'}; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } @@ -2352,12 +2501,8 @@ SECTION("Optimized with count") { // note the floats have been replaced by doubles - json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; - std::vector<uint8_t> const v = {'{', '#', 'i', 3, - 'i', 3, 'a', 'l', 't', 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 'i', 3, 'l', 'a', 't', 'D', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60, - 'i', 4, 'l', 'o', 'n', 'g', 'D', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8 - }; + json const j = {{"lat", 29.976}, {"long", 31.131}, {"alt", 67.0}}; + std::vector<uint8_t> const v = {'{', '#', 'i', 3, 'i', 3, 'a', 'l', 't', 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 'i', 3, 'l', 'a', 't', 'D', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60, 'i', 4, 'l', 'o', 'n', 'g', 'D', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8}; CHECK(json::to_ubjson(j, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2365,12 +2510,8 @@ SECTION("Optimized with type & count") { // note the floats have been replaced by doubles - json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; - std::vector<uint8_t> const v = {'{', '$', 'D', '#', 'i', 3, - 'i', 3, 'a', 'l', 't', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 'i', 3, 'l', 'a', 't', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60, - 'i', 4, 'l', 'o', 'n', 'g', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8 - }; + json const j = {{"lat", 29.976}, {"long", 31.131}, {"alt", 67.0}}; + std::vector<uint8_t> const v = {'{', '$', 'D', '#', 'i', 3, 'i', 3, 'a', 'l', 't', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 'i', 3, 'l', 'a', 't', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60, 'i', 4, 'l', 'o', 'n', 'g', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8}; CHECK(json::to_ubjson(j, true, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2387,7 +2528,7 @@ SECTION("Object") { std::vector<uint8_t> const v = {'{', '$', 'Z', '#', 'i', 3, 'i', 4, 'n', 'a', 'm', 'e', 'i', 8, 'p', 'a', 's', 's', 'w', 'o', 'r', 'd', 'i', 5, 'e', 'm', 'a', 'i', 'l'}; - CHECK(json::from_ubjson(v) == json({ {"name", nullptr}, {"password", nullptr}, {"email", nullptr} })); + CHECK(json::from_ubjson(v) == json({{"name", nullptr}, {"password", nullptr}, {"email", nullptr}})); } } } @@ -2398,9 +2539,23 @@ { // these bytes will fail immediately with exception parse_error.112 std::set<uint8_t> supported = - { - 'T', 'F', 'Z', 'U', 'i', 'I', 'l', 'L', 'd', 'D', 'C', 'S', '[', '{', 'N', 'H' - }; + { + 'T', + 'F', + 'Z', + 'U', + 'i', + 'I', + 'l', + 'L', + 'd', + 'D', + 'C', + 'S', + '[', + '{', + 'N', + 'H'}; for (auto i = 0; i < 256; ++i) { @@ -2434,50 +2589,49 @@ SECTION("input from self-generated UBJSON files") { for (std::string filename : - { - TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json", - TEST_DATA_DIRECTORY "/json.org/1.json", - TEST_DATA_DIRECTORY "/json.org/2.json", - TEST_DATA_DIRECTORY "/json.org/3.json", - TEST_DATA_DIRECTORY "/json.org/4.json", - TEST_DATA_DIRECTORY "/json.org/5.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json", - TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json", - TEST_DATA_DIRECTORY "/json_testsuite/sample.json", - TEST_DATA_DIRECTORY "/json_tests/pass1.json", - TEST_DATA_DIRECTORY "/json_tests/pass2.json", - TEST_DATA_DIRECTORY "/json_tests/pass3.json" - }) + { + TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json", + TEST_DATA_DIRECTORY "/json.org/1.json", + TEST_DATA_DIRECTORY "/json.org/2.json", + TEST_DATA_DIRECTORY "/json.org/3.json", + TEST_DATA_DIRECTORY "/json.org/4.json", + TEST_DATA_DIRECTORY "/json.org/5.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json", + TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json", + TEST_DATA_DIRECTORY "/json_testsuite/sample.json", + TEST_DATA_DIRECTORY "/json_tests/pass1.json", + TEST_DATA_DIRECTORY "/json_tests/pass2.json", + TEST_DATA_DIRECTORY "/json_tests/pass3.json"}) { CAPTURE(filename)
diff --git a/tests/src/unit-udl.cpp b/tests/src/unit-udl.cpp index bb72ccb..72f9fc3 100644 --- a/tests/src/unit-udl.cpp +++ b/tests/src/unit-udl.cpp
@@ -17,7 +17,7 @@ SECTION("using namespace nlohmann::literals::json_literals") { - using namespace nlohmann::literals::json_literals; // NOLINT(google-build-using-namespace) + using namespace nlohmann::literals::json_literals; // NOLINT(google-build-using-namespace) CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected); CHECK("/foo/bar"_json_pointer == ptr_expected); @@ -25,7 +25,7 @@ SECTION("using namespace nlohmann::json_literals") { - using namespace nlohmann::json_literals; // NOLINT(google-build-using-namespace) + using namespace nlohmann::json_literals; // NOLINT(google-build-using-namespace) CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected); CHECK("/foo/bar"_json_pointer == ptr_expected); @@ -33,7 +33,7 @@ SECTION("using namespace nlohmann::literals") { - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) + using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected); CHECK("/foo/bar"_json_pointer == ptr_expected); @@ -41,7 +41,7 @@ SECTION("using namespace nlohmann") { - using namespace nlohmann; // NOLINT(google-build-using-namespace) + using namespace nlohmann; // NOLINT(google-build-using-namespace) CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected); CHECK("/foo/bar"_json_pointer == ptr_expected);
diff --git a/tests/src/unit-udt.cpp b/tests/src/unit-udt.cpp index b138aa4..6709813 100644 --- a/tests/src/unit-udt.cpp +++ b/tests/src/unit-udt.cpp
@@ -15,7 +15,7 @@ #include <nlohmann/json.hpp> using nlohmann::json; #ifdef JSON_TEST_NO_GLOBAL_UDLS - using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) +using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif #include <map> @@ -23,8 +23,7 @@ #include <string> #include <utility> -namespace udt -{ +namespace udt { enum class country { china, @@ -35,19 +34,25 @@ struct age { int m_val; - age(int rhs = 0) : m_val(rhs) {} + age(int rhs = 0) + : m_val(rhs) + {} }; struct name { std::string m_val; - name(std::string rhs = "") : m_val(std::move(rhs)) {} + name(std::string rhs = "") + : m_val(std::move(rhs)) + {} }; struct address { std::string m_val; - address(std::string rhs = "") : m_val(std::move(rhs)) {} + address(std::string rhs = "") + : m_val(std::move(rhs)) + {} }; struct person @@ -56,7 +61,11 @@ name m_name{}; country m_country{}; person() = default; - person(const age& a, name n, const country& c) : m_age(a), m_name(std::move(n)), m_country(c) {} + person(const age& a, name n, const country& c) + : m_age(a) + , m_name(std::move(n)) + , m_country(c) + {} }; struct contact @@ -64,7 +73,10 @@ person m_person{}; address m_address{}; contact() = default; - contact(person p, address a) : m_person(std::move(p)), m_address(std::move(a)) {} + contact(person p, address a) + : m_person(std::move(p)) + , m_address(std::move(a)) + {} }; struct contact_book @@ -72,27 +84,29 @@ name m_book_name{}; std::vector<contact> m_contacts{}; contact_book() = default; - contact_book(name n, std::vector<contact> c) : m_book_name(std::move(n)), m_contacts(std::move(c)) {} + contact_book(name n, std::vector<contact> c) + : m_book_name(std::move(n)) + , m_contacts(std::move(c)) + {} }; -} // namespace udt +} // namespace udt // to_json methods -namespace udt -{ +namespace udt { // templates because of the custom_json tests (see below) -template <typename BasicJsonType> +template<typename BasicJsonType> static void to_json(BasicJsonType& j, age a) { j = a.m_val; } -template <typename BasicJsonType> +template<typename BasicJsonType> static void to_json(BasicJsonType& j, const name& n) { j = n.m_val; } -template <typename BasicJsonType> +template<typename BasicJsonType> static void to_json(BasicJsonType& j, country c) { switch (c) @@ -111,7 +125,7 @@ } } -template <typename BasicJsonType> +template<typename BasicJsonType> static void to_json(BasicJsonType& j, const person& p) { j = BasicJsonType{{"age", p.m_age}, {"name", p.m_name}, {"country", p.m_country}}; @@ -164,40 +178,38 @@ return std::tie(lhs.m_book_name, lhs.m_contacts) == std::tie(rhs.m_book_name, rhs.m_contacts); } -} // namespace udt +} // namespace udt // from_json methods -namespace udt -{ -template <typename BasicJsonType> +namespace udt { +template<typename BasicJsonType> static void from_json(const BasicJsonType& j, age& a) { a.m_val = j.template get<int>(); } -template <typename BasicJsonType> +template<typename BasicJsonType> static void from_json(const BasicJsonType& j, name& n) { n.m_val = j.template get<std::string>(); } -template <typename BasicJsonType> +template<typename BasicJsonType> static void from_json(const BasicJsonType& j, country& c) { const auto str = j.template get<std::string>(); const std::map<std::string, country> m = - { - {"中华人民共和国", country::china}, - {"France", country::france}, - {"Российская Федерация", country::russia} - }; + { + {"中华人民共和国", country::china}, + {"France", country::france}, + {"Российская Федерация", country::russia}}; const auto it = m.find(str); // TODO(nlohmann) test exceptions c = it->second; } -template <typename BasicJsonType> +template<typename BasicJsonType> static void from_json(const BasicJsonType& j, person& p) { p.m_age = j["age"].template get<age>(); @@ -221,16 +233,13 @@ cb.m_book_name = j["name"].get<name>(); cb.m_contacts = j["contacts"].get<std::vector<contact>>(); } -} // namespace udt +} // namespace udt TEST_CASE("basic usage" * doctest::test_suite("udt")) { - // a bit narcissistic maybe :) ? - const udt::age a - { - 23 - }; + const udt::age a{ + 23}; const udt::name n{"theo"}; const udt::country c{udt::country::france}; const udt::person sfinae_addict{a, n, c}; @@ -252,7 +261,6 @@ CHECK( json(book) == R"({"name":"C++", "contacts" : [{"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"}, {"person" : {"age":42, "country":"中华人民共和国", "name":"王芳"}, "address":"Paris"}]})"_json); - } SECTION("conversion from json via free-functions") @@ -326,19 +334,19 @@ } } -namespace udt -{ +namespace udt { struct legacy_type { std::string number{}; legacy_type() = default; - legacy_type(std::string n) : number(std::move(n)) {} + legacy_type(std::string n) + : number(std::move(n)) + {} }; -} // namespace udt +} // namespace udt -namespace nlohmann -{ -template <typename T> +namespace nlohmann { +template<typename T> struct adl_serializer<std::shared_ptr<T>> { static void to_json(json& j, const std::shared_ptr<T>& opt) @@ -361,12 +369,12 @@ } else { - opt.reset(new T(j.get<T>())); // NOLINT(cppcoreguidelines-owning-memory) + opt.reset(new T(j.get<T>())); // NOLINT(cppcoreguidelines-owning-memory) } } }; -template <> +template<> struct adl_serializer<udt::legacy_type> { static void to_json(json& j, const udt::legacy_type& l) @@ -379,7 +387,7 @@ l.number = std::to_string(j.get<int>()); } }; -} // namespace nlohmann +} // namespace nlohmann TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt")) { @@ -392,7 +400,7 @@ json j = optPerson; CHECK(j.is_null()); - optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia}); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-shared) + optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia}); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-shared) j = optPerson; CHECK_FALSE(j.is_null()); @@ -433,9 +441,8 @@ } } -namespace nlohmann -{ -template <> +namespace nlohmann { +template<> struct adl_serializer<std::vector<float>> { using type = std::vector<float>; @@ -455,20 +462,19 @@ return {4.0, 5.0, 6.0}; } }; -} // namespace nlohmann +} // namespace nlohmann TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt")) { - json const j = std::vector<float> {1.0, 2.0, 3.0}; + json const j = std::vector<float>{1.0, 2.0, 3.0}; CHECK(j.dump() == R"("hijacked!")"); auto f = j.get<std::vector<float>>(); // the single argument from_json method is preferred - CHECK((f == std::vector<float> {4.0, 5.0, 6.0})); + CHECK((f == std::vector<float>{4.0, 5.0, 6.0})); } -namespace nlohmann -{ -template <typename T> +namespace nlohmann { +template<typename T> struct adl_serializer<std::unique_ptr<T>> { static void to_json(json& j, const std::unique_ptr<T>& opt) @@ -494,7 +500,7 @@ return std::unique_ptr<T>(new T(j.get<T>())); } }; -} // namespace nlohmann +} // namespace nlohmann TEST_CASE("Non-copyable types" * doctest::test_suite("udt")) { @@ -505,7 +511,7 @@ json j = optPerson; CHECK(j.is_null()); - optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia}); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-unique) + optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia}); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-unique) j = optPerson; CHECK_FALSE(j.is_null()); @@ -530,14 +536,16 @@ // custom serializer - advanced usage // pack structs that are pod-types (but not scalar types) // relies on adl for any other type -template <typename T, typename = void> +template<typename T, typename = void> struct pod_serializer { // use adl for non-pods, or scalar types - template < - typename BasicJsonType, typename U = T, - typename std::enable_if < - !(std::is_pod<U>::value && std::is_class<U>::value), int >::type = 0 > + template< + typename BasicJsonType, + typename U = T, + typename std::enable_if< + !(std::is_pod<U>::value && std::is_class<U>::value), + int>::type = 0> static void from_json(const BasicJsonType& j, U& t) { using nlohmann::from_json; @@ -545,10 +553,8 @@ } // special behaviour for pods - template < typename BasicJsonType, typename U = T, - typename std::enable_if < - std::is_pod<U>::value && std::is_class<U>::value, int >::type = 0 > - static void from_json(const BasicJsonType& j, U& t) + template<typename BasicJsonType, typename U = T, typename std::enable_if<std::is_pod<U>::value && std::is_class<U>::value, int>::type = 0> + static void from_json(const BasicJsonType& j, U& t) { std::uint64_t value = 0; // The following block is no longer relevant in this serializer, make another one that shows the issue @@ -566,34 +572,33 @@ // calling get calls from_json, for now, we cannot do this in custom // serializers nlohmann::from_json(j, value); - auto* bytes = static_cast<char*>(static_cast<void*>(&value)); // NOLINT(bugprone-casting-through-void) + auto* bytes = static_cast<char*>(static_cast<void*>(&value)); // NOLINT(bugprone-casting-through-void) std::memcpy(&t, bytes, sizeof(value)); } - template < - typename BasicJsonType, typename U = T, - typename std::enable_if < - !(std::is_pod<U>::value && std::is_class<U>::value), int >::type = 0 > - static void to_json(BasicJsonType& j, const T& t) + template< + typename BasicJsonType, + typename U = T, + typename std::enable_if< + !(std::is_pod<U>::value && std::is_class<U>::value), + int>::type = 0> + static void to_json(BasicJsonType& j, const T& t) { using nlohmann::to_json; to_json(j, t); } - template < typename BasicJsonType, typename U = T, - typename std::enable_if < - std::is_pod<U>::value && std::is_class<U>::value, int >::type = 0 > - static void to_json(BasicJsonType& j, const T& t) noexcept + template<typename BasicJsonType, typename U = T, typename std::enable_if<std::is_pod<U>::value && std::is_class<U>::value, int>::type = 0> + static void to_json(BasicJsonType& j, const T& t) noexcept { - const auto* bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t)); // NOLINT(bugprone-casting-through-void) + const auto* bytes = static_cast<const unsigned char*>(static_cast<const void*>(&t)); // NOLINT(bugprone-casting-through-void) std::uint64_t value = 0; std::memcpy(&value, bytes, sizeof(value)); nlohmann::to_json(j, value); } }; -namespace udt -{ +namespace udt { struct small_pod { int begin; @@ -605,16 +610,18 @@ { std::string s{}; non_pod() = default; - non_pod(std::string S) : s(std::move(S)) {} + non_pod(std::string S) + : s(std::move(S)) + {} }; -template <typename BasicJsonType> +template<typename BasicJsonType> static void to_json(BasicJsonType& j, const non_pod& np) { j = np.s; } -template <typename BasicJsonType> +template<typename BasicJsonType> static void from_json(const BasicJsonType& j, non_pod& np) { np.s = j.template get<std::string>(); @@ -626,7 +633,7 @@ std::tie(rhs.begin, rhs.middle, rhs.end); } -static bool operator==(const non_pod& lhs, const non_pod& rhs) noexcept +static bool operator==(const non_pod& lhs, const non_pod& rhs) noexcept { return lhs.s == rhs.s; } @@ -635,13 +642,12 @@ { return os << "begin: " << l.begin << ", middle: " << l.middle << ", end: " << l.end; } -} // namespace udt +} // namespace udt TEST_CASE("custom serializer for pods" * doctest::test_suite("udt")) { using custom_json = - nlohmann::basic_json<std::map, std::vector, std::string, bool, - std::int64_t, std::uint64_t, double, std::allocator, pod_serializer>; + nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, pod_serializer>; auto p = udt::small_pod{42, '/', 42}; custom_json const j = p; @@ -656,12 +662,12 @@ CHECK(np == np2); } -template <typename T, typename> +template<typename T, typename> struct another_adl_serializer; using custom_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, another_adl_serializer>; -template <typename T, typename> +template<typename T, typename> struct another_adl_serializer { static void from_json(const custom_json& j, T& t) @@ -718,7 +724,7 @@ { json const j = {1, 2, 3}; custom_json const cj = j; - CHECK((cj == std::vector<int> {1, 2, 3})); + CHECK((cj == std::vector<int>{1, 2, 3})); } SECTION("integer") @@ -775,42 +781,43 @@ } } -namespace -{ +namespace { struct incomplete; // std::is_constructible is broken on macOS' libc++ // use the cppreference implementation -template <typename T, typename = void> -struct is_constructible_patched : std::false_type {}; +template<typename T, typename = void> +struct is_constructible_patched : std::false_type +{}; -template <typename T> -struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type {}; -} // namespace +template<typename T> +struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type +{}; +} // namespace TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context" * doctest::test_suite("udt")) { static_assert(!is_constructible_patched<json, incomplete>::value, ""); } -namespace -{ +namespace { class Evil { public: Evil() = default; - template <typename T> - Evil(T t) : m_i(sizeof(t)) + template<typename T> + Evil(T t) + : m_i(sizeof(t)) { - static_cast<void>(t); // fix MSVC's C4100 warning + static_cast<void>(t); // fix MSVC's C4100 warning } int m_i = 0; }; void from_json(const json& /*unused*/, Evil& /*unused*/) {} -} // namespace +} // namespace TEST_CASE("Issue #924") { @@ -827,17 +834,17 @@ TEST_CASE("Issue #1237") { - struct non_convertible_type {}; + struct non_convertible_type + {}; static_assert(!std::is_convertible<json, non_convertible_type>::value, ""); } -namespace -{ +namespace { class no_iterator_type { public: no_iterator_type(std::initializer_list<int> l) - : _v(l) + : _v(l) {} std::vector<int>::const_iterator begin() const
diff --git a/tests/src/unit-udt_macro.cpp b/tests/src/unit-udt_macro.cpp index e2383f4..ea27543 100644 --- a/tests/src/unit-udt_macro.cpp +++ b/tests/src/unit-udt_macro.cpp
@@ -6,15 +6,14 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> // SPDX-License-Identifier: MIT +#include "doctest_compatibility.h" #include <string> #include <vector> -#include "doctest_compatibility.h" #include <nlohmann/json.hpp> using nlohmann::json; -namespace persons -{ +namespace persons { class person_with_private_data { private: @@ -30,9 +29,9 @@ person_with_private_data() = default; person_with_private_data(std::string name_, int age_, json metadata_) - : name(std::move(name_)) - , age(age_) - , metadata(std::move(metadata_)) + : name(std::move(name_)) + , age(age_) + , metadata(std::move(metadata_)) {} NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_with_private_data, age, name, metadata) @@ -53,9 +52,9 @@ person_with_private_data_2() = default; person_with_private_data_2(std::string name_, int age_, json metadata_) - : name(std::move(name_)) - , age(age_) - , metadata(std::move(metadata_)) + : name(std::move(name_)) + , age(age_) + , metadata(std::move(metadata_)) {} std::string getName() const @@ -88,9 +87,9 @@ person_without_private_data_1() = default; person_without_private_data_1(std::string name_, int age_, json metadata_) - : name(std::move(name_)) - , age(age_) - , metadata(std::move(metadata_)) + : name(std::move(name_)) + , age(age_) + , metadata(std::move(metadata_)) {} NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_without_private_data_1, age, name, metadata) @@ -110,9 +109,9 @@ person_without_private_data_2() = default; person_without_private_data_2(std::string name_, int age_, json metadata_) - : name(std::move(name_)) - , age(age_) - , metadata(std::move(metadata_)) + : name(std::move(name_)) + , age(age_) + , metadata(std::move(metadata_)) {} }; @@ -132,9 +131,9 @@ person_without_private_data_3() = default; person_without_private_data_3(std::string name_, int age_, json metadata_) - : name(std::move(name_)) - , age(age_) - , metadata(std::move(metadata_)) + : name(std::move(name_)) + , age(age_) + , metadata(std::move(metadata_)) {} std::string getName() const @@ -158,32 +157,32 @@ public: bool operator==(const person_with_private_alphabet& other) const { - return a == other.a && - b == other.b && - c == other.c && - d == other.d && - e == other.e && - f == other.f && - g == other.g && - h == other.h && - i == other.i && - j == other.j && - k == other.k && - l == other.l && - m == other.m && - n == other.n && - o == other.o && - p == other.p && - q == other.q && - r == other.r && - s == other.s && - t == other.t && - u == other.u && - v == other.v && - w == other.w && - x == other.x && - y == other.y && - z == other.z; + return a == other.a && + b == other.b && + c == other.c && + d == other.d && + e == other.e && + f == other.f && + g == other.g && + h == other.h && + i == other.i && + j == other.j && + k == other.k && + l == other.l && + m == other.m && + n == other.n && + o == other.o && + p == other.p && + q == other.q && + r == other.r && + s == other.s && + t == other.t && + u == other.u && + v == other.v && + w == other.w && + x == other.x && + y == other.y && + z == other.z; } private: @@ -221,32 +220,32 @@ public: bool operator==(const person_with_public_alphabet& other) const { - return a == other.a && - b == other.b && - c == other.c && - d == other.d && - e == other.e && - f == other.f && - g == other.g && - h == other.h && - i == other.i && - j == other.j && - k == other.k && - l == other.l && - m == other.m && - n == other.n && - o == other.o && - p == other.p && - q == other.q && - r == other.r && - s == other.s && - t == other.t && - u == other.u && - v == other.v && - w == other.w && - x == other.x && - y == other.y && - z == other.z; + return a == other.a && + b == other.b && + c == other.c && + d == other.d && + e == other.e && + f == other.f && + g == other.g && + h == other.h && + i == other.i && + j == other.j && + k == other.k && + l == other.l && + m == other.m && + n == other.n && + o == other.o && + p == other.p && + q == other.q && + r == other.r && + s == other.s && + t == other.t && + u == other.u && + v == other.v && + w == other.w && + x == other.x && + y == other.y && + z == other.z; } int a = 0; @@ -291,8 +290,8 @@ } person_without_default_constructor_1(std::string name_, int age_) - : name{std::move(name_)} - , age{age_} + : name{std::move(name_)} + , age{age_} {} NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(person_without_default_constructor_1, name, age) @@ -310,19 +309,16 @@ } person_without_default_constructor_2(std::string name_, int age_) - : name{std::move(name_)} - , age{age_} + : name{std::move(name_)} + , age{age_} {} }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(person_without_default_constructor_2, name, age) -} // namespace persons +} // namespace persons -TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, - persons::person_with_private_data, - persons::person_without_private_data_1, - persons::person_without_private_data_2) +TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, persons::person_with_private_data, persons::person_without_private_data_1, persons::person_without_private_data_2) { SECTION("person") { @@ -345,9 +341,7 @@ } } -TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT", T, - persons::person_with_private_data_2, - persons::person_without_private_data_3) +TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT", T, persons::person_with_private_data_2, persons::person_without_private_data_3) { SECTION("person with default values") { @@ -379,15 +373,13 @@ } } -TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, - persons::person_with_private_alphabet, - persons::person_with_public_alphabet) +TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, persons::person_with_private_alphabet, persons::person_with_public_alphabet) { SECTION("alphabet") { { T obj1; - nlohmann::json const j = obj1; //via json object + nlohmann::json const j = obj1; //via json object T obj2; j.get_to(obj2); bool ok = (obj1 == obj2); @@ -396,7 +388,7 @@ { T obj1; - nlohmann::json const j1 = obj1; //via json string + nlohmann::json const j1 = obj1; //via json string std::string const s = j1.dump(); nlohmann::json const j2 = nlohmann::json::parse(s); T obj2; @@ -407,7 +399,7 @@ { T obj1; - nlohmann::json const j1 = obj1; //via msgpack + nlohmann::json const j1 = obj1; //via msgpack std::vector<uint8_t> const buf = nlohmann::json::to_msgpack(j1); nlohmann::json const j2 = nlohmann::json::from_msgpack(buf); T obj2; @@ -418,7 +410,7 @@ { T obj1; - nlohmann::json const j1 = obj1; //via bson + nlohmann::json const j1 = obj1; //via bson std::vector<uint8_t> const buf = nlohmann::json::to_bson(j1); nlohmann::json const j2 = nlohmann::json::from_bson(buf); T obj2; @@ -429,7 +421,7 @@ { T obj1; - nlohmann::json const j1 = obj1; //via cbor + nlohmann::json const j1 = obj1; //via cbor std::vector<uint8_t> const buf = nlohmann::json::to_cbor(j1); nlohmann::json const j2 = nlohmann::json::from_cbor(buf); T obj2; @@ -440,7 +432,7 @@ { T obj1; - nlohmann::json const j1 = obj1; //via ubjson + nlohmann::json const j1 = obj1; //via ubjson std::vector<uint8_t> const buf = nlohmann::json::to_ubjson(j1); nlohmann::json const j2 = nlohmann::json::from_ubjson(buf); T obj2; @@ -451,9 +443,7 @@ } } -TEST_CASE_TEMPLATE("Serialization of non-default-constructible classes via NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE", T, - persons::person_without_default_constructor_1, - persons::person_without_default_constructor_2) +TEST_CASE_TEMPLATE("Serialization of non-default-constructible classes via NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE", T, persons::person_without_default_constructor_1, persons::person_without_default_constructor_2) { SECTION("person") { @@ -463,11 +453,9 @@ CHECK(json(person).dump() == "{\"age\":1,\"name\":\"Erik\"}"); // serialization of a container with objects - std::vector<T> const two_persons - { + std::vector<T> const two_persons{ {"Erik", 1}, - {"Kyle", 2} - }; + {"Kyle", 2}}; CHECK(json(two_persons).dump() == "[{\"age\":1,\"name\":\"Erik\"},{\"age\":2,\"name\":\"Kyle\"}]"); } }
diff --git a/tests/src/unit-unicode1.cpp b/tests/src/unit-unicode1.cpp index e4405c4..1a1b085 100644 --- a/tests/src/unit-unicode1.cpp +++ b/tests/src/unit-unicode1.cpp
@@ -13,18 +13,17 @@ #include <nlohmann/json.hpp> using nlohmann::json; -#include <fstream> -#include <sstream> -#include <iomanip> #include "make_test_data_available.hpp" +#include <fstream> +#include <iomanip> +#include <sstream> TEST_CASE("Unicode (1/5)" * doctest::skip()) { SECTION("\\uxxxx sequences") { // create an escaped string from a code point - const auto codepoint_to_unicode = [](std::size_t cp) - { + const auto codepoint_to_unicode = [](std::size_t cp) { // code points are represented as a six-character sequence: a // reverse solidus, followed by the lowercase letter u, followed // by four hexadecimal digits that encode the character's code @@ -102,7 +101,7 @@ } } -#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if) +#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if) SECTION("incorrect sequences") { SECTION("high surrogate without low surrogate") @@ -223,8 +222,7 @@ } } -namespace -{ +namespace { void roundtrip(bool success_expected, const std::string& s); void roundtrip(bool success_expected, const std::string& s) @@ -265,7 +263,7 @@ CHECK_THROWS_AS(_ = json::parse(ps), json::parse_error&); } } -} // namespace +} // namespace TEST_CASE("Markus Kuhn's UTF-8 decoder capability and stress test") {
diff --git a/tests/src/unit-unicode2.cpp b/tests/src/unit-unicode2.cpp index ebc29db..5e9bb36 100644 --- a/tests/src/unit-unicode2.cpp +++ b/tests/src/unit-unicode2.cpp
@@ -14,18 +14,17 @@ #include <nlohmann/json.hpp> using nlohmann::json; -#include <fstream> -#include <sstream> -#include <iostream> -#include <iomanip> #include "make_test_data_available.hpp" +#include <fstream> +#include <iomanip> +#include <iostream> +#include <sstream> // this test suite uses static variables with non-trivial destructors DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors") -namespace -{ +namespace { extern size_t calls; size_t calls = 0; @@ -123,7 +122,7 @@ { if (++calls % 100000 == 0) { - std::cout << calls << " of 455355 UTF-8 strings checked" << std::endl; // NOLINT(performance-avoid-endl) + std::cout << calls << " of 455355 UTF-8 strings checked" << std::endl; // NOLINT(performance-avoid-endl) } static std::string json_string; @@ -164,7 +163,7 @@ CHECK_THROWS_AS(_ = json::parse(json_string), json::parse_error&); } } -} // namespace +} // namespace TEST_CASE("Unicode (2/5)" * doctest::skip()) {
diff --git a/tests/src/unit-unicode3.cpp b/tests/src/unit-unicode3.cpp index dffb1cf..6044574 100644 --- a/tests/src/unit-unicode3.cpp +++ b/tests/src/unit-unicode3.cpp
@@ -14,18 +14,17 @@ #include <nlohmann/json.hpp> using nlohmann::json; -#include <fstream> -#include <sstream> -#include <iostream> -#include <iomanip> #include "make_test_data_available.hpp" +#include <fstream> +#include <iomanip> +#include <iostream> +#include <sstream> // this test suite uses static variables with non-trivial destructors DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors") -namespace -{ +namespace { extern size_t calls; size_t calls = 0; @@ -123,7 +122,7 @@ { if (++calls % 100000 == 0) { - std::cout << calls << " of 1641521 UTF-8 strings checked" << std::endl; // NOLINT(performance-avoid-endl) + std::cout << calls << " of 1641521 UTF-8 strings checked" << std::endl; // NOLINT(performance-avoid-endl) } static std::string json_string; @@ -164,7 +163,7 @@ CHECK_THROWS_AS(_ = json::parse(json_string), json::parse_error&); } } -} // namespace +} // namespace TEST_CASE("Unicode (3/5)" * doctest::skip()) {
diff --git a/tests/src/unit-unicode4.cpp b/tests/src/unit-unicode4.cpp index 6a0e089..851b8a5 100644 --- a/tests/src/unit-unicode4.cpp +++ b/tests/src/unit-unicode4.cpp
@@ -14,18 +14,17 @@ #include <nlohmann/json.hpp> using nlohmann::json; -#include <fstream> -#include <sstream> -#include <iostream> -#include <iomanip> #include "make_test_data_available.hpp" +#include <fstream> +#include <iomanip> +#include <iostream> +#include <sstream> // this test suite uses static variables with non-trivial destructors DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors") -namespace -{ +namespace { extern size_t calls; size_t calls = 0; @@ -123,7 +122,7 @@ { if (++calls % 100000 == 0) { - std::cout << calls << " of 5517507 UTF-8 strings checked" << std::endl; // NOLINT(performance-avoid-endl) + std::cout << calls << " of 5517507 UTF-8 strings checked" << std::endl; // NOLINT(performance-avoid-endl) } static std::string json_string; @@ -164,7 +163,7 @@ CHECK_THROWS_AS(_ = json::parse(json_string), json::parse_error&); } } -} // namespace +} // namespace TEST_CASE("Unicode (4/5)" * doctest::skip()) {
diff --git a/tests/src/unit-unicode5.cpp b/tests/src/unit-unicode5.cpp index 217d3b3..1967fc2 100644 --- a/tests/src/unit-unicode5.cpp +++ b/tests/src/unit-unicode5.cpp
@@ -14,18 +14,17 @@ #include <nlohmann/json.hpp> using nlohmann::json; -#include <fstream> -#include <sstream> -#include <iostream> -#include <iomanip> #include "make_test_data_available.hpp" +#include <fstream> +#include <iomanip> +#include <iostream> +#include <sstream> // this test suite uses static variables with non-trivial destructors DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors") -namespace -{ +namespace { extern size_t calls; size_t calls = 0; @@ -123,7 +122,7 @@ { if (++calls % 100000 == 0) { - std::cout << calls << " of 1246225 UTF-8 strings checked" << std::endl; // NOLINT(performance-avoid-endl) + std::cout << calls << " of 1246225 UTF-8 strings checked" << std::endl; // NOLINT(performance-avoid-endl) } static std::string json_string; @@ -164,7 +163,7 @@ CHECK_THROWS_AS(_ = json::parse(json_string), json::parse_error&); } } -} // namespace +} // namespace TEST_CASE("Unicode (5/5)" * doctest::skip()) {
diff --git a/tests/src/unit-user_defined_input.cpp b/tests/src/unit-user_defined_input.cpp index 5483f6a..f9c096a 100644 --- a/tests/src/unit-user_defined_input.cpp +++ b/tests/src/unit-user_defined_input.cpp
@@ -13,8 +13,7 @@ #include <list> -namespace -{ +namespace { TEST_CASE("Use arbitrary stdlib container") { std::string raw_data = "[1,2,3,4]"; @@ -39,19 +38,17 @@ const char* end(const MyContainer& c) { - return c.data + strlen(c.data); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + return c.data + strlen(c.data); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } TEST_CASE("Custom container non-member begin/end") { - const MyContainer data{"[1,2,3,4]"}; json as_json = json::parse(data); CHECK(as_json.at(0) == 1); CHECK(as_json.at(1) == 2); CHECK(as_json.at(2) == 3); CHECK(as_json.at(3) == 4); - } TEST_CASE("Custom container member begin/end") @@ -67,7 +64,7 @@ const char* end() const { - return data + strlen(data); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + return data + strlen(data); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } }; @@ -93,7 +90,7 @@ MyIterator& operator++() { - ++ptr; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + ++ptr; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) return *this; } @@ -118,7 +115,7 @@ CHECK(std::is_same<MyIterator::iterator_category, std::input_iterator_tag>::value); const MyIterator begin{raw_data}; - const MyIterator end{raw_data + strlen(raw_data)}; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + const MyIterator end{raw_data + strlen(raw_data)}; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) json as_json = json::parse(begin, end); CHECK(as_json.at(0) == 1); @@ -127,4 +124,4 @@ CHECK(as_json.at(3) == 4); } -} // namespace +} // namespace
diff --git a/tests/src/unit-wstring.cpp b/tests/src/unit-wstring.cpp index 1aaa13b..7469fce 100644 --- a/tests/src/unit-wstring.cpp +++ b/tests/src/unit-wstring.cpp
@@ -13,8 +13,7 @@ // ICPC errors out on multibyte character sequences in source files #ifndef __INTEL_COMPILER -namespace -{ +namespace { bool wstring_is_utf16(); bool wstring_is_utf16() { @@ -32,7 +31,7 @@ { return (std::u32string(U"💩") == std::u32string(U"\U0001F4A9")); } -} // namespace +} // namespace TEST_CASE("wide strings") {