🎨 use Clang-Format
This commit is contained in:
108 files changed
+6491
-4516
No files matched your search
+4
-5
@@ -1,4 +1,3 @@
|
|||||||
#AccessModifierOffset: 2
|
|
||||||
AlignAfterOpenBracket: Align
|
AlignAfterOpenBracket: Align
|
||||||
AlignConsecutiveAssignments: false
|
AlignConsecutiveAssignments: false
|
||||||
#AlignConsecutiveBitFields: false
|
#AlignConsecutiveBitFields: false
|
||||||
@@ -12,7 +11,7 @@ AllowAllConstructorInitializersOnNextLine: false
|
|||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
AllowShortBlocksOnASingleLine: Empty
|
AllowShortBlocksOnASingleLine: Empty
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
#AllowShortEnumsOnASingleLine: true
|
AllowShortEnumsOnASingleLine: true
|
||||||
AllowShortFunctionsOnASingleLine: Empty
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
AllowShortIfStatementsOnASingleLine: Never
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
AllowShortLambdasOnASingleLine: Empty
|
AllowShortLambdasOnASingleLine: Empty
|
||||||
@@ -36,8 +35,8 @@ BraceWrapping:
|
|||||||
AfterExternBlock: false
|
AfterExternBlock: false
|
||||||
BeforeCatch: true
|
BeforeCatch: true
|
||||||
BeforeElse: true
|
BeforeElse: true
|
||||||
#BeforeLambdaBody: false
|
BeforeLambdaBody: false
|
||||||
#BeforeWhile: false
|
BeforeWhile: false
|
||||||
SplitEmptyFunction: false
|
SplitEmptyFunction: false
|
||||||
SplitEmptyRecord: false
|
SplitEmptyRecord: false
|
||||||
SplitEmptyNamespace: false
|
SplitEmptyNamespace: false
|
||||||
@@ -60,7 +59,7 @@ KeepEmptyLinesAtTheStartOfBlocks: false
|
|||||||
MaxEmptyLinesToKeep: 1
|
MaxEmptyLinesToKeep: 1
|
||||||
NamespaceIndentation: None
|
NamespaceIndentation: None
|
||||||
ReflowComments: false
|
ReflowComments: false
|
||||||
SortIncludes: true
|
SortIncludes: CaseSensitive
|
||||||
SortUsingDeclarations: true
|
SortUsingDeclarations: true
|
||||||
SpaceAfterCStyleCast: false
|
SpaceAfterCStyleCast: false
|
||||||
SpaceAfterLogicalNot: false
|
SpaceAfterLogicalNot: false
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ To make changes, you need to edit the following files:
|
|||||||
## Note
|
## 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.
|
- 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
|
## Please don't
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
MAIN_DIR: ${{ github.workspace }}/main
|
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:
|
steps:
|
||||||
- name: Checkout pull request
|
- name: Checkout pull request
|
||||||
@@ -44,27 +37,7 @@ jobs:
|
|||||||
path: tools
|
path: tools
|
||||||
ref: develop
|
ref: develop
|
||||||
|
|
||||||
- name: Install astyle
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install astyle
|
|
||||||
|
|
||||||
- name: Check amalgamation
|
- name: Check amalgamation
|
||||||
run: |
|
run: |
|
||||||
cd $MAIN_DIR
|
cd $MAIN_DIR
|
||||||
|
make check-amalgamation
|
||||||
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 {} \+
|
|
||||||
@@ -142,33 +142,9 @@ pvs_studio:
|
|||||||
# Code format and source amalgamation
|
# 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
|
# call the Clang-Format on all source files
|
||||||
pretty_format:
|
pretty:
|
||||||
for FILE in $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/examples/*.cpp; do echo $$FILE; clang-format -i $$FILE; done
|
clang-format --Werror --verbose -i $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE)
|
||||||
|
|
||||||
# create single header files and pretty print
|
# create single header files and pretty print
|
||||||
amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE)
|
amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE)
|
||||||
|
|||||||
@@ -1774,8 +1774,8 @@ The library itself consists of a single header file licensed under the MIT licen
|
|||||||
- [**amalgamate.py - Amalgamate C source and header files**](https://github.com/edlund/amalgamate) to create a single header file
|
- [**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
|
- [**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
|
- [**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**](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
|
- [**CMake**](https://cmake.org) for build automation
|
||||||
- [**Codacy**](https://www.codacy.com) for further [code analysis](https://www.codacy.com/app/nlohmann/json)
|
- [**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)
|
- [**Coveralls**](https://coveralls.io) to measure [code coverage](https://coveralls.io/github/nlohmann/json)
|
||||||
|
|||||||
+6
-31
@@ -8,16 +8,16 @@ set(N 10)
|
|||||||
include(FindPython3)
|
include(FindPython3)
|
||||||
find_package(Python3 COMPONENTS Interpreter)
|
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++)
|
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)
|
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}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
|
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)
|
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)
|
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}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TIDY_TOOL_VERSION "${CLANG_TIDY_TOOL_VERSION}")
|
||||||
@@ -581,33 +581,8 @@ add_custom_target(ci_test_clang_sanitizer
|
|||||||
# Check if header is amalgamated and sources are properly indented.
|
# 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
|
add_custom_target(ci_test_amalgamation
|
||||||
COMMAND rm -fr ${include_dir}/json.hpp~ ${include_dir}/json_fwd.hpp~
|
COMMAND make check-amalgamation
|
||||||
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
|
|
||||||
|
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
COMMENT "Check amalgamation and indentation"
|
COMMENT "Check amalgamation and indentation"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -85,12 +85,10 @@
|
|||||||
|
|
||||||
#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
|
#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
#define NLOHMANN_JSON_NAMESPACE_BEGIN \
|
#define NLOHMANN_JSON_NAMESPACE_BEGIN \
|
||||||
namespace nlohmann \
|
namespace nlohmann { \
|
||||||
{ \
|
|
||||||
inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
|
inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
|
||||||
NLOHMANN_JSON_ABI_TAGS, \
|
NLOHMANN_JSON_ABI_TAGS, \
|
||||||
NLOHMANN_JSON_NAMESPACE_VERSION) \
|
NLOHMANN_JSON_NAMESPACE_VERSION) {
|
||||||
{
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NLOHMANN_JSON_NAMESPACE_END
|
#ifndef NLOHMANN_JSON_NAMESPACE_END
|
||||||
|
|||||||
@@ -30,8 +30,7 @@
|
|||||||
#include <nlohmann/detail/value_t.hpp>
|
#include <nlohmann/detail/value_t.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
|
inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
|
||||||
@@ -44,10 +43,7 @@ inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// overloads for basic_json template parameters
|
// overloads for basic_json template parameters
|
||||||
template < typename BasicJsonType, typename ArithmeticType,
|
template<typename BasicJsonType, typename ArithmeticType, enable_if_t<std::is_arithmetic<ArithmeticType>::value && !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, int> = 0>
|
||||||
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)
|
void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
|
||||||
{
|
{
|
||||||
switch (static_cast<value_t>(j))
|
switch (static_cast<value_t>(j))
|
||||||
@@ -101,12 +97,11 @@ inline void from_json(const BasicJsonType& j, typename BasicJsonType::string_t&
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<
|
template<
|
||||||
typename BasicJsonType, typename StringType,
|
typename BasicJsonType,
|
||||||
|
typename StringType,
|
||||||
enable_if_t<
|
enable_if_t<
|
||||||
std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value
|
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,
|
||||||
&& is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value
|
int> = 0>
|
||||||
&& !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)
|
inline void from_json(const BasicJsonType& j, StringType& s)
|
||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
|
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
|
||||||
@@ -136,8 +131,7 @@ inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_int
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !JSON_DISABLE_ENUM_SERIALIZATION
|
#if !JSON_DISABLE_ENUM_SERIALIZATION
|
||||||
template<typename BasicJsonType, typename EnumType,
|
template<typename BasicJsonType, typename EnumType, enable_if_t<std::is_enum<EnumType>::value, int> = 0>
|
||||||
enable_if_t<std::is_enum<EnumType>::value, int> = 0>
|
|
||||||
inline void from_json(const BasicJsonType& j, EnumType& e)
|
inline void from_json(const BasicJsonType& j, EnumType& e)
|
||||||
{
|
{
|
||||||
typename std::underlying_type<EnumType>::type val;
|
typename std::underlying_type<EnumType>::type val;
|
||||||
@@ -147,8 +141,7 @@ inline void from_json(const BasicJsonType& j, EnumType& e)
|
|||||||
#endif // JSON_DISABLE_ENUM_SERIALIZATION
|
#endif // JSON_DISABLE_ENUM_SERIALIZATION
|
||||||
|
|
||||||
// forward_list doesn't have an insert method
|
// forward_list doesn't have an insert method
|
||||||
template<typename BasicJsonType, typename T, typename Allocator,
|
template<typename BasicJsonType, typename T, typename Allocator, enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
|
||||||
enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
|
|
||||||
inline void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
|
inline void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
|
||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
||||||
@@ -156,16 +149,13 @@ inline void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l
|
|||||||
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
|
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
|
||||||
}
|
}
|
||||||
l.clear();
|
l.clear();
|
||||||
std::transform(j.rbegin(), j.rend(),
|
std::transform(j.rbegin(), j.rend(), std::front_inserter(l), [](const BasicJsonType& i) {
|
||||||
std::front_inserter(l), [](const BasicJsonType & i)
|
|
||||||
{
|
|
||||||
return i.template get<T>();
|
return i.template get<T>();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// valarray doesn't have an insert method
|
// valarray doesn't have an insert method
|
||||||
template<typename BasicJsonType, typename T,
|
template<typename BasicJsonType, typename T, enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
|
||||||
enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
|
|
||||||
inline void from_json(const BasicJsonType& j, std::valarray<T>& l)
|
inline void from_json(const BasicJsonType& j, std::valarray<T>& l)
|
||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
||||||
@@ -173,9 +163,7 @@ inline void from_json(const BasicJsonType& j, std::valarray<T>& l)
|
|||||||
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
|
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
|
||||||
}
|
}
|
||||||
l.resize(j.size());
|
l.resize(j.size());
|
||||||
std::transform(j.begin(), j.end(), std::begin(l),
|
std::transform(j.begin(), j.end(), std::begin(l), [](const BasicJsonType& elem) {
|
||||||
[](const BasicJsonType & elem)
|
|
||||||
{
|
|
||||||
return elem.template get<T>();
|
return elem.template get<T>();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -197,8 +185,7 @@ inline void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename T, std::size_t N>
|
template<typename BasicJsonType, typename T, std::size_t N>
|
||||||
auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
|
auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, priority_tag<2> /*unused*/)
|
||||||
priority_tag<2> /*unused*/)
|
|
||||||
-> decltype(j.template get<T>(), void())
|
-> decltype(j.template get<T>(), void())
|
||||||
{
|
{
|
||||||
for (std::size_t i = 0; i < N; ++i)
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
@@ -207,13 +194,9 @@ auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename ConstructibleArrayType,
|
template<typename BasicJsonType, typename ConstructibleArrayType, enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, int> = 0>
|
||||||
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*/)
|
auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/)
|
||||||
-> decltype(
|
-> decltype(arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
|
||||||
arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
|
|
||||||
j.template get<typename ConstructibleArrayType::value_type>(),
|
j.template get<typename ConstructibleArrayType::value_type>(),
|
||||||
void())
|
void())
|
||||||
{
|
{
|
||||||
@@ -221,9 +204,7 @@ auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, p
|
|||||||
|
|
||||||
ConstructibleArrayType ret;
|
ConstructibleArrayType ret;
|
||||||
ret.reserve(j.size());
|
ret.reserve(j.size());
|
||||||
std::transform(j.begin(), j.end(),
|
std::transform(j.begin(), j.end(), std::inserter(ret, end(ret)), [](const BasicJsonType& i) {
|
||||||
std::inserter(ret, end(ret)), [](const BasicJsonType & i)
|
|
||||||
{
|
|
||||||
// get<BasicJsonType>() returns *this, this won't call a from_json
|
// get<BasicJsonType>() returns *this, this won't call a from_json
|
||||||
// method when value_type is BasicJsonType
|
// method when value_type is BasicJsonType
|
||||||
return i.template get<typename ConstructibleArrayType::value_type>();
|
return i.template get<typename ConstructibleArrayType::value_type>();
|
||||||
@@ -231,20 +212,17 @@ auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, p
|
|||||||
arr = std::move(ret);
|
arr = std::move(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename ConstructibleArrayType,
|
template<typename BasicJsonType, typename ConstructibleArrayType, enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, int> = 0>
|
||||||
enable_if_t<
|
inline void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<0> /*unused*/)
|
||||||
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;
|
using std::end;
|
||||||
|
|
||||||
ConstructibleArrayType ret;
|
ConstructibleArrayType ret;
|
||||||
std::transform(
|
std::transform(
|
||||||
j.begin(), j.end(), std::inserter(ret, end(ret)),
|
j.begin(),
|
||||||
[](const BasicJsonType & i)
|
j.end(),
|
||||||
{
|
std::inserter(ret, end(ret)),
|
||||||
|
[](const BasicJsonType& i) {
|
||||||
// get<BasicJsonType>() returns *this, this won't call a from_json
|
// get<BasicJsonType>() returns *this, this won't call a from_json
|
||||||
// method when value_type is BasicJsonType
|
// method when value_type is BasicJsonType
|
||||||
return i.template get<typename ConstructibleArrayType::value_type>();
|
return i.template get<typename ConstructibleArrayType::value_type>();
|
||||||
@@ -252,14 +230,7 @@ inline void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType&
|
|||||||
arr = std::move(ret);
|
arr = std::move(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename ConstructibleArrayType,
|
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>
|
||||||
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)
|
auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
|
||||||
-> decltype(from_json_array_impl(j, arr, priority_tag<3>{}),
|
-> decltype(from_json_array_impl(j, arr, priority_tag<3>{}),
|
||||||
j.template get<typename ConstructibleArrayType::value_type>(),
|
j.template get<typename ConstructibleArrayType::value_type>(),
|
||||||
@@ -275,7 +246,8 @@ void())
|
|||||||
|
|
||||||
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,
|
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>()...}};
|
||||||
}
|
}
|
||||||
@@ -303,8 +275,7 @@ inline void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t&
|
|||||||
bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
|
bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename ConstructibleObjectType,
|
template<typename BasicJsonType, typename ConstructibleObjectType, enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>
|
||||||
enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>
|
|
||||||
inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
|
if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
|
||||||
@@ -316,10 +287,10 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
|||||||
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
|
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
|
||||||
using value_type = typename ConstructibleObjectType::value_type;
|
using value_type = typename ConstructibleObjectType::value_type;
|
||||||
std::transform(
|
std::transform(
|
||||||
inner_object->begin(), inner_object->end(),
|
inner_object->begin(),
|
||||||
|
inner_object->end(),
|
||||||
std::inserter(ret, ret.begin()),
|
std::inserter(ret, ret.begin()),
|
||||||
[](typename BasicJsonType::object_t::value_type const & p)
|
[](typename BasicJsonType::object_t::value_type const& p) {
|
||||||
{
|
|
||||||
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
||||||
});
|
});
|
||||||
obj = std::move(ret);
|
obj = std::move(ret);
|
||||||
@@ -329,14 +300,7 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
|||||||
// (BooleanType, etc..); note: Is it really necessary to provide explicit
|
// (BooleanType, etc..); note: Is it really necessary to provide explicit
|
||||||
// overloads for boolean_t etc. in case of a custom BooleanType which is not
|
// overloads for boolean_t etc. in case of a custom BooleanType which is not
|
||||||
// an arithmetic type?
|
// an arithmetic type?
|
||||||
template < typename BasicJsonType, typename ArithmeticType,
|
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>
|
||||||
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)
|
inline void from_json(const BasicJsonType& j, ArithmeticType& val)
|
||||||
{
|
{
|
||||||
switch (static_cast<value_t>(j))
|
switch (static_cast<value_t>(j))
|
||||||
@@ -416,9 +380,7 @@ auto from_json(BasicJsonType&& j, TupleRelated&& t)
|
|||||||
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,
|
template<typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator, typename = enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, Key>::value>>
|
||||||
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)
|
inline void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
|
||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
||||||
@@ -436,9 +398,7 @@ inline void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator,
|
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>>
|
||||||
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)
|
inline void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
|
||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
||||||
|
|||||||
@@ -19,8 +19,7 @@
|
|||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief implements the Grisu2 algorithm for binary to decimal floating-point
|
@brief implements the Grisu2 algorithm for binary to decimal floating-point
|
||||||
@@ -41,8 +40,7 @@ For a detailed description of the algorithm see:
|
|||||||
Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language
|
Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language
|
||||||
Design and Implementation, PLDI 1996
|
Design and Implementation, PLDI 1996
|
||||||
*/
|
*/
|
||||||
namespace dtoa_impl
|
namespace dtoa_impl {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename Target, typename Source>
|
template<typename Target, typename Source>
|
||||||
Target reinterpret_bits(const Source source)
|
Target reinterpret_bits(const Source source)
|
||||||
@@ -61,7 +59,10 @@ struct diyfp // f * 2^e
|
|||||||
std::uint64_t f = 0;
|
std::uint64_t f = 0;
|
||||||
int e = 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
|
@brief returns x - y
|
||||||
@@ -462,8 +463,7 @@ inline cached_power get_cached_power_for_binary_exponent(int e)
|
|||||||
{0x8E679C2F5E44FF8F, 960, 308},
|
{0x8E679C2F5E44FF8F, 960, 308},
|
||||||
{0xD433179D9C8CB841, 986, 316},
|
{0xD433179D9C8CB841, 986, 316},
|
||||||
{0x9E19DB92B4E31BA9, 1013, 324},
|
{0x9E19DB92B4E31BA9, 1013, 324},
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
|
|
||||||
// This computation gives exactly the same results for k as
|
// This computation gives exactly the same results for k as
|
||||||
// k = ceil((kAlpha - e - 1) * 0.30102999566398114)
|
// k = ceil((kAlpha - e - 1) * 0.30102999566398114)
|
||||||
@@ -543,8 +543,7 @@ inline int find_largest_pow10(const std::uint32_t n, std::uint32_t& pow10)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta,
|
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)
|
||||||
std::uint64_t rest, std::uint64_t ten_k)
|
|
||||||
{
|
{
|
||||||
JSON_ASSERT(len >= 1);
|
JSON_ASSERT(len >= 1);
|
||||||
JSON_ASSERT(dist <= delta);
|
JSON_ASSERT(dist <= delta);
|
||||||
@@ -570,9 +569,7 @@ inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t d
|
|||||||
// The tests are written in this order to avoid overflow in unsigned
|
// The tests are written in this order to avoid overflow in unsigned
|
||||||
// integer arithmetic.
|
// integer arithmetic.
|
||||||
|
|
||||||
while (rest < dist
|
while (rest < dist && delta - rest >= ten_k && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
|
||||||
&& delta - rest >= ten_k
|
|
||||||
&& (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
|
|
||||||
{
|
{
|
||||||
JSON_ASSERT(buf[len - 1] != '0');
|
JSON_ASSERT(buf[len - 1] != '0');
|
||||||
buf[len - 1]--;
|
buf[len - 1]--;
|
||||||
@@ -584,8 +581,7 @@ inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t d
|
|||||||
Generates V = buffer * 10^decimal_exponent, such that M- <= V <= M+.
|
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.
|
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,
|
inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus)
|
||||||
diyfp M_minus, diyfp w, diyfp M_plus)
|
|
||||||
{
|
{
|
||||||
static_assert(kAlpha >= -60, "internal error");
|
static_assert(kAlpha >= -60, "internal error");
|
||||||
static_assert(kGamma <= -32, "internal error");
|
static_assert(kGamma <= -32, "internal error");
|
||||||
@@ -825,8 +821,7 @@ len is the length of the buffer (number of decimal digits)
|
|||||||
The buffer must be large enough, i.e. >= max_digits10.
|
The buffer must be large enough, i.e. >= max_digits10.
|
||||||
*/
|
*/
|
||||||
JSON_HEDLEY_NON_NULL(1)
|
JSON_HEDLEY_NON_NULL(1)
|
||||||
inline void grisu2(char* buf, int& len, int& decimal_exponent,
|
inline void grisu2(char* buf, int& len, int& decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
|
||||||
diyfp m_minus, diyfp v, diyfp m_plus)
|
|
||||||
{
|
{
|
||||||
JSON_ASSERT(m_plus.e == m_minus.e);
|
JSON_ASSERT(m_plus.e == m_minus.e);
|
||||||
JSON_ASSERT(m_plus.e == v.e);
|
JSON_ASSERT(m_plus.e == v.e);
|
||||||
@@ -977,8 +972,7 @@ notation. Otherwise it will be printed in exponential notation.
|
|||||||
*/
|
*/
|
||||||
JSON_HEDLEY_NON_NULL(1)
|
JSON_HEDLEY_NON_NULL(1)
|
||||||
JSON_HEDLEY_RETURNS_NON_NULL
|
JSON_HEDLEY_RETURNS_NON_NULL
|
||||||
inline char* format_buffer(char* buf, int len, int decimal_exponent,
|
inline char* format_buffer(char* buf, int len, int decimal_exponent, int min_exp, int max_exp)
|
||||||
int min_exp, int max_exp)
|
|
||||||
{
|
{
|
||||||
JSON_ASSERT(min_exp < 0);
|
JSON_ASSERT(min_exp < 0);
|
||||||
JSON_ASSERT(max_exp > 0);
|
JSON_ASSERT(max_exp > 0);
|
||||||
|
|||||||
@@ -25,8 +25,7 @@
|
|||||||
#include <nlohmann/detail/value_t.hpp>
|
#include <nlohmann/detail/value_t.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
//////////////////
|
//////////////////
|
||||||
// constructors //
|
// constructors //
|
||||||
@@ -39,7 +38,8 @@ namespace detail
|
|||||||
* https://github.com/nlohmann/json/issues/2865 for more information.
|
* https://github.com/nlohmann/json/issues/2865 for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<value_t> struct external_constructor;
|
template<value_t>
|
||||||
|
struct external_constructor;
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct external_constructor<value_t::boolean>
|
struct external_constructor<value_t::boolean>
|
||||||
@@ -75,9 +75,7 @@ struct external_constructor<value_t::string>
|
|||||||
j.assert_invariant();
|
j.assert_invariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename CompatibleStringType,
|
template<typename BasicJsonType, typename CompatibleStringType, enable_if_t<!std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value, int> = 0>
|
||||||
enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
|
|
||||||
int > = 0 >
|
|
||||||
static void construct(BasicJsonType& j, const CompatibleStringType& str)
|
static void construct(BasicJsonType& j, const CompatibleStringType& str)
|
||||||
{
|
{
|
||||||
j.m_data.m_value.destroy(j.m_data.m_type);
|
j.m_data.m_value.destroy(j.m_data.m_type);
|
||||||
@@ -171,9 +169,7 @@ struct external_constructor<value_t::array>
|
|||||||
j.assert_invariant();
|
j.assert_invariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename CompatibleArrayType,
|
template<typename BasicJsonType, typename CompatibleArrayType, enable_if_t<!std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value, int> = 0>
|
||||||
enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
|
|
||||||
int > = 0 >
|
|
||||||
static void construct(BasicJsonType& j, const CompatibleArrayType& arr)
|
static void construct(BasicJsonType& j, const CompatibleArrayType& arr)
|
||||||
{
|
{
|
||||||
using std::begin;
|
using std::begin;
|
||||||
@@ -201,8 +197,7 @@ struct external_constructor<value_t::array>
|
|||||||
j.assert_invariant();
|
j.assert_invariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename T,
|
template<typename BasicJsonType, typename T, enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
|
||||||
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
|
|
||||||
static void construct(BasicJsonType& j, const std::valarray<T>& arr)
|
static void construct(BasicJsonType& j, const std::valarray<T>& arr)
|
||||||
{
|
{
|
||||||
j.m_data.m_value.destroy(j.m_data.m_type);
|
j.m_data.m_value.destroy(j.m_data.m_type);
|
||||||
@@ -241,8 +236,7 @@ struct external_constructor<value_t::object>
|
|||||||
j.assert_invariant();
|
j.assert_invariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename CompatibleObjectType,
|
template<typename BasicJsonType, typename CompatibleObjectType, enable_if_t<!std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int> = 0>
|
||||||
enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int > = 0 >
|
|
||||||
static void construct(BasicJsonType& j, const CompatibleObjectType& obj)
|
static void construct(BasicJsonType& j, const CompatibleObjectType& obj)
|
||||||
{
|
{
|
||||||
using std::begin;
|
using std::begin;
|
||||||
@@ -260,28 +254,19 @@ struct external_constructor<value_t::object>
|
|||||||
// to_json //
|
// to_json //
|
||||||
/////////////
|
/////////////
|
||||||
|
|
||||||
template<typename BasicJsonType, typename T,
|
template<typename BasicJsonType, typename T, enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0>
|
||||||
enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0>
|
|
||||||
inline void to_json(BasicJsonType& j, T b) noexcept
|
inline void to_json(BasicJsonType& j, T b) noexcept
|
||||||
{
|
{
|
||||||
external_constructor<value_t::boolean>::construct(j, b);
|
external_constructor<value_t::boolean>::construct(j, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename BoolRef,
|
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>
|
||||||
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
|
inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept
|
||||||
{
|
{
|
||||||
external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b));
|
external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleString,
|
template<typename BasicJsonType, typename CompatibleString, enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
|
||||||
enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
|
|
||||||
inline void to_json(BasicJsonType& j, const CompatibleString& s)
|
inline void to_json(BasicJsonType& j, const CompatibleString& s)
|
||||||
{
|
{
|
||||||
external_constructor<value_t::string>::construct(j, s);
|
external_constructor<value_t::string>::construct(j, s);
|
||||||
@@ -293,30 +278,26 @@ inline void to_json(BasicJsonType& j, typename BasicJsonType::string_t&& s)
|
|||||||
external_constructor<value_t::string>::construct(j, std::move(s));
|
external_constructor<value_t::string>::construct(j, std::move(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename FloatType,
|
template<typename BasicJsonType, typename FloatType, enable_if_t<std::is_floating_point<FloatType>::value, int> = 0>
|
||||||
enable_if_t<std::is_floating_point<FloatType>::value, int> = 0>
|
|
||||||
inline void to_json(BasicJsonType& j, FloatType val) noexcept
|
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));
|
external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleNumberUnsignedType,
|
template<typename BasicJsonType, typename CompatibleNumberUnsignedType, enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0>
|
||||||
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
|
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));
|
external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleNumberIntegerType,
|
template<typename BasicJsonType, typename CompatibleNumberIntegerType, enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0>
|
||||||
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
|
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));
|
external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !JSON_DISABLE_ENUM_SERIALIZATION
|
#if !JSON_DISABLE_ENUM_SERIALIZATION
|
||||||
template<typename BasicJsonType, typename EnumType,
|
template<typename BasicJsonType, typename EnumType, enable_if_t<std::is_enum<EnumType>::value, int> = 0>
|
||||||
enable_if_t<std::is_enum<EnumType>::value, int> = 0>
|
|
||||||
inline void to_json(BasicJsonType& j, EnumType e) noexcept
|
inline void to_json(BasicJsonType& j, EnumType e) noexcept
|
||||||
{
|
{
|
||||||
using underlying_type = typename std::underlying_type<EnumType>::type;
|
using underlying_type = typename std::underlying_type<EnumType>::type;
|
||||||
@@ -330,14 +311,7 @@ inline void to_json(BasicJsonType& j, const std::vector<bool>& e)
|
|||||||
external_constructor<value_t::array>::construct(j, e);
|
external_constructor<value_t::array>::construct(j, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename CompatibleArrayType,
|
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>
|
||||||
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)
|
inline void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
|
||||||
{
|
{
|
||||||
external_constructor<value_t::array>::construct(j, arr);
|
external_constructor<value_t::array>::construct(j, arr);
|
||||||
@@ -349,8 +323,7 @@ inline void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bi
|
|||||||
external_constructor<value_t::binary>::construct(j, bin);
|
external_constructor<value_t::binary>::construct(j, bin);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename T,
|
template<typename BasicJsonType, typename T, enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
|
||||||
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
|
|
||||||
inline void to_json(BasicJsonType& j, const std::valarray<T>& arr)
|
inline void to_json(BasicJsonType& j, const std::valarray<T>& arr)
|
||||||
{
|
{
|
||||||
external_constructor<value_t::array>::construct(j, std::move(arr));
|
external_constructor<value_t::array>::construct(j, std::move(arr));
|
||||||
@@ -362,8 +335,7 @@ inline void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
|
|||||||
external_constructor<value_t::array>::construct(j, std::move(arr));
|
external_constructor<value_t::array>::construct(j, std::move(arr));
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename CompatibleObjectType,
|
template<typename BasicJsonType, typename CompatibleObjectType, enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value && !is_basic_json<CompatibleObjectType>::value, int> = 0>
|
||||||
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)
|
inline void to_json(BasicJsonType& j, const CompatibleObjectType& obj)
|
||||||
{
|
{
|
||||||
external_constructor<value_t::object>::construct(j, obj);
|
external_constructor<value_t::object>::construct(j, obj);
|
||||||
@@ -376,7 +348,9 @@ inline void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<
|
template<
|
||||||
typename BasicJsonType, typename T, std::size_t N,
|
typename BasicJsonType,
|
||||||
|
typename T,
|
||||||
|
std::size_t N,
|
||||||
enable_if_t<!std::is_constructible<typename BasicJsonType::string_t,
|
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)
|
const T (&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||||
int> = 0>
|
int> = 0>
|
||||||
@@ -392,8 +366,7 @@ inline void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// for https://github.com/nlohmann/json/pull/1134
|
// for https://github.com/nlohmann/json/pull/1134
|
||||||
template<typename BasicJsonType, typename T,
|
template<typename BasicJsonType, typename T, enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>
|
||||||
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)
|
inline void to_json(BasicJsonType& j, const T& b)
|
||||||
{
|
{
|
||||||
j = {{b.key(), b.value()}};
|
j = {{b.key(), b.value()}};
|
||||||
|
|||||||
@@ -17,17 +17,16 @@
|
|||||||
#include <string> // to_string
|
#include <string> // to_string
|
||||||
#include <vector> // vector
|
#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/input/position_t.hpp>
|
||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
#include <nlohmann/detail/meta/cpp_future.hpp>
|
#include <nlohmann/detail/meta/cpp_future.hpp>
|
||||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||||
#include <nlohmann/detail/string_concat.hpp>
|
#include <nlohmann/detail/string_concat.hpp>
|
||||||
|
#include <nlohmann/detail/string_escape.hpp>
|
||||||
|
#include <nlohmann/detail/value_t.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
// exceptions //
|
// exceptions //
|
||||||
@@ -49,7 +48,10 @@ class exception : public std::exception
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
JSON_HEDLEY_NON_NULL(3)
|
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_)
|
static std::string name(const std::string& ename, int id_)
|
||||||
{
|
{
|
||||||
@@ -114,9 +116,7 @@ class exception : public std::exception
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
|
auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, [](const std::string& a, const std::string& b) {
|
||||||
[](const std::string & a, const std::string & b)
|
|
||||||
{
|
|
||||||
return concat(a, '/', detail::escape(b));
|
return concat(a, '/', detail::escape(b));
|
||||||
});
|
});
|
||||||
return concat('(', str, ") ");
|
return concat('(', str, ") ");
|
||||||
@@ -148,17 +148,14 @@ class parse_error : public exception
|
|||||||
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
|
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)
|
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",
|
const std::string w = concat(exception::name("parse_error", id_), "parse error", position_string(pos), ": ", exception::diagnostics(context), what_arg);
|
||||||
position_string(pos), ": ", exception::diagnostics(context), what_arg);
|
|
||||||
return {id_, pos.chars_read_total, w.c_str()};
|
return {id_, pos.chars_read_total, w.c_str()};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
|
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)
|
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",
|
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);
|
||||||
(byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""),
|
|
||||||
": ", exception::diagnostics(context), what_arg);
|
|
||||||
return {id_, byte_, w.c_str()};
|
return {id_, byte_, w.c_str()};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,12 +172,13 @@ class parse_error : public exception
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
parse_error(int id_, std::size_t byte_, const char* what_arg)
|
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)
|
static std::string position_string(const position_t& pos)
|
||||||
{
|
{
|
||||||
return concat(" at line ", std::to_string(pos.lines_read + 1),
|
return concat(" at line ", std::to_string(pos.lines_read + 1), ", column ", std::to_string(pos.chars_read_current_line));
|
||||||
", column ", std::to_string(pos.chars_read_current_line));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -199,7 +197,8 @@ class invalid_iterator : public exception
|
|||||||
private:
|
private:
|
||||||
JSON_HEDLEY_NON_NULL(3)
|
JSON_HEDLEY_NON_NULL(3)
|
||||||
invalid_iterator(int id_, const char* what_arg)
|
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
|
/// @brief exception indicating executing a member function with a wrong type
|
||||||
@@ -216,7 +215,9 @@ class type_error : public exception
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
JSON_HEDLEY_NON_NULL(3)
|
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
|
/// @brief exception indicating access out of the defined range
|
||||||
@@ -233,7 +234,9 @@ class out_of_range : public exception
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
JSON_HEDLEY_NON_NULL(3)
|
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
|
/// @brief exception indicating other library errors
|
||||||
@@ -250,7 +253,9 @@ class other_error : public exception
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
JSON_HEDLEY_NON_NULL(3)
|
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
|
} // namespace detail
|
||||||
|
|||||||
@@ -8,16 +8,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint> // uint8_t
|
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
|
#include <cstdint> // uint8_t
|
||||||
#include <functional> // hash
|
#include <functional> // hash
|
||||||
|
|
||||||
#include <nlohmann/detail/abi_macros.hpp>
|
#include <nlohmann/detail/abi_macros.hpp>
|
||||||
#include <nlohmann/detail/value_t.hpp>
|
#include <nlohmann/detail/value_t.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
// boost::hash_combine
|
// boost::hash_combine
|
||||||
inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
|
inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
|
||||||
|
|||||||
@@ -32,8 +32,7 @@
|
|||||||
#include <nlohmann/detail/value_t.hpp>
|
#include <nlohmann/detail/value_t.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
/// how to treat CBOR tags
|
/// how to treat CBOR tags
|
||||||
enum class cbor_tag_handler_t
|
enum class cbor_tag_handler_t
|
||||||
@@ -80,7 +79,9 @@ class binary_reader
|
|||||||
|
|
||||||
@param[in] adapter input adapter to read from
|
@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>{};
|
||||||
}
|
}
|
||||||
@@ -147,8 +148,7 @@ class binary_reader
|
|||||||
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(current != char_traits<char_type>::eof()))
|
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,
|
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));
|
||||||
exception_message(input_format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,8 +224,7 @@ class binary_reader
|
|||||||
if (JSON_HEDLEY_UNLIKELY(len < 1))
|
if (JSON_HEDLEY_UNLIKELY(len < 1))
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
|
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));
|
||||||
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();
|
return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != char_traits<char_type>::eof();
|
||||||
@@ -246,8 +245,7 @@ class binary_reader
|
|||||||
if (JSON_HEDLEY_UNLIKELY(len < 0))
|
if (JSON_HEDLEY_UNLIKELY(len < 0))
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
|
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));
|
||||||
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
|
// All BSON binary values have a subtype
|
||||||
@@ -330,8 +328,7 @@ class binary_reader
|
|||||||
std::array<char, 3> cr{{}};
|
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()};
|
const std::string cr_str{cr.data()};
|
||||||
return sax->parse_error(element_type_parse_position, cr_str,
|
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));
|
||||||
parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -524,8 +521,7 @@ class binary_reader
|
|||||||
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{};
|
std::uint64_t number{};
|
||||||
return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1)
|
return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - static_cast<number_integer_t>(number));
|
||||||
- static_cast<number_integer_t>(number));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary data (0x00..0x17 bytes follow)
|
// Binary data (0x00..0x17 bytes follow)
|
||||||
@@ -624,7 +620,8 @@ class binary_reader
|
|||||||
case 0x96:
|
case 0x96:
|
||||||
case 0x97:
|
case 0x97:
|
||||||
return get_cbor_array(
|
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)
|
||||||
{
|
{
|
||||||
@@ -732,8 +729,7 @@ class binary_reader
|
|||||||
case cbor_tag_handler_t::error:
|
case cbor_tag_handler_t::error:
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
|
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));
|
||||||
exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case cbor_tag_handler_t::ignore:
|
case cbor_tag_handler_t::ignore:
|
||||||
@@ -852,8 +848,7 @@ class binary_reader
|
|||||||
// half-precision floating-point numbers in the C language
|
// half-precision floating-point numbers in the C language
|
||||||
// is shown in Fig. 3.
|
// is shown in Fig. 3.
|
||||||
const auto half = static_cast<unsigned int>((byte1 << 8u) + byte2);
|
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 int exp = (half >> 10u) & 0x1Fu;
|
||||||
const unsigned int mant = half & 0x3FFu;
|
const unsigned int mant = half & 0x3FFu;
|
||||||
JSON_ASSERT(0 <= exp && exp <= 32);
|
JSON_ASSERT(0 <= exp && exp <= 32);
|
||||||
@@ -872,7 +867,8 @@ class binary_reader
|
|||||||
}();
|
}();
|
||||||
return sax->number_float((half & 0x8000u) != 0
|
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)
|
||||||
@@ -890,8 +886,7 @@ class binary_reader
|
|||||||
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();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
|
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));
|
||||||
exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -986,8 +981,7 @@ class binary_reader
|
|||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
|
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));
|
||||||
exception_message(input_format_t::cbor, concat("expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token), "string"), nullptr));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1086,8 +1080,7 @@ class binary_reader
|
|||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
|
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));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1557,8 +1550,7 @@ class binary_reader
|
|||||||
default: // anything else
|
default: // anything else
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
|
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));
|
||||||
exception_message(input_format_t::msgpack, concat("invalid byte: 0x", last_token), "value"), nullptr));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1640,8 +1632,7 @@ class binary_reader
|
|||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
|
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));
|
||||||
exception_message(input_format_t::msgpack, concat("expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token), "string"), nullptr));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1659,8 +1650,7 @@ class binary_reader
|
|||||||
bool get_msgpack_binary(binary_t& result)
|
bool get_msgpack_binary(binary_t& result)
|
||||||
{
|
{
|
||||||
// helper function to set the subtype
|
// 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));
|
result.set_subtype(static_cast<std::uint8_t>(subtype));
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@@ -2034,8 +2024,7 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
if (number < 0)
|
if (number < 0)
|
||||||
{
|
{
|
||||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
|
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));
|
||||||
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;
|
return true;
|
||||||
@@ -2050,8 +2039,7 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
if (number < 0)
|
if (number < 0)
|
||||||
{
|
{
|
||||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
|
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));
|
||||||
exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr));
|
|
||||||
}
|
}
|
||||||
result = static_cast<std::size_t>(number);
|
result = static_cast<std::size_t>(number);
|
||||||
return true;
|
return true;
|
||||||
@@ -2066,8 +2054,7 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
if (number < 0)
|
if (number < 0)
|
||||||
{
|
{
|
||||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
|
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));
|
||||||
exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr));
|
|
||||||
}
|
}
|
||||||
result = static_cast<std::size_t>(number);
|
result = static_cast<std::size_t>(number);
|
||||||
return true;
|
return true;
|
||||||
@@ -2082,13 +2069,11 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
if (number < 0)
|
if (number < 0)
|
||||||
{
|
{
|
||||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
|
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));
|
||||||
exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr));
|
|
||||||
}
|
}
|
||||||
if (!value_in_range_of<std::size_t>(number))
|
if (!value_in_range_of<std::size_t>(number))
|
||||||
{
|
{
|
||||||
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
|
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "integer value overflow", "size"), nullptr));
|
||||||
exception_message(input_format, "integer value overflow", "size"), nullptr));
|
|
||||||
}
|
}
|
||||||
result = static_cast<std::size_t>(number);
|
result = static_cast<std::size_t>(number);
|
||||||
return true;
|
return true;
|
||||||
@@ -2137,8 +2122,7 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
if (!value_in_range_of<std::size_t>(number))
|
if (!value_in_range_of<std::size_t>(number))
|
||||||
{
|
{
|
||||||
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
|
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "integer value overflow", "size"), nullptr));
|
||||||
exception_message(input_format, "integer value overflow", "size"), nullptr));
|
|
||||||
}
|
}
|
||||||
result = detail::conditional_static_cast<std::size_t>(number);
|
result = detail::conditional_static_cast<std::size_t>(number);
|
||||||
return true;
|
return true;
|
||||||
@@ -2239,12 +2223,10 @@ class binary_reader
|
|||||||
if (current == '$')
|
if (current == '$')
|
||||||
{
|
{
|
||||||
result.second = get(); // must not ignore 'N', because 'N' maybe the type
|
result.second = get(); // must not ignore 'N', because 'N' maybe the type
|
||||||
if (input_format == input_format_t::bjdata
|
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)))
|
||||||
&& JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
|
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
|
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));
|
||||||
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")))
|
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "type")))
|
||||||
@@ -2260,8 +2242,7 @@ class binary_reader
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
|
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));
|
||||||
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);
|
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
||||||
@@ -2269,8 +2250,7 @@ class binary_reader
|
|||||||
{
|
{
|
||||||
if (inside_ndarray)
|
if (inside_ndarray)
|
||||||
{
|
{
|
||||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
|
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));
|
||||||
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
|
||||||
}
|
}
|
||||||
@@ -2282,8 +2262,7 @@ class binary_reader
|
|||||||
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
||||||
if (input_format == input_format_t::bjdata && 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,
|
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));
|
||||||
exception_message(input_format, "ndarray requires both type and size", "size"), nullptr));
|
|
||||||
}
|
}
|
||||||
return is_error;
|
return is_error;
|
||||||
}
|
}
|
||||||
@@ -2399,8 +2378,7 @@ class binary_reader
|
|||||||
// half-precision floating-point numbers in the C language
|
// half-precision floating-point numbers in the C language
|
||||||
// is shown in Fig. 3.
|
// is shown in Fig. 3.
|
||||||
const auto half = static_cast<unsigned int>((byte2 << 8u) + byte1);
|
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 int exp = (half >> 10u) & 0x1Fu;
|
||||||
const unsigned int mant = half & 0x3FFu;
|
const unsigned int mant = half & 0x3FFu;
|
||||||
JSON_ASSERT(0 <= exp && exp <= 32);
|
JSON_ASSERT(0 <= exp && exp <= 32);
|
||||||
@@ -2419,7 +2397,8 @@ class binary_reader
|
|||||||
}();
|
}();
|
||||||
return sax->number_float((half & 0x8000u) != 0
|
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':
|
case 'd':
|
||||||
@@ -2449,8 +2428,7 @@ class binary_reader
|
|||||||
if (JSON_HEDLEY_UNLIKELY(current > 127))
|
if (JSON_HEDLEY_UNLIKELY(current > 127))
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
|
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));
|
||||||
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));
|
string_t s(1, static_cast<typename string_t::value_type>(current));
|
||||||
return sax->string(s);
|
return sax->string(s);
|
||||||
@@ -2492,16 +2470,14 @@ class binary_reader
|
|||||||
if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
|
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
|
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;
|
return p.first < t;
|
||||||
});
|
});
|
||||||
string_t key = "_ArrayType_";
|
string_t key = "_ArrayType_";
|
||||||
if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))
|
if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
|
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));
|
||||||
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
|
||||||
@@ -2598,8 +2574,7 @@ class binary_reader
|
|||||||
if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
|
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();
|
auto last_token = get_token_string();
|
||||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
|
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));
|
||||||
exception_message(input_format, "BJData object does not support ND-array size in optimized format", "object"), nullptr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string_t key;
|
string_t key;
|
||||||
@@ -2703,8 +2678,7 @@ class binary_reader
|
|||||||
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
|
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,
|
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));
|
||||||
exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (result_number)
|
switch (result_number)
|
||||||
@@ -2730,8 +2704,7 @@ class binary_reader
|
|||||||
case token_type::end_of_input:
|
case token_type::end_of_input:
|
||||||
case token_type::literal_or_value:
|
case token_type::literal_or_value:
|
||||||
default:
|
default:
|
||||||
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
|
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));
|
||||||
exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2762,8 +2735,7 @@ class binary_reader
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
get();
|
get();
|
||||||
}
|
} while (current == 'N');
|
||||||
while (current == 'N');
|
|
||||||
|
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
@@ -2888,8 +2860,7 @@ class binary_reader
|
|||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof()))
|
if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof()))
|
||||||
{
|
{
|
||||||
return sax->parse_error(chars_read, "<end of file>",
|
return sax->parse_error(chars_read, "<end of file>", parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr));
|
||||||
parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr));
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,11 +28,18 @@
|
|||||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
/// the supported input formats
|
/// 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 //
|
// input adapters //
|
||||||
@@ -97,7 +104,8 @@ class input_stream_adapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
explicit input_stream_adapter(std::istream& i)
|
explicit input_stream_adapter(std::istream& i)
|
||||||
: is(&i), sb(i.rdbuf())
|
: is(&i)
|
||||||
|
, sb(i.rdbuf())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// delete because of pointer members
|
// delete because of pointer members
|
||||||
@@ -106,7 +114,8 @@ class input_stream_adapter
|
|||||||
input_stream_adapter& operator=(input_stream_adapter&&) = delete;
|
input_stream_adapter& operator=(input_stream_adapter&&) = delete;
|
||||||
|
|
||||||
input_stream_adapter(input_stream_adapter&& rhs) noexcept
|
input_stream_adapter(input_stream_adapter&& rhs) noexcept
|
||||||
: is(rhs.is), sb(rhs.sb)
|
: is(rhs.is)
|
||||||
|
, sb(rhs.sb)
|
||||||
{
|
{
|
||||||
rhs.is = nullptr;
|
rhs.is = nullptr;
|
||||||
rhs.sb = nullptr;
|
rhs.sb = nullptr;
|
||||||
@@ -142,7 +151,8 @@ class iterator_input_adapter
|
|||||||
using char_type = typename std::iterator_traits<IteratorType>::value_type;
|
using char_type = typename std::iterator_traits<IteratorType>::value_type;
|
||||||
|
|
||||||
iterator_input_adapter(IteratorType first, IteratorType last)
|
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()
|
typename char_traits<char_type>::int_type get_character()
|
||||||
@@ -301,7 +311,8 @@ class wide_string_input_adapter
|
|||||||
using char_type = char;
|
using char_type = char;
|
||||||
|
|
||||||
wide_string_input_adapter(BaseInputAdapter base)
|
wide_string_input_adapter(BaseInputAdapter base)
|
||||||
: base_adapter(base) {}
|
: base_adapter(base)
|
||||||
|
{}
|
||||||
|
|
||||||
typename std::char_traits<char>::int_type get_character() noexcept
|
typename std::char_traits<char>::int_type get_character() noexcept
|
||||||
{
|
{
|
||||||
@@ -387,14 +398,14 @@ typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapte
|
|||||||
// Enables ADL on begin(container) and end(container)
|
// Enables ADL on begin(container) and end(container)
|
||||||
// Encloses the using declarations in namespace for not to leak them to outside scope
|
// 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::begin;
|
||||||
using std::end;
|
using std::end;
|
||||||
|
|
||||||
template<typename ContainerType, typename Enable = void>
|
template<typename ContainerType, typename Enable = void>
|
||||||
struct container_input_adapter_factory {};
|
struct container_input_adapter_factory
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
struct container_input_adapter_factory<ContainerType,
|
struct container_input_adapter_factory<ContainerType,
|
||||||
@@ -470,14 +481,16 @@ class span_input_adapter
|
|||||||
sizeof(typename std::remove_pointer<CharT>::type) == 1,
|
sizeof(typename std::remove_pointer<CharT>::type) == 1,
|
||||||
int>::type = 0>
|
int>::type = 0>
|
||||||
span_input_adapter(CharT b, std::size_t l)
|
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,
|
template<class IteratorType,
|
||||||
typename std::enable_if<
|
typename std::enable_if<
|
||||||
std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
|
std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
|
||||||
int>::type = 0>
|
int>::type = 0>
|
||||||
span_input_adapter(IteratorType first, IteratorType last)
|
span_input_adapter(IteratorType first, IteratorType last)
|
||||||
: ia(input_adapter(first, last)) {}
|
: ia(input_adapter(first, last))
|
||||||
|
{}
|
||||||
|
|
||||||
contiguous_bytes_input_adapter&& get()
|
contiguous_bytes_input_adapter&& get()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -142,8 +142,7 @@ struct json_sax
|
|||||||
virtual ~json_sax() = default;
|
virtual ~json_sax() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
/*!
|
/*!
|
||||||
@brief SAX implementation to create a JSON value from SAX events
|
@brief SAX implementation to create a JSON value from SAX events
|
||||||
|
|
||||||
@@ -173,7 +172,8 @@ class json_sax_dom_parser
|
|||||||
@param[in] allow_exceptions_ whether parse errors yield exceptions
|
@param[in] allow_exceptions_ whether parse errors yield exceptions
|
||||||
*/
|
*/
|
||||||
explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true)
|
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
|
// make class move-only
|
||||||
@@ -280,8 +280,7 @@ class json_sax_dom_parser
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class Exception>
|
template<class Exception>
|
||||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,
|
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex)
|
||||||
const Exception& ex)
|
|
||||||
{
|
{
|
||||||
errored = true;
|
errored = true;
|
||||||
static_cast<void>(ex);
|
static_cast<void>(ex);
|
||||||
@@ -306,7 +305,8 @@ class json_sax_dom_parser
|
|||||||
*/
|
*/
|
||||||
template<typename Value>
|
template<typename Value>
|
||||||
JSON_HEDLEY_RETURNS_NON_NULL
|
JSON_HEDLEY_RETURNS_NON_NULL
|
||||||
BasicJsonType* handle_value(Value&& v)
|
BasicJsonType*
|
||||||
|
handle_value(Value&& v)
|
||||||
{
|
{
|
||||||
if (ref_stack.empty())
|
if (ref_stack.empty())
|
||||||
{
|
{
|
||||||
@@ -355,7 +355,9 @@ class json_sax_dom_callback_parser
|
|||||||
json_sax_dom_callback_parser(BasicJsonType& r,
|
json_sax_dom_callback_parser(BasicJsonType& r,
|
||||||
const parser_callback_t cb,
|
const parser_callback_t cb,
|
||||||
const bool allow_exceptions_ = true)
|
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);
|
keep_stack.push_back(true);
|
||||||
}
|
}
|
||||||
@@ -530,8 +532,7 @@ class json_sax_dom_callback_parser
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class Exception>
|
template<class Exception>
|
||||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,
|
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const Exception& ex)
|
||||||
const Exception& ex)
|
|
||||||
{
|
{
|
||||||
errored = true;
|
errored = true;
|
||||||
static_cast<void>(ex);
|
static_cast<void>(ex);
|
||||||
|
|||||||
@@ -24,8 +24,7 @@
|
|||||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
///////////
|
///////////
|
||||||
// lexer //
|
// lexer //
|
||||||
@@ -1298,8 +1297,7 @@ scan_number_done:
|
|||||||
@param[in] return_type the token type to return on success
|
@param[in] return_type the token type to return on success
|
||||||
*/
|
*/
|
||||||
JSON_HEDLEY_NON_NULL(2)
|
JSON_HEDLEY_NON_NULL(2)
|
||||||
token_type scan_literal(const char_type* literal_text, const std::size_t length,
|
token_type scan_literal(const char_type* literal_text, const std::size_t length, token_type return_type)
|
||||||
token_type return_type)
|
|
||||||
{
|
{
|
||||||
JSON_ASSERT(char_traits<char_type>::to_char_type(current) == literal_text[0]);
|
JSON_ASSERT(char_traits<char_type>::to_char_type(current) == literal_text[0]);
|
||||||
for (std::size_t i = 1; i < length; ++i)
|
for (std::size_t i = 1; i < length; ++i)
|
||||||
@@ -1503,8 +1501,7 @@ scan_number_done:
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
get();
|
get();
|
||||||
}
|
} while (current == ' ' || current == '\t' || current == '\n' || current == '\r');
|
||||||
while (current == ' ' || current == '\t' || current == '\n' || current == '\r');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
token_type scan()
|
token_type scan()
|
||||||
|
|||||||
@@ -25,8 +25,7 @@
|
|||||||
#include <nlohmann/detail/value_t.hpp>
|
#include <nlohmann/detail/value_t.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
////////////
|
////////////
|
||||||
// parser //
|
// parser //
|
||||||
////////////
|
////////////
|
||||||
@@ -102,8 +101,7 @@ class parser
|
|||||||
{
|
{
|
||||||
sdp.parse_error(m_lexer.get_position(),
|
sdp.parse_error(m_lexer.get_position(),
|
||||||
m_lexer.get_token_string(),
|
m_lexer.get_token_string(),
|
||||||
parse_error::create(101, m_lexer.get_position(),
|
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr));
|
||||||
exception_message(token_type::end_of_input, "value"), nullptr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case of an error, return discarded value
|
// in case of an error, return discarded value
|
||||||
@@ -347,8 +345,7 @@ class parser
|
|||||||
{
|
{
|
||||||
return sax->parse_error(m_lexer.get_position(),
|
return sax->parse_error(m_lexer.get_position(),
|
||||||
m_lexer.get_token_string(),
|
m_lexer.get_token_string(),
|
||||||
parse_error::create(101, m_lexer.get_position(),
|
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));
|
||||||
"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(),
|
return sax->parse_error(m_lexer.get_position(),
|
||||||
@@ -488,8 +485,7 @@ class parser
|
|||||||
|
|
||||||
if (last_token == token_type::parse_error)
|
if (last_token == token_type::parse_error)
|
||||||
{
|
{
|
||||||
error_msg += concat(m_lexer.get_error_message(), "; last read: '",
|
error_msg += concat(m_lexer.get_error_message(), "; last read: '", m_lexer.get_token_string(), '\'');
|
||||||
m_lexer.get_token_string(), '\'');
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,8 +13,7 @@
|
|||||||
#include <nlohmann/detail/abi_macros.hpp>
|
#include <nlohmann/detail/abi_macros.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
/// struct to capture the start position of the current token
|
/// struct to capture the start position of the current token
|
||||||
struct position_t
|
struct position_t
|
||||||
|
|||||||
@@ -12,8 +12,7 @@
|
|||||||
#include <nlohmann/detail/iterators/primitive_iterator.hpp>
|
#include <nlohmann/detail/iterators/primitive_iterator.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief an iterator value
|
@brief an iterator value
|
||||||
@@ -21,7 +20,8 @@ namespace detail
|
|||||||
@note This structure could easily be a union, but MSVC currently does not allow
|
@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.
|
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
|
/// iterator for JSON objects
|
||||||
typename BasicJsonType::object_t::iterator object_iterator{};
|
typename BasicJsonType::object_t::iterator object_iterator{};
|
||||||
|
|||||||
@@ -20,12 +20,13 @@
|
|||||||
#include <nlohmann/detail/value_t.hpp>
|
#include <nlohmann/detail/value_t.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
// forward declare, to be able to friend it later on
|
// forward declare, to be able to friend it later on
|
||||||
template<typename IteratorType> class iteration_proxy;
|
template<typename IteratorType>
|
||||||
template<typename IteratorType> class iteration_proxy_value;
|
class iteration_proxy;
|
||||||
|
template<typename IteratorType>
|
||||||
|
class iteration_proxy_value;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief a template for a bidirectional iterator for the @ref basic_json class
|
@brief a template for a bidirectional iterator for the @ref basic_json class
|
||||||
@@ -60,8 +61,7 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
|
|||||||
static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value,
|
static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value,
|
||||||
"iter_impl only accepts (const) basic_json");
|
"iter_impl only accepts (const) basic_json");
|
||||||
// superficial check for the LegacyBidirectionalIterator named requirement
|
// superficial check for the LegacyBidirectionalIterator named requirement
|
||||||
static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::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,
|
||||||
&& 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.");
|
"basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement.");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -97,7 +97,8 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
|
|||||||
@pre object != nullptr
|
@pre object != nullptr
|
||||||
@post The iterator is initialized; i.e. `m_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);
|
JSON_ASSERT(m_object != nullptr);
|
||||||
|
|
||||||
@@ -148,7 +149,8 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
|
|||||||
information refer to: https://github.com/nlohmann/json/issues/1608
|
information refer to: https://github.com/nlohmann/json/issues/1608
|
||||||
*/
|
*/
|
||||||
iter_impl(const iter_impl<const BasicJsonType>& other) noexcept
|
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 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
|
|||||||
@note It is not checked whether @a other is initialized.
|
@note It is not checked whether @a other is initialized.
|
||||||
*/
|
*/
|
||||||
iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept
|
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)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -194,7 +197,8 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
|
|||||||
@brief set the iterator to the first value
|
@brief set the iterator to the first value
|
||||||
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
||||||
*/
|
*/
|
||||||
void set_begin() noexcept
|
void
|
||||||
|
set_begin() noexcept
|
||||||
{
|
{
|
||||||
JSON_ASSERT(m_object != nullptr);
|
JSON_ASSERT(m_object != nullptr);
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,7 @@
|
|||||||
#include <nlohmann/detail/value_t.hpp>
|
#include <nlohmann/detail/value_t.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename string_type>
|
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)
|
||||||
@@ -33,7 +32,8 @@ void int_to_string( string_type& target, std::size_t value )
|
|||||||
using std::to_string;
|
using std::to_string;
|
||||||
target = to_string(value);
|
target = to_string(value);
|
||||||
}
|
}
|
||||||
template<typename IteratorType> class iteration_proxy_value
|
template<typename IteratorType>
|
||||||
|
class iteration_proxy_value
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using difference_type = std::ptrdiff_t;
|
using difference_type = std::ptrdiff_t;
|
||||||
@@ -57,9 +57,7 @@ template<typename IteratorType> class iteration_proxy_value
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit iteration_proxy_value() = default;
|
explicit iteration_proxy_value() = default;
|
||||||
explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0)
|
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)
|
||||||
noexcept(std::is_nothrow_move_constructible<IteratorType>::value
|
|
||||||
&& std::is_nothrow_default_constructible<string_type>::value)
|
|
||||||
: anchor(std::move(it))
|
: anchor(std::move(it))
|
||||||
, array_index(array_index_)
|
, array_index(array_index_)
|
||||||
{}
|
{}
|
||||||
@@ -67,12 +65,8 @@ template<typename IteratorType> class iteration_proxy_value
|
|||||||
iteration_proxy_value(iteration_proxy_value const&) = default;
|
iteration_proxy_value(iteration_proxy_value const&) = default;
|
||||||
iteration_proxy_value& operator=(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
|
// older GCCs are a bit fussy and require explicit noexcept specifiers on defaulted functions
|
||||||
iteration_proxy_value(iteration_proxy_value&&)
|
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)
|
||||||
noexcept(std::is_nothrow_move_constructible<IteratorType>::value
|
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)
|
||||||
&& 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;
|
~iteration_proxy_value() = default;
|
||||||
|
|
||||||
/// dereference operator (needed for range-based for)
|
/// dereference operator (needed for range-based for)
|
||||||
@@ -154,7 +148,8 @@ template<typename IteratorType> class iteration_proxy_value
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// proxy class for the items() function
|
/// proxy class for the items() function
|
||||||
template<typename IteratorType> class iteration_proxy
|
template<typename IteratorType>
|
||||||
|
class iteration_proxy
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
/// the container to iterate
|
/// the container to iterate
|
||||||
@@ -165,7 +160,8 @@ template<typename IteratorType> class iteration_proxy
|
|||||||
|
|
||||||
/// construct iteration proxy from a container
|
/// construct iteration proxy from a container
|
||||||
explicit iteration_proxy(typename IteratorType::reference cont) noexcept
|
explicit iteration_proxy(typename IteratorType::reference cont) noexcept
|
||||||
: container(&cont) {}
|
: container(&cont)
|
||||||
|
{}
|
||||||
|
|
||||||
iteration_proxy(iteration_proxy const&) = default;
|
iteration_proxy(iteration_proxy const&) = default;
|
||||||
iteration_proxy& operator=(iteration_proxy const&) = default;
|
iteration_proxy& operator=(iteration_proxy const&) = default;
|
||||||
@@ -210,8 +206,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
// Structured Bindings Support to the iteration_proxy_value class
|
// Structured Bindings Support to the iteration_proxy_value class
|
||||||
// For further reference see https://blog.tartanllama.xyz/structured-bindings/
|
// For further reference see https://blog.tartanllama.xyz/structured-bindings/
|
||||||
// And see https://github.com/nlohmann/json/pull/1391
|
// And see https://github.com/nlohmann/json/pull/1391
|
||||||
namespace std
|
namespace std {
|
||||||
{
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
// Fix: https://github.com/nlohmann/json/issues/1401
|
// Fix: https://github.com/nlohmann/json/issues/1401
|
||||||
@@ -220,14 +215,14 @@ namespace std
|
|||||||
#endif
|
#endif
|
||||||
template<typename IteratorType>
|
template<typename IteratorType>
|
||||||
class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp)
|
class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp)
|
||||||
: public std::integral_constant<std::size_t, 2> {};
|
: public std::integral_constant<std::size_t, 2>
|
||||||
|
{};
|
||||||
|
|
||||||
template<std::size_t N, typename IteratorType>
|
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:
|
public:
|
||||||
using type = decltype(
|
using type = decltype(get<N>(std::declval<
|
||||||
get<N>(std::declval <
|
|
||||||
::nlohmann::detail::iteration_proxy_value<IteratorType>>()));
|
::nlohmann::detail::iteration_proxy_value<IteratorType>>()));
|
||||||
};
|
};
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
|
|||||||
@@ -11,21 +11,20 @@
|
|||||||
#include <iterator> // random_access_iterator_tag
|
#include <iterator> // random_access_iterator_tag
|
||||||
|
|
||||||
#include <nlohmann/detail/abi_macros.hpp>
|
#include <nlohmann/detail/abi_macros.hpp>
|
||||||
#include <nlohmann/detail/meta/void_t.hpp>
|
|
||||||
#include <nlohmann/detail/meta/cpp_future.hpp>
|
#include <nlohmann/detail/meta/cpp_future.hpp>
|
||||||
|
#include <nlohmann/detail/meta/void_t.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename It, typename = void>
|
template<typename It, typename = void>
|
||||||
struct iterator_types {};
|
struct iterator_types
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename It>
|
template<typename It>
|
||||||
struct iterator_types<
|
struct iterator_types<
|
||||||
It,
|
It,
|
||||||
void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
|
void_t<typename It::difference_type, typename It::value_type, typename It::pointer, typename It::reference, typename It::iterator_category>>
|
||||||
typename It::reference, typename It::iterator_category >>
|
|
||||||
{
|
{
|
||||||
using difference_type = typename It::difference_type;
|
using difference_type = typename It::difference_type;
|
||||||
using value_type = typename It::value_type;
|
using value_type = typename It::value_type;
|
||||||
|
|||||||
@@ -15,8 +15,7 @@
|
|||||||
#include <nlohmann/detail/abi_macros.hpp>
|
#include <nlohmann/detail/abi_macros.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// reverse_iterator //
|
// reverse_iterator //
|
||||||
@@ -52,10 +51,13 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
|
|||||||
|
|
||||||
/// create reverse iterator from iterator
|
/// create reverse iterator from iterator
|
||||||
explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
|
explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
|
||||||
: base_iterator(it) {}
|
: base_iterator(it)
|
||||||
|
{}
|
||||||
|
|
||||||
/// create reverse iterator from base class
|
/// 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++)
|
/// post-increment (it++)
|
||||||
json_reverse_iterator operator++(int) & // NOLINT(cert-dcl21-cpp)
|
json_reverse_iterator operator++(int) & // NOLINT(cert-dcl21-cpp)
|
||||||
|
|||||||
@@ -14,8 +14,7 @@
|
|||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@brief an iterator for primitive JSON types
|
@brief an iterator for primitive JSON types
|
||||||
|
|||||||
@@ -13,8 +13,7 @@
|
|||||||
#include <nlohmann/detail/abi_macros.hpp>
|
#include <nlohmann/detail/abi_macros.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief Default base class of the @ref basic_json class.
|
@brief Default base class of the @ref basic_json class.
|
||||||
@@ -26,14 +25,14 @@ of @ref basic_json do not require complex case distinctions
|
|||||||
By default, this class is used because it is empty and thus has no effect
|
By default, this class is used because it is empty and thus has no effect
|
||||||
on the behavior of @ref basic_json.
|
on the behavior of @ref basic_json.
|
||||||
*/
|
*/
|
||||||
struct json_default_base {};
|
struct json_default_base
|
||||||
|
{};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
using json_base_class = typename std::conditional<
|
using json_base_class = typename std::conditional<
|
||||||
std::is_same<T, void>::value,
|
std::is_same<T, void>::value,
|
||||||
json_default_base,
|
json_default_base,
|
||||||
T
|
T>::type;
|
||||||
>::type;
|
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
NLOHMANN_JSON_NAMESPACE_END
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
@@ -67,10 +67,7 @@ class json_pointer
|
|||||||
/// @sa https://json.nlohmann.me/api/json_pointer/to_string/
|
/// @sa https://json.nlohmann.me/api/json_pointer/to_string/
|
||||||
string_t to_string() const
|
string_t to_string() const
|
||||||
{
|
{
|
||||||
return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
|
return std::accumulate(reference_tokens.begin(), reference_tokens.end(), string_t{}, [](const string_t& a, const string_t& b) {
|
||||||
string_t{},
|
|
||||||
[](const string_t& a, const string_t& b)
|
|
||||||
{
|
|
||||||
return detail::concat(a, '/', detail::escape(b));
|
return detail::concat(a, '/', detail::escape(b));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -248,8 +245,7 @@ class json_pointer
|
|||||||
return static_cast<size_type>(res);
|
return static_cast<size_type>(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED:
|
JSON_PRIVATE_UNLESS_TESTED : json_pointer top() const
|
||||||
json_pointer top() const
|
|
||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||||
{
|
{
|
||||||
@@ -360,9 +356,7 @@ class json_pointer
|
|||||||
{
|
{
|
||||||
// check if reference token is a number
|
// check if reference token is a number
|
||||||
const bool nums =
|
const bool nums =
|
||||||
std::all_of(reference_token.begin(), reference_token.end(),
|
std::all_of(reference_token.begin(), reference_token.end(), [](const unsigned char x) {
|
||||||
[](const unsigned char x)
|
|
||||||
{
|
|
||||||
return std::isdigit(x);
|
return std::isdigit(x);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -437,9 +431,7 @@ class json_pointer
|
|||||||
if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
|
if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
|
||||||
{
|
{
|
||||||
// "-" always fails the range check
|
// "-" always fails the range check
|
||||||
JSON_THROW(detail::out_of_range::create(402, detail::concat(
|
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));
|
||||||
"array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
|
|
||||||
") is out of range"), ptr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// note: at performs range check
|
// note: at performs range check
|
||||||
@@ -544,9 +536,7 @@ class json_pointer
|
|||||||
if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
|
if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
|
||||||
{
|
{
|
||||||
// "-" always fails the range check
|
// "-" always fails the range check
|
||||||
JSON_THROW(detail::out_of_range::create(402, detail::concat(
|
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));
|
||||||
"array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
|
|
||||||
") is out of range"), ptr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// note: at performs range check
|
// note: at performs range check
|
||||||
@@ -751,7 +741,8 @@ class json_pointer
|
|||||||
for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i)
|
for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i)
|
||||||
{
|
{
|
||||||
flatten(detail::concat(reference_string, '/', std::to_string(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;
|
break;
|
||||||
|
|||||||
@@ -15,8 +15,7 @@
|
|||||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
class json_ref
|
class json_ref
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <utility> // declval, pair
|
|
||||||
#include <nlohmann/detail/meta/detected.hpp>
|
#include <nlohmann/detail/meta/detected.hpp>
|
||||||
#include <nlohmann/thirdparty/hedley/hedley.hpp>
|
#include <nlohmann/thirdparty/hedley/hedley.hpp>
|
||||||
|
#include <utility> // declval, pair
|
||||||
|
|
||||||
// This file contains all internal macro definitions (except those affecting ABI)
|
// 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
|
// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them
|
||||||
@@ -114,8 +114,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef JSON_HAS_THREE_WAY_COMPARISON
|
#ifndef JSON_HAS_THREE_WAY_COMPARISON
|
||||||
#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_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
|
||||||
&& defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L
|
|
||||||
#define JSON_HAS_THREE_WAY_COMPARISON 1
|
#define JSON_HAS_THREE_WAY_COMPARISON 1
|
||||||
#else
|
#else
|
||||||
#define JSON_HAS_THREE_WAY_COMPARISON 0
|
#define JSON_HAS_THREE_WAY_COMPARISON 0
|
||||||
@@ -218,9 +217,7 @@
|
|||||||
{ \
|
{ \
|
||||||
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
||||||
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
||||||
auto it = std::find_if(std::begin(m), std::end(m), \
|
auto it = std::find_if(std::begin(m), std::end(m), [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool { \
|
||||||
[e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
|
||||||
{ \
|
|
||||||
return ej_pair.first == e; \
|
return ej_pair.first == e; \
|
||||||
}); \
|
}); \
|
||||||
j = ((it != std::end(m)) ? it : std::begin(m))->second; \
|
j = ((it != std::end(m)) ? it : std::begin(m))->second; \
|
||||||
@@ -230,9 +227,7 @@
|
|||||||
{ \
|
{ \
|
||||||
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
||||||
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
||||||
auto it = std::find_if(std::begin(m), std::end(m), \
|
auto it = std::find_if(std::begin(m), std::end(m), [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool { \
|
||||||
[&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
|
||||||
{ \
|
|
||||||
return ej_pair.second == j; \
|
return ej_pair.second == j; \
|
||||||
}); \
|
}); \
|
||||||
e = ((it != std::end(m)) ? it : std::begin(m))->first; \
|
e = ((it != std::end(m)) ? it : std::begin(m))->first; \
|
||||||
@@ -243,18 +238,22 @@
|
|||||||
|
|
||||||
#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
|
#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
|
||||||
template<template<typename, typename, typename...> class ObjectType, \
|
template<template<typename, typename, typename...> class ObjectType, \
|
||||||
template<typename, typename...> class ArrayType, \
|
template<typename, typename...> \
|
||||||
class StringType, class BooleanType, class NumberIntegerType, \
|
class ArrayType, \
|
||||||
class NumberUnsignedType, class NumberFloatType, \
|
class StringType, \
|
||||||
template<typename> class AllocatorType, \
|
class BooleanType, \
|
||||||
template<typename, typename = void> class JSONSerializer, \
|
class NumberIntegerType, \
|
||||||
|
class NumberUnsignedType, \
|
||||||
|
class NumberFloatType, \
|
||||||
|
template<typename> \
|
||||||
|
class AllocatorType, \
|
||||||
|
template<typename, typename = void> \
|
||||||
|
class JSONSerializer, \
|
||||||
class BinaryType, \
|
class BinaryType, \
|
||||||
class CustomBaseClass>
|
class CustomBaseClass>
|
||||||
|
|
||||||
#define NLOHMANN_BASIC_JSON_TPL \
|
#define NLOHMANN_BASIC_JSON_TPL \
|
||||||
basic_json<ObjectType, ArrayType, StringType, BooleanType, \
|
basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>
|
||||||
NumberIntegerType, NumberUnsignedType, NumberFloatType, \
|
|
||||||
AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>
|
|
||||||
|
|
||||||
// Macros to simplify conversion from/to types
|
// Macros to simplify conversion from/to types
|
||||||
|
|
||||||
@@ -399,15 +398,31 @@
|
|||||||
@since version 3.9.0
|
@since version 3.9.0
|
||||||
*/
|
*/
|
||||||
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
|
#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 to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \
|
||||||
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__)) }
|
{ \
|
||||||
|
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, ...) \
|
#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 to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \
|
||||||
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__)) }
|
{ \
|
||||||
|
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, ...) \
|
#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__)) }
|
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
|
@brief macro
|
||||||
@@ -415,15 +430,31 @@
|
|||||||
@since version 3.9.0
|
@since version 3.9.0
|
||||||
*/
|
*/
|
||||||
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
|
#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 to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \
|
||||||
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__)) }
|
{ \
|
||||||
|
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, ...) \
|
#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__)) }
|
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, ...) \
|
#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 to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \
|
||||||
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__)) }
|
{ \
|
||||||
|
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
|
// inspired from https://stackoverflow.com/a/26745591
|
||||||
// allows to call any std function as if (e.g. with begin):
|
// allows to call any std function as if (e.g. with begin):
|
||||||
|
|||||||
@@ -17,8 +17,7 @@
|
|||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
|
using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
|
||||||
@@ -28,8 +27,8 @@ using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::typ
|
|||||||
// the following utilities are natively available in C++14
|
// the following utilities are natively available in C++14
|
||||||
using std::enable_if_t;
|
using std::enable_if_t;
|
||||||
using std::index_sequence;
|
using std::index_sequence;
|
||||||
using std::make_index_sequence;
|
|
||||||
using std::index_sequence_for;
|
using std::index_sequence_for;
|
||||||
|
using std::make_index_sequence;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -79,8 +78,7 @@ struct integer_sequence
|
|||||||
template<size_t... Ints>
|
template<size_t... Ints>
|
||||||
using index_sequence = integer_sequence<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;
|
struct Extend;
|
||||||
@@ -146,8 +144,12 @@ using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// dispatch utility (taken from ranges-v3)
|
// dispatch utility (taken from ranges-v3)
|
||||||
template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
|
template<unsigned N>
|
||||||
template<> struct priority_tag<0> {};
|
struct priority_tag : priority_tag<N - 1>
|
||||||
|
{};
|
||||||
|
template<>
|
||||||
|
struct priority_tag<0>
|
||||||
|
{};
|
||||||
|
|
||||||
// taken from ranges-v3
|
// taken from ranges-v3
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
@@ -13,8 +13,7 @@
|
|||||||
#include <nlohmann/detail/meta/void_t.hpp>
|
#include <nlohmann/detail/meta/void_t.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
// https://en.cppreference.com/w/cpp/experimental/is_detected
|
// https://en.cppreference.com/w/cpp/experimental/is_detected
|
||||||
struct nonesuch
|
struct nonesuch
|
||||||
@@ -29,7 +28,8 @@ struct nonesuch
|
|||||||
|
|
||||||
template<class Default,
|
template<class Default,
|
||||||
class AlwaysVoid,
|
class AlwaysVoid,
|
||||||
template<class...> class Op,
|
template<class...>
|
||||||
|
class Op,
|
||||||
class... Args>
|
class... Args>
|
||||||
struct detector
|
struct detector
|
||||||
{
|
{
|
||||||
@@ -48,7 +48,8 @@ template<template<class...> class Op, class... Args>
|
|||||||
using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
|
using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
|
||||||
|
|
||||||
template<template<class...> class Op, class... Args>
|
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>
|
template<template<class...> class Op, class... Args>
|
||||||
using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
|
using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
|
||||||
|
|||||||
@@ -11,11 +11,12 @@
|
|||||||
#include <nlohmann/detail/abi_macros.hpp>
|
#include <nlohmann/detail/abi_macros.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
// dispatching helper struct
|
// dispatching helper struct
|
||||||
template <class T> struct identity_tag {};
|
template<class T>
|
||||||
|
struct identity_tag
|
||||||
|
{};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
NLOHMANN_JSON_NAMESPACE_END
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
@@ -9,16 +9,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint> // size_t
|
#include <cstdint> // size_t
|
||||||
#include <utility> // declval
|
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
|
#include <utility> // declval
|
||||||
|
|
||||||
#include <nlohmann/detail/abi_macros.hpp>
|
#include <nlohmann/detail/abi_macros.hpp>
|
||||||
#include <nlohmann/detail/meta/detected.hpp>
|
#include <nlohmann/detail/meta/detected.hpp>
|
||||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using null_function_t = decltype(std::declval<T&>().null());
|
using null_function_t = decltype(std::declval<T&>().null());
|
||||||
@@ -37,7 +36,8 @@ using number_unsigned_function_t =
|
|||||||
|
|
||||||
template<typename T, typename Float, typename String>
|
template<typename T, typename Float, typename String>
|
||||||
using number_float_function_t = decltype(std::declval<T&>().number_float(
|
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>
|
template<typename T, typename String>
|
||||||
using string_function_t =
|
using string_function_t =
|
||||||
@@ -67,7 +67,8 @@ using end_array_function_t = decltype(std::declval<T&>().end_array());
|
|||||||
|
|
||||||
template<typename T, typename Exception>
|
template<typename T, typename Exception>
|
||||||
using parse_error_function_t = decltype(std::declval<T&>().parse_error(
|
using parse_error_function_t = decltype(std::declval<T&>().parse_error(
|
||||||
std::declval<std::size_t>(), std::declval<const std::string&>(),
|
std::declval<std::size_t>(),
|
||||||
|
std::declval<const std::string&>(),
|
||||||
std::declval<const Exception&>()));
|
std::declval<const Exception&>()));
|
||||||
|
|
||||||
template<typename SAX, typename BasicJsonType>
|
template<typename SAX, typename BasicJsonType>
|
||||||
@@ -123,15 +124,12 @@ struct is_sax_static_asserts
|
|||||||
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
|
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
|
||||||
"Missing/invalid function: bool boolean(bool)");
|
"Missing/invalid function: bool boolean(bool)");
|
||||||
static_assert(
|
static_assert(
|
||||||
is_detected_exact<bool, number_integer_function_t, SAX,
|
is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value,
|
||||||
number_integer_t>::value,
|
|
||||||
"Missing/invalid function: bool number_integer(number_integer_t)");
|
"Missing/invalid function: bool number_integer(number_integer_t)");
|
||||||
static_assert(
|
static_assert(
|
||||||
is_detected_exact<bool, number_unsigned_function_t, SAX,
|
is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value,
|
||||||
number_unsigned_t>::value,
|
|
||||||
"Missing/invalid function: bool number_unsigned(number_unsigned_t)");
|
"Missing/invalid function: bool number_unsigned(number_unsigned_t)");
|
||||||
static_assert(is_detected_exact<bool, number_float_function_t, SAX,
|
static_assert(is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value,
|
||||||
number_float_t, string_t>::value,
|
|
||||||
"Missing/invalid function: bool number_float(number_float_t, const string_t&)");
|
"Missing/invalid function: bool number_float(number_float_t, const string_t&)");
|
||||||
static_assert(
|
static_assert(
|
||||||
is_detected_exact<bool, string_function_t, SAX, string_t>::value,
|
is_detected_exact<bool, string_function_t, SAX, string_t>::value,
|
||||||
|
|||||||
@@ -13,16 +13,14 @@
|
|||||||
#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
||||||
#include <experimental/filesystem>
|
#include <experimental/filesystem>
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
namespace std_fs = std::experimental::filesystem;
|
namespace std_fs = std::experimental::filesystem;
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
NLOHMANN_JSON_NAMESPACE_END
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
#elif JSON_HAS_FILESYSTEM
|
#elif JSON_HAS_FILESYSTEM
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
namespace std_fs = std::filesystem;
|
namespace std_fs = std::filesystem;
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
NLOHMANN_JSON_NAMESPACE_END
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
|
|||||||
@@ -9,10 +9,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <limits> // numeric_limits
|
#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 <type_traits> // false_type, is_constructible, is_integral, is_same, true_type
|
||||||
#include <utility> // declval
|
#include <utility> // declval
|
||||||
#include <tuple> // tuple
|
|
||||||
#include <string> // char_traits
|
|
||||||
|
|
||||||
#include <nlohmann/detail/iterators/iterator_traits.hpp>
|
#include <nlohmann/detail/iterators/iterator_traits.hpp>
|
||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
@@ -31,8 +31,7 @@ implementations of some @ref basic_json methods, and meta-programming helpers.
|
|||||||
|
|
||||||
@since version 2.1.0
|
@since version 2.1.0
|
||||||
*/
|
*/
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
/////////////
|
/////////////
|
||||||
// helpers //
|
// helpers //
|
||||||
@@ -47,19 +46,20 @@ namespace detail
|
|||||||
// In this case, T has to be properly CV-qualified to constraint the function arguments
|
// In this case, T has to be properly CV-qualified to constraint the function arguments
|
||||||
// (e.g. to_json(BasicJsonType&, const T&))
|
// (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
|
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
|
// used by exceptions create() member functions
|
||||||
// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t
|
// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t
|
||||||
// false_type otherwise
|
// false_type otherwise
|
||||||
template<typename BasicJsonContext>
|
template<typename BasicJsonContext>
|
||||||
struct is_basic_json_context :
|
struct is_basic_json_context : std::integral_constant<bool,
|
||||||
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>
|
||||||
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 @@ template<typename>
|
|||||||
class json_ref;
|
class json_ref;
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
struct is_json_ref : std::false_type {};
|
struct is_json_ref : std::false_type
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename T>
|
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 //
|
// aliases for detected //
|
||||||
@@ -111,7 +113,8 @@ using get_template_function = decltype(std::declval<T>().template get<U>());
|
|||||||
|
|
||||||
// trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists
|
// trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists
|
||||||
template<typename BasicJsonType, typename T, typename = void>
|
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
|
// trait checking if j.get<T> is valid
|
||||||
// use this trait instead of std::is_constructible or std::is_convertible,
|
// use this trait instead of std::is_constructible or std::is_convertible,
|
||||||
@@ -129,14 +132,14 @@ struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value
|
|||||||
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
||||||
|
|
||||||
static constexpr bool value =
|
static constexpr bool value =
|
||||||
is_detected_exact<void, from_json_function, serializer,
|
is_detected_exact<void, from_json_function, serializer, const BasicJsonType&, T&>::value;
|
||||||
const BasicJsonType&, T&>::value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// This trait checks if JSONSerializer<T>::from_json(json const&) exists
|
// This trait checks if JSONSerializer<T>::from_json(json const&) exists
|
||||||
// this overload is used for non-default-constructible user-defined-types
|
// this overload is used for non-default-constructible user-defined-types
|
||||||
template<typename BasicJsonType, typename T, typename = void>
|
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>
|
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>>
|
||||||
@@ -144,14 +147,14 @@ struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_jso
|
|||||||
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
||||||
|
|
||||||
static constexpr bool value =
|
static constexpr bool value =
|
||||||
is_detected_exact<T, from_json_function, serializer,
|
is_detected_exact<T, from_json_function, serializer, const BasicJsonType&>::value;
|
||||||
const BasicJsonType&>::value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// This trait checks if BasicJsonType::json_serializer<T>::to_json exists
|
// 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.
|
// 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>
|
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>
|
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>>
|
||||||
@@ -159,15 +162,15 @@ struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
|
|||||||
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
||||||
|
|
||||||
static constexpr bool value =
|
static constexpr bool value =
|
||||||
is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
|
is_detected_exact<void, to_json_function, serializer, BasicJsonType&, T>::value;
|
||||||
T>::value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using detect_key_compare = typename T::key_compare;
|
using detect_key_compare = typename T::key_compare;
|
||||||
|
|
||||||
template<typename T>
|
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
|
// obtains the actual object key comparator
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
@@ -176,7 +179,8 @@ struct actual_object_comparator
|
|||||||
using object_t = typename BasicJsonType::object_t;
|
using object_t = typename BasicJsonType::object_t;
|
||||||
using object_comparator_t = typename BasicJsonType::default_object_comparator_t;
|
using object_comparator_t = typename BasicJsonType::default_object_comparator_t;
|
||||||
using type = typename std::conditional<has_key_compare<object_t>::value,
|
using type = typename std::conditional<has_key_compare<object_t>::value,
|
||||||
typename object_t::key_compare, object_comparator_t>::type;
|
typename object_t::key_compare,
|
||||||
|
object_comparator_t>::type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
@@ -244,54 +248,72 @@ struct char_traits<signed char> : std::char_traits<char>
|
|||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
// https://en.cppreference.com/w/cpp/types/conjunction
|
// https://en.cppreference.com/w/cpp/types/conjunction
|
||||||
template<class...> struct conjunction : std::true_type { };
|
template<class...>
|
||||||
template<class B> struct conjunction<B> : B { };
|
struct conjunction : std::true_type
|
||||||
|
{};
|
||||||
|
template<class B>
|
||||||
|
struct conjunction<B> : B
|
||||||
|
{};
|
||||||
template<class B, class... Bn>
|
template<class B, class... Bn>
|
||||||
struct conjunction<B, 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
|
// 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
|
// 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).
|
// 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.
|
// This causes compile errors in e.g. clang 3.5 or gcc 4.9.
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_default_constructible : std::is_default_constructible<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>>
|
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>>
|
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...>>
|
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...>>
|
struct is_default_constructible<const std::tuple<Ts...>>
|
||||||
: conjunction<is_default_constructible<Ts>...> {};
|
: conjunction<is_default_constructible<Ts>...>
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
struct is_constructible : std::is_constructible<T, Args...> {};
|
struct is_constructible : std::is_constructible<T, Args...>
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {};
|
struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>>
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {};
|
struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>>
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {};
|
struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>>
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {};
|
struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>>
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename T, typename = void>
|
template<typename T, typename = void>
|
||||||
struct is_iterator_traits : std::false_type {};
|
struct is_iterator_traits : std::false_type
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_iterator_traits<iterator_traits<T>>
|
struct is_iterator_traits<iterator_traits<T>>
|
||||||
@@ -338,18 +360,21 @@ using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
|
|||||||
// and is written by Xiang Fan who agreed to using it in this library.
|
// and is written by Xiang Fan who agreed to using it in this library.
|
||||||
|
|
||||||
template<typename T, typename = void>
|
template<typename T, typename = void>
|
||||||
struct is_complete_type : std::false_type {};
|
struct is_complete_type : std::false_type
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename T>
|
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,
|
template<typename BasicJsonType, typename CompatibleObjectType, typename = void>
|
||||||
typename = void>
|
struct is_compatible_object_type_impl : std::false_type
|
||||||
struct is_compatible_object_type_impl : std::false_type {};
|
{};
|
||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleObjectType>
|
template<typename BasicJsonType, typename CompatibleObjectType>
|
||||||
struct is_compatible_object_type_impl<
|
struct is_compatible_object_type_impl<
|
||||||
BasicJsonType, CompatibleObjectType,
|
BasicJsonType,
|
||||||
|
CompatibleObjectType,
|
||||||
enable_if_t<is_detected<mapped_type_t, CompatibleObjectType>::value &&
|
enable_if_t<is_detected<mapped_type_t, CompatibleObjectType>::value &&
|
||||||
is_detected<key_type_t, CompatibleObjectType>::value>>
|
is_detected<key_type_t, CompatibleObjectType>::value>>
|
||||||
{
|
{
|
||||||
@@ -365,15 +390,17 @@ struct is_compatible_object_type_impl <
|
|||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleObjectType>
|
template<typename BasicJsonType, typename CompatibleObjectType>
|
||||||
struct is_compatible_object_type
|
struct is_compatible_object_type
|
||||||
: is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
|
: is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType>
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename BasicJsonType, typename ConstructibleObjectType,
|
template<typename BasicJsonType, typename ConstructibleObjectType, typename = void>
|
||||||
typename = void>
|
struct is_constructible_object_type_impl : std::false_type
|
||||||
struct is_constructible_object_type_impl : std::false_type {};
|
{};
|
||||||
|
|
||||||
template<typename BasicJsonType, typename ConstructibleObjectType>
|
template<typename BasicJsonType, typename ConstructibleObjectType>
|
||||||
struct is_constructible_object_type_impl<
|
struct is_constructible_object_type_impl<
|
||||||
BasicJsonType, ConstructibleObjectType,
|
BasicJsonType,
|
||||||
|
ConstructibleObjectType,
|
||||||
enable_if_t<is_detected<mapped_type_t, ConstructibleObjectType>::value &&
|
enable_if_t<is_detected<mapped_type_t, ConstructibleObjectType>::value &&
|
||||||
is_detected<key_type_t, ConstructibleObjectType>::value>>
|
is_detected<key_type_t, ConstructibleObjectType>::value>>
|
||||||
{
|
{
|
||||||
@@ -398,7 +425,8 @@ struct is_constructible_object_type_impl <
|
|||||||
template<typename BasicJsonType, typename ConstructibleObjectType>
|
template<typename BasicJsonType, typename ConstructibleObjectType>
|
||||||
struct is_constructible_object_type
|
struct is_constructible_object_type
|
||||||
: is_constructible_object_type_impl<BasicJsonType,
|
: is_constructible_object_type_impl<BasicJsonType,
|
||||||
ConstructibleObjectType> {};
|
ConstructibleObjectType>
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleStringType>
|
template<typename BasicJsonType, typename CompatibleStringType>
|
||||||
struct is_compatible_string_type
|
struct is_compatible_string_type
|
||||||
@@ -421,15 +449,18 @@ struct is_constructible_string_type
|
|||||||
conjunction<
|
conjunction<
|
||||||
is_constructible<laundered_type, typename BasicJsonType::string_t>,
|
is_constructible<laundered_type, typename BasicJsonType::string_t>,
|
||||||
is_detected_exact<typename BasicJsonType::string_t::value_type,
|
is_detected_exact<typename BasicJsonType::string_t::value_type,
|
||||||
value_type_t, laundered_type >>::value;
|
value_type_t,
|
||||||
|
laundered_type>>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleArrayType, typename = void>
|
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>
|
template<typename BasicJsonType, typename CompatibleArrayType>
|
||||||
struct is_compatible_array_type_impl<
|
struct is_compatible_array_type_impl<
|
||||||
BasicJsonType, CompatibleArrayType,
|
BasicJsonType,
|
||||||
|
CompatibleArrayType,
|
||||||
enable_if_t<
|
enable_if_t<
|
||||||
is_detected<iterator_t, CompatibleArrayType>::value &&
|
is_detected<iterator_t, CompatibleArrayType>::value &&
|
||||||
is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value &&
|
is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value &&
|
||||||
@@ -444,21 +475,26 @@ struct is_compatible_array_type_impl <
|
|||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleArrayType>
|
template<typename BasicJsonType, typename CompatibleArrayType>
|
||||||
struct is_compatible_array_type
|
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>
|
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>
|
template<typename BasicJsonType, typename ConstructibleArrayType>
|
||||||
struct is_constructible_array_type_impl<
|
struct is_constructible_array_type_impl<
|
||||||
BasicJsonType, ConstructibleArrayType,
|
BasicJsonType,
|
||||||
|
ConstructibleArrayType,
|
||||||
enable_if_t<std::is_same<ConstructibleArrayType,
|
enable_if_t<std::is_same<ConstructibleArrayType,
|
||||||
typename BasicJsonType::value_type>::value>>
|
typename BasicJsonType::value_type>::value>>
|
||||||
: std::true_type {};
|
: std::true_type
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename BasicJsonType, typename ConstructibleArrayType>
|
template<typename BasicJsonType, typename ConstructibleArrayType>
|
||||||
struct is_constructible_array_type_impl<
|
struct is_constructible_array_type_impl<
|
||||||
BasicJsonType, ConstructibleArrayType,
|
BasicJsonType,
|
||||||
|
ConstructibleArrayType,
|
||||||
enable_if_t<!std::is_same<ConstructibleArrayType,
|
enable_if_t<!std::is_same<ConstructibleArrayType,
|
||||||
typename BasicJsonType::value_type>::value &&
|
typename BasicJsonType::value_type>::value &&
|
||||||
!is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value &&
|
!is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value &&
|
||||||
@@ -488,15 +524,17 @@ is_detected<range_value_t, ConstructibleArrayType>::value&&
|
|||||||
|
|
||||||
template<typename BasicJsonType, typename ConstructibleArrayType>
|
template<typename BasicJsonType, typename ConstructibleArrayType>
|
||||||
struct is_constructible_array_type
|
struct is_constructible_array_type
|
||||||
: is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
|
: is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType>
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename RealIntegerType, typename CompatibleNumberIntegerType,
|
template<typename RealIntegerType, typename CompatibleNumberIntegerType, typename = void>
|
||||||
typename = void>
|
struct is_compatible_integer_type_impl : std::false_type
|
||||||
struct is_compatible_integer_type_impl : std::false_type {};
|
{};
|
||||||
|
|
||||||
template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
||||||
struct is_compatible_integer_type_impl<
|
struct is_compatible_integer_type_impl<
|
||||||
RealIntegerType, CompatibleNumberIntegerType,
|
RealIntegerType,
|
||||||
|
CompatibleNumberIntegerType,
|
||||||
enable_if_t<std::is_integral<RealIntegerType>::value &&
|
enable_if_t<std::is_integral<RealIntegerType>::value &&
|
||||||
std::is_integral<CompatibleNumberIntegerType>::value &&
|
std::is_integral<CompatibleNumberIntegerType>::value &&
|
||||||
!std::is_same<bool, CompatibleNumberIntegerType>::value>>
|
!std::is_same<bool, CompatibleNumberIntegerType>::value>>
|
||||||
@@ -515,14 +553,17 @@ struct is_compatible_integer_type_impl <
|
|||||||
template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
||||||
struct is_compatible_integer_type
|
struct is_compatible_integer_type
|
||||||
: is_compatible_integer_type_impl<RealIntegerType,
|
: is_compatible_integer_type_impl<RealIntegerType,
|
||||||
CompatibleNumberIntegerType> {};
|
CompatibleNumberIntegerType>
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleType, typename = void>
|
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>
|
template<typename BasicJsonType, typename CompatibleType>
|
||||||
struct is_compatible_type_impl<
|
struct is_compatible_type_impl<
|
||||||
BasicJsonType, CompatibleType,
|
BasicJsonType,
|
||||||
|
CompatibleType,
|
||||||
enable_if_t<is_complete_type<CompatibleType>::value>>
|
enable_if_t<is_complete_type<CompatibleType>::value>>
|
||||||
{
|
{
|
||||||
static constexpr bool value =
|
static constexpr bool value =
|
||||||
@@ -531,19 +572,24 @@ struct is_compatible_type_impl <
|
|||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleType>
|
template<typename BasicJsonType, typename CompatibleType>
|
||||||
struct is_compatible_type
|
struct is_compatible_type
|
||||||
: is_compatible_type_impl<BasicJsonType, CompatibleType> {};
|
: is_compatible_type_impl<BasicJsonType, CompatibleType>
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct is_constructible_tuple : std::false_type {};
|
struct is_constructible_tuple : std::false_type
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename T1, typename... Args>
|
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>
|
template<typename BasicJsonType, typename T>
|
||||||
struct is_json_iterator_of : std::false_type {};
|
struct is_json_iterator_of : std::false_type
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename BasicJsonType>
|
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>
|
template<typename BasicJsonType>
|
||||||
struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type
|
struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type
|
||||||
@@ -551,38 +597,33 @@ struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator
|
|||||||
|
|
||||||
// checks if a given type T is a template specialization of Primary
|
// checks if a given type T is a template specialization of Primary
|
||||||
template<template<typename...> class Primary, typename T>
|
template<template<typename...> class Primary, typename T>
|
||||||
struct is_specialization_of : std::false_type {};
|
struct is_specialization_of : std::false_type
|
||||||
|
{};
|
||||||
|
|
||||||
template<template<typename...> class Primary, typename... Args>
|
template<template<typename...> class Primary, typename... Args>
|
||||||
struct is_specialization_of<Primary, Primary<Args...>> : std::true_type {};
|
struct is_specialization_of<Primary, Primary<Args...>> : std::true_type
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using is_json_pointer = is_specialization_of<::nlohmann::json_pointer, uncvref_t<T>>;
|
using is_json_pointer = is_specialization_of<::nlohmann::json_pointer, uncvref_t<T>>;
|
||||||
|
|
||||||
// checks if A and B are comparable using Compare functor
|
// checks if A and B are comparable using Compare functor
|
||||||
template<typename Compare, typename A, typename B, typename = void>
|
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>
|
template<typename Compare, typename A, typename B>
|
||||||
struct is_comparable<Compare, A, B, void_t<
|
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
|
||||||
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>
|
template<typename T>
|
||||||
using detect_is_transparent = typename T::is_transparent;
|
using detect_is_transparent = typename T::is_transparent;
|
||||||
|
|
||||||
// type trait to check if KeyType can be used as object key (without a BasicJsonType)
|
// type trait to check if KeyType can be used as object key (without a BasicJsonType)
|
||||||
// see is_usable_as_basic_json_key_type below
|
// see is_usable_as_basic_json_key_type below
|
||||||
template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true,
|
template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
|
||||||
bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
|
|
||||||
using is_usable_as_key_type = typename std::conditional<
|
using is_usable_as_key_type = typename std::conditional<
|
||||||
is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value
|
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,
|
||||||
&& !(ExcludeObjectKeyType && std::is_same<KeyType,
|
|
||||||
ObjectKeyType>::value)
|
|
||||||
&& (!RequireTransparentComparator
|
|
||||||
|| is_detected <detect_is_transparent, Comparator>::value)
|
|
||||||
&& !is_json_pointer<KeyType>::value,
|
|
||||||
std::true_type,
|
std::true_type,
|
||||||
std::false_type>::type;
|
std::false_type>::type;
|
||||||
|
|
||||||
@@ -592,13 +633,14 @@ using is_usable_as_key_type = typename std::conditional <
|
|||||||
// - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type
|
// - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type
|
||||||
// - the comparator is transparent or RequireTransparentComparator is false
|
// - the comparator is transparent or RequireTransparentComparator is false
|
||||||
// - KeyType is not a JSON iterator or json_pointer
|
// - KeyType is not a JSON iterator or json_pointer
|
||||||
template<typename BasicJsonType, typename KeyTypeCVRef, bool RequireTransparentComparator = true,
|
template<typename BasicJsonType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
|
||||||
bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
|
|
||||||
using is_usable_as_basic_json_key_type = typename std::conditional<
|
using is_usable_as_basic_json_key_type = typename std::conditional<
|
||||||
is_usable_as_key_type<typename BasicJsonType::object_comparator_t,
|
is_usable_as_key_type<typename BasicJsonType::object_comparator_t,
|
||||||
typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
|
typename BasicJsonType::object_t::key_type,
|
||||||
RequireTransparentComparator, ExcludeObjectKeyType>::value
|
KeyTypeCVRef,
|
||||||
&& !is_json_iterator_of<BasicJsonType, KeyType>::value,
|
RequireTransparentComparator,
|
||||||
|
ExcludeObjectKeyType>::value &&
|
||||||
|
!is_json_iterator_of<BasicJsonType, KeyType>::value,
|
||||||
std::true_type,
|
std::true_type,
|
||||||
std::false_type>::type;
|
std::false_type>::type;
|
||||||
|
|
||||||
@@ -610,7 +652,8 @@ template<typename BasicJsonType, typename KeyType>
|
|||||||
using has_erase_with_key_type = typename std::conditional<
|
using has_erase_with_key_type = typename std::conditional<
|
||||||
is_detected<
|
is_detected<
|
||||||
detect_erase_with_key_type,
|
detect_erase_with_key_type,
|
||||||
typename BasicJsonType::object_t, KeyType >::value,
|
typename BasicJsonType::object_t,
|
||||||
|
KeyType>::value,
|
||||||
std::true_type,
|
std::true_type,
|
||||||
std::false_type>::type;
|
std::false_type>::type;
|
||||||
|
|
||||||
@@ -626,10 +669,15 @@ struct is_ordered_map
|
|||||||
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>
|
||||||
template <typename C> static two test(...);
|
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)
|
// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)
|
||||||
@@ -661,12 +709,9 @@ using same_sign = std::integral_constant < bool,
|
|||||||
|
|
||||||
template<typename OfType, typename T>
|
template<typename OfType, typename T>
|
||||||
using never_out_of_range = std::integral_constant<bool,
|
using never_out_of_range = std::integral_constant<bool,
|
||||||
(std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType)))
|
(std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType))) || (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T))>;
|
||||||
|| (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T)) >;
|
|
||||||
|
|
||||||
template<typename OfType, typename T,
|
template<typename OfType, typename T, bool OfTypeSigned = std::is_signed<OfType>::value, bool TSigned = std::is_signed<T>::value>
|
||||||
bool OfTypeSigned = std::is_signed<OfType>::value,
|
|
||||||
bool TSigned = std::is_signed<T>::value>
|
|
||||||
struct value_in_range_of_impl2;
|
struct value_in_range_of_impl2;
|
||||||
|
|
||||||
template<typename OfType, typename T>
|
template<typename OfType, typename T>
|
||||||
@@ -705,14 +750,11 @@ struct value_in_range_of_impl2<OfType, T, true, true>
|
|||||||
static constexpr bool test(T val)
|
static constexpr bool test(T val)
|
||||||
{
|
{
|
||||||
using CommonType = typename std::common_type<OfType, T>::type;
|
using CommonType = typename std::common_type<OfType, T>::type;
|
||||||
return static_cast<CommonType>(val) >= static_cast<CommonType>((std::numeric_limits<OfType>::min)())
|
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)());
|
||||||
&& static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename OfType, typename T,
|
template<typename OfType, typename T, bool NeverOutOfRange = never_out_of_range<OfType, T>::value, typename = detail::enable_if_t<all_integral<OfType, T>::value>>
|
||||||
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;
|
struct value_in_range_of_impl1;
|
||||||
|
|
||||||
template<typename OfType, typename T>
|
template<typename OfType, typename T>
|
||||||
@@ -746,8 +788,7 @@ using bool_constant = std::integral_constant<bool, Value>;
|
|||||||
// is_c_string
|
// is_c_string
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
namespace impl
|
namespace impl {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline constexpr bool is_c_string()
|
inline constexpr bool is_c_string()
|
||||||
@@ -756,16 +797,15 @@ inline constexpr bool is_c_string()
|
|||||||
using TUnCVExt = typename std::remove_cv<TUnExt>::type;
|
using TUnCVExt = typename std::remove_cv<TUnExt>::type;
|
||||||
using TUnPtr = typename std::remove_pointer<T>::type;
|
using TUnPtr = typename std::remove_pointer<T>::type;
|
||||||
using TUnCVPtr = typename std::remove_cv<TUnPtr>::type;
|
using TUnCVPtr = typename std::remove_cv<TUnPtr>::type;
|
||||||
return
|
return (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value) || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
|
||||||
(std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)
|
|
||||||
|| (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
|
|
||||||
// checks whether T is a [cv] char */[cv] char[] C string
|
// checks whether T is a [cv] char */[cv] char[] C string
|
||||||
template<typename T>
|
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>
|
template<typename T>
|
||||||
using is_c_string_uncvref = is_c_string<uncvref_t<T>>;
|
using is_c_string_uncvref = is_c_string<uncvref_t<T>>;
|
||||||
@@ -774,8 +814,7 @@ using is_c_string_uncvref = is_c_string<uncvref_t<T>>;
|
|||||||
// is_transparent
|
// is_transparent
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
namespace impl
|
namespace impl {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline constexpr bool is_transparent()
|
inline constexpr bool is_transparent()
|
||||||
@@ -787,7 +826,8 @@ inline constexpr bool is_transparent()
|
|||||||
|
|
||||||
// checks whether T has a member named is_transparent
|
// checks whether T has a member named is_transparent
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_transparent : bool_constant<impl::is_transparent<T>()> {};
|
struct is_transparent : bool_constant<impl::is_transparent<T>()>
|
||||||
|
{};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@@ -11,14 +11,15 @@
|
|||||||
#include <nlohmann/detail/abi_macros.hpp>
|
#include <nlohmann/detail/abi_macros.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename ...Ts> struct make_void
|
template<typename... Ts>
|
||||||
|
struct make_void
|
||||||
{
|
{
|
||||||
using type = 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
|
} // namespace detail
|
||||||
NLOHMANN_JSON_NAMESPACE_END
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
@@ -10,11 +10,11 @@
|
|||||||
|
|
||||||
#include <algorithm> // reverse
|
#include <algorithm> // reverse
|
||||||
#include <array> // array
|
#include <array> // array
|
||||||
#include <map> // map
|
|
||||||
#include <cmath> // isnan, isinf
|
#include <cmath> // isnan, isinf
|
||||||
#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
|
#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
|
||||||
#include <cstring> // memcpy
|
#include <cstring> // memcpy
|
||||||
#include <limits> // numeric_limits
|
#include <limits> // numeric_limits
|
||||||
|
#include <map> // map
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
#include <utility> // move
|
#include <utility> // move
|
||||||
#include <vector> // vector
|
#include <vector> // vector
|
||||||
@@ -25,8 +25,7 @@
|
|||||||
#include <nlohmann/detail/string_concat.hpp>
|
#include <nlohmann/detail/string_concat.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// binary writer //
|
// binary writer //
|
||||||
@@ -48,7 +47,8 @@ class binary_writer
|
|||||||
|
|
||||||
@param[in] adapter output adapter to write to
|
@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);
|
JSON_ASSERT(oa);
|
||||||
}
|
}
|
||||||
@@ -645,7 +645,6 @@ class binary_writer
|
|||||||
fixed = false;
|
fixed = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -736,9 +735,7 @@ class binary_writer
|
|||||||
@param[in] add_prefix whether prefixes need to be used for this value
|
@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
|
@param[in] use_bjdata whether write in BJData format, default is false
|
||||||
*/
|
*/
|
||||||
void write_ubjson(const BasicJsonType& j, const bool use_count,
|
void write_ubjson(const BasicJsonType& j, const bool use_count, const bool use_type, const bool add_prefix = true, const bool use_bjdata = false)
|
||||||
const bool use_type, const bool add_prefix = true,
|
|
||||||
const bool use_bjdata = false)
|
|
||||||
{
|
{
|
||||||
switch (j.type())
|
switch (j.type())
|
||||||
{
|
{
|
||||||
@@ -805,9 +802,7 @@ class binary_writer
|
|||||||
{
|
{
|
||||||
JSON_ASSERT(use_count);
|
JSON_ASSERT(use_count);
|
||||||
const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
|
const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
|
||||||
const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
|
const bool same_prefix = std::all_of(j.begin() + 1, j.end(), [this, first_prefix, use_bjdata](const BasicJsonType& v) {
|
||||||
[this, first_prefix, use_bjdata](const BasicJsonType & v)
|
|
||||||
{
|
|
||||||
return ubjson_prefix(v, use_bjdata) == first_prefix;
|
return ubjson_prefix(v, use_bjdata) == first_prefix;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -903,9 +898,7 @@ class binary_writer
|
|||||||
{
|
{
|
||||||
JSON_ASSERT(use_count);
|
JSON_ASSERT(use_count);
|
||||||
const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
|
const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
|
||||||
const bool same_prefix = std::all_of(j.begin(), j.end(),
|
const bool same_prefix = std::all_of(j.begin(), j.end(), [this, first_prefix, use_bjdata](const BasicJsonType& v) {
|
||||||
[this, first_prefix, use_bjdata](const BasicJsonType & v)
|
|
||||||
{
|
|
||||||
return ubjson_prefix(v, use_bjdata) == first_prefix;
|
return ubjson_prefix(v, use_bjdata) == first_prefix;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1108,8 +1101,7 @@ class binary_writer
|
|||||||
{
|
{
|
||||||
std::size_t array_index = 0ul;
|
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);
|
return result + calc_bson_element_size(std::to_string(array_index++), el);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1258,9 +1250,7 @@ class binary_writer
|
|||||||
*/
|
*/
|
||||||
static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value)
|
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),
|
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) {
|
||||||
[](size_t result, const typename BasicJsonType::object_t::value_type & el)
|
|
||||||
{
|
|
||||||
return result += calc_bson_element_size(el.first, el.second);
|
return result += calc_bson_element_size(el.first, el.second);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1316,8 +1306,7 @@ class binary_writer
|
|||||||
////////////
|
////////////
|
||||||
|
|
||||||
// UBJSON: write number (floating point)
|
// UBJSON: write number (floating point)
|
||||||
template<typename NumberType, typename std::enable_if<
|
template<typename NumberType, typename std::enable_if<std::is_floating_point<NumberType>::value, int>::type = 0>
|
||||||
std::is_floating_point<NumberType>::value, int>::type = 0>
|
|
||||||
void write_number_with_ubjson_prefix(const NumberType n,
|
void write_number_with_ubjson_prefix(const NumberType n,
|
||||||
const bool add_prefix,
|
const bool add_prefix,
|
||||||
const bool use_bjdata)
|
const bool use_bjdata)
|
||||||
@@ -1330,8 +1319,7 @@ class binary_writer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UBJSON: write number (unsigned integer)
|
// UBJSON: write number (unsigned integer)
|
||||||
template<typename NumberType, typename std::enable_if<
|
template<typename NumberType, typename std::enable_if<std::is_unsigned<NumberType>::value, int>::type = 0>
|
||||||
std::is_unsigned<NumberType>::value, int>::type = 0>
|
|
||||||
void write_number_with_ubjson_prefix(const NumberType n,
|
void write_number_with_ubjson_prefix(const NumberType n,
|
||||||
const bool add_prefix,
|
const bool add_prefix,
|
||||||
const bool use_bjdata)
|
const bool use_bjdata)
|
||||||
@@ -1417,9 +1405,7 @@ class binary_writer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UBJSON: write number (signed integer)
|
// UBJSON: write number (signed integer)
|
||||||
template < typename NumberType, typename std::enable_if <
|
template<typename NumberType, typename std::enable_if<std::is_signed<NumberType>::value && !std::is_floating_point<NumberType>::value, int>::type = 0>
|
||||||
std::is_signed<NumberType>::value&&
|
|
||||||
!std::is_floating_point<NumberType>::value, int >::type = 0 >
|
|
||||||
void write_number_with_ubjson_prefix(const NumberType n,
|
void write_number_with_ubjson_prefix(const NumberType n,
|
||||||
const bool add_prefix,
|
const bool add_prefix,
|
||||||
const bool use_bjdata)
|
const bool use_bjdata)
|
||||||
@@ -1617,9 +1603,7 @@ class binary_writer
|
|||||||
*/
|
*/
|
||||||
bool write_bjdata_ndarray(const typename BasicJsonType::object_t& value, const bool use_count, const bool use_type)
|
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'},
|
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'}};
|
||||||
{"uint32", 'm'}, {"int32", 'l'}, {"uint64", 'M'}, {"int64", 'L'}, {"single", 'd'}, {"double", 'D'}, {"char", 'C'}
|
|
||||||
};
|
|
||||||
|
|
||||||
string_t key = "_ArrayType_";
|
string_t key = "_ArrayType_";
|
||||||
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
|
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
|
||||||
@@ -1815,12 +1799,7 @@ class binary_writer
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputCharType, typename C = CharType,
|
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>
|
||||||
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
|
static constexpr CharType to_char_type(InputCharType x) noexcept
|
||||||
{
|
{
|
||||||
return x;
|
return x;
|
||||||
|
|||||||
@@ -23,11 +23,11 @@
|
|||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
/// abstract output adapter interface
|
/// 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_character(CharType c) = 0;
|
||||||
virtual void write_characters(const CharType* s, std::size_t length) = 0;
|
virtual void write_characters(const CharType* s, std::size_t length) = 0;
|
||||||
@@ -124,15 +124,18 @@ class output_adapter
|
|||||||
public:
|
public:
|
||||||
template<typename AllocatorType = std::allocator<CharType>>
|
template<typename AllocatorType = std::allocator<CharType>>
|
||||||
output_adapter(std::vector<CharType, AllocatorType>& vec)
|
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
|
#ifndef JSON_NO_IO
|
||||||
output_adapter(std::basic_ostream<CharType>& s)
|
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
|
#endif // JSON_NO_IO
|
||||||
|
|
||||||
output_adapter(StringType& s)
|
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>()
|
operator output_adapter_t<CharType>()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,9 +16,9 @@
|
|||||||
#include <cstddef> // size_t, ptrdiff_t
|
#include <cstddef> // size_t, ptrdiff_t
|
||||||
#include <cstdint> // uint8_t
|
#include <cstdint> // uint8_t
|
||||||
#include <cstdio> // snprintf
|
#include <cstdio> // snprintf
|
||||||
|
#include <iomanip> // setfill, setw
|
||||||
#include <limits> // numeric_limits
|
#include <limits> // numeric_limits
|
||||||
#include <string> // string, char_traits
|
#include <string> // string, char_traits
|
||||||
#include <iomanip> // setfill, setw
|
|
||||||
#include <type_traits> // is_same
|
#include <type_traits> // is_same
|
||||||
#include <utility> // move
|
#include <utility> // move
|
||||||
|
|
||||||
@@ -32,8 +32,7 @@
|
|||||||
#include <nlohmann/detail/value_t.hpp>
|
#include <nlohmann/detail/value_t.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// serialization //
|
// serialization //
|
||||||
@@ -64,8 +63,7 @@ class serializer
|
|||||||
@param[in] ichar indentation character to use
|
@param[in] ichar indentation character to use
|
||||||
@param[in] error_handler_ how to react on decoding errors
|
@param[in] error_handler_ how to react on decoding errors
|
||||||
*/
|
*/
|
||||||
serializer(output_adapter_t<char> s, const char ichar,
|
serializer(output_adapter_t<char> s, const char ichar, error_handler_t error_handler_ = error_handler_t::strict)
|
||||||
error_handler_t error_handler_ = error_handler_t::strict)
|
|
||||||
: o(std::move(s))
|
: o(std::move(s))
|
||||||
, loc(std::localeconv())
|
, loc(std::localeconv())
|
||||||
, thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(*(loc->thousands_sep)))
|
, thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(*(loc->thousands_sep)))
|
||||||
@@ -206,7 +204,8 @@ class serializer
|
|||||||
|
|
||||||
// first n-1 elements
|
// first n-1 elements
|
||||||
for (auto i = val.m_data.m_value.array->cbegin();
|
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);
|
o->write_characters(indent_string.c_str(), new_indent);
|
||||||
dump(*i, true, ensure_ascii, indent_step, new_indent);
|
dump(*i, true, ensure_ascii, indent_step, new_indent);
|
||||||
@@ -228,7 +227,8 @@ class serializer
|
|||||||
|
|
||||||
// first n-1 elements
|
// first n-1 elements
|
||||||
for (auto i = val.m_data.m_value.array->cbegin();
|
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);
|
dump(*i, false, ensure_ascii, indent_step, current_indent);
|
||||||
o->write_character(',');
|
o->write_character(',');
|
||||||
@@ -272,7 +272,8 @@ class serializer
|
|||||||
if (!val.m_data.m_value.binary->empty())
|
if (!val.m_data.m_value.binary->empty())
|
||||||
{
|
{
|
||||||
for (auto i = val.m_data.m_value.binary->cbegin();
|
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);
|
dump_integer(*i);
|
||||||
o->write_characters(", ", 2);
|
o->write_characters(", ", 2);
|
||||||
@@ -303,7 +304,8 @@ class serializer
|
|||||||
if (!val.m_data.m_value.binary->empty())
|
if (!val.m_data.m_value.binary->empty())
|
||||||
{
|
{
|
||||||
for (auto i = val.m_data.m_value.binary->cbegin();
|
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);
|
dump_integer(*i);
|
||||||
o->write_character(',');
|
o->write_character(',');
|
||||||
@@ -388,7 +390,8 @@ class serializer
|
|||||||
|
|
||||||
@complexity Linear in the length of string @a s.
|
@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::uint32_t codepoint{};
|
||||||
std::uint8_t state = UTF8_ACCEPT;
|
std::uint8_t state = UTF8_ACCEPT;
|
||||||
@@ -466,16 +469,13 @@ class serializer
|
|||||||
if (codepoint <= 0xFFFF)
|
if (codepoint <= 0xFFFF)
|
||||||
{
|
{
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||||
static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x",
|
static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", static_cast<std::uint16_t>(codepoint)));
|
||||||
static_cast<std::uint16_t>(codepoint)));
|
|
||||||
bytes += 6;
|
bytes += 6;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||||
static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x",
|
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<std::uint16_t>(0xD7C0u + (codepoint >> 10u)),
|
|
||||||
static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu))));
|
|
||||||
bytes += 12;
|
bytes += 12;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -705,29 +705,112 @@ class serializer
|
|||||||
@param[in] x integer number (signed or unsigned) to dump
|
@param[in] x integer number (signed or unsigned) to dump
|
||||||
@tparam NumberType either @a number_integer_t or @a number_unsigned_t
|
@tparam NumberType either @a number_integer_t or @a number_unsigned_t
|
||||||
*/
|
*/
|
||||||
template < typename NumberType, detail::enable_if_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>
|
||||||
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)
|
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', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}},
|
{{'0', '1'}},
|
||||||
{{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
|
{{'0', '2'}},
|
||||||
{{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
|
{{'0', '3'}},
|
||||||
{{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
|
{{'0', '4'}},
|
||||||
{{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
|
{{'0', '5'}},
|
||||||
{{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
|
{{'0', '6'}},
|
||||||
{{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
|
{{'0', '7'}},
|
||||||
{{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
|
{{'0', '8'}},
|
||||||
{{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
|
{{'0', '9'}},
|
||||||
{{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '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"
|
// special case for "0"
|
||||||
if (x == 0)
|
if (x == 0)
|
||||||
@@ -810,8 +893,7 @@ class serializer
|
|||||||
// guaranteed to round-trip, using strtof and strtod, resp.
|
// guaranteed to round-trip, using strtof and strtod, resp.
|
||||||
//
|
//
|
||||||
// NB: The test below works if <long double> == <double>.
|
// NB: The test below works if <long double> == <double>.
|
||||||
static constexpr bool is_ieee_single_or_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 == 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);
|
(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>());
|
dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
|
||||||
@@ -864,9 +946,7 @@ class serializer
|
|||||||
|
|
||||||
// determine if we need to append ".0"
|
// determine if we need to append ".0"
|
||||||
const bool value_is_int_like =
|
const bool value_is_int_like =
|
||||||
std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
|
std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, [](char c) {
|
||||||
[](char c)
|
|
||||||
{
|
|
||||||
return c == '.' || c == 'e';
|
return c == '.' || c == 'e';
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -902,22 +982,407 @@ class serializer
|
|||||||
static const std::array<std::uint8_t, 400> utf8d =
|
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, 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, 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, 0, // 60..7F
|
0,
|
||||||
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
|
0,
|
||||||
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
|
0,
|
||||||
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
|
0,
|
||||||
0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF
|
0,
|
||||||
0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF
|
0,
|
||||||
0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0
|
0,
|
||||||
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
|
0,
|
||||||
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
|
0,
|
||||||
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
|
0,
|
||||||
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, // 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());
|
JSON_ASSERT(byte < utf8d.size());
|
||||||
const std::uint8_t type = utf8d[byte];
|
const std::uint8_t type = utf8d[byte];
|
||||||
|
|||||||
@@ -16,8 +16,7 @@
|
|||||||
#include <nlohmann/detail/meta/detected.hpp>
|
#include <nlohmann/detail/meta/detected.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
inline std::size_t concat_length()
|
inline std::size_t concat_length()
|
||||||
{
|
{
|
||||||
@@ -77,56 +76,37 @@ using string_can_append_data = decltype(std::declval<StringType&>().append(std::
|
|||||||
template<typename StringType, typename Arg>
|
template<typename StringType, typename Arg>
|
||||||
using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
|
using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
|
||||||
|
|
||||||
template < typename OutStringType, typename Arg, typename... Args,
|
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>
|
||||||
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);
|
inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest);
|
||||||
|
|
||||||
template < typename OutStringType, typename Arg, typename... Args,
|
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>
|
||||||
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);
|
inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest);
|
||||||
|
|
||||||
template < typename OutStringType, typename Arg, typename... Args,
|
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>
|
||||||
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);
|
inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest);
|
||||||
|
|
||||||
template<typename OutStringType, typename Arg, typename... Args,
|
template<typename OutStringType, typename Arg, typename... Args, enable_if_t<detect_string_can_append<OutStringType, Arg>::value, int> = 0>
|
||||||
enable_if_t<detect_string_can_append<OutStringType, Arg>::value, int> = 0>
|
|
||||||
inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest)
|
inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest)
|
||||||
{
|
{
|
||||||
out.append(std::forward<Arg>(arg));
|
out.append(std::forward<Arg>(arg));
|
||||||
concat_into(out, std::forward<Args>(rest)...);
|
concat_into(out, std::forward<Args>(rest)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename OutStringType, typename Arg, typename... Args,
|
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>>
|
||||||
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)
|
inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest)
|
||||||
{
|
{
|
||||||
out += std::forward<Arg>(arg);
|
out += std::forward<Arg>(arg);
|
||||||
concat_into(out, std::forward<Args>(rest)...);
|
concat_into(out, std::forward<Args>(rest)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename OutStringType, typename Arg, typename... Args,
|
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>>
|
||||||
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)
|
inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest)
|
||||||
{
|
{
|
||||||
out.append(arg.begin(), arg.end());
|
out.append(arg.begin(), arg.end());
|
||||||
concat_into(out, std::forward<Args>(rest)...);
|
concat_into(out, std::forward<Args>(rest)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename OutStringType, typename Arg, typename... Args,
|
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>>
|
||||||
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)
|
inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest)
|
||||||
{
|
{
|
||||||
out.append(arg.data(), arg.size());
|
out.append(arg.data(), arg.size());
|
||||||
|
|||||||
@@ -11,8 +11,7 @@
|
|||||||
#include <nlohmann/detail/abi_macros.hpp>
|
#include <nlohmann/detail/abi_macros.hpp>
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief replace all occurrences of a substring by another string
|
@brief replace all occurrences of a substring by another string
|
||||||
@@ -28,8 +27,7 @@ enforced with an assertion.**
|
|||||||
@since version 2.0.0
|
@since version 2.0.0
|
||||||
*/
|
*/
|
||||||
template<typename StringType>
|
template<typename StringType>
|
||||||
inline void replace_substring(StringType& s, const StringType& f,
|
inline void replace_substring(StringType& s, const StringType& f, const StringType& t)
|
||||||
const StringType& t)
|
|
||||||
{
|
{
|
||||||
JSON_ASSERT(!f.empty());
|
JSON_ASSERT(!f.empty());
|
||||||
for (auto pos = s.find(f); // find first occurrence of f
|
for (auto pos = s.find(f); // find first occurrence of f
|
||||||
|
|||||||
@@ -19,8 +19,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
// JSON type enumeration //
|
// JSON type enumeration //
|
||||||
@@ -84,11 +83,16 @@ Returns an ordering that is similar to Python:
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
static constexpr std::array<std::uint8_t, 9> order = {{
|
static constexpr std::array<std::uint8_t, 9> order = {{
|
||||||
0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */,
|
0 /* null */,
|
||||||
1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */,
|
3 /* object */,
|
||||||
|
4 /* array */,
|
||||||
|
5 /* string */,
|
||||||
|
1 /* boolean */,
|
||||||
|
2 /* integer */,
|
||||||
|
2 /* unsigned */,
|
||||||
|
2 /* float */,
|
||||||
6 /* binary */
|
6 /* binary */
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
|
|
||||||
const auto l_index = static_cast<std::size_t>(lhs);
|
const auto l_index = static_cast<std::size_t>(lhs);
|
||||||
const auto r_index = static_cast<std::size_t>(rhs);
|
const auto r_index = static_cast<std::size_t>(rhs);
|
||||||
|
|||||||
+211
-313
File diff suppressed because it is too large.
Load diff
@@ -39,7 +39,8 @@ struct adl_serializer;
|
|||||||
template<template<typename U, typename V, typename... Args> class ObjectType =
|
template<template<typename U, typename V, typename... Args> class ObjectType =
|
||||||
std::map,
|
std::map,
|
||||||
template<typename U, typename... Args> class ArrayType = std::vector,
|
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 NumberIntegerType = std::int64_t,
|
||||||
class NumberUnsignedType = std::uint64_t,
|
class NumberUnsignedType = std::uint64_t,
|
||||||
class NumberFloatType = double,
|
class NumberFloatType = double,
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ NLOHMANN_JSON_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
/// ordered_map: a minimal map-like container that preserves insertion order
|
/// ordered_map: a minimal map-like container that preserves insertion order
|
||||||
/// for use within nlohmann::basic_json<ordered_map>
|
/// for use within nlohmann::basic_json<ordered_map>
|
||||||
template <class Key, class T, class IgnoredLess = std::less<Key>,
|
template<class Key, class T, class IgnoredLess = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
|
||||||
class Allocator = std::allocator<std::pair<const Key, T>>>
|
|
||||||
struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
|
struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
|
||||||
{
|
{
|
||||||
using key_type = Key;
|
using key_type = Key;
|
||||||
@@ -43,13 +42,19 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
|||||||
|
|
||||||
// Explicit constructors instead of `using Container::Container`
|
// Explicit constructors instead of `using Container::Container`
|
||||||
// otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4)
|
// otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4)
|
||||||
ordered_map() noexcept(noexcept(Container())) : Container{} {}
|
ordered_map() noexcept(noexcept(Container()))
|
||||||
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {}
|
: Container{}
|
||||||
|
{}
|
||||||
|
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc)))
|
||||||
|
: Container{alloc}
|
||||||
|
{}
|
||||||
template<class It>
|
template<class It>
|
||||||
ordered_map(It first, It last, const Allocator& alloc = Allocator())
|
ordered_map(It first, It last, const Allocator& alloc = Allocator())
|
||||||
: Container{first, last, alloc} {}
|
: Container{first, last, alloc}
|
||||||
|
{}
|
||||||
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator())
|
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator())
|
||||||
: Container{init, alloc} {}
|
: Container{init, alloc}
|
||||||
|
{}
|
||||||
|
|
||||||
std::pair<iterator, bool> emplace(const key_type& key, T&& t)
|
std::pair<iterator, bool> emplace(const key_type& key, T&& t)
|
||||||
{
|
{
|
||||||
@@ -64,8 +69,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
|||||||
return {std::prev(this->end()), true};
|
return {std::prev(this->end()), true};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class KeyType, detail::enable_if_t<
|
template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
||||||
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
|
||||||
std::pair<iterator, bool> emplace(KeyType&& key, T&& t)
|
std::pair<iterator, bool> emplace(KeyType&& key, T&& t)
|
||||||
{
|
{
|
||||||
for (auto it = this->begin(); it != this->end(); ++it)
|
for (auto it = this->begin(); it != this->end(); ++it)
|
||||||
@@ -84,8 +88,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
|||||||
return emplace(key, T{}).first->second;
|
return emplace(key, T{}).first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class KeyType, detail::enable_if_t<
|
template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
||||||
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
|
||||||
T& operator[](KeyType&& key)
|
T& operator[](KeyType&& key)
|
||||||
{
|
{
|
||||||
return emplace(std::forward<KeyType>(key), T{}).first->second;
|
return emplace(std::forward<KeyType>(key), T{}).first->second;
|
||||||
@@ -96,8 +99,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
|||||||
return at(key);
|
return at(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class KeyType, detail::enable_if_t<
|
template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
||||||
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
|
||||||
const T& operator[](KeyType&& key) const
|
const T& operator[](KeyType&& key) const
|
||||||
{
|
{
|
||||||
return at(std::forward<KeyType>(key));
|
return at(std::forward<KeyType>(key));
|
||||||
@@ -116,8 +118,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
|||||||
JSON_THROW(std::out_of_range("key not found"));
|
JSON_THROW(std::out_of_range("key not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class KeyType, detail::enable_if_t<
|
template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
||||||
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
|
||||||
T& at(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward)
|
T& at(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward)
|
||||||
{
|
{
|
||||||
for (auto it = this->begin(); it != this->end(); ++it)
|
for (auto it = this->begin(); it != this->end(); ++it)
|
||||||
@@ -144,8 +145,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
|||||||
JSON_THROW(std::out_of_range("key not found"));
|
JSON_THROW(std::out_of_range("key not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class KeyType, detail::enable_if_t<
|
template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
||||||
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)
|
const T& at(KeyType&& key) const // NOLINT(cppcoreguidelines-missing-std-forward)
|
||||||
{
|
{
|
||||||
for (auto it = this->begin(); it != this->end(); ++it)
|
for (auto it = this->begin(); it != this->end(); ++it)
|
||||||
@@ -178,8 +178,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class KeyType, detail::enable_if_t<
|
template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
||||||
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
|
||||||
size_type erase(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward)
|
size_type erase(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward)
|
||||||
{
|
{
|
||||||
for (auto it = this->begin(); it != this->end(); ++it)
|
for (auto it = this->begin(); it != this->end(); ++it)
|
||||||
@@ -269,8 +268,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class KeyType, detail::enable_if_t<
|
template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
||||||
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)
|
size_type count(KeyType&& key) const // NOLINT(cppcoreguidelines-missing-std-forward)
|
||||||
{
|
{
|
||||||
for (auto it = this->begin(); it != this->end(); ++it)
|
for (auto it = this->begin(); it != this->end(); ++it)
|
||||||
@@ -295,8 +293,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
|||||||
return Container::end();
|
return Container::end();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class KeyType, detail::enable_if_t<
|
template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
||||||
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
|
|
||||||
iterator find(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward)
|
iterator find(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward)
|
||||||
{
|
{
|
||||||
for (auto it = this->begin(); it != this->end(); ++it)
|
for (auto it = this->begin(); it != this->end(); ++it)
|
||||||
|
|||||||
+74
-155
@@ -240,13 +240,10 @@
|
|||||||
#if defined(JSON_HEDLEY_TI_VERSION)
|
#if defined(JSON_HEDLEY_TI_VERSION)
|
||||||
#undef JSON_HEDLEY_TI_VERSION
|
#undef JSON_HEDLEY_TI_VERSION
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if defined(__TI_COMPILER_VERSION__) && \
|
||||||
defined(__TI_COMPILER_VERSION__) && \
|
(defined(__TMS470__) || defined(__TI_ARM__) || \
|
||||||
( \
|
|
||||||
defined(__TMS470__) || defined(__TI_ARM__) || \
|
|
||||||
defined(__MSP430__) || \
|
defined(__MSP430__) || \
|
||||||
defined(__TMS320C2000__) \
|
defined(__TMS320C2000__))
|
||||||
)
|
|
||||||
#if (__TI_COMPILER_VERSION__ >= 16000000)
|
#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))
|
#define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
|
||||||
#endif
|
#endif
|
||||||
@@ -480,8 +477,7 @@
|
|||||||
#if defined(JSON_HEDLEY_GCC_VERSION)
|
#if defined(JSON_HEDLEY_GCC_VERSION)
|
||||||
#undef JSON_HEDLEY_GCC_VERSION
|
#undef JSON_HEDLEY_GCC_VERSION
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if defined(JSON_HEDLEY_GNUC_VERSION) && \
|
||||||
defined(JSON_HEDLEY_GNUC_VERSION) && \
|
|
||||||
!defined(__clang__) && \
|
!defined(__clang__) && \
|
||||||
!defined(JSON_HEDLEY_INTEL_VERSION) && \
|
!defined(JSON_HEDLEY_INTEL_VERSION) && \
|
||||||
!defined(JSON_HEDLEY_PGI_VERSION) && \
|
!defined(JSON_HEDLEY_PGI_VERSION) && \
|
||||||
@@ -511,11 +507,8 @@
|
|||||||
#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
|
#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
|
||||||
#undef JSON_HEDLEY_HAS_ATTRIBUTE
|
#undef JSON_HEDLEY_HAS_ATTRIBUTE
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if defined(__has_attribute) && \
|
||||||
defined(__has_attribute) && \
|
((!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8, 5, 9)))
|
||||||
( \
|
|
||||||
(!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
|
|
||||||
)
|
|
||||||
#define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
|
#define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
|
||||||
#else
|
#else
|
||||||
#define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
|
#define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
|
||||||
@@ -542,8 +535,7 @@
|
|||||||
#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
|
#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
|
||||||
#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
|
#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if defined(__has_cpp_attribute) && \
|
||||||
defined(__has_cpp_attribute) && \
|
|
||||||
defined(__cplusplus) && \
|
defined(__cplusplus) && \
|
||||||
(!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0))
|
(!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0))
|
||||||
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
|
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
|
||||||
@@ -556,8 +548,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
|
#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
|
||||||
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns, attribute) (0)
|
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns, attribute) (0)
|
||||||
#elif \
|
#elif !defined(JSON_HEDLEY_PGI_VERSION) && \
|
||||||
!defined(JSON_HEDLEY_PGI_VERSION) && \
|
|
||||||
!defined(JSON_HEDLEY_IAR_VERSION) && \
|
!defined(JSON_HEDLEY_IAR_VERSION) && \
|
||||||
(!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0)) && \
|
(!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))
|
(!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19, 20, 0))
|
||||||
@@ -719,8 +710,7 @@
|
|||||||
#define JSON_HEDLEY_GCC_HAS_WARNING(warning, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch)
|
#define JSON_HEDLEY_GCC_HAS_WARNING(warning, major, minor, patch) JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if \
|
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
|
||||||
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
|
|
||||||
defined(__clang__) || \
|
defined(__clang__) || \
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
@@ -760,16 +750,14 @@
|
|||||||
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0)
|
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0)
|
||||||
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
|
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
|
||||||
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
|
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
|
||||||
#elif \
|
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) || \
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
|
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
||||||
#define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
|
#define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
|
||||||
#define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
|
#define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
|
||||||
#elif JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0)
|
#elif JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0)
|
||||||
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
|
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
|
||||||
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
|
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
|
||||||
#elif \
|
#elif JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
|
||||||
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
|
|
||||||
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
|
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
|
||||||
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 4, 0) || \
|
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 4, 0) || \
|
||||||
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 1, 0) || \
|
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 1, 0) || \
|
||||||
@@ -827,14 +815,12 @@
|
|||||||
#endif
|
#endif
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
#define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
|
#define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
|
||||||
#elif \
|
#elif JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
|
||||||
JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
|
||||||
#define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__({ \
|
#define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__({ \
|
||||||
JSON_HEDLEY_DIAGNOSTIC_PUSH \
|
JSON_HEDLEY_DIAGNOSTIC_PUSH \
|
||||||
JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
|
JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL((T)(expr)); \
|
||||||
((T) (expr)); \
|
|
||||||
JSON_HEDLEY_DIAGNOSTIC_POP \
|
JSON_HEDLEY_DIAGNOSTIC_POP \
|
||||||
}))
|
}))
|
||||||
#else
|
#else
|
||||||
@@ -866,8 +852,7 @@
|
|||||||
#if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
|
#if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
|
||||||
#define JSON_HEDLEY_CPP_CAST(T, expr) \
|
#define JSON_HEDLEY_CPP_CAST(T, expr) \
|
||||||
JSON_HEDLEY_DIAGNOSTIC_PUSH \
|
JSON_HEDLEY_DIAGNOSTIC_PUSH \
|
||||||
_Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
|
_Pragma("clang diagnostic ignored \"-Wold-style-cast\"")((T)(expr)) \
|
||||||
((T) (expr)) \
|
|
||||||
JSON_HEDLEY_DIAGNOSTIC_POP
|
JSON_HEDLEY_DIAGNOSTIC_POP
|
||||||
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 3, 0)
|
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 3, 0)
|
||||||
#define JSON_HEDLEY_CPP_CAST(T, expr) \
|
#define JSON_HEDLEY_CPP_CAST(T, expr) \
|
||||||
@@ -900,8 +885,7 @@
|
|||||||
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable : 4996))
|
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable : 4996))
|
||||||
#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
||||||
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
|
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
|
||||||
#elif \
|
#elif JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 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(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
|
||||||
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
|
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, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
|
||||||
@@ -940,8 +924,7 @@
|
|||||||
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
|
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
|
||||||
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0)
|
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0)
|
||||||
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable : 4068))
|
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable : 4068))
|
||||||
#elif \
|
#elif JSON_HEDLEY_TI_VERSION_CHECK(16, 9, 0) || \
|
||||||
JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
|
|
||||||
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0) || \
|
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0) || \
|
||||||
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
|
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
|
||||||
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 3, 0)
|
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 3, 0)
|
||||||
@@ -975,8 +958,7 @@
|
|||||||
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
|
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
|
||||||
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus)
|
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus)
|
||||||
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
|
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
|
||||||
#elif \
|
#elif JSON_HEDLEY_TI_VERSION_CHECK(18, 1, 0) || \
|
||||||
JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
|
|
||||||
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 3, 0) || \
|
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 3, 0) || \
|
||||||
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0)
|
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0)
|
||||||
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
|
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
|
||||||
@@ -1022,13 +1004,11 @@
|
|||||||
#if defined(JSON_HEDLEY_DEPRECATED_FOR)
|
#if defined(JSON_HEDLEY_DEPRECATED_FOR)
|
||||||
#undef JSON_HEDLEY_DEPRECATED_FOR
|
#undef JSON_HEDLEY_DEPRECATED_FOR
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || \
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
|
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
||||||
#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " #since))
|
#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " #since))
|
||||||
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
|
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
|
||||||
#elif \
|
#elif (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
|
||||||
(JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) || \
|
JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) || \
|
||||||
@@ -1045,8 +1025,7 @@
|
|||||||
#elif defined(__cplusplus) && (__cplusplus >= 201402L)
|
#elif defined(__cplusplus) && (__cplusplus >= 201402L)
|
||||||
#define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
|
#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)]])
|
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
|
||||||
#elif \
|
#elif JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \
|
||||||
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \
|
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \
|
||||||
JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
|
JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
|
||||||
@@ -1064,8 +1043,7 @@
|
|||||||
JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0)
|
JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0)
|
||||||
#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
|
#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
|
||||||
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
|
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
|
||||||
#elif \
|
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
|
|
||||||
JSON_HEDLEY_PELLES_VERSION_CHECK(6, 50, 0) || \
|
JSON_HEDLEY_PELLES_VERSION_CHECK(6, 50, 0) || \
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
||||||
#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
|
#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
|
||||||
@@ -1081,8 +1059,7 @@
|
|||||||
#if defined(JSON_HEDLEY_UNAVAILABLE)
|
#if defined(JSON_HEDLEY_UNAVAILABLE)
|
||||||
#undef JSON_HEDLEY_UNAVAILABLE
|
#undef JSON_HEDLEY_UNAVAILABLE
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(4, 3, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(4, 3, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
||||||
@@ -1097,8 +1074,7 @@
|
|||||||
#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
|
#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
|
||||||
#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
|
#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
|
JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
|
||||||
@@ -1134,8 +1110,7 @@
|
|||||||
#if defined(JSON_HEDLEY_SENTINEL)
|
#if defined(JSON_HEDLEY_SENTINEL)
|
||||||
#undef JSON_HEDLEY_SENTINEL
|
#undef JSON_HEDLEY_SENTINEL
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_ARM_VERSION_CHECK(5, 4, 0) || \
|
JSON_HEDLEY_ARM_VERSION_CHECK(5, 4, 0) || \
|
||||||
@@ -1150,16 +1125,14 @@
|
|||||||
#endif
|
#endif
|
||||||
#if JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
|
#if JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
|
||||||
#define JSON_HEDLEY_NO_RETURN __noreturn
|
#define JSON_HEDLEY_NO_RETURN __noreturn
|
||||||
#elif \
|
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
|
|
||||||
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
||||||
#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
|
#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
|
||||||
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||||
#define JSON_HEDLEY_NO_RETURN _Noreturn
|
#define JSON_HEDLEY_NO_RETURN _Noreturn
|
||||||
#elif defined(__cplusplus) && (__cplusplus >= 201103L)
|
#elif defined(__cplusplus) && (__cplusplus >= 201103L)
|
||||||
#define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
|
#define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
|
||||||
#elif \
|
#elif JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 2, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 2, 0) || \
|
||||||
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
||||||
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \
|
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \
|
||||||
@@ -1179,8 +1152,7 @@
|
|||||||
#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
|
#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
|
||||||
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0)
|
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0)
|
||||||
#define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
|
#define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
|
||||||
#elif \
|
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
|
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
||||||
#define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
|
#define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
|
||||||
#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 0, 0) && defined(__cplusplus)
|
#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 0, 0) && defined(__cplusplus)
|
||||||
@@ -1211,15 +1183,13 @@
|
|||||||
#if defined(JSON_HEDLEY_ASSUME)
|
#if defined(JSON_HEDLEY_ASSUME)
|
||||||
#undef JSON_HEDLEY_ASSUME
|
#undef JSON_HEDLEY_ASSUME
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
|
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
||||||
#define JSON_HEDLEY_ASSUME(expr) __assume(expr)
|
#define JSON_HEDLEY_ASSUME(expr) __assume(expr)
|
||||||
#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
|
#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
|
||||||
#define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
|
#define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
|
||||||
#elif \
|
#elif JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 0) || \
|
||||||
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
|
|
||||||
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0)
|
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0)
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
#define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
|
#define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
|
||||||
@@ -1227,8 +1197,7 @@
|
|||||||
#define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
|
#define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
|
||||||
(JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \
|
||||||
JSON_HEDLEY_PGI_VERSION_CHECK(18, 10, 0) || \
|
JSON_HEDLEY_PGI_VERSION_CHECK(18, 10, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
@@ -1247,8 +1216,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if defined(JSON_HEDLEY_UNREACHABLE)
|
#if defined(JSON_HEDLEY_UNREACHABLE)
|
||||||
#if \
|
#if JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 0) || \
|
||||||
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
|
|
||||||
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 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))
|
#define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
|
||||||
#else
|
#else
|
||||||
@@ -1278,8 +1246,7 @@ JSON_HEDLEY_DIAGNOSTIC_PUSH
|
|||||||
#if defined(JSON_HEDLEY_NON_NULL)
|
#if defined(JSON_HEDLEY_NON_NULL)
|
||||||
#undef JSON_HEDLEY_NON_NULL
|
#undef JSON_HEDLEY_NON_NULL
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0)
|
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0)
|
||||||
@@ -1296,8 +1263,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
|
#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)
|
#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)))
|
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
|
||||||
#elif \
|
#elif JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) || \
|
JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) || \
|
||||||
@@ -1348,8 +1314,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
|
#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
|
||||||
#define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
|
#define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
|
||||||
(JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(9, 0, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(9, 0, 0) || \
|
||||||
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
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(expr, value, probability) __builtin_expect_with_probability((expr), (value), (probability))
|
||||||
@@ -1357,8 +1322,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0, (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_LIKELY(expr) __builtin_expect(!!(expr), 1)
|
||||||
#define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
|
#define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
|
||||||
#elif \
|
#elif (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
|
||||||
(JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0) && defined(__cplusplus)) || \
|
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0) && defined(__cplusplus)) || \
|
||||||
@@ -1402,8 +1366,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_MALLOC)
|
#if defined(JSON_HEDLEY_MALLOC)
|
||||||
#undef JSON_HEDLEY_MALLOC
|
#undef JSON_HEDLEY_MALLOC
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
||||||
@@ -1424,8 +1387,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
|
#define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
|
||||||
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0)
|
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0)
|
||||||
#define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
|
#define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
|
||||||
#elif \
|
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || \
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
|
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
||||||
#define JSON_HEDLEY_MALLOC __declspec(restrict)
|
#define JSON_HEDLEY_MALLOC __declspec(restrict)
|
||||||
#else
|
#else
|
||||||
@@ -1435,8 +1397,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_PURE)
|
#if defined(JSON_HEDLEY_PURE)
|
||||||
#undef JSON_HEDLEY_PURE
|
#undef JSON_HEDLEY_PURE
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(2, 96, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(2, 96, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
||||||
@@ -1459,11 +1420,9 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0)
|
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0)
|
||||||
#define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
|
#define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
|
||||||
#elif defined(__cplusplus) && \
|
#elif defined(__cplusplus) && \
|
||||||
( \
|
(JSON_HEDLEY_TI_CL430_VERSION_CHECK(2, 0, 1) || \
|
||||||
JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
|
|
||||||
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0) || \
|
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0) || \
|
||||||
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
|
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0))
|
||||||
)
|
|
||||||
#define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
|
#define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
|
||||||
#else
|
#else
|
||||||
#define JSON_HEDLEY_PURE
|
#define JSON_HEDLEY_PURE
|
||||||
@@ -1472,8 +1431,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_CONST)
|
#if defined(JSON_HEDLEY_CONST)
|
||||||
#undef JSON_HEDLEY_CONST
|
#undef JSON_HEDLEY_CONST
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(2, 5, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(2, 5, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
||||||
@@ -1493,8 +1451,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \
|
JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \
|
||||||
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
||||||
#define JSON_HEDLEY_CONST __attribute__((__const__))
|
#define JSON_HEDLEY_CONST __attribute__((__const__))
|
||||||
#elif \
|
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0)
|
||||||
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
|
|
||||||
#define JSON_HEDLEY_CONST _Pragma("no_side_effect")
|
#define JSON_HEDLEY_CONST _Pragma("no_side_effect")
|
||||||
#else
|
#else
|
||||||
#define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
|
#define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
|
||||||
@@ -1505,8 +1462,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#endif
|
#endif
|
||||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
|
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
|
||||||
#define JSON_HEDLEY_RESTRICT restrict
|
#define JSON_HEDLEY_RESTRICT restrict
|
||||||
#elif \
|
#elif JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
|
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || \
|
JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \
|
||||||
@@ -1531,16 +1487,13 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_INLINE)
|
#if defined(JSON_HEDLEY_INLINE)
|
||||||
#undef JSON_HEDLEY_INLINE
|
#undef JSON_HEDLEY_INLINE
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
|
||||||
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
|
|
||||||
(defined(__cplusplus) && (__cplusplus >= 199711L))
|
(defined(__cplusplus) && (__cplusplus >= 199711L))
|
||||||
#define JSON_HEDLEY_INLINE inline
|
#define JSON_HEDLEY_INLINE inline
|
||||||
#elif \
|
#elif defined(JSON_HEDLEY_GCC_VERSION) || \
|
||||||
defined(JSON_HEDLEY_GCC_VERSION) || \
|
|
||||||
JSON_HEDLEY_ARM_VERSION_CHECK(6, 2, 0)
|
JSON_HEDLEY_ARM_VERSION_CHECK(6, 2, 0)
|
||||||
#define JSON_HEDLEY_INLINE __inline__
|
#define JSON_HEDLEY_INLINE __inline__
|
||||||
#elif \
|
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(12, 0, 0) || \
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
|
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \
|
||||||
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \
|
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \
|
||||||
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 1, 0) || \
|
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 1, 0) || \
|
||||||
@@ -1558,8 +1511,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_ALWAYS_INLINE)
|
#if defined(JSON_HEDLEY_ALWAYS_INLINE)
|
||||||
#undef JSON_HEDLEY_ALWAYS_INLINE
|
#undef JSON_HEDLEY_ALWAYS_INLINE
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
||||||
@@ -1579,19 +1531,16 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || \
|
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || \
|
||||||
JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0)
|
JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0)
|
||||||
#define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
|
#define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
|
||||||
#elif \
|
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(12, 0, 0) || \
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
|
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
||||||
#define JSON_HEDLEY_ALWAYS_INLINE __forceinline
|
#define JSON_HEDLEY_ALWAYS_INLINE __forceinline
|
||||||
#elif defined(__cplusplus) && \
|
#elif defined(__cplusplus) && \
|
||||||
( \
|
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
|
||||||
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
|
|
||||||
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
|
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
|
||||||
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
|
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
|
||||||
JSON_HEDLEY_TI_CL6X_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_CL7X_VERSION_CHECK(1, 2, 0) || \
|
||||||
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
|
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0))
|
||||||
)
|
|
||||||
#define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
|
#define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
|
||||||
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
|
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
|
||||||
#define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
|
#define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
|
||||||
@@ -1602,8 +1551,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_NEVER_INLINE)
|
#if defined(JSON_HEDLEY_NEVER_INLINE)
|
||||||
#undef JSON_HEDLEY_NEVER_INLINE
|
#undef JSON_HEDLEY_NEVER_INLINE
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
||||||
@@ -1623,8 +1571,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || \
|
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || \
|
||||||
JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0)
|
JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0)
|
||||||
#define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
|
#define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
|
||||||
#elif \
|
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || \
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
|
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
||||||
#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
|
#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
|
||||||
#elif JSON_HEDLEY_PGI_VERSION_CHECK(10, 2, 0)
|
#elif JSON_HEDLEY_PGI_VERSION_CHECK(10, 2, 0)
|
||||||
@@ -1655,20 +1602,15 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#define JSON_HEDLEY_PUBLIC __declspec(dllexport)
|
#define JSON_HEDLEY_PUBLIC __declspec(dllexport)
|
||||||
#define JSON_HEDLEY_IMPORT __declspec(dllimport)
|
#define JSON_HEDLEY_IMPORT __declspec(dllimport)
|
||||||
#else
|
#else
|
||||||
# if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \
|
||||||
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \
|
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \
|
||||||
JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \
|
JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \
|
||||||
( \
|
(defined(__TI_EABI__) && \
|
||||||
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_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)
|
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
||||||
#define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
|
#define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
|
||||||
#define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
|
#define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
|
||||||
@@ -1682,14 +1624,12 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_NO_THROW)
|
#if defined(JSON_HEDLEY_NO_THROW)
|
||||||
#undef JSON_HEDLEY_NO_THROW
|
#undef JSON_HEDLEY_NO_THROW
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
||||||
#define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
|
#define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
|
||||||
#elif \
|
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 1, 0) || \
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
|
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \
|
||||||
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0)
|
JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0)
|
||||||
#define JSON_HEDLEY_NO_THROW __declspec(nothrow)
|
#define JSON_HEDLEY_NO_THROW __declspec(nothrow)
|
||||||
@@ -1700,8 +1640,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_FALL_THROUGH)
|
#if defined(JSON_HEDLEY_FALL_THROUGH)
|
||||||
#undef JSON_HEDLEY_FALL_THROUGH
|
#undef JSON_HEDLEY_FALL_THROUGH
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(7, 0, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(7, 0, 0) || \
|
||||||
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
||||||
#define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
|
#define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
|
||||||
@@ -1718,8 +1657,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_RETURNS_NON_NULL)
|
#if defined(JSON_HEDLEY_RETURNS_NON_NULL)
|
||||||
#undef JSON_HEDLEY_RETURNS_NON_NULL
|
#undef JSON_HEDLEY_RETURNS_NON_NULL
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
|
||||||
JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) || \
|
||||||
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
|
||||||
#define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
|
#define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
|
||||||
@@ -1732,8 +1670,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_ARRAY_PARAM)
|
#if defined(JSON_HEDLEY_ARRAY_PARAM)
|
||||||
#undef JSON_HEDLEY_ARRAY_PARAM
|
#undef JSON_HEDLEY_ARRAY_PARAM
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
|
||||||
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
|
|
||||||
!defined(__STDC_NO_VLA__) && \
|
!defined(__STDC_NO_VLA__) && \
|
||||||
!defined(__cplusplus) && \
|
!defined(__cplusplus) && \
|
||||||
!defined(JSON_HEDLEY_PGI_VERSION) && \
|
!defined(JSON_HEDLEY_PGI_VERSION) && \
|
||||||
@@ -1754,8 +1691,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
|
#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
|
||||||
#undef JSON_HEDLEY_IS_CONSTEXPR_
|
#undef JSON_HEDLEY_IS_CONSTEXPR_
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
|
||||||
JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 19) || \
|
JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 19) || \
|
||||||
@@ -1768,8 +1704,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
|
#define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
|
||||||
#endif
|
#endif
|
||||||
#if !defined(__cplusplus)
|
#if !defined(__cplusplus)
|
||||||
# if \
|
#if JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
|
||||||
JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
|
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \
|
JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \
|
||||||
@@ -1782,8 +1717,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*)((intptr_t)((expr) * 0)) : (int*)0)), int*)
|
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*)((intptr_t)((expr) * 0)) : (int*)0)), int*)
|
||||||
#endif
|
#endif
|
||||||
# elif \
|
#elif ( \
|
||||||
( \
|
|
||||||
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
|
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
|
||||||
!defined(JSON_HEDLEY_SUNPRO_VERSION) && \
|
!defined(JSON_HEDLEY_SUNPRO_VERSION) && \
|
||||||
!defined(JSON_HEDLEY_PGI_VERSION) && \
|
!defined(JSON_HEDLEY_PGI_VERSION) && \
|
||||||
@@ -1799,8 +1733,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*)((intptr_t) * 0) : (int*)0), int*: 1, void*: 0)
|
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*)((intptr_t) * 0) : (int*)0), int*: 1, void*: 0)
|
||||||
#endif
|
#endif
|
||||||
# elif \
|
#elif defined(JSON_HEDLEY_GCC_VERSION) || \
|
||||||
defined(JSON_HEDLEY_GCC_VERSION) || \
|
|
||||||
defined(JSON_HEDLEY_INTEL_VERSION) || \
|
defined(JSON_HEDLEY_INTEL_VERSION) || \
|
||||||
defined(JSON_HEDLEY_TINYC_VERSION) || \
|
defined(JSON_HEDLEY_TINYC_VERSION) || \
|
||||||
defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
|
defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
|
||||||
@@ -1813,12 +1746,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
|
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
|
||||||
sizeof(void) != \
|
sizeof(void) != \
|
||||||
sizeof(*( \
|
sizeof(*( \
|
||||||
1 ? \
|
1 ? ((void*)((expr) * 0L)) : ((struct { char v[sizeof(void) * 2]; }*)1))))
|
||||||
((void*) ((expr) * 0L) ) : \
|
|
||||||
((struct { char v[sizeof(void) * 2]; } *) 1) \
|
|
||||||
) \
|
|
||||||
) \
|
|
||||||
)
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
|
#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
|
||||||
@@ -1855,17 +1783,13 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_STATIC_ASSERT)
|
#if defined(JSON_HEDLEY_STATIC_ASSERT)
|
||||||
#undef JSON_HEDLEY_STATIC_ASSERT
|
#undef JSON_HEDLEY_STATIC_ASSERT
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if !defined(__cplusplus) && ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
|
||||||
!defined(__cplusplus) && ( \
|
|
||||||
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
|
|
||||||
(JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
|
(JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(6, 0, 0) || \
|
JSON_HEDLEY_GCC_VERSION_CHECK(6, 0, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
|
||||||
defined(_Static_assert) \
|
defined(_Static_assert))
|
||||||
)
|
|
||||||
#define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
|
#define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
|
||||||
#elif \
|
#elif (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
|
||||||
(defined(__cplusplus) && (__cplusplus >= 201103L)) || \
|
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(16, 0, 0) || \
|
JSON_HEDLEY_MSVC_VERSION_CHECK(16, 0, 0) || \
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 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))
|
#define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
|
||||||
@@ -1899,8 +1823,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
|
JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
|
||||||
JSON_HEDLEY_PRAGMA(message msg) \
|
JSON_HEDLEY_PRAGMA(message msg) \
|
||||||
JSON_HEDLEY_DIAGNOSTIC_POP
|
JSON_HEDLEY_DIAGNOSTIC_POP
|
||||||
#elif \
|
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 4, 0) || \
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
|
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
|
||||||
#define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
|
#define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
|
||||||
#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5, 0, 0)
|
#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5, 0, 0)
|
||||||
@@ -1922,13 +1845,11 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
|
JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
|
||||||
JSON_HEDLEY_PRAGMA(clang warning msg) \
|
JSON_HEDLEY_PRAGMA(clang warning msg) \
|
||||||
JSON_HEDLEY_DIAGNOSTIC_POP
|
JSON_HEDLEY_DIAGNOSTIC_POP
|
||||||
#elif \
|
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 8, 0) || \
|
||||||
JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
|
|
||||||
JSON_HEDLEY_PGI_VERSION_CHECK(18, 4, 0) || \
|
JSON_HEDLEY_PGI_VERSION_CHECK(18, 4, 0) || \
|
||||||
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
|
JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
|
||||||
#define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
|
#define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
|
||||||
#elif \
|
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) || \
|
||||||
JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
|
|
||||||
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
||||||
#define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
|
#define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
|
||||||
#else
|
#else
|
||||||
@@ -1977,8 +1898,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if JSON_HEDLEY_INTEL_VERSION_CHECK(19, 0, 0)
|
#if JSON_HEDLEY_INTEL_VERSION_CHECK(19, 0, 0)
|
||||||
#define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__({ \
|
#define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__({ \
|
||||||
JSON_HEDLEY_DIAGNOSTIC_PUSH \
|
JSON_HEDLEY_DIAGNOSTIC_PUSH \
|
||||||
_Pragma("warning(disable:188)") \
|
_Pragma("warning(disable:188)")((T)(expr)); \
|
||||||
((T) (expr)); \
|
|
||||||
JSON_HEDLEY_DIAGNOSTIC_POP \
|
JSON_HEDLEY_DIAGNOSTIC_POP \
|
||||||
}))
|
}))
|
||||||
#else
|
#else
|
||||||
@@ -1988,8 +1908,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
#if defined(JSON_HEDLEY_EMPTY_BASES)
|
#if defined(JSON_HEDLEY_EMPTY_BASES)
|
||||||
#undef JSON_HEDLEY_EMPTY_BASES
|
#undef JSON_HEDLEY_EMPTY_BASES
|
||||||
#endif
|
#endif
|
||||||
#if \
|
#if (JSON_HEDLEY_MSVC_VERSION_CHECK(19, 0, 23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20, 0, 0)) || \
|
||||||
(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)
|
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
|
||||||
#define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
|
#define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
|
||||||
#else
|
#else
|
||||||
|
|||||||
+1554
-1471
File diff suppressed because it is too large.
Load diff
@@ -24,8 +24,6 @@
|
|||||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This file contains all macro definitions affecting or depending on the ABI
|
// This file contains all macro definitions affecting or depending on the ABI
|
||||||
|
|
||||||
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
|
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
|
||||||
@@ -103,12 +101,10 @@
|
|||||||
|
|
||||||
#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
|
#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
#define NLOHMANN_JSON_NAMESPACE_BEGIN \
|
#define NLOHMANN_JSON_NAMESPACE_BEGIN \
|
||||||
namespace nlohmann \
|
namespace nlohmann { \
|
||||||
{ \
|
|
||||||
inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
|
inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
|
||||||
NLOHMANN_JSON_ABI_TAGS, \
|
NLOHMANN_JSON_ABI_TAGS, \
|
||||||
NLOHMANN_JSON_NAMESPACE_VERSION) \
|
NLOHMANN_JSON_NAMESPACE_VERSION) {
|
||||||
{
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NLOHMANN_JSON_NAMESPACE_END
|
#ifndef NLOHMANN_JSON_NAMESPACE_END
|
||||||
@@ -117,7 +113,6 @@
|
|||||||
} // namespace nlohmann
|
} // namespace nlohmann
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief namespace for Niels Lohmann
|
@brief namespace for Niels Lohmann
|
||||||
@see https://github.com/nlohmann
|
@see https://github.com/nlohmann
|
||||||
@@ -140,7 +135,8 @@ struct adl_serializer;
|
|||||||
template<template<typename U, typename V, typename... Args> class ObjectType =
|
template<template<typename U, typename V, typename... Args> class ObjectType =
|
||||||
std::map,
|
std::map,
|
||||||
template<typename U, typename... Args> class ArrayType = std::vector,
|
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 NumberIntegerType = std::int64_t,
|
||||||
class NumberUnsignedType = std::uint64_t,
|
class NumberUnsignedType = std::uint64_t,
|
||||||
class NumberFloatType = double,
|
class NumberFloatType = double,
|
||||||
|
|||||||
@@ -7,11 +7,11 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
#include <benchmark/benchmark.h>
|
#include <benchmark/benchmark.h>
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <vector>
|
|
||||||
#include <test_data.hpp>
|
#include <test_data.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include "Foo.hpp"
|
#include "Foo.hpp"
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
class Bar : public Foo {};
|
class Bar : public Foo
|
||||||
|
{};
|
||||||
@@ -9,4 +9,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
class Foo {};
|
class Foo
|
||||||
|
{};
|
||||||
@@ -12,9 +12,9 @@ an implementation of the `LLVMFuzzerTestOneInput` function which processes a
|
|||||||
passed byte array.
|
passed byte array.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <vector> // for vector
|
|
||||||
#include <cstdint> // for uint8_t
|
#include <cstdint> // for uint8_t
|
||||||
#include <iostream> // for cin
|
#include <iostream> // for cin
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ drivers.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ drivers.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ drivers.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ drivers.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ drivers.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ drivers.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdio> // fopen, fclose, FILE
|
#include <cstdio> // fopen, fclose, FILE
|
||||||
|
#include <doctest.h>
|
||||||
#include <memory> // unique_ptr
|
#include <memory> // unique_ptr
|
||||||
#include <test_data.hpp>
|
#include <test_data.hpp>
|
||||||
#include <doctest.h>
|
|
||||||
|
|
||||||
namespace utils
|
namespace utils {
|
||||||
{
|
|
||||||
|
|
||||||
inline bool check_testsuite_downloaded()
|
inline bool check_testsuite_downloaded()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,8 +12,7 @@
|
|||||||
#include <fstream> // ifstream, istreambuf_iterator, ios
|
#include <fstream> // ifstream, istreambuf_iterator, ios
|
||||||
#include <vector> // vector
|
#include <vector> // vector
|
||||||
|
|
||||||
namespace utils
|
namespace utils {
|
||||||
{
|
|
||||||
|
|
||||||
inline std::vector<std::uint8_t> read_binary_file(const std::string& filename)
|
inline std::vector<std::uint8_t> read_binary_file(const std::string& filename)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ TEST_CASE("32bit")
|
|||||||
REQUIRE(SIZE_MAX == 0xffffffff);
|
REQUIRE(SIZE_MAX == 0xffffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, \
|
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::int32_t, false, true>,
|
||||||
trait_test_arg<std::size_t, std::uint32_t, true, 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::int64_t, false, false>,
|
||||||
trait_test_arg<std::size_t, std::uint64_t, true, false>);
|
trait_test_arg<std::size_t, std::uint64_t, true, false>);
|
||||||
|
|
||||||
TEST_CASE("BJData")
|
TEST_CASE("BJData")
|
||||||
|
|||||||
@@ -21,36 +21,30 @@ TEST_CASE("algorithms")
|
|||||||
{
|
{
|
||||||
SECTION("std::all_of")
|
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();
|
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;
|
return value.type() == json::value_t::number_integer;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("std::any_of")
|
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";
|
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;
|
return value.get<int>() > 1;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("std::none_of")
|
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();
|
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;
|
return value.get<int>() <= 0;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -61,8 +55,7 @@ TEST_CASE("algorithms")
|
|||||||
{
|
{
|
||||||
int sum = 0;
|
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())
|
if (value.is_number())
|
||||||
{
|
{
|
||||||
sum += static_cast<int>(value);
|
sum += static_cast<int>(value);
|
||||||
@@ -74,8 +67,7 @@ TEST_CASE("algorithms")
|
|||||||
|
|
||||||
SECTION("writing")
|
SECTION("writing")
|
||||||
{
|
{
|
||||||
auto add17 = [](json & value)
|
auto add17 = [](json& value) {
|
||||||
{
|
|
||||||
if (value.is_array())
|
if (value.is_array())
|
||||||
{
|
{
|
||||||
value.push_back(17);
|
value.push_back(17);
|
||||||
@@ -95,12 +87,10 @@ TEST_CASE("algorithms")
|
|||||||
|
|
||||||
SECTION("std::count_if")
|
SECTION("std::count_if")
|
||||||
{
|
{
|
||||||
CHECK(std::count_if(j_array.begin(), j_array.end(), [](const json & value)
|
CHECK(std::count_if(j_array.begin(), j_array.end(), [](const json& value) {
|
||||||
{
|
|
||||||
return (value.is_number());
|
return (value.is_number());
|
||||||
}) == 3);
|
}) == 3);
|
||||||
CHECK(std::count_if(j_array.begin(), j_array.end(), [](const json&)
|
CHECK(std::count_if(j_array.begin(), j_array.end(), [](const json&) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}) == 9);
|
}) == 9);
|
||||||
}
|
}
|
||||||
@@ -127,9 +117,7 @@ TEST_CASE("algorithms")
|
|||||||
// compare objects only by size of its elements
|
// 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"};
|
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()));
|
||||||
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) {
|
||||||
[](const json & a, const json & b)
|
|
||||||
{
|
|
||||||
return (a.size() == b.size());
|
return (a.size() == b.size());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -143,9 +131,7 @@ TEST_CASE("algorithms")
|
|||||||
|
|
||||||
SECTION("std::find_if")
|
SECTION("std::find_if")
|
||||||
{
|
{
|
||||||
auto it = std::find_if(j_array.begin(), j_array.end(),
|
auto it = std::find_if(j_array.begin(), j_array.end(), [](const json& value) {
|
||||||
[](const json & value)
|
|
||||||
{
|
|
||||||
return value.is_boolean();
|
return value.is_boolean();
|
||||||
});
|
});
|
||||||
CHECK(std::distance(j_array.begin(), it) == 4);
|
CHECK(std::distance(j_array.begin(), it) == 4);
|
||||||
@@ -153,9 +139,7 @@ TEST_CASE("algorithms")
|
|||||||
|
|
||||||
SECTION("std::find_if_not")
|
SECTION("std::find_if_not")
|
||||||
{
|
{
|
||||||
auto it = std::find_if_not(j_array.begin(), j_array.end(),
|
auto it = std::find_if_not(j_array.begin(), j_array.end(), [](const json& value) {
|
||||||
[](const json & value)
|
|
||||||
{
|
|
||||||
return value.is_number();
|
return value.is_number();
|
||||||
});
|
});
|
||||||
CHECK(std::distance(j_array.begin(), it) == 3);
|
CHECK(std::distance(j_array.begin(), it) == 3);
|
||||||
@@ -164,9 +148,7 @@ TEST_CASE("algorithms")
|
|||||||
SECTION("std::adjacent_find")
|
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()) == j_array.end());
|
||||||
CHECK(std::adjacent_find(j_array.begin(), j_array.end(),
|
CHECK(std::adjacent_find(j_array.begin(), j_array.end(), [](const json& v1, const json& v2) {
|
||||||
[](const json & v1, const json & v2)
|
|
||||||
{
|
|
||||||
return v1.type() == v2.type();
|
return v1.type() == v2.type();
|
||||||
}) == j_array.begin());
|
}) == j_array.begin());
|
||||||
}
|
}
|
||||||
@@ -188,8 +170,7 @@ TEST_CASE("algorithms")
|
|||||||
|
|
||||||
SECTION("std::partition")
|
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();
|
return v.is_string();
|
||||||
});
|
});
|
||||||
CHECK(std::distance(j_array.begin(), it) == 2);
|
CHECK(std::distance(j_array.begin(), it) == 2);
|
||||||
@@ -211,8 +192,7 @@ TEST_CASE("algorithms")
|
|||||||
SECTION("with user-defined comparison")
|
SECTION("with user-defined comparison")
|
||||||
{
|
{
|
||||||
json j = {3, {{"one", 1}, {"two", 2}}, {1, 2, 3}, nullptr};
|
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();
|
return a.size() < b.size();
|
||||||
});
|
});
|
||||||
CHECK(j == json({nullptr, 3, {{"one", 1}, {"two", 2}}, {1, 2, 3}}));
|
CHECK(j == json({nullptr, 3, {{"one", 1}, {"two", 2}}, {1, 2, 3}}));
|
||||||
@@ -335,8 +315,7 @@ TEST_CASE("algorithms")
|
|||||||
json dest_arr;
|
json dest_arr;
|
||||||
const json source_arr = {0, 3, 6, 9, 12, 15, 20};
|
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;
|
return _value.get<int>() % 3 == 0;
|
||||||
});
|
});
|
||||||
CHECK(dest_arr == json({0, 3, 6, 9, 12, 15}));
|
CHECK(dest_arr == json({0, 3, 6, 9, 12, 15}));
|
||||||
@@ -349,7 +328,6 @@ TEST_CASE("algorithms")
|
|||||||
|
|
||||||
std::copy_n(source_arr.begin(), numToCopy, std::back_inserter(dest_arr));
|
std::copy_n(source_arr.begin(), numToCopy, std::back_inserter(dest_arr));
|
||||||
CHECK(dest_arr == json{0, 1});
|
CHECK(dest_arr == json{0, 1});
|
||||||
|
|
||||||
}
|
}
|
||||||
SECTION("copy n chars")
|
SECTION("copy n chars")
|
||||||
{
|
{
|
||||||
@@ -361,5 +339,4 @@ TEST_CASE("algorithms")
|
|||||||
CHECK(dest_arr == json{'1', '2', '3', '4'});
|
CHECK(dest_arr == json{'1', '2', '3', '4'});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,8 +12,7 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
// special test case to check if memory is leaked if constructor throws
|
// special test case to check if memory is leaked if constructor throws
|
||||||
template<class T>
|
template<class T>
|
||||||
struct bad_allocator : std::allocator<T>
|
struct bad_allocator : std::allocator<T>
|
||||||
@@ -21,7 +20,9 @@ struct bad_allocator : std::allocator<T>
|
|||||||
using std::allocator<T>::allocator;
|
using std::allocator<T>::allocator;
|
||||||
|
|
||||||
bad_allocator() = default;
|
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>
|
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)
|
||||||
@@ -56,8 +57,7 @@ TEST_CASE("bad_alloc")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
bool next_construct_fails = false;
|
bool next_construct_fails = false;
|
||||||
bool next_destroy_fails = false;
|
bool next_destroy_fails = false;
|
||||||
bool next_deallocate_fails = false;
|
bool next_deallocate_fails = false;
|
||||||
@@ -219,14 +219,14 @@ TEST_CASE("controlled bad_alloc")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<class T>
|
template<class T>
|
||||||
struct allocator_no_forward : std::allocator<T>
|
struct allocator_no_forward : std::allocator<T>
|
||||||
{
|
{
|
||||||
allocator_no_forward() = default;
|
allocator_no_forward() = default;
|
||||||
template<class U>
|
template<class U>
|
||||||
allocator_no_forward(allocator_no_forward<U> /*unused*/) {}
|
allocator_no_forward(allocator_no_forward<U> /*unused*/)
|
||||||
|
{}
|
||||||
|
|
||||||
template<class U>
|
template<class U>
|
||||||
struct rebind
|
struct rebind
|
||||||
|
|||||||
@@ -30,9 +30,15 @@ class alt_string
|
|||||||
|
|
||||||
static constexpr auto npos = static_cast<std::size_t>(-1);
|
static constexpr auto npos = static_cast<std::size_t>(-1);
|
||||||
|
|
||||||
alt_string(const char* str): str_impl(str) {}
|
alt_string(const char* str)
|
||||||
alt_string(const char* str, std::size_t count): str_impl(str, count) {}
|
: str_impl(str)
|
||||||
alt_string(size_t count, char chr): str_impl(count, chr) {}
|
{}
|
||||||
|
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;
|
alt_string() = default;
|
||||||
|
|
||||||
template<typename... TParams>
|
template<typename... TParams>
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ DOCTEST_CLANG_SUPPRESS_WARNING("-Wstrict-overflow")
|
|||||||
static int assert_counter;
|
static int assert_counter;
|
||||||
|
|
||||||
/// set failure variable to true instead of calling assert(x)
|
/// 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>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include "make_test_data_available.hpp"
|
#include "make_test_data_available.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
TEST_CASE("Binary Formats" * doctest::skip())
|
TEST_CASE("Binary Formats" * doctest::skip())
|
||||||
{
|
{
|
||||||
|
|||||||
+769
-211
File diff suppressed because it is too large.
Load diff
+661
-190
File diff suppressed because it is too large.
Load diff
+262
-127
@@ -11,21 +11,21 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
|
#include "make_test_data_available.hpp"
|
||||||
|
#include "test_utils.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include "make_test_data_available.hpp"
|
#include <sstream>
|
||||||
#include "test_utils.hpp"
|
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class SaxCountdown
|
class SaxCountdown
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit SaxCountdown(const int count) : events_left(count)
|
explicit SaxCountdown(const int count)
|
||||||
|
: events_left(count)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool null()
|
bool null()
|
||||||
@@ -173,8 +173,7 @@ TEST_CASE("CBOR")
|
|||||||
{
|
{
|
||||||
SECTION("-9223372036854775808..-4294967297")
|
SECTION("-9223372036854775808..-4294967297")
|
||||||
{
|
{
|
||||||
const std::vector<int64_t> numbers
|
const std::vector<int64_t> numbers{
|
||||||
{
|
|
||||||
(std::numeric_limits<int64_t>::min)(),
|
(std::numeric_limits<int64_t>::min)(),
|
||||||
-1000000000000000000,
|
-1000000000000000000,
|
||||||
-100000000000000000,
|
-100000000000000000,
|
||||||
@@ -199,8 +198,7 @@ TEST_CASE("CBOR")
|
|||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const auto positive = static_cast<uint64_t>(-1 - i);
|
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>(0x3b),
|
||||||
static_cast<uint8_t>((positive >> 56) & 0xff),
|
static_cast<uint8_t>((positive >> 56) & 0xff),
|
||||||
static_cast<uint8_t>((positive >> 48) & 0xff),
|
static_cast<uint8_t>((positive >> 48) & 0xff),
|
||||||
@@ -238,8 +236,7 @@ TEST_CASE("CBOR")
|
|||||||
|
|
||||||
SECTION("-4294967296..-65537")
|
SECTION("-4294967296..-65537")
|
||||||
{
|
{
|
||||||
const std::vector<int64_t> numbers
|
const std::vector<int64_t> numbers{
|
||||||
{
|
|
||||||
-65537,
|
-65537,
|
||||||
-100000,
|
-100000,
|
||||||
-1000000,
|
-1000000,
|
||||||
@@ -260,8 +257,7 @@ TEST_CASE("CBOR")
|
|||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
auto positive = static_cast<uint32_t>(static_cast<uint64_t>(-1 - i) & 0x00000000ffffffff);
|
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>(0x3a),
|
||||||
static_cast<uint8_t>((positive >> 24) & 0xff),
|
static_cast<uint8_t>((positive >> 24) & 0xff),
|
||||||
static_cast<uint8_t>((positive >> 16) & 0xff),
|
static_cast<uint8_t>((positive >> 16) & 0xff),
|
||||||
@@ -303,8 +299,7 @@ TEST_CASE("CBOR")
|
|||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const auto positive = static_cast<uint16_t>(-1 - i);
|
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>(0x39),
|
||||||
static_cast<uint8_t>((positive >> 8) & 0xff),
|
static_cast<uint8_t>((positive >> 8) & 0xff),
|
||||||
static_cast<uint8_t>(positive & 0xff),
|
static_cast<uint8_t>(positive & 0xff),
|
||||||
@@ -356,8 +351,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const std::vector<uint8_t> expected
|
const std::vector<uint8_t> expected{
|
||||||
{
|
|
||||||
0x38,
|
0x38,
|
||||||
static_cast<uint8_t>(-1 - i),
|
static_cast<uint8_t>(-1 - i),
|
||||||
};
|
};
|
||||||
@@ -390,8 +384,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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)),
|
static_cast<uint8_t>(0x20 - 1 - static_cast<uint8_t>(i)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -423,8 +416,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const std::vector<uint8_t> expected
|
const std::vector<uint8_t> expected{
|
||||||
{
|
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -456,8 +448,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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>(0x18),
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
@@ -491,8 +482,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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>(0x19),
|
||||||
static_cast<uint8_t>((i >> 8) & 0xff),
|
static_cast<uint8_t>((i >> 8) & 0xff),
|
||||||
static_cast<uint8_t>(i & 0xff),
|
static_cast<uint8_t>(i & 0xff),
|
||||||
@@ -518,8 +508,9 @@ TEST_CASE("CBOR")
|
|||||||
{
|
{
|
||||||
for (const uint32_t i :
|
for (const uint32_t i :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u})
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@@ -531,8 +522,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const std::vector<uint8_t> expected
|
const std::vector<uint8_t> expected{
|
||||||
{
|
|
||||||
0x1a,
|
0x1a,
|
||||||
static_cast<uint8_t>((i >> 24) & 0xff),
|
static_cast<uint8_t>((i >> 24) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 16) & 0xff),
|
static_cast<uint8_t>((i >> 16) & 0xff),
|
||||||
@@ -563,8 +553,8 @@ TEST_CASE("CBOR")
|
|||||||
{
|
{
|
||||||
for (const uint64_t i :
|
for (const uint64_t i :
|
||||||
{
|
{
|
||||||
4294967296ul, 4611686018427387903ul
|
4294967296ul,
|
||||||
})
|
4611686018427387903ul})
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@@ -576,8 +566,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const std::vector<uint8_t> expected
|
const std::vector<uint8_t> expected{
|
||||||
{
|
|
||||||
0x1b,
|
0x1b,
|
||||||
static_cast<uint8_t>((i >> 070) & 0xff),
|
static_cast<uint8_t>((i >> 070) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 060) & 0xff),
|
static_cast<uint8_t>((i >> 060) & 0xff),
|
||||||
@@ -625,8 +614,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const std::vector<uint8_t> expected
|
const std::vector<uint8_t> expected{
|
||||||
{
|
|
||||||
0xd1,
|
0xd1,
|
||||||
static_cast<uint8_t>((i >> 8) & 0xff),
|
static_cast<uint8_t>((i >> 8) & 0xff),
|
||||||
static_cast<uint8_t>(i & 0xff),
|
static_cast<uint8_t>(i & 0xff),
|
||||||
@@ -663,8 +651,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const std::vector<uint8_t> expected
|
const std::vector<uint8_t> expected{
|
||||||
{
|
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -695,8 +682,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const std::vector<uint8_t> expected
|
const std::vector<uint8_t> expected{
|
||||||
{
|
|
||||||
0x18,
|
0x18,
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
@@ -730,8 +716,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const std::vector<uint8_t> expected
|
const std::vector<uint8_t> expected{
|
||||||
{
|
|
||||||
0x19,
|
0x19,
|
||||||
static_cast<uint8_t>((i >> 8) & 0xff),
|
static_cast<uint8_t>((i >> 8) & 0xff),
|
||||||
static_cast<uint8_t>(i & 0xff),
|
static_cast<uint8_t>(i & 0xff),
|
||||||
@@ -757,8 +742,9 @@ TEST_CASE("CBOR")
|
|||||||
{
|
{
|
||||||
for (const uint32_t i :
|
for (const uint32_t i :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u})
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@@ -769,8 +755,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const std::vector<uint8_t> expected
|
const std::vector<uint8_t> expected{
|
||||||
{
|
|
||||||
0x1a,
|
0x1a,
|
||||||
static_cast<uint8_t>((i >> 24) & 0xff),
|
static_cast<uint8_t>((i >> 24) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 16) & 0xff),
|
static_cast<uint8_t>((i >> 16) & 0xff),
|
||||||
@@ -801,8 +786,8 @@ TEST_CASE("CBOR")
|
|||||||
{
|
{
|
||||||
for (const uint64_t i :
|
for (const uint64_t i :
|
||||||
{
|
{
|
||||||
4294967296ul, 4611686018427387903ul
|
4294967296ul,
|
||||||
})
|
4611686018427387903ul})
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@@ -813,8 +798,7 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
const std::vector<uint8_t> expected
|
const std::vector<uint8_t> expected{
|
||||||
{
|
|
||||||
0x1b,
|
0x1b,
|
||||||
static_cast<uint8_t>((i >> 070) & 0xff),
|
static_cast<uint8_t>((i >> 070) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 060) & 0xff),
|
static_cast<uint8_t>((i >> 060) & 0xff),
|
||||||
@@ -858,8 +842,15 @@ TEST_CASE("CBOR")
|
|||||||
const json j = v;
|
const json j = v;
|
||||||
std::vector<uint8_t> expected =
|
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);
|
const auto result = json::to_cbor(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@@ -945,8 +936,11 @@ TEST_CASE("CBOR")
|
|||||||
const json j = v;
|
const json j = v;
|
||||||
const std::vector<uint8_t> expected =
|
const std::vector<uint8_t> expected =
|
||||||
{
|
{
|
||||||
0xfa, 0x7f, 0x7f, 0xff, 0xff
|
0xfa,
|
||||||
};
|
0x7f,
|
||||||
|
0x7f,
|
||||||
|
0xff,
|
||||||
|
0xff};
|
||||||
const auto result = json::to_cbor(j);
|
const auto result = json::to_cbor(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
// roundtrip
|
// roundtrip
|
||||||
@@ -959,8 +953,11 @@ TEST_CASE("CBOR")
|
|||||||
const json j = v;
|
const json j = v;
|
||||||
const std::vector<uint8_t> expected =
|
const std::vector<uint8_t> expected =
|
||||||
{
|
{
|
||||||
0xfa, 0xff, 0x7f, 0xff, 0xff
|
0xfa,
|
||||||
};
|
0xff,
|
||||||
|
0x7f,
|
||||||
|
0xff,
|
||||||
|
0xff};
|
||||||
const auto result = json::to_cbor(j);
|
const auto result = json::to_cbor(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
// roundtrip
|
// roundtrip
|
||||||
@@ -973,8 +970,15 @@ TEST_CASE("CBOR")
|
|||||||
const json j = v;
|
const json j = v;
|
||||||
const std::vector<uint8_t> expected =
|
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
|
// double
|
||||||
const auto result = json::to_cbor(j);
|
const auto result = json::to_cbor(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
@@ -988,8 +992,11 @@ TEST_CASE("CBOR")
|
|||||||
const json j = v;
|
const json j = v;
|
||||||
const std::vector<uint8_t> expected =
|
const std::vector<uint8_t> expected =
|
||||||
{
|
{
|
||||||
0xfa, 0xff, 0x7f, 0xff, 0xff
|
0xfa,
|
||||||
};
|
0xff,
|
||||||
|
0x7f,
|
||||||
|
0xff,
|
||||||
|
0xff};
|
||||||
// the same with lowest float
|
// the same with lowest float
|
||||||
const auto result = json::to_cbor(j);
|
const auto result = json::to_cbor(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
@@ -997,7 +1004,6 @@ TEST_CASE("CBOR")
|
|||||||
CHECK(json::from_cbor(result) == j);
|
CHECK(json::from_cbor(result) == j);
|
||||||
CHECK(json::from_cbor(result) == v);
|
CHECK(json::from_cbor(result) == v);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("half-precision float (edge cases)")
|
SECTION("half-precision float (edge cases)")
|
||||||
@@ -1176,8 +1182,12 @@ TEST_CASE("CBOR")
|
|||||||
{
|
{
|
||||||
for (const size_t N :
|
for (const size_t N :
|
||||||
{
|
{
|
||||||
256u, 999u, 1025u, 3333u, 2048u, 65535u
|
256u,
|
||||||
})
|
999u,
|
||||||
|
1025u,
|
||||||
|
3333u,
|
||||||
|
2048u,
|
||||||
|
65535u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1209,8 +1219,9 @@ TEST_CASE("CBOR")
|
|||||||
{
|
{
|
||||||
for (const size_t N :
|
for (const size_t N :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1355,8 +1366,16 @@ TEST_CASE("CBOR")
|
|||||||
const json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
const json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||||
const std::vector<uint8_t> expected =
|
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);
|
const auto result = json::to_cbor(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@@ -1525,8 +1544,12 @@ TEST_CASE("CBOR")
|
|||||||
{
|
{
|
||||||
for (const size_t N :
|
for (const size_t N :
|
||||||
{
|
{
|
||||||
256u, 999u, 1025u, 3333u, 2048u, 65535u
|
256u,
|
||||||
})
|
999u,
|
||||||
|
1025u,
|
||||||
|
3333u,
|
||||||
|
2048u,
|
||||||
|
65535u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1558,8 +1581,9 @@ TEST_CASE("CBOR")
|
|||||||
{
|
{
|
||||||
for (const size_t N :
|
for (const size_t N :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1622,8 +1646,7 @@ TEST_CASE("CBOR")
|
|||||||
|
|
||||||
// callback to set binary_seen to true if a binary value was seen
|
// callback to set binary_seen to true if a binary value was seen
|
||||||
bool binary_seen = false;
|
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())
|
if (parsed.is_binary())
|
||||||
{
|
{
|
||||||
binary_seen = true;
|
binary_seen = true;
|
||||||
@@ -1644,36 +1667,28 @@ TEST_CASE("CBOR")
|
|||||||
{
|
{
|
||||||
SECTION("0x5b (byte array)")
|
SECTION("0x5b (byte array)")
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> const given = {0x5b, 0x00, 0x00, 0x00, 0x00,
|
std::vector<uint8_t> const given = {0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x61};
|
||||||
0x00, 0x00, 0x00, 0x01, 0x61
|
|
||||||
};
|
|
||||||
const json j = json::from_cbor(given);
|
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)")
|
SECTION("0x7b (string)")
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> const given = {0x7b, 0x00, 0x00, 0x00, 0x00,
|
std::vector<uint8_t> const given = {0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x61};
|
||||||
0x00, 0x00, 0x00, 0x01, 0x61
|
|
||||||
};
|
|
||||||
const json j = json::from_cbor(given);
|
const json j = json::from_cbor(given);
|
||||||
CHECK(j == "a");
|
CHECK(j == "a");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("0x9b (array)")
|
SECTION("0x9b (array)")
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> const given = {0x9b, 0x00, 0x00, 0x00, 0x00,
|
std::vector<uint8_t> const given = {0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf4};
|
||||||
0x00, 0x00, 0x00, 0x01, 0xf4
|
|
||||||
};
|
|
||||||
const json j = json::from_cbor(given);
|
const json j = json::from_cbor(given);
|
||||||
CHECK(j == json::parse("[false]"));
|
CHECK(j == json::parse("[false]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("0xbb (map)")
|
SECTION("0xbb (map)")
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> const given = {0xbb, 0x00, 0x00, 0x00, 0x00,
|
std::vector<uint8_t> const given = {0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x60, 0xf4};
|
||||||
0x00, 0x00, 0x00, 0x01, 0x60, 0xf4
|
|
||||||
};
|
|
||||||
const json j = json::from_cbor(given);
|
const json j = json::from_cbor(given);
|
||||||
CHECK(j == json::parse("{\"\": false}"));
|
CHECK(j == json::parse("{\"\": false}"));
|
||||||
}
|
}
|
||||||
@@ -1765,40 +1780,96 @@ TEST_CASE("CBOR")
|
|||||||
for (const auto byte :
|
for (const auto byte :
|
||||||
{
|
{
|
||||||
// ?
|
// ?
|
||||||
0x1c, 0x1d, 0x1e, 0x1f,
|
0x1c,
|
||||||
|
0x1d,
|
||||||
|
0x1e,
|
||||||
|
0x1f,
|
||||||
// ?
|
// ?
|
||||||
0x3c, 0x3d, 0x3e, 0x3f,
|
0x3c,
|
||||||
|
0x3d,
|
||||||
|
0x3e,
|
||||||
|
0x3f,
|
||||||
// ?
|
// ?
|
||||||
0x5c, 0x5d, 0x5e,
|
0x5c,
|
||||||
|
0x5d,
|
||||||
|
0x5e,
|
||||||
// ?
|
// ?
|
||||||
0x7c, 0x7d, 0x7e,
|
0x7c,
|
||||||
|
0x7d,
|
||||||
|
0x7e,
|
||||||
// ?
|
// ?
|
||||||
0x9c, 0x9d, 0x9e,
|
0x9c,
|
||||||
|
0x9d,
|
||||||
|
0x9e,
|
||||||
// ?
|
// ?
|
||||||
0xbc, 0xbd, 0xbe,
|
0xbc,
|
||||||
|
0xbd,
|
||||||
|
0xbe,
|
||||||
// date/time
|
// date/time
|
||||||
0xc0, 0xc1,
|
0xc0,
|
||||||
|
0xc1,
|
||||||
// bignum
|
// bignum
|
||||||
0xc2, 0xc3,
|
0xc2,
|
||||||
|
0xc3,
|
||||||
// fraction
|
// fraction
|
||||||
0xc4,
|
0xc4,
|
||||||
// bigfloat
|
// bigfloat
|
||||||
0xc5,
|
0xc5,
|
||||||
// tagged item
|
// tagged item
|
||||||
0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4,
|
0xc6,
|
||||||
|
0xc7,
|
||||||
|
0xc8,
|
||||||
|
0xc9,
|
||||||
|
0xca,
|
||||||
|
0xcb,
|
||||||
|
0xcc,
|
||||||
|
0xcd,
|
||||||
|
0xce,
|
||||||
|
0xcf,
|
||||||
|
0xd0,
|
||||||
|
0xd1,
|
||||||
|
0xd2,
|
||||||
|
0xd3,
|
||||||
|
0xd4,
|
||||||
// expected conversion
|
// expected conversion
|
||||||
0xd5, 0xd6, 0xd7,
|
0xd5,
|
||||||
|
0xd6,
|
||||||
|
0xd7,
|
||||||
// more tagged items
|
// more tagged items
|
||||||
0xd8, 0xd9, 0xda, 0xdb,
|
0xd8,
|
||||||
|
0xd9,
|
||||||
|
0xda,
|
||||||
|
0xdb,
|
||||||
// ?
|
// ?
|
||||||
0xdc, 0xdd, 0xde, 0xdf,
|
0xdc,
|
||||||
|
0xdd,
|
||||||
|
0xde,
|
||||||
|
0xdf,
|
||||||
// (simple value)
|
// (simple value)
|
||||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,
|
0xe0,
|
||||||
|
0xe1,
|
||||||
|
0xe2,
|
||||||
|
0xe3,
|
||||||
|
0xe4,
|
||||||
|
0xe5,
|
||||||
|
0xe6,
|
||||||
|
0xe7,
|
||||||
|
0xe8,
|
||||||
|
0xe9,
|
||||||
|
0xea,
|
||||||
|
0xeb,
|
||||||
|
0xec,
|
||||||
|
0xed,
|
||||||
|
0xee,
|
||||||
|
0xef,
|
||||||
|
0xf0,
|
||||||
|
0xf1,
|
||||||
|
0xf2,
|
||||||
|
0xf3,
|
||||||
// undefined
|
// undefined
|
||||||
0xf7,
|
0xf7,
|
||||||
// simple value
|
// simple value
|
||||||
0xf8
|
0xf8})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
|
||||||
@@ -1934,8 +2005,7 @@ TEST_CASE("CBOR regressions")
|
|||||||
TEST_DATA_DIRECTORY "/cbor_regression/test18",
|
TEST_DATA_DIRECTORY "/cbor_regression/test18",
|
||||||
TEST_DATA_DIRECTORY "/cbor_regression/test19",
|
TEST_DATA_DIRECTORY "/cbor_regression/test19",
|
||||||
TEST_DATA_DIRECTORY "/cbor_regression/test20",
|
TEST_DATA_DIRECTORY "/cbor_regression/test20",
|
||||||
TEST_DATA_DIRECTORY "/cbor_regression/test21"
|
TEST_DATA_DIRECTORY "/cbor_regression/test21"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
|
|
||||||
@@ -2135,8 +2205,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
|
|||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.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_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_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_structure_whitespace_array.json"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
|
|
||||||
@@ -2217,43 +2286,97 @@ TEST_CASE("all CBOR first bytes")
|
|||||||
//// types not supported by this library
|
//// types not supported by this library
|
||||||
|
|
||||||
// date/time
|
// date/time
|
||||||
0xc0, 0xc1,
|
0xc0,
|
||||||
|
0xc1,
|
||||||
// bignum
|
// bignum
|
||||||
0xc2, 0xc3,
|
0xc2,
|
||||||
|
0xc3,
|
||||||
// decimal fracion
|
// decimal fracion
|
||||||
0xc4,
|
0xc4,
|
||||||
// bigfloat
|
// bigfloat
|
||||||
0xc5,
|
0xc5,
|
||||||
// tagged item
|
// tagged item
|
||||||
0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd,
|
0xc6,
|
||||||
0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd8,
|
0xc7,
|
||||||
0xd9, 0xda, 0xdb,
|
0xc8,
|
||||||
|
0xc9,
|
||||||
|
0xca,
|
||||||
|
0xcb,
|
||||||
|
0xcc,
|
||||||
|
0xcd,
|
||||||
|
0xce,
|
||||||
|
0xcf,
|
||||||
|
0xd0,
|
||||||
|
0xd1,
|
||||||
|
0xd2,
|
||||||
|
0xd3,
|
||||||
|
0xd4,
|
||||||
|
0xd8,
|
||||||
|
0xd9,
|
||||||
|
0xda,
|
||||||
|
0xdb,
|
||||||
// expected conversion
|
// expected conversion
|
||||||
0xd5, 0xd6, 0xd7,
|
0xd5,
|
||||||
|
0xd6,
|
||||||
|
0xd7,
|
||||||
// simple value
|
// simple value
|
||||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
0xe0,
|
||||||
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xef, 0xf0,
|
0xe1,
|
||||||
0xf1, 0xf2, 0xf3,
|
0xe2,
|
||||||
|
0xe3,
|
||||||
|
0xe4,
|
||||||
|
0xe5,
|
||||||
|
0xe6,
|
||||||
|
0xe7,
|
||||||
|
0xe8,
|
||||||
|
0xe9,
|
||||||
|
0xea,
|
||||||
|
0xeb,
|
||||||
|
0xec,
|
||||||
|
0xed,
|
||||||
|
0xef,
|
||||||
|
0xf0,
|
||||||
|
0xf1,
|
||||||
|
0xf2,
|
||||||
|
0xf3,
|
||||||
0xf8,
|
0xf8,
|
||||||
// undefined
|
// undefined
|
||||||
0xf7,
|
0xf7,
|
||||||
|
|
||||||
//// bytes not specified by CBOR
|
//// bytes not specified by CBOR
|
||||||
|
|
||||||
0x1c, 0x1d, 0x1e, 0x1f,
|
0x1c,
|
||||||
0x3c, 0x3d, 0x3e, 0x3f,
|
0x1d,
|
||||||
0x5c, 0x5d, 0x5e,
|
0x1e,
|
||||||
0x7c, 0x7d, 0x7e,
|
0x1f,
|
||||||
0x9c, 0x9d, 0x9e,
|
0x3c,
|
||||||
0xbc, 0xbd, 0xbe,
|
0x3d,
|
||||||
0xdc, 0xdd, 0xde, 0xdf,
|
0x3e,
|
||||||
|
0x3f,
|
||||||
|
0x5c,
|
||||||
|
0x5d,
|
||||||
|
0x5e,
|
||||||
|
0x7c,
|
||||||
|
0x7d,
|
||||||
|
0x7e,
|
||||||
|
0x9c,
|
||||||
|
0x9d,
|
||||||
|
0x9e,
|
||||||
|
0xbc,
|
||||||
|
0xbd,
|
||||||
|
0xbe,
|
||||||
|
0xdc,
|
||||||
|
0xdd,
|
||||||
|
0xde,
|
||||||
|
0xdf,
|
||||||
0xee,
|
0xee,
|
||||||
0xfc, 0xfe, 0xfd,
|
0xfc,
|
||||||
|
0xfe,
|
||||||
|
0xfd,
|
||||||
|
|
||||||
/// break cannot be the first byte
|
/// break cannot be the first byte
|
||||||
|
|
||||||
0xff
|
0xff};
|
||||||
};
|
|
||||||
|
|
||||||
for (auto i = 0; i < 256; ++i)
|
for (auto i = 0; i < 256; ++i)
|
||||||
{
|
{
|
||||||
@@ -2503,10 +2626,22 @@ TEST_CASE("Tagged values")
|
|||||||
|
|
||||||
SECTION("0xC6..0xD4")
|
SECTION("0xC6..0xD4")
|
||||||
{
|
{
|
||||||
for (const auto b : std::vector<std::uint8_t>
|
for (const auto b : std::vector<std::uint8_t>{
|
||||||
{
|
0xC6,
|
||||||
0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4
|
0xC7,
|
||||||
})
|
0xC8,
|
||||||
|
0xC9,
|
||||||
|
0xCA,
|
||||||
|
0xCB,
|
||||||
|
0xCC,
|
||||||
|
0xCD,
|
||||||
|
0xCE,
|
||||||
|
0xCF,
|
||||||
|
0xD0,
|
||||||
|
0xD1,
|
||||||
|
0xD2,
|
||||||
|
0xD3,
|
||||||
|
0xD4})
|
||||||
{
|
{
|
||||||
CAPTURE(b);
|
CAPTURE(b);
|
||||||
|
|
||||||
|
|||||||
@@ -462,7 +462,6 @@ TEST_CASE("iterator class")
|
|||||||
using Iter = nlohmann::detail::json_reverse_iterator<Base>;
|
using Iter = nlohmann::detail::json_reverse_iterator<Base>;
|
||||||
CHECK_FALSE(is_detected<can_post_decrement_temporary, Iter&>::value);
|
CHECK_FALSE(is_detected<can_post_decrement_temporary, Iter&>::value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,8 +12,7 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
// shortcut to scan a string literal
|
// 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, bool ignore_comments = false);
|
||||||
json::lexer::token_type scan_string(const char* s, const bool ignore_comments)
|
json::lexer::token_type scan_string(const char* s, const bool ignore_comments)
|
||||||
|
|||||||
+162
-108
@@ -17,8 +17,7 @@ using nlohmann::json;
|
|||||||
|
|
||||||
#include <valarray>
|
#include <valarray>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class SaxEventLogger
|
class SaxEventLogger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -131,7 +130,8 @@ class SaxEventLogger
|
|||||||
class SaxCountdown : public nlohmann::json::json_sax_t
|
class SaxCountdown : public nlohmann::json::json_sax_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit SaxCountdown(const int count) : events_left(count)
|
explicit SaxCountdown(const int count)
|
||||||
|
: events_left(count)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool null() override
|
bool null() override
|
||||||
@@ -249,8 +249,7 @@ bool accept_helper(const std::string& s)
|
|||||||
CHECK(json::parser(nlohmann::detail::input_adapter(s)).accept(false) == !el.errored);
|
CHECK(json::parser(nlohmann::detail::input_adapter(s)).accept(false) == !el.errored);
|
||||||
|
|
||||||
// 5. parse with simple callback
|
// 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;
|
return true;
|
||||||
};
|
};
|
||||||
json const j_cb = json::parse(s, cb, false);
|
json const j_cb = json::parse(s, cb, false);
|
||||||
@@ -592,39 +591,56 @@ TEST_CASE("parser class")
|
|||||||
CHECK_THROWS_AS(parser_helper("+0"), json::parse_error&);
|
CHECK_THROWS_AS(parser_helper("+0"), json::parse_error&);
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(parser_helper("01"),
|
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"),
|
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"),
|
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."),
|
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"),
|
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-"),
|
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"),
|
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"),
|
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#"),
|
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-#"),
|
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#"),
|
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:"),
|
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"),
|
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:"),
|
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-:"),
|
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-:"),
|
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"),
|
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&);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -895,119 +911,170 @@ TEST_CASE("parser class")
|
|||||||
{
|
{
|
||||||
// unexpected end of number
|
// unexpected end of number
|
||||||
CHECK_THROWS_WITH_AS(parser_helper("0."),
|
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("-"),
|
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("--"),
|
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."),
|
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("-."),
|
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("-:"),
|
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.:"),
|
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."),
|
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."),
|
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/"),
|
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:"),
|
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."),
|
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/"),
|
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:"),
|
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
|
// unexpected end of null
|
||||||
CHECK_THROWS_WITH_AS(parser_helper("n"),
|
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"),
|
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"),
|
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"),
|
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"),
|
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
|
// unexpected end of true
|
||||||
CHECK_THROWS_WITH_AS(parser_helper("t"),
|
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"),
|
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"),
|
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"),
|
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"),
|
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
|
// unexpected end of false
|
||||||
CHECK_THROWS_WITH_AS(parser_helper("f"),
|
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"),
|
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"),
|
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"),
|
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"),
|
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"),
|
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
|
// missing/unexpected end of array
|
||||||
CHECK_THROWS_WITH_AS(parser_helper("["),
|
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"),
|
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,"),
|
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,]"),
|
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("]"),
|
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
|
// missing/unexpected end of object
|
||||||
CHECK_THROWS_WITH_AS(parser_helper("{"),
|
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\""),
|
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\":"),
|
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\":}"),
|
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,}"),
|
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("}"),
|
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
|
// missing/unexpected end of string
|
||||||
CHECK_THROWS_WITH_AS(parser_helper("\""),
|
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("\"\\\""),
|
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\""),
|
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\""),
|
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\""),
|
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\""),
|
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"),
|
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"),
|
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"),
|
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"),
|
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
|
// invalid escapes
|
||||||
for (int c = 1; c < 128; ++c)
|
for (int c = 1; c < 128; ++c)
|
||||||
@@ -1054,8 +1121,7 @@ TEST_CASE("parser class")
|
|||||||
// invalid \uxxxx escapes
|
// invalid \uxxxx escapes
|
||||||
{
|
{
|
||||||
// check whether character is a valid hex character
|
// check whether character is a valid hex character
|
||||||
const auto valid = [](int c)
|
const auto valid = [](int c) {
|
||||||
{
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case ('0'):
|
case ('0'):
|
||||||
@@ -1159,11 +1225,14 @@ TEST_CASE("parser class")
|
|||||||
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&);
|
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
|
// invalid surrogate pair
|
||||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD80C\\uD80C\""),
|
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\""),
|
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\""),
|
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)")
|
SECTION("parse errors (accept)")
|
||||||
@@ -1269,8 +1338,7 @@ TEST_CASE("parser class")
|
|||||||
// invalid \uxxxx escapes
|
// invalid \uxxxx escapes
|
||||||
{
|
{
|
||||||
// check whether character is a valid hex character
|
// check whether character is a valid hex character
|
||||||
const auto valid = [](int c)
|
const auto valid = [](int c) {
|
||||||
{
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case ('0'):
|
case ('0'):
|
||||||
@@ -1361,8 +1429,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
// test case to make sure the callback is properly evaluated after reading a key
|
// 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;
|
return event != json::parse_event_t::key;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1400,15 +1467,13 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("filter nothing")
|
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;
|
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;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1417,16 +1482,14 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("filter everything")
|
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;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// the top-level object will be discarded, leaving a null
|
// 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;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1436,16 +1499,14 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("filter specific element")
|
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
|
// filter all number(2) elements
|
||||||
return event != json::parse_event_t::value || j != json(2);
|
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);
|
return event != json::parse_event_t::value || j != json(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1454,8 +1515,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("filter object in array")
|
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"));
|
return !(e == json::parse_event_t::object_end && parsed.contains("foo"));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1463,8 +1523,7 @@ TEST_CASE("parser class")
|
|||||||
CHECK(j_filtered1.size() == 2);
|
CHECK(j_filtered1.size() == 2);
|
||||||
CHECK(j_filtered1 == json({1, {{"qux", "baz"}}}));
|
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;
|
return e != json::parse_event_t::object_end;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1478,8 +1537,7 @@ TEST_CASE("parser class")
|
|||||||
SECTION("first closing event")
|
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;
|
static bool first = true;
|
||||||
if (e == json::parse_event_t::object_end && first)
|
if (e == json::parse_event_t::object_end && first)
|
||||||
{
|
{
|
||||||
@@ -1495,8 +1553,7 @@ TEST_CASE("parser class")
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
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;
|
static bool first = true;
|
||||||
if (e == json::parse_event_t::array_end && first)
|
if (e == json::parse_event_t::array_end && first)
|
||||||
{
|
{
|
||||||
@@ -1519,14 +1576,12 @@ TEST_CASE("parser class")
|
|||||||
// object and array is discarded only after the closing character
|
// object and array is discarded only after the closing character
|
||||||
// has been read
|
// 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;
|
return e != json::parse_event_t::object_end;
|
||||||
});
|
});
|
||||||
CHECK(j_empty_object == json());
|
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;
|
return e != json::parse_event_t::array_end;
|
||||||
});
|
});
|
||||||
CHECK(j_empty_array == json());
|
CHECK(j_empty_array == json());
|
||||||
@@ -1593,8 +1648,7 @@ TEST_CASE("parser class")
|
|||||||
{
|
{
|
||||||
SECTION("parser with callback")
|
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;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ using nlohmann::json;
|
|||||||
|
|
||||||
#if JSON_HAS_THREE_WAY_COMPARISON
|
#if JSON_HAS_THREE_WAY_COMPARISON
|
||||||
// this can be replaced with the doctest stl extension header in version 2.5
|
// this can be replaced with the doctest stl extension header in version 2.5
|
||||||
namespace doctest
|
namespace doctest {
|
||||||
{
|
template<>
|
||||||
template<> struct StringMaker<std::partial_ordering>
|
struct StringMaker<std::partial_ordering>
|
||||||
{
|
{
|
||||||
static String convert(const std::partial_ordering& order)
|
static String convert(const std::partial_ordering& order)
|
||||||
{
|
{
|
||||||
@@ -50,8 +50,7 @@ template<> struct StringMaker<std::partial_ordering>
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
// helper function to check std::less<json::value_t>
|
// helper function to check std::less<json::value_t>
|
||||||
// see https://en.cppreference.com/w/cpp/utility/functional/less
|
// 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>>
|
||||||
@@ -97,8 +96,7 @@ TEST_CASE("lexicographical comparison operators")
|
|||||||
json::value_t::array,
|
json::value_t::array,
|
||||||
json::value_t::string,
|
json::value_t::string,
|
||||||
json::value_t::binary,
|
json::value_t::binary,
|
||||||
json::value_t::discarded
|
json::value_t::discarded};
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<std::vector<bool>> expected_lt =
|
std::vector<std::vector<bool>> expected_lt =
|
||||||
{
|
{
|
||||||
@@ -188,17 +186,28 @@ TEST_CASE("lexicographical comparison operators")
|
|||||||
{
|
{
|
||||||
json j_values =
|
json j_values =
|
||||||
{
|
{
|
||||||
nullptr, nullptr, // 0 1
|
nullptr,
|
||||||
-17, 42, // 2 3
|
nullptr, // 0 1
|
||||||
8u, 13u, // 4 5
|
-17,
|
||||||
3.14159, 23.42, // 6 7
|
42, // 2 3
|
||||||
nan, nan, // 8 9
|
8u,
|
||||||
"foo", "bar", // 10 11
|
13u, // 4 5
|
||||||
true, false, // 12 13
|
3.14159,
|
||||||
{1, 2, 3}, {"one", "two", "three"}, // 14 15
|
23.42, // 6 7
|
||||||
{{"first", 1}, {"second", 2}}, {{"a", "A"}, {"b", {"B"}}}, // 16 17
|
nan,
|
||||||
json::binary({1, 2, 3}), json::binary({1, 2, 4}), // 18 19
|
nan, // 8 9
|
||||||
json(json::value_t::discarded), json(json::value_t::discarded) // 20 21
|
"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 =
|
std::vector<std::vector<bool>> expected_eq =
|
||||||
@@ -576,16 +585,14 @@ TEST_CASE("lexicographical comparison operators")
|
|||||||
[1,2,[3,4,5],4,5]
|
[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
|
// filter all number(2) elements
|
||||||
return j != json(2);
|
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);
|
return j != json(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -153,8 +153,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::map<std::string, std::string> #600")
|
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"},
|
{"a", "b"},
|
||||||
{"c", "d"},
|
{"c", "d"},
|
||||||
{"e", "f"},
|
{"e", "f"},
|
||||||
@@ -1250,7 +1249,6 @@ TEST_CASE("constructors")
|
|||||||
CHECK(&j["key"][0] == source_addr);
|
CHECK(&j["key"][0] == source_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ using nlohmann::json;
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct alt_string_iter
|
struct alt_string_iter
|
||||||
{
|
{
|
||||||
alt_string_iter() = default;
|
alt_string_iter() = default;
|
||||||
|
|||||||
+159
-86
@@ -41,8 +41,7 @@ TEST_CASE("value conversion")
|
|||||||
{"number", 42},
|
{"number", 42},
|
||||||
{"boolean", false},
|
{"boolean", false},
|
||||||
{"null", nullptr},
|
{"null", nullptr},
|
||||||
{"string", "Hello world"}
|
{"string", "Hello world"}};
|
||||||
};
|
|
||||||
json j(o_reference);
|
json j(o_reference);
|
||||||
|
|
||||||
SECTION("json::object_t")
|
SECTION("json::object_t")
|
||||||
@@ -83,25 +82,32 @@ TEST_CASE("value conversion")
|
|||||||
{
|
{
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::null).get<json::object_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::array).get<json::object_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::string).get<json::object_t>(),
|
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>(),
|
CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::object_t>(),
|
||||||
"[json.exception.type_error.302] type must be object, "
|
"[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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_integer).get<json::object_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_unsigned).get<json::object_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_float).get<json::object_t>(),
|
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&);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,8 +118,7 @@ TEST_CASE("value conversion")
|
|||||||
{"number", 42},
|
{"number", 42},
|
||||||
{"boolean", false},
|
{"boolean", false},
|
||||||
{"null", nullptr},
|
{"null", nullptr},
|
||||||
{"string", "Hello world"}
|
{"string", "Hello world"}};
|
||||||
};
|
|
||||||
json j(o_reference);
|
json j(o_reference);
|
||||||
|
|
||||||
SECTION("json::object_t")
|
SECTION("json::object_t")
|
||||||
@@ -160,8 +165,7 @@ TEST_CASE("value conversion")
|
|||||||
{"number", 42},
|
{"number", 42},
|
||||||
{"boolean", false},
|
{"boolean", false},
|
||||||
{"null", nullptr},
|
{"null", nullptr},
|
||||||
{"string", "Hello world"}
|
{"string", "Hello world"}};
|
||||||
};
|
|
||||||
json j(o_reference);
|
json j(o_reference);
|
||||||
|
|
||||||
SECTION("json::object_t")
|
SECTION("json::object_t")
|
||||||
@@ -198,8 +202,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("get an array (explicit)")
|
SECTION("get an array (explicit)")
|
||||||
{
|
{
|
||||||
const json::array_t a_reference{json(1), json(1u), json(2.2),
|
const json::array_t a_reference{json(1), json(1u), json(2.2), json(false), json("string"), json()};
|
||||||
json(false), json("string"), json()};
|
|
||||||
json j(a_reference);
|
json j(a_reference);
|
||||||
|
|
||||||
SECTION("json::array_t")
|
SECTION("json::array_t")
|
||||||
@@ -221,7 +224,8 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::null).get<std::forward_list<json>>(),
|
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>")
|
SECTION("std::vector<json>")
|
||||||
@@ -231,7 +235,8 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::null).get<std::vector<json>>(),
|
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)
|
#if !defined(JSON_NOEXCEPTION)
|
||||||
SECTION("reserve is called on containers that supports it")
|
SECTION("reserve is called on containers that supports it")
|
||||||
@@ -268,35 +273,42 @@ TEST_CASE("value conversion")
|
|||||||
{
|
{
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::object).get<std::vector<int>>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::null).get<json::array_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::object).get<json::array_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::string).get<json::array_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::boolean).get<json::array_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_integer).get<json::array_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_unsigned).get<json::array_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_float).get<json::array_t>(),
|
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)")
|
SECTION("get an array (explicit, get_to)")
|
||||||
{
|
{
|
||||||
const json::array_t a_reference{json(1), json(1u), json(2.2),
|
const json::array_t a_reference{json(1), json(1u), json(2.2), json(false), json("string"), json()};
|
||||||
json(false), json("string"), json()};
|
|
||||||
json j(a_reference);
|
json j(a_reference);
|
||||||
|
|
||||||
SECTION("json::array_t")
|
SECTION("json::array_t")
|
||||||
@@ -355,8 +367,7 @@ TEST_CASE("value conversion")
|
|||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
SECTION("get an array (implicit)")
|
SECTION("get an array (implicit)")
|
||||||
{
|
{
|
||||||
const json::array_t a_reference{json(1), json(1u), json(2.2),
|
const json::array_t a_reference{json(1), json(1u), json(2.2), json(false), json("string"), json()};
|
||||||
json(false), json("string"), json()};
|
|
||||||
json j(a_reference);
|
json j(a_reference);
|
||||||
|
|
||||||
SECTION("json::array_t")
|
SECTION("json::array_t")
|
||||||
@@ -419,44 +430,58 @@ TEST_CASE("value conversion")
|
|||||||
{
|
{
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::null).get<json::string_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::object).get<json::string_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::array).get<json::string_t>(),
|
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>(),
|
CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::string_t>(),
|
||||||
"[json.exception.type_error.302] type must be string, "
|
"[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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_integer).get<json::string_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_unsigned).get<json::string_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_float).get<json::string_t>(),
|
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)
|
#if defined(JSON_HAS_CPP_17)
|
||||||
SECTION("exception in case of a non-string type using string_view")
|
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>(),
|
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>(),
|
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>(),
|
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>(),
|
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>(),
|
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>(),
|
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>(),
|
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
|
#endif
|
||||||
}
|
}
|
||||||
@@ -499,19 +524,26 @@ TEST_CASE("value conversion")
|
|||||||
CHECK(n2 == n);
|
CHECK(n2 == n);
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(json(json::value_t::string).get<std::nullptr_t>(),
|
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>(),
|
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>(),
|
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>(),
|
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>(),
|
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>(),
|
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>(),
|
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
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
@@ -572,28 +604,35 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::null).get<json::boolean_t>(),
|
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>(),
|
CHECK_THROWS_WITH_AS(json(json::value_t::object).get<json::boolean_t>(),
|
||||||
"[json.exception.type_error.302] type must be boolean, "
|
"[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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::array).get<json::boolean_t>(),
|
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>(),
|
CHECK_THROWS_WITH_AS(json(json::value_t::string).get<json::boolean_t>(),
|
||||||
"[json.exception.type_error.302] type must be boolean, "
|
"[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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_integer).get<json::boolean_t>(),
|
json(json::value_t::number_integer).get<json::boolean_t>(),
|
||||||
"[json.exception.type_error.302] type must be boolean, but is "
|
"[json.exception.type_error.302] type must be boolean, but is "
|
||||||
"number", json::type_error&);
|
"number",
|
||||||
|
json::type_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_unsigned).get<json::boolean_t>(),
|
json(json::value_t::number_unsigned).get<json::boolean_t>(),
|
||||||
"[json.exception.type_error.302] type must be boolean, but is "
|
"[json.exception.type_error.302] type must be boolean, but is "
|
||||||
"number", json::type_error&);
|
"number",
|
||||||
|
json::type_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::number_float).get<json::boolean_t>(),
|
json(json::value_t::number_float).get<json::boolean_t>(),
|
||||||
"[json.exception.type_error.302] type must be boolean, but is "
|
"[json.exception.type_error.302] type must be boolean, but is "
|
||||||
"number", json::type_error&);
|
"number",
|
||||||
|
json::type_error&);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -832,20 +871,25 @@ TEST_CASE("value conversion")
|
|||||||
{
|
{
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::null).get<json::number_integer_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::object).get<json::number_integer_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::array).get<json::number_integer_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::string).get<json::number_integer_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::boolean).get<json::number_integer_t>(),
|
json(json::value_t::boolean).get<json::number_integer_t>(),
|
||||||
"[json.exception.type_error.302] type must be number, but is "
|
"[json.exception.type_error.302] type must be number, but is "
|
||||||
"boolean", json::type_error&);
|
"boolean",
|
||||||
|
json::type_error&);
|
||||||
|
|
||||||
CHECK_NOTHROW(
|
CHECK_NOTHROW(
|
||||||
json(json::value_t::number_float).get<json::number_integer_t>());
|
json(json::value_t::number_float).get<json::number_integer_t>());
|
||||||
@@ -1095,20 +1139,25 @@ TEST_CASE("value conversion")
|
|||||||
{
|
{
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::null).get<json::number_float_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::object).get<json::number_float_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::array).get<json::number_float_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::string).get<json::number_float_t>(),
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
json(json::value_t::boolean).get<json::number_float_t>(),
|
json(json::value_t::boolean).get<json::number_float_t>(),
|
||||||
"[json.exception.type_error.302] type must be number, but is "
|
"[json.exception.type_error.302] type must be number, but is "
|
||||||
"boolean", json::type_error&);
|
"boolean",
|
||||||
|
json::type_error&);
|
||||||
|
|
||||||
CHECK_NOTHROW(
|
CHECK_NOTHROW(
|
||||||
json(json::value_t::number_integer).get<json::number_float_t>());
|
json(json::value_t::number_integer).get<json::number_float_t>());
|
||||||
@@ -1265,8 +1314,16 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("get an enum")
|
SECTION("get an enum")
|
||||||
{
|
{
|
||||||
enum c_enum { value_1, value_2 };
|
enum c_enum
|
||||||
enum class cpp_enum { value_1, value_2 };
|
{
|
||||||
|
value_1,
|
||||||
|
value_2
|
||||||
|
};
|
||||||
|
enum class cpp_enum
|
||||||
|
{
|
||||||
|
value_1,
|
||||||
|
value_2
|
||||||
|
};
|
||||||
|
|
||||||
CHECK(json(value_1).get<c_enum>() == value_1);
|
CHECK(json(value_1).get<c_enum>() == value_1);
|
||||||
CHECK(json(cpp_enum::value_1).get<cpp_enum>() == cpp_enum::value_1);
|
CHECK(json(cpp_enum::value_1).get<cpp_enum>() == cpp_enum::value_1);
|
||||||
@@ -1325,7 +1382,8 @@ TEST_CASE("value conversion")
|
|||||||
{
|
{
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
(json().get<std::map<std::string, int>>()),
|
(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 @@ TEST_CASE("value conversion")
|
|||||||
{
|
{
|
||||||
std::array<int, 6> arr6 = {{1, 2, 3, 4, 5, 6}};
|
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] "
|
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")
|
SECTION("std::array is smaller than JSON")
|
||||||
@@ -1436,10 +1495,12 @@ TEST_CASE("value conversion")
|
|||||||
json const j8 = 2;
|
json const j8 = 2;
|
||||||
CHECK_THROWS_WITH_AS((j7.get<std::map<int, int>>()),
|
CHECK_THROWS_WITH_AS((j7.get<std::map<int, int>>()),
|
||||||
"[json.exception.type_error.302] type must be array, "
|
"[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>>()),
|
CHECK_THROWS_WITH_AS((j8.get<std::map<int, int>>()),
|
||||||
"[json.exception.type_error.302] type must be array, "
|
"[json.exception.type_error.302] type must be array, "
|
||||||
"but is number", json::type_error&);
|
"but is number",
|
||||||
|
json::type_error&);
|
||||||
|
|
||||||
SECTION("superfluous entries")
|
SECTION("superfluous entries")
|
||||||
{
|
{
|
||||||
@@ -1461,10 +1522,12 @@ TEST_CASE("value conversion")
|
|||||||
json const j8 = 2;
|
json const j8 = 2;
|
||||||
CHECK_THROWS_WITH_AS((j7.get<std::unordered_map<int, int>>()),
|
CHECK_THROWS_WITH_AS((j7.get<std::unordered_map<int, int>>()),
|
||||||
"[json.exception.type_error.302] type must be array, "
|
"[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>>()),
|
CHECK_THROWS_WITH_AS((j8.get<std::unordered_map<int, int>>()),
|
||||||
"[json.exception.type_error.302] type must be array, "
|
"[json.exception.type_error.302] type must be array, "
|
||||||
"but is number", json::type_error&);
|
"but is number",
|
||||||
|
json::type_error&);
|
||||||
|
|
||||||
SECTION("superfluous entries")
|
SECTION("superfluous entries")
|
||||||
{
|
{
|
||||||
@@ -1480,38 +1543,48 @@ TEST_CASE("value conversion")
|
|||||||
// that's what I thought when other test like this one broke
|
// that's what I thought when other test like this one broke
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
(json().get<std::list<int>>()),
|
(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(
|
CHECK_THROWS_WITH_AS(
|
||||||
(json().get<std::vector<int>>()),
|
(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(
|
CHECK_THROWS_WITH_AS(
|
||||||
(json().get<std::vector<json>>()),
|
(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(
|
CHECK_THROWS_WITH_AS(
|
||||||
(json().get<std::list<json>>()),
|
(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(
|
CHECK_THROWS_WITH_AS(
|
||||||
(json().get<std::valarray<int>>()),
|
(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(
|
CHECK_THROWS_WITH_AS(
|
||||||
(json().get<std::map<int, int>>()),
|
(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
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - false positive
|
||||||
NLOHMANN_JSON_SERIALIZE_ENUM(cards,
|
NLOHMANN_JSON_SERIALIZE_ENUM(cards,
|
||||||
{
|
{{cards::kreuz, "kreuz"},
|
||||||
{cards::kreuz, "kreuz"},
|
|
||||||
{cards::pik, "pik"},
|
{cards::pik, "pik"},
|
||||||
{cards::pik, "puk"}, // second entry for cards::puk; will not be used
|
{cards::pik, "puk"}, // second entry for cards::puk; will not be used
|
||||||
{cards::herz, "herz"},
|
{cards::herz, "herz"},
|
||||||
{cards::karo, "karo"}
|
{cards::karo, "karo"}})
|
||||||
})
|
|
||||||
|
|
||||||
enum TaskState
|
enum TaskState
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class json_metadata
|
|||||||
{
|
{
|
||||||
return m_metadata;
|
return m_metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
metadata_t m_metadata = {};
|
metadata_t m_metadata = {};
|
||||||
};
|
};
|
||||||
@@ -47,8 +48,7 @@ using json_with_metadata =
|
|||||||
std::allocator,
|
std::allocator,
|
||||||
nlohmann::adl_serializer,
|
nlohmann::adl_serializer,
|
||||||
std::vector<std::uint8_t>,
|
std::vector<std::uint8_t>,
|
||||||
json_metadata<T>
|
json_metadata<T>>;
|
||||||
>;
|
|
||||||
|
|
||||||
TEST_CASE("JSON Node Metadata")
|
TEST_CASE("JSON Node Metadata")
|
||||||
{
|
{
|
||||||
@@ -190,6 +190,7 @@ class visitor_adaptor
|
|||||||
public:
|
public:
|
||||||
template<class Fnc>
|
template<class Fnc>
|
||||||
void visit(const Fnc& fnc) const;
|
void visit(const Fnc& fnc) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<class Ptr, class Fnc>
|
template<class Ptr, class Fnc>
|
||||||
void do_visit(const Ptr& ptr, const Fnc& fnc) const;
|
void do_visit(const Ptr& ptr, const Fnc& fnc) const;
|
||||||
@@ -206,8 +207,7 @@ using json_with_visitor_t = nlohmann::basic_json <
|
|||||||
std::allocator,
|
std::allocator,
|
||||||
nlohmann::adl_serializer,
|
nlohmann::adl_serializer,
|
||||||
std::vector<std::uint8_t>,
|
std::vector<std::uint8_t>,
|
||||||
visitor_adaptor
|
visitor_adaptor>;
|
||||||
>;
|
|
||||||
|
|
||||||
template<class Fnc>
|
template<class Fnc>
|
||||||
void visitor_adaptor::visit(const Fnc& fnc) const
|
void visitor_adaptor::visit(const Fnc& fnc) const
|
||||||
@@ -261,8 +261,7 @@ TEST_CASE("JSON Visit Node")
|
|||||||
json["array"].push_back(1);
|
json["array"].push_back(1);
|
||||||
json["array"].push_back(json);
|
json["array"].push_back(json);
|
||||||
|
|
||||||
std::set<std::string> expected
|
std::set<std::string> expected{
|
||||||
{
|
|
||||||
"/null - null - null",
|
"/null - null - null",
|
||||||
"/int - number_integer - -1",
|
"/int - number_integer - -1",
|
||||||
"/uint - number_unsigned - 1",
|
"/uint - number_unsigned - 1",
|
||||||
@@ -279,13 +278,11 @@ TEST_CASE("JSON Visit Node")
|
|||||||
"/array/2/boolean - boolean - true",
|
"/array/2/boolean - boolean - true",
|
||||||
"/array/2/string - string - \"string\"",
|
"/array/2/string - string - \"string\"",
|
||||||
"/array/2/array/0 - number_integer - 0",
|
"/array/2/array/0 - number_integer - 0",
|
||||||
"/array/2/array/1 - number_integer - 1"
|
"/array/2/array/1 - number_integer - 1"};
|
||||||
};
|
|
||||||
|
|
||||||
json.visit(
|
json.visit(
|
||||||
[&](const json_with_visitor_t::json_pointer& p,
|
[&](const json_with_visitor_t::json_pointer& p,
|
||||||
const json_with_visitor_t& j)
|
const json_with_visitor_t& j) {
|
||||||
{
|
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
str << p.to_string() << " - ";
|
str << p.to_string() << " - ";
|
||||||
using value_t = nlohmann::detail::value_t;
|
using value_t = nlohmann::detail::value_t;
|
||||||
@@ -330,7 +327,6 @@ TEST_CASE("JSON Visit Node")
|
|||||||
INFO(str.str());
|
INFO(str.str());
|
||||||
CHECK(expected.count(str.str()) == 1);
|
CHECK(expected.count(str.str()) == 1);
|
||||||
expected.erase(str.str());
|
expected.erase(str.str());
|
||||||
}
|
});
|
||||||
);
|
|
||||||
CHECK(expected.empty());
|
CHECK(expected.empty());
|
||||||
}
|
}
|
||||||
@@ -20,8 +20,7 @@ using nlohmann::json;
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <valarray>
|
#include <valarray>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct SaxEventLogger : public nlohmann::json_sax<json>
|
struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||||
{
|
{
|
||||||
bool null() override
|
bool null() override
|
||||||
@@ -182,7 +181,9 @@ class proxy_iterator
|
|||||||
using iterator_category = std::input_iterator_tag;
|
using iterator_category = std::input_iterator_tag;
|
||||||
|
|
||||||
proxy_iterator() = default;
|
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++()
|
proxy_iterator& operator++()
|
||||||
{
|
{
|
||||||
@@ -236,12 +237,7 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(json::sax_parse(ss3, &l));
|
CHECK(json::sax_parse(ss3, &l));
|
||||||
CHECK(l.events.size() == 11);
|
CHECK(l.events.size() == 11);
|
||||||
CHECK(l.events == std::vector<std::string>(
|
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")
|
SECTION("string literal")
|
||||||
@@ -255,12 +251,7 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(json::sax_parse(s, &l));
|
CHECK(json::sax_parse(s, &l));
|
||||||
CHECK(l.events.size() == 11);
|
CHECK(l.events.size() == 11);
|
||||||
CHECK(l.events == std::vector<std::string>(
|
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")
|
SECTION("string_t")
|
||||||
@@ -274,12 +265,7 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(json::sax_parse(s, &l));
|
CHECK(json::sax_parse(s, &l));
|
||||||
CHECK(l.events.size() == 11);
|
CHECK(l.events.size() == 11);
|
||||||
CHECK(l.events == std::vector<std::string>(
|
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<<")
|
SECTION("operator<<")
|
||||||
@@ -331,12 +317,7 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(!json::sax_parse(ss5, &l));
|
CHECK(!json::sax_parse(ss5, &l));
|
||||||
CHECK(l.events.size() == 11);
|
CHECK(l.events.size() == 11);
|
||||||
CHECK(l.events == std::vector<std::string>(
|
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")
|
SECTION("string")
|
||||||
@@ -354,12 +335,7 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(!json::sax_parse(s, &l));
|
CHECK(!json::sax_parse(s, &l));
|
||||||
CHECK(l.events.size() == 11);
|
CHECK(l.events.size() == 11);
|
||||||
CHECK(l.events == std::vector<std::string>(
|
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<<")
|
SECTION("operator<<")
|
||||||
@@ -493,7 +469,6 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
CHECK(l.events.size() == 1);
|
||||||
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
|
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("from std::array")
|
SECTION("from std::array")
|
||||||
@@ -585,8 +560,7 @@ TEST_CASE("deserialization")
|
|||||||
json j;
|
json j;
|
||||||
json_sax_dom_parser<json> sax(j, true);
|
json_sax_dom_parser<json> sax(j, true);
|
||||||
|
|
||||||
CHECK(json::sax_parse(proxy(first), proxy(last), &sax,
|
CHECK(json::sax_parse(proxy(first), proxy(last), &sax, input_format_t::json, false));
|
||||||
input_format_t::json, false));
|
|
||||||
CHECK(j.dump() == str1);
|
CHECK(j.dump() == str1);
|
||||||
CHECK(std::string(first, last) == str2);
|
CHECK(std::string(first, last) == str2);
|
||||||
}
|
}
|
||||||
@@ -865,10 +839,7 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 4);
|
CHECK(l.events.size() == 4);
|
||||||
CHECK(l.events == std::vector<std::string>(
|
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 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(!json::sax_parse(bom, &l));
|
CHECK(!json::sax_parse(bom, &l));
|
||||||
CHECK(l.events.size() == 1);
|
CHECK(l.events.size() == 1);
|
||||||
CHECK(l.events == std::vector<std::string>(
|
CHECK(l.events == std::vector<std::string>(
|
||||||
{
|
{"parse_error(4)"}));
|
||||||
"parse_error(4)"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("BOM and content")
|
SECTION("BOM and content")
|
||||||
@@ -904,14 +873,10 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(json::sax_parse(bom + "1", &l2));
|
CHECK(json::sax_parse(bom + "1", &l2));
|
||||||
CHECK(l1.events.size() == 1);
|
CHECK(l1.events.size() == 1);
|
||||||
CHECK(l1.events == std::vector<std::string>(
|
CHECK(l1.events == std::vector<std::string>(
|
||||||
{
|
{"number_unsigned(1)"}));
|
||||||
"number_unsigned(1)"
|
|
||||||
}));
|
|
||||||
CHECK(l2.events.size() == 1);
|
CHECK(l2.events.size() == 1);
|
||||||
CHECK(l2.events == std::vector<std::string>(
|
CHECK(l2.events == std::vector<std::string>(
|
||||||
{
|
{"number_unsigned(1)"}));
|
||||||
"number_unsigned(1)"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("2 byte of BOM")
|
SECTION("2 byte of BOM")
|
||||||
@@ -927,14 +892,10 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(!json::sax_parse(bom.substr(0, 2), &l2));
|
CHECK(!json::sax_parse(bom.substr(0, 2), &l2));
|
||||||
CHECK(l1.events.size() == 1);
|
CHECK(l1.events.size() == 1);
|
||||||
CHECK(l1.events == std::vector<std::string>(
|
CHECK(l1.events == std::vector<std::string>(
|
||||||
{
|
{"parse_error(3)"}));
|
||||||
"parse_error(3)"
|
|
||||||
}));
|
|
||||||
CHECK(l2.events.size() == 1);
|
CHECK(l2.events.size() == 1);
|
||||||
CHECK(l2.events == std::vector<std::string>(
|
CHECK(l2.events == std::vector<std::string>(
|
||||||
{
|
{"parse_error(3)"}));
|
||||||
"parse_error(3)"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("1 byte of BOM")
|
SECTION("1 byte of BOM")
|
||||||
@@ -950,14 +911,10 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(!json::sax_parse(bom.substr(0, 1), &l2));
|
CHECK(!json::sax_parse(bom.substr(0, 1), &l2));
|
||||||
CHECK(l1.events.size() == 1);
|
CHECK(l1.events.size() == 1);
|
||||||
CHECK(l1.events == std::vector<std::string>(
|
CHECK(l1.events == std::vector<std::string>(
|
||||||
{
|
{"parse_error(2)"}));
|
||||||
"parse_error(2)"
|
|
||||||
}));
|
|
||||||
CHECK(l2.events.size() == 1);
|
CHECK(l2.events.size() == 1);
|
||||||
CHECK(l2.events == std::vector<std::string>(
|
CHECK(l2.events == std::vector<std::string>(
|
||||||
{
|
{"parse_error(2)"}));
|
||||||
"parse_error(2)"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("variations")
|
SECTION("variations")
|
||||||
@@ -990,9 +947,7 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(json::sax_parse(s + "null", &l));
|
CHECK(json::sax_parse(s + "null", &l));
|
||||||
CHECK(l.events.size() == 1);
|
CHECK(l.events.size() == 1);
|
||||||
CHECK(l.events == std::vector<std::string>(
|
CHECK(l.events == std::vector<std::string>(
|
||||||
{
|
{"null()"}));
|
||||||
"null()"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1008,23 +963,17 @@ TEST_CASE("deserialization")
|
|||||||
if (i0 != 0)
|
if (i0 != 0)
|
||||||
{
|
{
|
||||||
CHECK(l.events == std::vector<std::string>(
|
CHECK(l.events == std::vector<std::string>(
|
||||||
{
|
{"parse_error(1)"}));
|
||||||
"parse_error(1)"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
else if (i1 != 0)
|
else if (i1 != 0)
|
||||||
{
|
{
|
||||||
CHECK(l.events == std::vector<std::string>(
|
CHECK(l.events == std::vector<std::string>(
|
||||||
{
|
{"parse_error(2)"}));
|
||||||
"parse_error(2)"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CHECK(l.events == std::vector<std::string>(
|
CHECK(l.events == std::vector<std::string>(
|
||||||
{
|
{"parse_error(3)"}));
|
||||||
"parse_error(3)"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1055,37 +1004,22 @@ TEST_CASE("deserialization")
|
|||||||
json::sax_parse(s, &default_logger);
|
json::sax_parse(s, &default_logger);
|
||||||
CHECK(default_logger.events.size() == 14);
|
CHECK(default_logger.events.size() == 14);
|
||||||
CHECK(default_logger.events == std::vector<std::string>(
|
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);
|
json::sax_parse(s, &exit_after_start_object);
|
||||||
CHECK(exit_after_start_object.events.size() == 8);
|
CHECK(exit_after_start_object.events.size() == 8);
|
||||||
CHECK(exit_after_start_object.events == std::vector<std::string>(
|
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);
|
json::sax_parse(s, &exit_after_key);
|
||||||
CHECK(exit_after_key.events.size() == 9);
|
CHECK(exit_after_key.events.size() == 9);
|
||||||
CHECK(exit_after_key.events == std::vector<std::string>(
|
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);
|
json::sax_parse(s, &exit_after_start_array);
|
||||||
CHECK(exit_after_start_array.events.size() == 1);
|
CHECK(exit_after_start_array.events.size() == 1);
|
||||||
CHECK(exit_after_start_array.events == std::vector<std::string>(
|
CHECK(exit_after_start_array.events == std::vector<std::string>(
|
||||||
{
|
{"start_array()"}));
|
||||||
"start_array()"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("JSON Lines")
|
SECTION("JSON Lines")
|
||||||
@@ -1131,13 +1065,7 @@ TEST_CASE("deserialization")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", 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)
|
||||||
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'};
|
std::vector<T> const v = {'t', 'r', 'u', 'e'};
|
||||||
CHECK(json::parse(v) == json(true));
|
CHECK(json::parse(v) == json(true));
|
||||||
@@ -1149,8 +1077,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T,
|
|||||||
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
|
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T,
|
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, char, unsigned char, std::uint8_t)
|
||||||
char, unsigned char, std::uint8_t)
|
|
||||||
{
|
{
|
||||||
// a star emoji
|
// 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), '"'};
|
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 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T,
|
|||||||
CHECK(l.events.size() == 1);
|
CHECK(l.events.size() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T,
|
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, char16_t, std::uint16_t)
|
||||||
char16_t, std::uint16_t)
|
|
||||||
{
|
{
|
||||||
// a star emoji
|
// a star emoji
|
||||||
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
|
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
|
||||||
@@ -1175,8 +1101,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T,
|
|||||||
CHECK(l.events.size() == 1);
|
CHECK(l.events.size() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T,
|
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, char32_t, std::uint32_t)
|
||||||
char32_t, std::uint32_t)
|
|
||||||
{
|
{
|
||||||
// a star emoji
|
// a star emoji
|
||||||
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
|
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ using json = nlohmann::json;
|
|||||||
class sax_no_exception : public nlohmann::detail::json_sax_dom_parser<json>
|
class sax_no_exception : public nlohmann::detail::json_sax_dom_parser<json>
|
||||||
{
|
{
|
||||||
public:
|
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)
|
static bool parse_error(std::size_t /*position*/, const std::string& /*last_token*/, const json::exception& ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,9 +45,11 @@ TEST_CASE("element access 1")
|
|||||||
SECTION("access outside bounds")
|
SECTION("access outside bounds")
|
||||||
{
|
{
|
||||||
CHECK_THROWS_WITH_AS(j.at(8),
|
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),
|
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")
|
SECTION("access on non-array type")
|
||||||
@@ -359,26 +361,34 @@ TEST_CASE("element access 1")
|
|||||||
json jarray2 = {"foo", "bar"};
|
json jarray2 = {"foo", "bar"};
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(jarray.erase(jarray2.begin()),
|
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()),
|
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()),
|
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()),
|
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 jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
|
||||||
json const jarray2 = {"foo", "bar"};
|
json const jarray2 = {"foo", "bar"};
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(jarray.erase(jarray2.cbegin()),
|
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()),
|
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()),
|
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()),
|
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 @@ TEST_CASE("element access 1")
|
|||||||
{
|
{
|
||||||
json j;
|
json j;
|
||||||
CHECK_THROWS_WITH_AS(j.erase(j.begin()),
|
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&);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -455,10 +455,8 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("non-const operator[]")
|
SECTION("non-const operator[]"){
|
||||||
{
|
{Json j_null;
|
||||||
{
|
|
||||||
Json j_null;
|
|
||||||
CHECK(j_null.is_null());
|
CHECK(j_null.is_null());
|
||||||
j_null["key"] = 1;
|
j_null["key"] = 1;
|
||||||
CHECK(j_null.is_object());
|
CHECK(j_null.is_object());
|
||||||
@@ -626,13 +624,17 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
Json j_nonobject(Json::value_t::boolean);
|
Json j_nonobject(Json::value_t::boolean);
|
||||||
const Json j_const_nonobject(j_nonobject);
|
const Json j_const_nonobject(j_nonobject);
|
||||||
CHECK_THROWS_WITH_AS(j_nonobject["foo"],
|
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&);
|
"[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")],
|
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&);
|
"[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"],
|
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&);
|
"[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")],
|
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&);
|
"[json.exception.type_error.305] cannot use operator[] with a string argument with boolean",
|
||||||
|
typename Json::type_error&);
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#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_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typename Json::type_error&);
|
||||||
@@ -645,13 +647,17 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
Json j_nonobject(Json::value_t::string);
|
Json j_nonobject(Json::value_t::string);
|
||||||
const Json j_const_nonobject(j_nonobject);
|
const Json j_const_nonobject(j_nonobject);
|
||||||
CHECK_THROWS_WITH_AS(j_nonobject["foo"],
|
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&);
|
"[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")],
|
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&);
|
"[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"],
|
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&);
|
"[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")],
|
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&);
|
"[json.exception.type_error.305] cannot use operator[] with a string argument with string",
|
||||||
|
typename Json::type_error&);
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#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_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with string", typename Json::type_error&);
|
||||||
@@ -664,12 +670,15 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
Json j_nonobject(Json::value_t::array);
|
Json j_nonobject(Json::value_t::array);
|
||||||
const Json j_const_nonobject(j_nonobject);
|
const Json j_const_nonobject(j_nonobject);
|
||||||
CHECK_THROWS_WITH_AS(j_nonobject["foo"],
|
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&);
|
"[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_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"],
|
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&);
|
"[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")],
|
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&);
|
"[json.exception.type_error.305] cannot use operator[] with a string argument with array",
|
||||||
|
typename Json::type_error&);
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#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_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&);
|
||||||
@@ -682,13 +691,17 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
Json j_nonobject(Json::value_t::number_integer);
|
Json j_nonobject(Json::value_t::number_integer);
|
||||||
const Json j_const_nonobject(j_nonobject);
|
const Json j_const_nonobject(j_nonobject);
|
||||||
CHECK_THROWS_WITH_AS(j_nonobject["foo"],
|
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&);
|
"[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")],
|
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&);
|
"[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"],
|
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&);
|
"[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")],
|
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&);
|
"[json.exception.type_error.305] cannot use operator[] with a string argument with number",
|
||||||
|
typename Json::type_error&);
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#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_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&);
|
||||||
@@ -701,13 +714,17 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
Json j_nonobject(Json::value_t::number_unsigned);
|
Json j_nonobject(Json::value_t::number_unsigned);
|
||||||
const Json j_const_nonobject(j_nonobject);
|
const Json j_const_nonobject(j_nonobject);
|
||||||
CHECK_THROWS_WITH_AS(j_nonobject["foo"],
|
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&);
|
"[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")],
|
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&);
|
"[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"],
|
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&);
|
"[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")],
|
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&);
|
"[json.exception.type_error.305] cannot use operator[] with a string argument with number",
|
||||||
|
typename Json::type_error&);
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#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_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&);
|
||||||
@@ -720,13 +737,17 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
Json j_nonobject(Json::value_t::number_float);
|
Json j_nonobject(Json::value_t::number_float);
|
||||||
const Json j_const_nonobject(j_nonobject);
|
const Json j_const_nonobject(j_nonobject);
|
||||||
CHECK_THROWS_WITH_AS(j_nonobject["foo"],
|
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&);
|
"[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")],
|
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&);
|
"[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"],
|
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&);
|
"[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")],
|
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&);
|
"[json.exception.type_error.305] cannot use operator[] with a string argument with number",
|
||||||
|
typename Json::type_error&);
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#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_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&);
|
||||||
@@ -916,25 +937,33 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
|
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
|
||||||
Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
||||||
CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin()),
|
CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin()),
|
||||||
"[json.exception.invalid_iterator.202] iterator does not fit current value", typename Json::invalid_iterator&);
|
"[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()),
|
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&);
|
"[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()),
|
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&);
|
"[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()),
|
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.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 jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
|
||||||
Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
||||||
CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin()),
|
CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin()),
|
||||||
"[json.exception.invalid_iterator.202] iterator does not fit current value", typename Json::invalid_iterator&);
|
"[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()),
|
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&);
|
"[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()),
|
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&);
|
"[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()),
|
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&);
|
"[json.exception.invalid_iterator.203] iterators do not fit current value",
|
||||||
|
typename Json::invalid_iterator&);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1008,8 +1037,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
SECTION("existing element")
|
SECTION("existing element")
|
||||||
{
|
{
|
||||||
for (const auto* key :
|
for (const auto* key :
|
||||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"
|
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CHECK(j.find(key) != j.end());
|
CHECK(j.find(key) != j.end());
|
||||||
CHECK(*j.find(key) == j.at(key));
|
CHECK(*j.find(key) == j.at(key));
|
||||||
@@ -1018,8 +1046,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
}
|
}
|
||||||
#ifdef JSON_HAS_CPP_17
|
#ifdef JSON_HAS_CPP_17
|
||||||
for (const std::string_view key :
|
for (const std::string_view key :
|
||||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"
|
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CHECK(j.find(key) != j.end());
|
CHECK(j.find(key) != j.end());
|
||||||
CHECK(*j.find(key) == j.at(key));
|
CHECK(*j.find(key) == j.at(key));
|
||||||
@@ -1161,16 +1188,14 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
SECTION("existing element")
|
SECTION("existing element")
|
||||||
{
|
{
|
||||||
for (const auto* key :
|
for (const auto* key :
|
||||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"
|
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CHECK(j.count(key) == 1);
|
CHECK(j.count(key) == 1);
|
||||||
CHECK(j_const.count(key) == 1);
|
CHECK(j_const.count(key) == 1);
|
||||||
}
|
}
|
||||||
#ifdef JSON_HAS_CPP_17
|
#ifdef JSON_HAS_CPP_17
|
||||||
for (const std::string_view key :
|
for (const std::string_view key :
|
||||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"
|
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CHECK(j.count(key) == 1);
|
CHECK(j.count(key) == 1);
|
||||||
CHECK(j_const.count(key) == 1);
|
CHECK(j_const.count(key) == 1);
|
||||||
@@ -1310,8 +1335,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
SECTION("existing element")
|
SECTION("existing element")
|
||||||
{
|
{
|
||||||
for (const auto* key :
|
for (const auto* key :
|
||||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"
|
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CHECK(j.contains(key) == true);
|
CHECK(j.contains(key) == true);
|
||||||
CHECK(j_const.contains(key) == true);
|
CHECK(j_const.contains(key) == true);
|
||||||
@@ -1319,8 +1343,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#ifdef JSON_HAS_CPP_17
|
||||||
for (const std::string_view key :
|
for (const std::string_view key :
|
||||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"
|
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CHECK(j.contains(key) == true);
|
CHECK(j.contains(key) == true);
|
||||||
CHECK(j_const.contains(key) == true);
|
CHECK(j_const.contains(key) == true);
|
||||||
@@ -1500,11 +1523,9 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
|
|||||||
// test assumes string_t and object_t::key_type are the same
|
// 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);
|
REQUIRE(std::is_same<string_t, typename Json::object_t::key_type>::value);
|
||||||
|
|
||||||
Json j
|
Json j{
|
||||||
{
|
|
||||||
{"foo", "bar"},
|
{"foo", "bar"},
|
||||||
{"baz", 42}
|
{"baz", 42}};
|
||||||
};
|
|
||||||
|
|
||||||
const char* cpstr = "default";
|
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)
|
||||||
@@ -1513,10 +1534,8 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
|
|||||||
number_integer_t integer = 69;
|
number_integer_t integer = 69;
|
||||||
std::size_t size = 69;
|
std::size_t size = 69;
|
||||||
|
|
||||||
SECTION("deduced ValueType")
|
SECTION("deduced ValueType"){
|
||||||
{
|
SECTION("literal key"){
|
||||||
SECTION("literal key")
|
|
||||||
{
|
|
||||||
CHECK(j.value("foo", "default") == "bar");
|
CHECK(j.value("foo", "default") == "bar");
|
||||||
CHECK(j.value("foo", cpstr) == "bar");
|
CHECK(j.value("foo", cpstr) == "bar");
|
||||||
CHECK(j.value("foo", castr) == "bar");
|
CHECK(j.value("foo", castr) == "bar");
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
|
#include "make_test_data_available.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "make_test_data_available.hpp"
|
|
||||||
|
|
||||||
TEST_CASE("object inspection")
|
TEST_CASE("object inspection")
|
||||||
{
|
{
|
||||||
@@ -329,8 +329,7 @@ TEST_CASE("object inspection")
|
|||||||
SECTION("round trips")
|
SECTION("round trips")
|
||||||
{
|
{
|
||||||
for (const auto& s :
|
for (const auto& s :
|
||||||
{"3.141592653589793", "1000000000000000010E5"
|
{"3.141592653589793", "1000000000000000010E5"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
json const j1 = json::parse(s);
|
json const j1 = json::parse(s);
|
||||||
std::string s1 = j1.dump();
|
std::string s1 = j1.dump();
|
||||||
|
|||||||
@@ -718,10 +718,8 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
TEST_CASE("items()")
|
TEST_CASE("items()")
|
||||||
{
|
{
|
||||||
SECTION("object")
|
SECTION("object"){
|
||||||
{
|
SECTION("value"){
|
||||||
SECTION("value")
|
|
||||||
{
|
|
||||||
json j = {{"A", 1}, {"B", 2}};
|
json j = {{"A", 1}, {"B", 2}};
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -913,13 +913,11 @@ TEST_CASE("iterators 2")
|
|||||||
auto j_even = json::array();
|
auto j_even = json::array();
|
||||||
|
|
||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
auto it = std::ranges::find_if(j, [](int v) noexcept
|
auto it = std::ranges::find_if(j, [](int v) noexcept {
|
||||||
{
|
|
||||||
return (v % 2) == 0;
|
return (v % 2) == 0;
|
||||||
});
|
});
|
||||||
#else
|
#else
|
||||||
auto it = std::ranges::find_if(j, [](const json & j) noexcept
|
auto it = std::ranges::find_if(j, [](const json& j) noexcept {
|
||||||
{
|
|
||||||
int v;
|
int v;
|
||||||
j.get_to(v);
|
j.get_to(v);
|
||||||
return (v % 2) == 0;
|
return (v % 2) == 0;
|
||||||
@@ -947,16 +945,14 @@ TEST_CASE("iterators 2")
|
|||||||
|
|
||||||
SECTION("transform")
|
SECTION("transform")
|
||||||
{
|
{
|
||||||
json j
|
json j{
|
||||||
{
|
|
||||||
{"a_key", "a_value"},
|
{"a_key", "a_value"},
|
||||||
{"b_key", "b_value"},
|
{"b_key", "b_value"},
|
||||||
{"c_key", "c_value"},
|
{"c_key", "c_value"},
|
||||||
};
|
};
|
||||||
json j_expected{"a_key", "b_key", "c_key"};
|
json j_expected{"a_key", "b_key", "c_key"};
|
||||||
|
|
||||||
auto transformed = j.items() | std::views::transform([](const auto & item)
|
auto transformed = j.items() | std::views::transform([](const auto& item) {
|
||||||
{
|
|
||||||
return item.key();
|
return item.key();
|
||||||
});
|
});
|
||||||
auto j_transformed = json::array();
|
auto j_transformed = json::array();
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ using nlohmann::json;
|
|||||||
using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
|
using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include "make_test_data_available.hpp"
|
#include "make_test_data_available.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
TEST_CASE("JSON patch")
|
TEST_CASE("JSON patch")
|
||||||
{
|
{
|
||||||
@@ -1217,60 +1217,49 @@ TEST_CASE("JSON patch")
|
|||||||
SECTION("add")
|
SECTION("add")
|
||||||
{
|
{
|
||||||
CHECK(R"( {} )"_json.patch(
|
CHECK(R"( {} )"_json.patch(
|
||||||
R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json
|
R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json) == R"( {"foo": "bar"} )"_json);
|
||||||
) == R"( {"foo": "bar"} )"_json);
|
|
||||||
|
|
||||||
CHECK(R"( {"foo": [1, 3]} )"_json.patch(
|
CHECK(R"( {"foo": [1, 3]} )"_json.patch(
|
||||||
R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json
|
R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json) == R"( {"foo": "bar"} )"_json);
|
||||||
) == R"( {"foo": "bar"} )"_json);
|
|
||||||
|
|
||||||
CHECK(R"( {"foo": [{}]} )"_json.patch(
|
CHECK(R"( {"foo": [{}]} )"_json.patch(
|
||||||
R"( [{"op": "add", "path": "/foo/0/bar", "value": "baz"}] )"_json
|
R"( [{"op": "add", "path": "/foo/0/bar", "value": "baz"}] )"_json) == R"( {"foo": [{"bar": "baz"}]} )"_json);
|
||||||
) == R"( {"foo": [{"bar": "baz"}]} )"_json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("remove")
|
SECTION("remove")
|
||||||
{
|
{
|
||||||
CHECK(R"( {"foo": "bar"} )"_json.patch(
|
CHECK(R"( {"foo": "bar"} )"_json.patch(
|
||||||
R"( [{"op": "remove", "path": "/foo"}] )"_json
|
R"( [{"op": "remove", "path": "/foo"}] )"_json) == R"( {} )"_json);
|
||||||
) == R"( {} )"_json);
|
|
||||||
|
|
||||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
||||||
R"( [{"op": "remove", "path": "/foo/1"}] )"_json
|
R"( [{"op": "remove", "path": "/foo/1"}] )"_json) == R"( {"foo": [1, 3]} )"_json);
|
||||||
) == R"( {"foo": [1, 3]} )"_json);
|
|
||||||
|
|
||||||
CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch(
|
CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch(
|
||||||
R"( [{"op": "remove", "path": "/foo/0/bar"}] )"_json
|
R"( [{"op": "remove", "path": "/foo/0/bar"}] )"_json) == R"( {"foo": [{}]} )"_json);
|
||||||
) == R"( {"foo": [{}]} )"_json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("replace")
|
SECTION("replace")
|
||||||
{
|
{
|
||||||
CHECK(R"( {"foo": "bar"} )"_json.patch(
|
CHECK(R"( {"foo": "bar"} )"_json.patch(
|
||||||
R"( [{"op": "replace", "path": "/foo", "value": 1}] )"_json
|
R"( [{"op": "replace", "path": "/foo", "value": 1}] )"_json) == R"( {"foo": 1} )"_json);
|
||||||
) == R"( {"foo": 1} )"_json);
|
|
||||||
|
|
||||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
||||||
R"( [{"op": "replace", "path": "/foo/1", "value": 4}] )"_json
|
R"( [{"op": "replace", "path": "/foo/1", "value": 4}] )"_json) == R"( {"foo": [1, 4, 3]} )"_json);
|
||||||
) == R"( {"foo": [1, 4, 3]} )"_json);
|
|
||||||
|
|
||||||
CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch(
|
CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch(
|
||||||
R"( [{"op": "replace", "path": "/foo/0/bar", "value": 1}] )"_json
|
R"( [{"op": "replace", "path": "/foo/0/bar", "value": 1}] )"_json) == R"( {"foo": [{"bar": 1}]} )"_json);
|
||||||
) == R"( {"foo": [{"bar": 1}]} )"_json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("move")
|
SECTION("move")
|
||||||
{
|
{
|
||||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
||||||
R"( [{"op": "move", "from": "/foo", "path": "/bar"}] )"_json
|
R"( [{"op": "move", "from": "/foo", "path": "/bar"}] )"_json) == R"( {"bar": [1, 2, 3]} )"_json);
|
||||||
) == R"( {"bar": [1, 2, 3]} )"_json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("copy")
|
SECTION("copy")
|
||||||
{
|
{
|
||||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
||||||
R"( [{"op": "copy", "from": "/foo/1", "path": "/bar"}] )"_json
|
R"( [{"op": "copy", "from": "/foo/1", "path": "/bar"}] )"_json) == R"( {"foo": [1, 2, 3], "bar": 2} )"_json);
|
||||||
) == R"( {"foo": [1, 2, 3], "bar": 2} )"_json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("copy")
|
SECTION("copy")
|
||||||
@@ -1285,8 +1274,7 @@ TEST_CASE("JSON patch")
|
|||||||
for (const auto* filename :
|
for (const auto* filename :
|
||||||
{
|
{
|
||||||
TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json",
|
TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json",
|
||||||
TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"
|
TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
|
|||||||
@@ -23,26 +23,32 @@ TEST_CASE("JSON pointers")
|
|||||||
SECTION("errors")
|
SECTION("errors")
|
||||||
{
|
{
|
||||||
CHECK_THROWS_WITH_AS(json::json_pointer("foo"),
|
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("/~~"),
|
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("/~"),
|
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;
|
json::json_pointer p;
|
||||||
CHECK_THROWS_WITH_AS(p.top(),
|
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(),
|
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")
|
SECTION("array index error")
|
||||||
{
|
{
|
||||||
json v = {1, 2, 3, 4};
|
json v = {1, 2, 3, 4};
|
||||||
json::json_pointer const ptr("/10e");
|
json::json_pointer const ptr("/10e");
|
||||||
CHECK_THROWS_WITH_AS(v[ptr],
|
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 @@ TEST_CASE("JSON pointers")
|
|||||||
// unresolved access
|
// unresolved access
|
||||||
json j_primitive = 1;
|
json j_primitive = 1;
|
||||||
CHECK_THROWS_WITH_AS(j_primitive["/foo"_json_pointer],
|
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),
|
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")));
|
CHECK(!j_primitive.contains(json::json_pointer("/foo")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,14 +214,17 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
// unescaped access
|
// unescaped access
|
||||||
CHECK_THROWS_WITH_AS(j.at(json::json_pointer("/a/b")),
|
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
|
// unresolved access
|
||||||
const json j_primitive = 1;
|
const json j_primitive = 1;
|
||||||
CHECK_THROWS_WITH_AS(j_primitive["/foo"_json_pointer],
|
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),
|
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")
|
SECTION("user-defined string literal")
|
||||||
@@ -274,13 +285,17 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
// error with leading 0
|
// error with leading 0
|
||||||
CHECK_THROWS_WITH_AS(j["/01"_json_pointer],
|
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],
|
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),
|
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),
|
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));
|
||||||
CHECK(!j.contains("/01"_json_pointer));
|
CHECK(!j.contains("/01"_json_pointer));
|
||||||
@@ -289,24 +304,32 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
// error with incorrect numbers
|
// error with incorrect numbers
|
||||||
CHECK_THROWS_WITH_AS(j["/one"_json_pointer] = 1,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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";
|
auto too_large_index = std::to_string((std::numeric_limits<unsigned long long>::max)()) + "1";
|
||||||
@@ -335,9 +358,11 @@ TEST_CASE("JSON pointers")
|
|||||||
DOCTEST_MSVC_SUPPRESS_WARNING_POP
|
DOCTEST_MSVC_SUPPRESS_WARNING_POP
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(j.at("/one"_json_pointer) = 1,
|
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,
|
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));
|
||||||
CHECK(!j.contains("/one"_json_pointer));
|
CHECK(!j.contains("/one"_json_pointer));
|
||||||
@@ -345,7 +370,8 @@ TEST_CASE("JSON pointers")
|
|||||||
CHECK(!j_const.contains("/one"_json_pointer));
|
CHECK(!j_const.contains("/one"_json_pointer));
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(json({{"/list/0", 1}, {"/list/1", 2}, {"/list/three", 3}}).unflatten(),
|
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 "-"
|
// assign to "-"
|
||||||
j["/-"_json_pointer] = 99;
|
j["/-"_json_pointer] = 99;
|
||||||
@@ -353,14 +379,17 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
// error when using "-" in const object
|
// error when using "-" in const object
|
||||||
CHECK_THROWS_WITH_AS(j_const["/-"_json_pointer],
|
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));
|
CHECK(!j_const.contains("/-"_json_pointer));
|
||||||
|
|
||||||
// error when using "-" with at
|
// error when using "-" with at
|
||||||
CHECK_THROWS_WITH_AS(j.at("/-"_json_pointer),
|
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),
|
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));
|
CHECK(!j_const.contains("/-"_json_pointer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,19 +404,23 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
// assign to nonexisting index
|
// assign to nonexisting index
|
||||||
CHECK_THROWS_WITH_AS(j.at("/3"_json_pointer),
|
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));
|
CHECK(!j.contains("/3"_json_pointer));
|
||||||
|
|
||||||
// assign to nonexisting index (with gap)
|
// assign to nonexisting index (with gap)
|
||||||
CHECK_THROWS_WITH_AS(j.at("/5"_json_pointer),
|
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));
|
CHECK(!j.contains("/5"_json_pointer));
|
||||||
|
|
||||||
// assign to "-"
|
// assign to "-"
|
||||||
CHECK_THROWS_WITH_AS(j["/-"_json_pointer],
|
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),
|
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));
|
CHECK(!j.contains("/-"_json_pointer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,23 +433,9 @@ TEST_CASE("JSON pointers")
|
|||||||
{"happy", true},
|
{"happy", true},
|
||||||
{"name", "Niels"},
|
{"name", "Niels"},
|
||||||
{"nothing", nullptr},
|
{"nothing", nullptr},
|
||||||
{
|
{"answer", {{"everything", 42}}},
|
||||||
"answer", {
|
|
||||||
{"everything", 42}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{"list", {1, 0, 2}},
|
{"list", {1, 0, 2}},
|
||||||
{
|
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||||
"object", {
|
|
||||||
{"currency", "USD"},
|
|
||||||
{"value", 42.99},
|
|
||||||
{"", "empty string"},
|
|
||||||
{"/", "slash"},
|
|
||||||
{"~", "tilde"},
|
|
||||||
{"~1", "tilde1"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
json j_flatten =
|
json j_flatten =
|
||||||
{
|
{
|
||||||
@@ -433,8 +452,7 @@ TEST_CASE("JSON pointers")
|
|||||||
{"/object/", "empty string"},
|
{"/object/", "empty string"},
|
||||||
{"/object/~1", "slash"},
|
{"/object/~1", "slash"},
|
||||||
{"/object/~0", "tilde"},
|
{"/object/~0", "tilde"},
|
||||||
{"/object/~01", "tilde1"}
|
{"/object/~01", "tilde1"}};
|
||||||
};
|
|
||||||
|
|
||||||
// check if flattened result is as expected
|
// check if flattened result is as expected
|
||||||
CHECK(j.flatten() == j_flatten);
|
CHECK(j.flatten() == j_flatten);
|
||||||
@@ -444,7 +462,8 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
// error for nonobjects
|
// error for nonobjects
|
||||||
CHECK_THROWS_WITH_AS(json(1).unflatten(),
|
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
|
// error for nonprimitve values
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
@@ -456,7 +475,8 @@ TEST_CASE("JSON pointers")
|
|||||||
// error for conflicting values
|
// error for conflicting values
|
||||||
json const j_error = {{"", 42}, {"/foo", 17}};
|
json const j_error = {{"", 42}, {"/foo", 17}};
|
||||||
CHECK_THROWS_WITH_AS(j_error.unflatten(),
|
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
|
// explicit roundtrip check
|
||||||
CHECK(j.flatten().unflatten() == j);
|
CHECK(j.flatten().unflatten() == j);
|
||||||
@@ -481,8 +501,7 @@ TEST_CASE("JSON pointers")
|
|||||||
SECTION("string representation")
|
SECTION("string representation")
|
||||||
{
|
{
|
||||||
for (const auto* ptr_str :
|
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);
|
json::json_pointer const ptr(ptr_str);
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@@ -521,23 +540,9 @@ TEST_CASE("JSON pointers")
|
|||||||
{"happy", true},
|
{"happy", true},
|
||||||
{"name", "Niels"},
|
{"name", "Niels"},
|
||||||
{"nothing", nullptr},
|
{"nothing", nullptr},
|
||||||
{
|
{"answer", {{"everything", 42}}},
|
||||||
"answer", {
|
|
||||||
{"everything", 42}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{"list", {1, 0, 2}},
|
{"list", {1, 0, 2}},
|
||||||
{
|
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||||
"object", {
|
|
||||||
{"currency", "USD"},
|
|
||||||
{"value", 42.99},
|
|
||||||
{"", "empty string"},
|
|
||||||
{"/", "slash"},
|
|
||||||
{"~", "tilde"},
|
|
||||||
{"~1", "tilde1"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// empty json_pointer returns the root JSON-object
|
// empty json_pointer returns the root JSON-object
|
||||||
auto ptr = ""_json_pointer;
|
auto ptr = ""_json_pointer;
|
||||||
@@ -597,23 +602,9 @@ TEST_CASE("JSON pointers")
|
|||||||
{"happy", true},
|
{"happy", true},
|
||||||
{"name", "Niels"},
|
{"name", "Niels"},
|
||||||
{"nothing", nullptr},
|
{"nothing", nullptr},
|
||||||
{
|
{"answer", {{"everything", 42}}},
|
||||||
"answer", {
|
|
||||||
{"everything", 42}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{"list", {1, 0, 2}},
|
{"list", {1, 0, 2}},
|
||||||
{
|
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||||
"object", {
|
|
||||||
{"currency", "USD"},
|
|
||||||
{"value", 42.99},
|
|
||||||
{"", "empty string"},
|
|
||||||
{"/", "slash"},
|
|
||||||
{"~", "tilde"},
|
|
||||||
{"~1", "tilde1"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// empty json_pointer returns the root JSON-object
|
// empty json_pointer returns the root JSON-object
|
||||||
auto ptr = ""_json_pointer;
|
auto ptr = ""_json_pointer;
|
||||||
@@ -687,13 +678,17 @@ TEST_CASE("JSON pointers")
|
|||||||
SECTION("exceptions")
|
SECTION("exceptions")
|
||||||
{
|
{
|
||||||
CHECK_THROWS_WITH_AS(ptr1 == "foo",
|
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,
|
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 == "/~~",
|
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,
|
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&);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,4 +26,3 @@ TEST_CASE("tests on very large JSONs")
|
|||||||
CHECK_NOTHROW(_ = nlohmann::json::parse(s));
|
CHECK_NOTHROW(_ = nlohmann::json::parse(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,12 +21,10 @@ TEST_CASE("version information")
|
|||||||
CHECK(j["copyright"] == "(C) 2013-2023 Niels Lohmann");
|
CHECK(j["copyright"] == "(C) 2013-2023 Niels Lohmann");
|
||||||
CHECK(j["url"] == "https://github.com/nlohmann/json");
|
CHECK(j["url"] == "https://github.com/nlohmann/json");
|
||||||
CHECK(j["version"] == json(
|
CHECK(j["version"] == json(
|
||||||
{
|
{{"string", "3.11.3"},
|
||||||
{"string", "3.11.3"},
|
|
||||||
{"major", 3},
|
{"major", 3},
|
||||||
{"minor", 11},
|
{"minor", 11},
|
||||||
{"patch", 3}
|
{"patch", 3}}));
|
||||||
}));
|
|
||||||
|
|
||||||
CHECK(j.find("platform") != j.end());
|
CHECK(j.find("platform") != j.end());
|
||||||
CHECK(j.at("compiler").find("family") != j.at("compiler").end());
|
CHECK(j.at("compiler").find("family") != j.at("compiler").end());
|
||||||
|
|||||||
@@ -637,10 +637,8 @@ TEST_CASE("modifiers")
|
|||||||
{
|
{
|
||||||
json j_other_array2 = {"first", "second"};
|
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",
|
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&);
|
||||||
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_other_array.begin(), j_other_array2.end()), "[json.exception.invalid_iterator.210] iterators do not fit",
|
|
||||||
json::invalid_iterator&);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+164
-95
@@ -14,20 +14,20 @@ using nlohmann::json;
|
|||||||
using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
|
using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "make_test_data_available.hpp"
|
||||||
|
#include "test_utils.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include "make_test_data_available.hpp"
|
#include <sstream>
|
||||||
#include "test_utils.hpp"
|
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class SaxCountdown
|
class SaxCountdown
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit SaxCountdown(const int count) : events_left(count)
|
explicit SaxCountdown(const int count)
|
||||||
|
: events_left(count)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool null()
|
bool null()
|
||||||
@@ -168,10 +168,8 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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)
|
|
||||||
};
|
|
||||||
|
|
||||||
// compare result + size
|
// compare result + size
|
||||||
const auto result = json::to_msgpack(j);
|
const auto result = json::to_msgpack(j);
|
||||||
@@ -231,8 +229,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xcc,
|
0xcc,
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
@@ -267,8 +264,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xcd,
|
0xcd,
|
||||||
static_cast<uint8_t>((i >> 8) & 0xff),
|
static_cast<uint8_t>((i >> 8) & 0xff),
|
||||||
static_cast<uint8_t>(i & 0xff),
|
static_cast<uint8_t>(i & 0xff),
|
||||||
@@ -294,8 +290,10 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
for (uint32_t i :
|
for (uint32_t i :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u, 4294967295u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u,
|
||||||
|
4294967295u})
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@@ -307,8 +305,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xce,
|
0xce,
|
||||||
static_cast<uint8_t>((i >> 24) & 0xff),
|
static_cast<uint8_t>((i >> 24) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 16) & 0xff),
|
static_cast<uint8_t>((i >> 16) & 0xff),
|
||||||
@@ -339,8 +336,8 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
for (uint64_t i :
|
for (uint64_t i :
|
||||||
{
|
{
|
||||||
4294967296LU, 9223372036854775807LU
|
4294967296LU,
|
||||||
})
|
9223372036854775807LU})
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@@ -352,8 +349,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xcf,
|
0xcf,
|
||||||
static_cast<uint8_t>((i >> 070) & 0xff),
|
static_cast<uint8_t>((i >> 070) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 060) & 0xff),
|
static_cast<uint8_t>((i >> 060) & 0xff),
|
||||||
@@ -401,8 +397,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xd0,
|
0xd0,
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
@@ -451,8 +446,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xd1,
|
0xd1,
|
||||||
static_cast<uint8_t>((i >> 8) & 0xff),
|
static_cast<uint8_t>((i >> 8) & 0xff),
|
||||||
static_cast<uint8_t>(i & 0xff),
|
static_cast<uint8_t>(i & 0xff),
|
||||||
@@ -476,8 +470,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("-32769..-2147483648")
|
SECTION("-32769..-2147483648")
|
||||||
{
|
{
|
||||||
std::vector<int32_t> const numbers
|
std::vector<int32_t> const numbers{
|
||||||
{
|
|
||||||
-32769,
|
-32769,
|
||||||
-65536,
|
-65536,
|
||||||
-77777,
|
-77777,
|
||||||
@@ -495,8 +488,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xd2,
|
0xd2,
|
||||||
static_cast<uint8_t>((i >> 24) & 0xff),
|
static_cast<uint8_t>((i >> 24) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 16) & 0xff),
|
static_cast<uint8_t>((i >> 16) & 0xff),
|
||||||
@@ -525,8 +517,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("-9223372036854775808..-2147483649 (int 64)")
|
SECTION("-9223372036854775808..-2147483649 (int 64)")
|
||||||
{
|
{
|
||||||
std::vector<int64_t> const numbers
|
std::vector<int64_t> const numbers{
|
||||||
{
|
|
||||||
(std::numeric_limits<int64_t>::min)(),
|
(std::numeric_limits<int64_t>::min)(),
|
||||||
-2147483649LL,
|
-2147483649LL,
|
||||||
};
|
};
|
||||||
@@ -541,8 +532,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xd3,
|
0xd3,
|
||||||
static_cast<uint8_t>((i >> 070) & 0xff),
|
static_cast<uint8_t>((i >> 070) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 060) & 0xff),
|
static_cast<uint8_t>((i >> 060) & 0xff),
|
||||||
@@ -622,8 +612,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xcc,
|
0xcc,
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
@@ -657,8 +646,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xcd,
|
0xcd,
|
||||||
static_cast<uint8_t>((i >> 8) & 0xff),
|
static_cast<uint8_t>((i >> 8) & 0xff),
|
||||||
static_cast<uint8_t>(i & 0xff),
|
static_cast<uint8_t>(i & 0xff),
|
||||||
@@ -684,8 +672,10 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
for (const uint32_t i :
|
for (const uint32_t i :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u, 4294967295u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u,
|
||||||
|
4294967295u})
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@@ -696,8 +686,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xce,
|
0xce,
|
||||||
static_cast<uint8_t>((i >> 24) & 0xff),
|
static_cast<uint8_t>((i >> 24) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 16) & 0xff),
|
static_cast<uint8_t>((i >> 16) & 0xff),
|
||||||
@@ -728,8 +717,8 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
for (const uint64_t i :
|
for (const uint64_t i :
|
||||||
{
|
{
|
||||||
4294967296LU, 18446744073709551615LU
|
4294967296LU,
|
||||||
})
|
18446744073709551615LU})
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@@ -740,8 +729,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
0xcf,
|
0xcf,
|
||||||
static_cast<uint8_t>((i >> 070) & 0xff),
|
static_cast<uint8_t>((i >> 070) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 060) & 0xff),
|
static_cast<uint8_t>((i >> 060) & 0xff),
|
||||||
@@ -785,8 +773,15 @@ TEST_CASE("MessagePack")
|
|||||||
json const j = v;
|
json const j = v;
|
||||||
std::vector<uint8_t> const expected =
|
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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@@ -802,8 +797,11 @@ TEST_CASE("MessagePack")
|
|||||||
json const j = v;
|
json const j = v;
|
||||||
std::vector<uint8_t> const expected =
|
std::vector<uint8_t> const expected =
|
||||||
{
|
{
|
||||||
0xca, 0x3f, 0x80, 0x00, 0x00
|
0xca,
|
||||||
};
|
0x3f,
|
||||||
|
0x80,
|
||||||
|
0x00,
|
||||||
|
0x00};
|
||||||
const auto result = json::to_msgpack(j);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@@ -819,8 +817,11 @@ TEST_CASE("MessagePack")
|
|||||||
json const j = v;
|
json const j = v;
|
||||||
std::vector<uint8_t> const expected =
|
std::vector<uint8_t> const expected =
|
||||||
{
|
{
|
||||||
0xca, 0x43, 0x00, 0x20, 0xc5
|
0xca,
|
||||||
};
|
0x43,
|
||||||
|
0x00,
|
||||||
|
0x20,
|
||||||
|
0xc5};
|
||||||
const auto result = json::to_msgpack(j);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@@ -839,11 +840,38 @@ TEST_CASE("MessagePack")
|
|||||||
// explicitly enumerate the first byte for all 32 strings
|
// explicitly enumerate the first byte for all 32 strings
|
||||||
const std::vector<uint8_t> first_bytes =
|
const std::vector<uint8_t> first_bytes =
|
||||||
{
|
{
|
||||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8,
|
0xa0,
|
||||||
0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1,
|
0xa1,
|
||||||
0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba,
|
0xa2,
|
||||||
0xbb, 0xbc, 0xbd, 0xbe, 0xbf
|
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)
|
for (size_t N = 0; N < first_bytes.size(); ++N)
|
||||||
{
|
{
|
||||||
@@ -916,8 +944,12 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
for (size_t N :
|
for (size_t N :
|
||||||
{
|
{
|
||||||
256u, 999u, 1025u, 3333u, 2048u, 65535u
|
256u,
|
||||||
})
|
999u,
|
||||||
|
1025u,
|
||||||
|
3333u,
|
||||||
|
2048u,
|
||||||
|
65535u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -949,8 +981,9 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
for (size_t N :
|
for (size_t N :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1102,8 +1135,16 @@ TEST_CASE("MessagePack")
|
|||||||
json const j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
json const j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||||
std::vector<uint8_t> const expected =
|
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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@@ -1246,8 +1287,12 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
for (std::size_t N :
|
for (std::size_t N :
|
||||||
{
|
{
|
||||||
256u, 999u, 1025u, 3333u, 2048u, 65535u
|
256u,
|
||||||
})
|
999u,
|
||||||
|
1025u,
|
||||||
|
3333u,
|
||||||
|
2048u,
|
||||||
|
65535u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1282,8 +1327,9 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
for (std::size_t N :
|
for (std::size_t N :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1358,8 +1404,12 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
for (std::size_t N :
|
for (std::size_t N :
|
||||||
{
|
{
|
||||||
256u, 999u, 1025u, 3333u, 2048u, 65535u
|
256u,
|
||||||
})
|
999u,
|
||||||
|
1025u,
|
||||||
|
3333u,
|
||||||
|
2048u,
|
||||||
|
65535u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1391,8 +1441,9 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
for (std::size_t N :
|
for (std::size_t N :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1445,45 +1496,65 @@ TEST_CASE("MessagePack")
|
|||||||
json _;
|
json _;
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x87})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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})),
|
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>({0x87}), true, false).is_discarded());
|
||||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcc}), true, false).is_discarded());
|
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcc}), true, false).is_discarded());
|
||||||
@@ -1521,8 +1592,7 @@ TEST_CASE("MessagePack")
|
|||||||
for (auto byte :
|
for (auto byte :
|
||||||
{
|
{
|
||||||
// never used
|
// never used
|
||||||
0xc1
|
0xc1})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
|
||||||
@@ -1792,8 +1862,7 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
|||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.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_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_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_structure_whitespace_array.json"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
#include "doctest_compatibility.h"
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
struct Foo
|
struct Foo
|
||||||
{
|
{
|
||||||
@@ -18,8 +18,7 @@ struct Foo
|
|||||||
int b;
|
int b;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace nlohmann
|
namespace nlohmann {
|
||||||
{
|
|
||||||
template<>
|
template<>
|
||||||
struct adl_serializer<Foo>
|
struct adl_serializer<Foo>
|
||||||
{
|
{
|
||||||
@@ -82,5 +81,3 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-2")
|
|||||||
// just ignore the exception in this POC
|
// just ignore the exception in this POC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -16,12 +16,15 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
|
|||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
|
enum test
|
||||||
{
|
{
|
||||||
enum test {};
|
};
|
||||||
|
|
||||||
struct pod {};
|
struct pod
|
||||||
struct pod_bis {};
|
{};
|
||||||
|
struct pod_bis
|
||||||
|
{};
|
||||||
|
|
||||||
void to_json(json& /*unused*/, pod /*unused*/) noexcept;
|
void to_json(json& /*unused*/, pod /*unused*/) noexcept;
|
||||||
void to_json(json& /*unused*/, pod_bis /*unused*/);
|
void to_json(json& /*unused*/, pod_bis /*unused*/);
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ using nlohmann::json;
|
|||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <forward_list>
|
#include <forward_list>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <sstream>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
// local variable is initialized but not referenced
|
// local variable is initialized but not referenced
|
||||||
DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
|
DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
|
||||||
@@ -67,19 +67,9 @@ TEST_CASE("README" * doctest::skip())
|
|||||||
{"happy", true},
|
{"happy", true},
|
||||||
{"name", "Niels"},
|
{"name", "Niels"},
|
||||||
{"nothing", nullptr},
|
{"nothing", nullptr},
|
||||||
{
|
{"answer", {{"everything", 42}}},
|
||||||
"answer", {
|
|
||||||
{"everything", 42}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{"list", {1, 0, 2}},
|
{"list", {1, 0, 2}},
|
||||||
{
|
{"object", {{"currency", "USD"}, {"value", 42.99}}}};
|
||||||
"object", {
|
|
||||||
{"currency", "USD"},
|
|
||||||
{"value", 42.99}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,16 +17,10 @@ TEST_CASE("reference access")
|
|||||||
const json json_types =
|
const json json_types =
|
||||||
{
|
{
|
||||||
{"boolean", true},
|
{"boolean", true},
|
||||||
{
|
{"number", {{"integer", 42}, {"floating-point", 17.23}}},
|
||||||
"number", {
|
|
||||||
{"integer", 42},
|
|
||||||
{"floating-point", 17.23}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{"string", "Hello, world!"},
|
{"string", "Hello, world!"},
|
||||||
{"array", {1, 2, 3, 4, 5}},
|
{"array", {1, 2, 3, 4, 5}},
|
||||||
{"null", nullptr}
|
{"null", nullptr}};
|
||||||
};
|
|
||||||
|
|
||||||
SECTION("reference access to object_t")
|
SECTION("reference access to object_t")
|
||||||
{
|
{
|
||||||
@@ -45,17 +39,23 @@ TEST_CASE("reference access")
|
|||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_NOTHROW(value.get_ref<json::object_t&>());
|
CHECK_NOTHROW(value.get_ref<json::object_t&>());
|
||||||
CHECK_THROWS_WITH_AS(value.get_ref<json::array_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&>(),
|
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&>(),
|
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&>(),
|
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&>(),
|
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&>(),
|
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")
|
SECTION("const reference access to const object_t")
|
||||||
@@ -88,18 +88,24 @@ TEST_CASE("reference access")
|
|||||||
|
|
||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
|
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_NOTHROW(value.get_ref<json::array_t&>());
|
||||||
CHECK_THROWS_WITH_AS(value.get_ref<json::string_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&>(),
|
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&>(),
|
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&>(),
|
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&>(),
|
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")
|
SECTION("reference access to string_t")
|
||||||
@@ -118,18 +124,24 @@ TEST_CASE("reference access")
|
|||||||
|
|
||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
|
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&>(),
|
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_NOTHROW(value.get_ref<json::string_t&>());
|
||||||
CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_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&>(),
|
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&>(),
|
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&>(),
|
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")
|
SECTION("reference access to boolean_t")
|
||||||
@@ -148,18 +160,24 @@ TEST_CASE("reference access")
|
|||||||
|
|
||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
|
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&>(),
|
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&>(),
|
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_NOTHROW(value.get_ref<json::boolean_t&>());
|
||||||
CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_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&>(),
|
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&>(),
|
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")
|
SECTION("reference access to number_integer_t")
|
||||||
@@ -178,18 +196,24 @@ TEST_CASE("reference access")
|
|||||||
|
|
||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
|
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&>(),
|
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&>(),
|
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&>(),
|
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_NOTHROW(value.get_ref<json::number_integer_t&>());
|
||||||
CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_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&>(),
|
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")
|
SECTION("reference access to number_unsigned_t")
|
||||||
@@ -208,13 +232,17 @@ TEST_CASE("reference access")
|
|||||||
|
|
||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
|
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&>(),
|
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&>(),
|
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&>(),
|
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&>(),
|
//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&);
|
// "[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&>());
|
CHECK_NOTHROW(value.get_ref<json::number_unsigned_t&>());
|
||||||
|
|||||||
+429
-109
@@ -18,12 +18,12 @@ using nlohmann::json;
|
|||||||
using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
|
using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <list>
|
|
||||||
#include <limits>
|
|
||||||
#include <cstdio>
|
|
||||||
#include "make_test_data_available.hpp"
|
#include "make_test_data_available.hpp"
|
||||||
|
#include <cstdio>
|
||||||
|
#include <fstream>
|
||||||
|
#include <limits>
|
||||||
|
#include <list>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#ifdef JSON_HAS_CPP_17
|
||||||
#include <variant>
|
#include <variant>
|
||||||
@@ -43,8 +43,7 @@ using my_json = nlohmann::basic_json<my_workaround_fifo_map>;
|
|||||||
// for #977
|
// for #977
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
namespace ns
|
namespace ns {
|
||||||
{
|
|
||||||
struct foo
|
struct foo
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
@@ -84,15 +83,13 @@ struct foo_serializer < T, typename std::enable_if < !std::is_same<foo, T>::valu
|
|||||||
};
|
};
|
||||||
} // namespace ns
|
} // namespace ns
|
||||||
|
|
||||||
using foo_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_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>>;
|
||||||
std::uint64_t, double, std::allocator, ns::foo_serializer, std::vector<std::uint8_t>>;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
// for #805
|
// for #805
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct nocopy // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
|
struct nocopy // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
|
||||||
{
|
{
|
||||||
nocopy() = default;
|
nocopy() = default;
|
||||||
@@ -171,7 +168,11 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
SECTION("pull request #71 - handle enum type")
|
SECTION("pull request #71 - handle enum type")
|
||||||
{
|
{
|
||||||
enum { t = 0, u = 102};
|
enum
|
||||||
|
{
|
||||||
|
t = 0,
|
||||||
|
u = 102
|
||||||
|
};
|
||||||
json j = json::array();
|
json j = json::array();
|
||||||
j.push_back(t);
|
j.push_back(t);
|
||||||
|
|
||||||
@@ -187,9 +188,7 @@ TEST_CASE("regression tests 1")
|
|||||||
static_assert(std::is_same<decltype(anon_enum_value), decltype(u)>::value, "types must be the same");
|
static_assert(std::is_same<decltype(anon_enum_value), decltype(u)>::value, "types must be the same");
|
||||||
|
|
||||||
j.push_back(json::object(
|
j.push_back(json::object(
|
||||||
{
|
{{"game_type", t}}));
|
||||||
{"game_type", t}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("issue #76 - dump() / parse() not idempotent")
|
SECTION("issue #76 - dump() / parse() not idempotent")
|
||||||
@@ -298,8 +297,7 @@ TEST_CASE("regression tests 1")
|
|||||||
json::reverse_iterator rit = a.rbegin();
|
json::reverse_iterator rit = a.rbegin();
|
||||||
++rit;
|
++rit;
|
||||||
json b = {0, 0, 0};
|
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;
|
return el;
|
||||||
});
|
});
|
||||||
CHECK(b == json({0, 1, 2}));
|
CHECK(b == json({0, 1, 2}));
|
||||||
@@ -307,8 +305,7 @@ TEST_CASE("regression tests 1")
|
|||||||
{
|
{
|
||||||
json a = {1, 2, 3};
|
json a = {1, 2, 3};
|
||||||
json b = {0, 0, 0};
|
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;
|
return el;
|
||||||
});
|
});
|
||||||
CHECK(b == json({0, 1, 2}));
|
CHECK(b == json({0, 1, 2}));
|
||||||
@@ -321,8 +318,7 @@ TEST_CASE("regression tests 1")
|
|||||||
{
|
{
|
||||||
{"111", 111},
|
{"111", 111},
|
||||||
{"112", 112},
|
{"112", 112},
|
||||||
{ "113", 113 }
|
{"113", 113}};
|
||||||
};
|
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
@@ -342,7 +338,9 @@ TEST_CASE("regression tests 1")
|
|||||||
SECTION("issue #101 - binary string causes numbers to be dumped as hex")
|
SECTION("issue #101 - binary string causes numbers to be dumped as hex")
|
||||||
{
|
{
|
||||||
int64_t const number = 10;
|
int64_t const number = 10;
|
||||||
std::string const bytes{"\x00" "asdf\n", 6};
|
std::string const bytes{"\x00"
|
||||||
|
"asdf\n",
|
||||||
|
6};
|
||||||
json j;
|
json j;
|
||||||
j["int64"] = number;
|
j["int64"] = number;
|
||||||
j["binary string"] = bytes;
|
j["binary string"] = bytes;
|
||||||
@@ -476,8 +474,7 @@ TEST_CASE("regression tests 1")
|
|||||||
CHECK(j_double.get<double>() == 1.23e35);
|
CHECK(j_double.get<double>() == 1.23e35);
|
||||||
|
|
||||||
// long double
|
// long double
|
||||||
nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, long double>
|
nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, long double> const j_long_double = 1.23e45L;
|
||||||
const j_long_double = 1.23e45L;
|
|
||||||
CHECK(j_long_double.get<long double>() == 1.23e45L);
|
CHECK(j_long_double.get<long double>() == 1.23e45L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,8 +617,7 @@ TEST_CASE("regression tests 1")
|
|||||||
for (const auto* filename :
|
for (const auto* filename :
|
||||||
{
|
{
|
||||||
TEST_DATA_DIRECTORY "/regression/broken_file.json",
|
TEST_DATA_DIRECTORY "/regression/broken_file.json",
|
||||||
TEST_DATA_DIRECTORY "/regression/working_file.json"
|
TEST_DATA_DIRECTORY "/regression/working_file.json"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
json j;
|
json j;
|
||||||
@@ -637,8 +633,7 @@ TEST_CASE("regression tests 1")
|
|||||||
TEST_DATA_DIRECTORY "/regression/floats.json",
|
TEST_DATA_DIRECTORY "/regression/floats.json",
|
||||||
TEST_DATA_DIRECTORY "/regression/signed_ints.json",
|
TEST_DATA_DIRECTORY "/regression/signed_ints.json",
|
||||||
TEST_DATA_DIRECTORY "/regression/unsigned_ints.json",
|
TEST_DATA_DIRECTORY "/regression/unsigned_ints.json",
|
||||||
TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"
|
TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
json j;
|
json j;
|
||||||
@@ -662,8 +657,7 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
SECTION("issue #360 - Loss of precision when serializing <double>")
|
SECTION("issue #360 - Loss of precision when serializing <double>")
|
||||||
{
|
{
|
||||||
auto check_roundtrip = [](double number)
|
auto check_roundtrip = [](double number) {
|
||||||
{
|
|
||||||
CAPTURE(number)
|
CAPTURE(number)
|
||||||
|
|
||||||
json j = number;
|
json j = number;
|
||||||
@@ -754,7 +748,8 @@ TEST_CASE("regression tests 1")
|
|||||||
ss << " ";
|
ss << " ";
|
||||||
json j;
|
json j;
|
||||||
CHECK_THROWS_WITH_AS(ss >> 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")
|
SECTION("one value")
|
||||||
@@ -777,7 +772,8 @@ TEST_CASE("regression tests 1")
|
|||||||
CHECK(j == 222);
|
CHECK(j == 222);
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(ss >> j,
|
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")
|
SECTION("whitespace + one value")
|
||||||
@@ -941,11 +937,67 @@ TEST_CASE("regression tests 1")
|
|||||||
// more test cases for MessagePack
|
// more test cases for MessagePack
|
||||||
for (auto b :
|
for (auto b :
|
||||||
{
|
{
|
||||||
0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, // fixmap
|
0x81,
|
||||||
0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, // fixarray
|
0x82,
|
||||||
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, // fixstr
|
0x83,
|
||||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf
|
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));
|
std::vector<uint8_t> const vec(1, static_cast<uint8_t>(b));
|
||||||
CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error&);
|
||||||
@@ -954,12 +1006,75 @@ TEST_CASE("regression tests 1")
|
|||||||
// more test cases for CBOR
|
// more test cases for CBOR
|
||||||
for (auto b :
|
for (auto b :
|
||||||
{
|
{
|
||||||
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
0x61,
|
||||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, // UTF-8 string
|
0x62,
|
||||||
0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
0x63,
|
||||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, // array
|
0x64,
|
||||||
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
0x65,
|
||||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7 // map
|
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));
|
std::vector<uint8_t> const vec(1, static_cast<uint8_t>(b));
|
||||||
@@ -992,26 +1107,143 @@ TEST_CASE("regression tests 1")
|
|||||||
SECTION("issue #412 - Heap-buffer-overflow (OSS-Fuzz issue 367)")
|
SECTION("issue #412 - Heap-buffer-overflow (OSS-Fuzz issue 367)")
|
||||||
{
|
{
|
||||||
// original test case
|
// original test case
|
||||||
std::vector<uint8_t> const vec
|
std::vector<uint8_t> const vec{
|
||||||
{
|
0xab,
|
||||||
0xab, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98,
|
0x98,
|
||||||
0x98, 0x98, 0x98, 0x98, 0x98, 0x00, 0x00, 0x00,
|
0x98,
|
||||||
0x60, 0xab, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98,
|
0x98,
|
||||||
0x98, 0x98, 0x98, 0x98, 0x98, 0x00, 0x00, 0x00,
|
0x98,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
0x98,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
0x98,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
0x98,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
0x98,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
0x98,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
0x98,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0xa0, 0x9f,
|
0x98,
|
||||||
0x9f, 0x97, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
0x98,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
0x00,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
0x00,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
0x00,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
0x60,
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 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 _;
|
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&);
|
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&);
|
||||||
@@ -1050,29 +1282,109 @@ TEST_CASE("regression tests 1")
|
|||||||
SECTION("issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)")
|
SECTION("issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)")
|
||||||
{
|
{
|
||||||
// original test case
|
// original test case
|
||||||
std::vector<uint8_t> const vec1
|
std::vector<uint8_t> const vec1{
|
||||||
{
|
0x94,
|
||||||
0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
|
0xfa,
|
||||||
0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4,
|
0xfa,
|
||||||
0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0x71,
|
0xfa,
|
||||||
0xb4, 0xb4, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a,
|
0xfa,
|
||||||
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61,
|
0xfa,
|
||||||
0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 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 _;
|
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&);
|
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
|
// related test case: double-precision
|
||||||
std::vector<uint8_t> const vec2
|
std::vector<uint8_t> const vec2{
|
||||||
{
|
0x94,
|
||||||
0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
|
0xfa,
|
||||||
0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4,
|
0xfa,
|
||||||
0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0x71,
|
0xfa,
|
||||||
0xb4, 0xb4, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a,
|
0xfa,
|
||||||
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61,
|
0xfa,
|
||||||
0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfb
|
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&);
|
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 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
SECTION("std::vector")
|
SECTION("std::vector")
|
||||||
{
|
{
|
||||||
auto create = [](const json & j)
|
auto create = [](const json& j) {
|
||||||
{
|
|
||||||
std::vector<int> const v = j;
|
std::vector<int> const v = j;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1129,8 +1440,7 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
SECTION("std::list")
|
SECTION("std::list")
|
||||||
{
|
{
|
||||||
auto create = [](const json & j)
|
auto create = [](const json& j) {
|
||||||
{
|
|
||||||
std::list<int> const v = j;
|
std::list<int> const v = j;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1141,8 +1451,7 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
SECTION("std::forward_list")
|
SECTION("std::forward_list")
|
||||||
{
|
{
|
||||||
auto create = [](const json & j)
|
auto create = [](const json& j) {
|
||||||
{
|
|
||||||
std::forward_list<int> const v = j;
|
std::forward_list<int> const v = j;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1328,10 +1637,7 @@ TEST_CASE("regression tests 1")
|
|||||||
{
|
{
|
||||||
std::ifstream is;
|
std::ifstream is;
|
||||||
is.exceptions(
|
is.exceptions(
|
||||||
is.exceptions()
|
is.exceptions() | std::ios_base::failbit | std::ios_base::badbit); // handle different exceptions as 'file not found', 'permission denied'
|
||||||
| 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");
|
is.open(TEST_DATA_DIRECTORY "/regression/working_file.json");
|
||||||
json _;
|
json _;
|
||||||
@@ -1341,10 +1647,7 @@ TEST_CASE("regression tests 1")
|
|||||||
{
|
{
|
||||||
std::ifstream is;
|
std::ifstream is;
|
||||||
is.exceptions(
|
is.exceptions(
|
||||||
is.exceptions()
|
is.exceptions() | std::ios_base::failbit | std::ios_base::badbit); // handle different exceptions as 'file not found', 'permission denied'
|
||||||
| 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",
|
is.open(TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json.cbor",
|
||||||
std::ios_base::in | std::ios_base::binary);
|
std::ios_base::in | std::ios_base::binary);
|
||||||
@@ -1394,13 +1697,15 @@ TEST_CASE("regression tests 1")
|
|||||||
"from": "/one/two/three",
|
"from": "/one/two/three",
|
||||||
"path": "/a/b/c"}])"_json;
|
"path": "/a/b/c"}])"_json;
|
||||||
CHECK_THROWS_WITH_AS(model.patch(p1),
|
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",
|
auto p2 = R"([{"op": "copy",
|
||||||
"from": "/one/two/three",
|
"from": "/one/two/three",
|
||||||
"path": "/a/b/c"}])"_json;
|
"path": "/a/b/c"}])"_json;
|
||||||
CHECK_THROWS_WITH_AS(model.patch(p2),
|
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")
|
SECTION("issue #961 - incorrect parsing of indefinite length CBOR strings")
|
||||||
@@ -1409,11 +1714,15 @@ TEST_CASE("regression tests 1")
|
|||||||
{
|
{
|
||||||
0x7F,
|
0x7F,
|
||||||
0x64,
|
0x64,
|
||||||
'a', 'b', 'c', 'd',
|
'a',
|
||||||
|
'b',
|
||||||
|
'c',
|
||||||
|
'd',
|
||||||
0x63,
|
0x63,
|
||||||
'1', '2', '3',
|
'1',
|
||||||
0xFF
|
'2',
|
||||||
};
|
'3',
|
||||||
|
0xFF};
|
||||||
json j = json::from_cbor(v_cbor);
|
json j = json::from_cbor(v_cbor);
|
||||||
CHECK(j == "abcd123");
|
CHECK(j == "abcd123");
|
||||||
}
|
}
|
||||||
@@ -1453,8 +1762,7 @@ TEST_CASE("regression tests 1")
|
|||||||
)";
|
)";
|
||||||
|
|
||||||
// define parser callback
|
// 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"
|
// skip object elements with key "Thumbnail"
|
||||||
return !(event == json::parse_event_t::key && parsed == json("Thumbnail"));
|
return !(event == json::parse_event_t::key && parsed == json("Thumbnail"));
|
||||||
};
|
};
|
||||||
@@ -1504,10 +1812,22 @@ TEST_CASE("regression tests, exceptions dependent")
|
|||||||
// the code below fails with Clang on Windows, so we need to exclude it there
|
// 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__))
|
#if DOCTEST_CLANG && (defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__))
|
||||||
#else
|
#else
|
||||||
template <typename T> class array {};
|
template<typename T>
|
||||||
template <typename T> class object {};
|
class array
|
||||||
template <typename T> class string {};
|
{};
|
||||||
template <typename T> class number_integer {};
|
template<typename T>
|
||||||
template <typename T> class number_unsigned {};
|
class object
|
||||||
template <typename T> class number_float {};
|
{};
|
||||||
|
template<typename T>
|
||||||
|
class string
|
||||||
|
{};
|
||||||
|
template<typename T>
|
||||||
|
class number_integer
|
||||||
|
{};
|
||||||
|
template<typename T>
|
||||||
|
class number_unsigned
|
||||||
|
{};
|
||||||
|
template<typename T>
|
||||||
|
class number_float
|
||||||
|
{};
|
||||||
#endif
|
#endif
|
||||||
@@ -55,8 +55,7 @@ using float_json = nlohmann::basic_json<std::map, std::vector, std::string, bool
|
|||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
// for #1647
|
// for #1647
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct NonDefaultFromJsonStruct
|
struct NonDefaultFromJsonStruct
|
||||||
{};
|
{};
|
||||||
|
|
||||||
@@ -112,8 +111,7 @@ bool operator==(Data const& lhs, Data const& rhs)
|
|||||||
// return !(lhs == rhs);
|
// return !(lhs == rhs);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
namespace nlohmann
|
namespace nlohmann {
|
||||||
{
|
|
||||||
template<>
|
template<>
|
||||||
struct adl_serializer<NonDefaultFromJsonStruct>
|
struct adl_serializer<NonDefaultFromJsonStruct>
|
||||||
{
|
{
|
||||||
@@ -146,8 +144,7 @@ struct NonDefaultConstructible
|
|||||||
int x;
|
int x;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace nlohmann
|
namespace nlohmann {
|
||||||
{
|
|
||||||
template<>
|
template<>
|
||||||
struct adl_serializer<NonDefaultConstructible>
|
struct adl_serializer<NonDefaultConstructible>
|
||||||
{
|
{
|
||||||
@@ -191,7 +188,9 @@ class my_allocator : public std::allocator<T>
|
|||||||
using std::allocator<T>::allocator;
|
using std::allocator<T>::allocator;
|
||||||
|
|
||||||
my_allocator() = default;
|
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
|
struct rebind
|
||||||
@@ -290,9 +289,11 @@ struct for_3204_bar
|
|||||||
};
|
};
|
||||||
|
|
||||||
explicit for_3204_bar(std::function<void(for_3204_foo)> /*unused*/) noexcept // NOLINT(performance-unnecessary-value-param)
|
explicit for_3204_bar(std::function<void(for_3204_foo)> /*unused*/) noexcept // NOLINT(performance-unnecessary-value-param)
|
||||||
: constructed_from(constructed_from_foo) {}
|
: constructed_from(constructed_from_foo)
|
||||||
|
{}
|
||||||
explicit for_3204_bar(std::function<void(json)> /*unused*/) noexcept // NOLINT(performance-unnecessary-value-param)
|
explicit for_3204_bar(std::function<void(json)> /*unused*/) noexcept // NOLINT(performance-unnecessary-value-param)
|
||||||
: constructed_from(constructed_from_json) {}
|
: constructed_from(constructed_from_json)
|
||||||
|
{}
|
||||||
|
|
||||||
constructed_from_t constructed_from = constructed_from_none;
|
constructed_from_t constructed_from = constructed_from_none;
|
||||||
};
|
};
|
||||||
@@ -303,7 +304,10 @@ struct for_3204_bar
|
|||||||
|
|
||||||
struct for_3333 final
|
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*/)
|
for_3333(const T& /*unused*/)
|
||||||
@@ -359,8 +363,7 @@ TEST_CASE("regression tests 2")
|
|||||||
]
|
]
|
||||||
})";
|
})";
|
||||||
|
|
||||||
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
|
// skip uninteresting events
|
||||||
if (event == json::parse_event_t::value && !parsed.is_primitive())
|
if (event == json::parse_event_t::value && !parsed.is_primitive())
|
||||||
{
|
{
|
||||||
@@ -432,8 +435,7 @@ TEST_CASE("regression tests 2")
|
|||||||
p2.begin(),
|
p2.begin(),
|
||||||
p2.end(),
|
p2.end(),
|
||||||
std::inserter(diffs, diffs.end()),
|
std::inserter(diffs, diffs.end()),
|
||||||
[&](const it_type & e1, const it_type & e2) -> bool
|
[&](const it_type& e1, const it_type& e2) -> bool {
|
||||||
{
|
|
||||||
using comper_pair = std::pair<std::string, decltype(e1.value())>; // Trying to avoid unneeded copy
|
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
|
return comper_pair(e1.key(), e1.value()) < comper_pair(e2.key(), e2.value()); // Using pair comper
|
||||||
});
|
});
|
||||||
@@ -458,8 +460,7 @@ TEST_CASE("regression tests 2")
|
|||||||
{"3", {{"a", "testa_3"}, {"b", "testb_3"}}},
|
{"3", {{"a", "testa_3"}, {"b", "testb_3"}}},
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<std::string, Data> expected
|
std::map<std::string, Data> expected{
|
||||||
{
|
|
||||||
{"1", {"testa_1", "testb_1"}},
|
{"1", {"testa_1", "testb_1"}},
|
||||||
{"2", {"testa_2", "testb_2"}},
|
{"2", {"testa_2", "testb_2"}},
|
||||||
{"3", {"testa_3", "testb_3"}},
|
{"3", {"testa_3", "testb_3"}},
|
||||||
@@ -509,8 +510,7 @@ TEST_CASE("regression tests 2")
|
|||||||
nlohmann::json dump_test;
|
nlohmann::json dump_test;
|
||||||
const std::array<int, 108> data =
|
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;
|
std::string s;
|
||||||
for (const int i : data)
|
for (const int i : data)
|
||||||
{
|
{
|
||||||
@@ -639,8 +639,7 @@ TEST_CASE("regression tests 2")
|
|||||||
0x74,
|
0x74,
|
||||||
0x20,
|
0x20,
|
||||||
0x4F,
|
0x4F,
|
||||||
0x42
|
0x42};
|
||||||
};
|
|
||||||
const json result = json::from_cbor(data, true, false);
|
const json result = json::from_cbor(data, true, false);
|
||||||
CHECK(result.is_discarded());
|
CHECK(result.is_discarded());
|
||||||
}
|
}
|
||||||
@@ -656,8 +655,7 @@ TEST_CASE("regression tests 2")
|
|||||||
CHECK(jsonAnimals == jsonAnimals_parsed);
|
CHECK(jsonAnimals == jsonAnimals_parsed);
|
||||||
|
|
||||||
const std::vector<std::pair<std::string, int64_t>> intData = {std::make_pair("aaaa", 11),
|
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;
|
nlohmann::ordered_json jsonObj;
|
||||||
for (const auto& data : intData)
|
for (const auto& data : intData)
|
||||||
{
|
{
|
||||||
@@ -858,10 +856,10 @@ TEST_CASE("regression tests 2")
|
|||||||
|
|
||||||
CHECK(j.dump() == "[1,2,4]");
|
CHECK(j.dump() == "[1,2,4]");
|
||||||
|
|
||||||
j.erase(std::remove_if(j.begin(), j.end(), [](const ordered_json & val)
|
j.erase(std::remove_if(j.begin(), j.end(), [](const ordered_json& val) {
|
||||||
{
|
|
||||||
return val == 2;
|
return val == 2;
|
||||||
}), j.end());
|
}),
|
||||||
|
j.end());
|
||||||
|
|
||||||
CHECK(j.dump() == "[1,4]");
|
CHECK(j.dump() == "[1,4]");
|
||||||
}
|
}
|
||||||
@@ -926,11 +924,9 @@ TEST_CASE("regression tests 2")
|
|||||||
|
|
||||||
SECTION("issue #3333 - Ambiguous conversion from nlohmann::basic_json<> to custom class")
|
SECTION("issue #3333 - Ambiguous conversion from nlohmann::basic_json<> to custom class")
|
||||||
{
|
{
|
||||||
const json j
|
const json j{
|
||||||
{
|
|
||||||
{"x", 1},
|
{"x", 1},
|
||||||
{"y", 2}
|
{"y", 2}};
|
||||||
};
|
|
||||||
for_3333 p = j;
|
for_3333 p = j;
|
||||||
|
|
||||||
CHECK(p.x == 1);
|
CHECK(p.x == 1);
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
TEST_CASE("serialization")
|
TEST_CASE("serialization")
|
||||||
{
|
{
|
||||||
@@ -118,41 +118,90 @@ TEST_CASE("serialization")
|
|||||||
// https://www.unicode.org/versions/Unicode11.0.0/ch03.pdf
|
// https://www.unicode.org/versions/Unicode11.0.0/ch03.pdf
|
||||||
// Section 3.9 -- U+FFFD Substitution of Maximal Subparts
|
// 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;
|
const json j = input;
|
||||||
CHECK(j.dump(-1, ' ', true, json::error_handler_t::replace) == "\"" + expected + "\"");
|
CHECK(j.dump(-1, ' ', true, json::error_handler_t::replace) == "\"" + expected + "\"");
|
||||||
};
|
};
|
||||||
|
|
||||||
test("\xC2", "\\ufffd");
|
test("\xC2", "\\ufffd");
|
||||||
test("\xC2\x41\x42", "\\ufffd" "\x41" "\x42");
|
test("\xC2\x41\x42", "\\ufffd"
|
||||||
test("\xC2\xF4", "\\ufffd" "\\ufffd");
|
"\x41"
|
||||||
|
"\x42");
|
||||||
|
test("\xC2\xF4", "\\ufffd"
|
||||||
|
"\\ufffd");
|
||||||
|
|
||||||
test("\xF0\x80\x80\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\x41");
|
test("\xF0\x80\x80\x41", "\\ufffd"
|
||||||
test("\xF1\x80\x80\x41", "\\ufffd" "\x41");
|
"\\ufffd"
|
||||||
test("\xF2\x80\x80\x41", "\\ufffd" "\x41");
|
"\\ufffd"
|
||||||
test("\xF3\x80\x80\x41", "\\ufffd" "\x41");
|
"\x41");
|
||||||
test("\xF4\x80\x80\x41", "\\ufffd" "\x41");
|
test("\xF1\x80\x80\x41", "\\ufffd"
|
||||||
test("\xF5\x80\x80\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\x41");
|
"\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("\xF0\x90\x80\x41", "\\ufffd"
|
||||||
test("\xF1\x90\x80\x41", "\\ufffd" "\x41");
|
"\x41");
|
||||||
test("\xF2\x90\x80\x41", "\\ufffd" "\x41");
|
test("\xF1\x90\x80\x41", "\\ufffd"
|
||||||
test("\xF3\x90\x80\x41", "\\ufffd" "\x41");
|
"\x41");
|
||||||
test("\xF4\x90\x80\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\x41");
|
test("\xF2\x90\x80\x41", "\\ufffd"
|
||||||
test("\xF5\x90\x80\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\x41");
|
"\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("\xC0\xAF\xE0\x80\xBF\xF0\x81\x82\x41", "\\ufffd"
|
||||||
test("\xED\xA0\x80\xED\xBF\xBF\xED\xAF\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\x41");
|
"\\ufffd"
|
||||||
test("\xF4\x91\x92\x93\xFF\x41\x80\xBF\x42", "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\x41" "\\ufffd""\\ufffd" "\x42");
|
"\\ufffd"
|
||||||
test("\xE1\x80\xE2\xF0\x91\x92\xF1\xBF\x41", "\\ufffd" "\\ufffd" "\\ufffd" "\\ufffd" "\x41");
|
"\\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")
|
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;
|
using std::to_string;
|
||||||
const json j = input;
|
const json j = input;
|
||||||
CHECK(to_string(j) == "\"" + expected + "\"");
|
CHECK(to_string(j) == "\"" + expected + "\"");
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include "make_test_data_available.hpp"
|
#include "make_test_data_available.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
TEST_CASE("compliance tests from json.org")
|
TEST_CASE("compliance tests from json.org")
|
||||||
{
|
{
|
||||||
@@ -54,8 +54,7 @@ TEST_CASE("compliance tests from json.org")
|
|||||||
TEST_DATA_DIRECTORY "/json_tests/fail30.json",
|
TEST_DATA_DIRECTORY "/json_tests/fail30.json",
|
||||||
TEST_DATA_DIRECTORY "/json_tests/fail31.json",
|
TEST_DATA_DIRECTORY "/json_tests/fail31.json",
|
||||||
TEST_DATA_DIRECTORY "/json_tests/fail32.json",
|
TEST_DATA_DIRECTORY "/json_tests/fail32.json",
|
||||||
TEST_DATA_DIRECTORY "/json_tests/fail33.json"
|
TEST_DATA_DIRECTORY "/json_tests/fail33.json"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -89,8 +88,7 @@ TEST_CASE("compliance tests from json.org")
|
|||||||
{
|
{
|
||||||
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
||||||
TEST_DATA_DIRECTORY "/json_tests/pass2.json",
|
TEST_DATA_DIRECTORY "/json_tests/pass2.json",
|
||||||
TEST_DATA_DIRECTORY "/json_tests/pass3.json"
|
TEST_DATA_DIRECTORY "/json_tests/pass3.json"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -106,8 +104,7 @@ TEST_CASE("compliance tests from nativejson-benchmark")
|
|||||||
|
|
||||||
SECTION("doubles")
|
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(json_string)
|
||||||
CAPTURE(expected)
|
CAPTURE(expected)
|
||||||
CHECK(json::parse(json_string)[0].get<double>() == Approx(expected));
|
CHECK(json::parse(json_string)[0].get<double>() == Approx(expected));
|
||||||
@@ -238,8 +235,7 @@ TEST_CASE("compliance tests from nativejson-benchmark")
|
|||||||
|
|
||||||
SECTION("strings")
|
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(json_string)
|
||||||
CAPTURE(expected)
|
CAPTURE(expected)
|
||||||
CHECK(json::parse(json_string)[0].get<std::string>() == expected);
|
CHECK(json::parse(json_string)[0].get<std::string>() == expected);
|
||||||
@@ -572,9 +568,7 @@ TEST_CASE("nst's JSONTestSuite")
|
|||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.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_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_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_structure_whitespace_array.json"})
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -781,9 +775,7 @@ TEST_CASE("nst's JSONTestSuite")
|
|||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_object.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_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_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_structure_whitespace_formfeed.json"})
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -814,9 +806,7 @@ TEST_CASE("nst's JSONTestSuite")
|
|||||||
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_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_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_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_structure_trailing_#.json"})
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -837,9 +827,7 @@ TEST_CASE("nst's JSONTestSuite")
|
|||||||
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+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+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+FDD0_nonchar.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+FFFE_nonchar.json"
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+FFFE_nonchar.json"})
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -857,9 +845,7 @@ TEST_CASE("nst's JSONTestSuite")
|
|||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_pos_double_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_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_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/y_number_real_pos_overflow.json"})
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -884,9 +870,7 @@ TEST_CASE("nst's JSONTestSuite")
|
|||||||
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_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_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_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_string_truncated-utf-8.json"})
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -999,9 +983,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
|||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_string_empty.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_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_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_structure_whitespace_array.json"})
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -1201,9 +1183,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
|||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_object.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_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_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_structure_whitespace_formfeed.json"})
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -1219,9 +1199,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
|||||||
for (const auto* filename :
|
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_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_open_array_object.json"})
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -1267,9 +1245,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
|||||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16BE_no_BOM.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_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_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_structure_UTF-8_BOM_empty_object.json"})
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -1319,8 +1295,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
|||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16LE_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_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_structure_UTF-8_BOM_empty_object.json"
|
||||||
}
|
})
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
@@ -1333,8 +1308,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
std::string trim(const std::string& str);
|
std::string trim(const std::string& str);
|
||||||
|
|
||||||
// from https://stackoverflow.com/a/25829178/266378
|
// from https://stackoverflow.com/a/25829178/266378
|
||||||
|
|||||||
@@ -15,8 +15,7 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::detail::dtoa_impl::reinterpret_bits;
|
using nlohmann::detail::dtoa_impl::reinterpret_bits;
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t significand)
|
float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t significand)
|
||||||
{
|
{
|
||||||
assert(sign_bit == 0 || sign_bit == 1);
|
assert(sign_bit == 0 || sign_bit == 1);
|
||||||
@@ -126,8 +125,7 @@ TEST_CASE("digit gen")
|
|||||||
{
|
{
|
||||||
SECTION("single precision")
|
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(number)
|
||||||
CAPTURE(digits)
|
CAPTURE(digits)
|
||||||
CAPTURE(expected_exponent)
|
CAPTURE(expected_exponent)
|
||||||
@@ -190,8 +188,7 @@ TEST_CASE("digit gen")
|
|||||||
|
|
||||||
SECTION("double precision")
|
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(number)
|
||||||
CAPTURE(digits)
|
CAPTURE(digits)
|
||||||
CAPTURE(expected_exponent)
|
CAPTURE(expected_exponent)
|
||||||
@@ -336,8 +333,7 @@ TEST_CASE("formatting")
|
|||||||
{
|
{
|
||||||
SECTION("single precision")
|
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{};
|
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);
|
std::string actual(buf.data(), end);
|
||||||
@@ -396,8 +392,7 @@ TEST_CASE("formatting")
|
|||||||
|
|
||||||
SECTION("double precision")
|
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{};
|
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);
|
std::string actual(buf.data(), end);
|
||||||
@@ -456,8 +451,7 @@ TEST_CASE("formatting")
|
|||||||
|
|
||||||
SECTION("integer")
|
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;
|
const nlohmann::json j = number;
|
||||||
CHECK(j.dump() == expected);
|
CHECK(j.dump() == expected);
|
||||||
};
|
};
|
||||||
|
|||||||
+321
-167
@@ -11,18 +11,18 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <set>
|
|
||||||
#include "make_test_data_available.hpp"
|
#include "make_test_data_available.hpp"
|
||||||
#include "test_utils.hpp"
|
#include "test_utils.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class SaxCountdown
|
class SaxCountdown
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit SaxCountdown(const int count) : events_left(count)
|
explicit SaxCountdown(const int count)
|
||||||
|
: events_left(count)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool null()
|
bool null()
|
||||||
@@ -152,8 +152,7 @@ TEST_CASE("UBJSON")
|
|||||||
{
|
{
|
||||||
SECTION("-9223372036854775808..-2147483649 (int64)")
|
SECTION("-9223372036854775808..-2147483649 (int64)")
|
||||||
{
|
{
|
||||||
std::vector<int64_t> const numbers
|
std::vector<int64_t> const numbers{
|
||||||
{
|
|
||||||
(std::numeric_limits<int64_t>::min)(),
|
(std::numeric_limits<int64_t>::min)(),
|
||||||
-1000000000000000000LL,
|
-1000000000000000000LL,
|
||||||
-100000000000000000LL,
|
-100000000000000000LL,
|
||||||
@@ -177,8 +176,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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>('L'),
|
||||||
static_cast<uint8_t>((i >> 56) & 0xff),
|
static_cast<uint8_t>((i >> 56) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 48) & 0xff),
|
static_cast<uint8_t>((i >> 48) & 0xff),
|
||||||
@@ -234,8 +232,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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>('l'),
|
||||||
static_cast<uint8_t>((i >> 24) & 0xff),
|
static_cast<uint8_t>((i >> 24) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 16) & 0xff),
|
static_cast<uint8_t>((i >> 16) & 0xff),
|
||||||
@@ -275,8 +272,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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'),
|
||||||
static_cast<uint8_t>((i >> 8) & 0xff),
|
static_cast<uint8_t>((i >> 8) & 0xff),
|
||||||
static_cast<uint8_t>(i & 0xff),
|
static_cast<uint8_t>(i & 0xff),
|
||||||
@@ -331,8 +327,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
'i',
|
'i',
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
@@ -366,8 +361,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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'),
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
@@ -401,8 +395,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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>('U'),
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
@@ -436,8 +429,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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'),
|
||||||
static_cast<uint8_t>((i >> 8) & 0xff),
|
static_cast<uint8_t>((i >> 8) & 0xff),
|
||||||
static_cast<uint8_t>(i & 0xff),
|
static_cast<uint8_t>(i & 0xff),
|
||||||
@@ -463,8 +455,9 @@ TEST_CASE("UBJSON")
|
|||||||
{
|
{
|
||||||
for (uint32_t i :
|
for (uint32_t i :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u})
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@@ -476,8 +469,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
'l',
|
'l',
|
||||||
static_cast<uint8_t>((i >> 24) & 0xff),
|
static_cast<uint8_t>((i >> 24) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 16) & 0xff),
|
static_cast<uint8_t>((i >> 16) & 0xff),
|
||||||
@@ -519,8 +511,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
'L',
|
'L',
|
||||||
static_cast<uint8_t>((i >> 070) & 0xff),
|
static_cast<uint8_t>((i >> 070) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 060) & 0xff),
|
static_cast<uint8_t>((i >> 060) & 0xff),
|
||||||
@@ -571,8 +562,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
'i',
|
'i',
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
@@ -606,8 +596,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
'U',
|
'U',
|
||||||
static_cast<uint8_t>(i),
|
static_cast<uint8_t>(i),
|
||||||
};
|
};
|
||||||
@@ -641,8 +630,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
'I',
|
'I',
|
||||||
static_cast<uint8_t>((i >> 8) & 0xff),
|
static_cast<uint8_t>((i >> 8) & 0xff),
|
||||||
static_cast<uint8_t>(i & 0xff),
|
static_cast<uint8_t>(i & 0xff),
|
||||||
@@ -668,8 +656,9 @@ TEST_CASE("UBJSON")
|
|||||||
{
|
{
|
||||||
for (uint32_t i :
|
for (uint32_t i :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u})
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@@ -680,8 +669,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
'l',
|
'l',
|
||||||
static_cast<uint8_t>((i >> 24) & 0xff),
|
static_cast<uint8_t>((i >> 24) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 16) & 0xff),
|
static_cast<uint8_t>((i >> 16) & 0xff),
|
||||||
@@ -722,8 +710,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// create expected byte vector
|
||||||
std::vector<uint8_t> const expected
|
std::vector<uint8_t> const expected{
|
||||||
{
|
|
||||||
'L',
|
'L',
|
||||||
static_cast<uint8_t>((i >> 070) & 0xff),
|
static_cast<uint8_t>((i >> 070) & 0xff),
|
||||||
static_cast<uint8_t>((i >> 060) & 0xff),
|
static_cast<uint8_t>((i >> 060) & 0xff),
|
||||||
@@ -767,8 +754,15 @@ TEST_CASE("UBJSON")
|
|||||||
json const j = v;
|
json const j = v;
|
||||||
std::vector<uint8_t> expected =
|
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);
|
const auto result = json::to_ubjson(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@@ -915,8 +909,12 @@ TEST_CASE("UBJSON")
|
|||||||
{
|
{
|
||||||
for (size_t N :
|
for (size_t N :
|
||||||
{
|
{
|
||||||
256u, 999u, 1025u, 3333u, 2048u, 32767u
|
256u,
|
||||||
})
|
999u,
|
||||||
|
1025u,
|
||||||
|
3333u,
|
||||||
|
2048u,
|
||||||
|
32767u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -949,8 +947,9 @@ TEST_CASE("UBJSON")
|
|||||||
{
|
{
|
||||||
for (size_t N :
|
for (size_t N :
|
||||||
{
|
{
|
||||||
65536u, 77777u, 1048576u
|
65536u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1076,8 +1075,12 @@ TEST_CASE("UBJSON")
|
|||||||
{
|
{
|
||||||
for (std::size_t N :
|
for (std::size_t N :
|
||||||
{
|
{
|
||||||
256u, 999u, 1025u, 3333u, 2048u, 32767u
|
256u,
|
||||||
})
|
999u,
|
||||||
|
1025u,
|
||||||
|
3333u,
|
||||||
|
2048u,
|
||||||
|
32767u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1113,8 +1116,9 @@ TEST_CASE("UBJSON")
|
|||||||
{
|
{
|
||||||
for (std::size_t N :
|
for (std::size_t N :
|
||||||
{
|
{
|
||||||
32768u, 77777u, 1048576u
|
32768u,
|
||||||
})
|
77777u,
|
||||||
|
1048576u})
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@@ -1547,8 +1551,23 @@ TEST_CASE("UBJSON")
|
|||||||
json const j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
json const j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||||
std::vector<uint8_t> expected =
|
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);
|
const auto result = json::to_ubjson(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@@ -1562,8 +1581,31 @@ TEST_CASE("UBJSON")
|
|||||||
json const j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
json const j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||||
std::vector<uint8_t> expected =
|
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);
|
const auto result = json::to_ubjson(j, true);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@@ -1577,8 +1619,34 @@ TEST_CASE("UBJSON")
|
|||||||
json const j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
json const j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||||
std::vector<uint8_t> expected =
|
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);
|
const auto result = json::to_ubjson(j, true, true);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@@ -1617,8 +1685,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||||
|
|
||||||
json j;
|
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;
|
return true;
|
||||||
});
|
});
|
||||||
CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&);
|
CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&);
|
||||||
@@ -1631,8 +1698,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||||
|
|
||||||
json j;
|
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;
|
return true;
|
||||||
});
|
});
|
||||||
CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&);
|
CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&);
|
||||||
@@ -2097,14 +2163,8 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
SECTION("No-Op Value")
|
SECTION("No-Op Value")
|
||||||
{
|
{
|
||||||
json const j = {"foo", "bar", "baz"};
|
json const j = {"foo", "bar", "baz"};
|
||||||
std::vector<uint8_t> const v = {'[', 'S', 'i', 3, 'f', 'o', 'o',
|
std::vector<uint8_t> const v = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'S', 'i', 3, 'b', 'a', 'r', 'S', 'i', 3, 'b', 'a', 'z', ']'};
|
||||||
'S', 'i', 3, 'b', 'a', 'r',
|
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', ']'};
|
||||||
'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::to_ubjson(j) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
CHECK(json::from_ubjson(v2) == j);
|
CHECK(json::from_ubjson(v2) == j);
|
||||||
@@ -2113,9 +2173,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
SECTION("Boolean Types")
|
SECTION("Boolean Types")
|
||||||
{
|
{
|
||||||
json const j = {{"authorized", true}, {"verified", false}};
|
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',
|
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', '}'};
|
||||||
'i', 8, 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'F', '}'
|
|
||||||
};
|
|
||||||
CHECK(json::to_ubjson(j) == v);
|
CHECK(json::to_ubjson(j) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
}
|
}
|
||||||
@@ -2129,17 +2187,82 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
{"int16", 32767},
|
{"int16", 32767},
|
||||||
{"int32", 2147483647},
|
{"int32", 2147483647},
|
||||||
{"int64", 9223372036854775807},
|
{"int64", 9223372036854775807},
|
||||||
{"float64", 113243.7863123}
|
{"float64", 113243.7863123}};
|
||||||
};
|
|
||||||
std::vector<uint8_t> const v = {'{',
|
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',
|
||||||
'i', 5, 'i', 'n', 't', '1', '6', 'I', 0x7f, 0xff,
|
7,
|
||||||
'i', 5, 'i', 'n', 't', '3', '2', 'l', 0x7f, 0xff, 0xff, 0xff,
|
'f',
|
||||||
'i', 5, 'i', 'n', 't', '6', '4', 'L', 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
'l',
|
||||||
'i', 4, 'i', 'n', 't', '8', 'i', 16,
|
'o',
|
||||||
'i', 5, 'u', 'i', 'n', 't', '8', 'U', 0xff,
|
'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::to_ubjson(j) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
}
|
}
|
||||||
@@ -2215,22 +2338,8 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
{
|
{
|
||||||
json const j =
|
json const j =
|
||||||
{
|
{
|
||||||
{
|
{"post", {{"id", 1137}, {"author", "rkalla"}, {"timestamp", 1364482090592}, {"body", "I totally agree!"}}}};
|
||||||
"post", {
|
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, '}', '}'};
|
||||||
{"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::to_ubjson(j) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
}
|
}
|
||||||
@@ -2239,21 +2348,8 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
{
|
{
|
||||||
json const j =
|
json const j =
|
||||||
{
|
{
|
||||||
{
|
{"post", {{"id", 1137}, {"author", "rkalla"}, {"timestamp", 1364482090592}, {"body", "I totally agree!"}}}};
|
||||||
"post", {
|
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};
|
||||||
{"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::to_ubjson(j, true) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
}
|
}
|
||||||
@@ -2262,21 +2358,8 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
{
|
{
|
||||||
json const j =
|
json const j =
|
||||||
{
|
{
|
||||||
{
|
{"post", {{"id", 1137}, {"author", "rkalla"}, {"timestamp", 1364482090592}, {"body", "I totally agree!"}}}};
|
||||||
"post", {
|
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};
|
||||||
{"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::to_ubjson(j, true, true) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
}
|
}
|
||||||
@@ -2291,13 +2374,52 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
// note the floats have been replaced by doubles
|
// note the floats have been replaced by doubles
|
||||||
json const j = {29.97, 31.13, 67.0, 2.113, 23.888};
|
json const j = {29.97, 31.13, 67.0, 2.113, 23.888};
|
||||||
std::vector<uint8_t> const v = {'[',
|
std::vector<uint8_t> const v = {'[',
|
||||||
'D', 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8,
|
'D',
|
||||||
'D', 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1,
|
0x40,
|
||||||
'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x3d,
|
||||||
'D', 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81,
|
0xf8,
|
||||||
'D', 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17,
|
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::to_ubjson(j) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
}
|
}
|
||||||
@@ -2306,13 +2428,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
{
|
{
|
||||||
// note the floats have been replaced by doubles
|
// note the floats have been replaced by doubles
|
||||||
json const j = {29.97, 31.13, 67.0, 2.113, 23.888};
|
json const j = {29.97, 31.13, 67.0, 2.113, 23.888};
|
||||||
std::vector<uint8_t> const v = {'[', '#', 'i', 5,
|
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};
|
||||||
'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::to_ubjson(j, true) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
}
|
}
|
||||||
@@ -2321,13 +2437,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
{
|
{
|
||||||
// note the floats have been replaced by doubles
|
// note the floats have been replaced by doubles
|
||||||
json const j = {29.97, 31.13, 67.0, 2.113, 23.888};
|
json const j = {29.97, 31.13, 67.0, 2.113, 23.888};
|
||||||
std::vector<uint8_t> const v = {'[', '$', 'D', '#', 'i', 5,
|
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};
|
||||||
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::to_ubjson(j, true, true) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
}
|
}
|
||||||
@@ -2340,11 +2450,50 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
// note the floats have been replaced by doubles
|
// 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 = {'{',
|
std::vector<uint8_t> const v = {'{',
|
||||||
'i', 3, 'a', 'l', 't', 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
'i',
|
||||||
'i', 3, 'l', 'a', 't', 'D', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60,
|
3,
|
||||||
'i', 4, 'l', 'o', 'n', 'g', 'D', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8,
|
'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::to_ubjson(j) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
}
|
}
|
||||||
@@ -2353,11 +2502,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
{
|
{
|
||||||
// note the floats have been replaced by doubles
|
// 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,
|
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};
|
||||||
'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::to_ubjson(j, true) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
}
|
}
|
||||||
@@ -2366,11 +2511,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
|||||||
{
|
{
|
||||||
// note the floats have been replaced by doubles
|
// 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 = {'{', '$', 'D', '#', 'i', 3,
|
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};
|
||||||
'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::to_ubjson(j, true, true) == v);
|
||||||
CHECK(json::from_ubjson(v) == j);
|
CHECK(json::from_ubjson(v) == j);
|
||||||
}
|
}
|
||||||
@@ -2399,8 +2540,22 @@ TEST_CASE("all UBJSON first bytes")
|
|||||||
// these bytes will fail immediately with exception parse_error.112
|
// these bytes will fail immediately with exception parse_error.112
|
||||||
std::set<uint8_t> supported =
|
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)
|
for (auto i = 0; i < 256; ++i)
|
||||||
{
|
{
|
||||||
@@ -2476,8 +2631,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip())
|
|||||||
TEST_DATA_DIRECTORY "/json_testsuite/sample.json",
|
TEST_DATA_DIRECTORY "/json_testsuite/sample.json",
|
||||||
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
||||||
TEST_DATA_DIRECTORY "/json_tests/pass2.json",
|
TEST_DATA_DIRECTORY "/json_tests/pass2.json",
|
||||||
TEST_DATA_DIRECTORY "/json_tests/pass3.json"
|
TEST_DATA_DIRECTORY "/json_tests/pass3.json"})
|
||||||
})
|
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
|
|
||||||
|
|||||||
+61
-54
@@ -23,8 +23,7 @@ using nlohmann::json;
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace udt
|
namespace udt {
|
||||||
{
|
|
||||||
enum class country
|
enum class country
|
||||||
{
|
{
|
||||||
china,
|
china,
|
||||||
@@ -35,19 +34,25 @@ enum class country
|
|||||||
struct age
|
struct age
|
||||||
{
|
{
|
||||||
int m_val;
|
int m_val;
|
||||||
age(int rhs = 0) : m_val(rhs) {}
|
age(int rhs = 0)
|
||||||
|
: m_val(rhs)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct name
|
struct name
|
||||||
{
|
{
|
||||||
std::string m_val;
|
std::string m_val;
|
||||||
name(std::string rhs = "") : m_val(std::move(rhs)) {}
|
name(std::string rhs = "")
|
||||||
|
: m_val(std::move(rhs))
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct address
|
struct address
|
||||||
{
|
{
|
||||||
std::string m_val;
|
std::string m_val;
|
||||||
address(std::string rhs = "") : m_val(std::move(rhs)) {}
|
address(std::string rhs = "")
|
||||||
|
: m_val(std::move(rhs))
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct person
|
struct person
|
||||||
@@ -56,7 +61,11 @@ struct person
|
|||||||
name m_name{};
|
name m_name{};
|
||||||
country m_country{};
|
country m_country{};
|
||||||
person() = default;
|
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
|
struct contact
|
||||||
@@ -64,7 +73,10 @@ struct contact
|
|||||||
person m_person{};
|
person m_person{};
|
||||||
address m_address{};
|
address m_address{};
|
||||||
contact() = default;
|
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
|
struct contact_book
|
||||||
@@ -72,13 +84,15 @@ struct contact_book
|
|||||||
name m_book_name{};
|
name m_book_name{};
|
||||||
std::vector<contact> m_contacts{};
|
std::vector<contact> m_contacts{};
|
||||||
contact_book() = default;
|
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
|
// to_json methods
|
||||||
namespace udt
|
namespace udt {
|
||||||
{
|
|
||||||
// templates because of the custom_json tests (see below)
|
// templates because of the custom_json tests (see below)
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
static void to_json(BasicJsonType& j, age a)
|
static void to_json(BasicJsonType& j, age a)
|
||||||
@@ -167,8 +181,7 @@ static bool operator==(const contact_book& lhs, const contact_book& rhs)
|
|||||||
} // namespace udt
|
} // namespace udt
|
||||||
|
|
||||||
// from_json methods
|
// from_json methods
|
||||||
namespace udt
|
namespace udt {
|
||||||
{
|
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
static void from_json(const BasicJsonType& j, age& a)
|
static void from_json(const BasicJsonType& j, age& a)
|
||||||
{
|
{
|
||||||
@@ -189,8 +202,7 @@ static void from_json(const BasicJsonType& j, country& c)
|
|||||||
{
|
{
|
||||||
{"中华人民共和国", country::china},
|
{"中华人民共和国", country::china},
|
||||||
{"France", country::france},
|
{"France", country::france},
|
||||||
{"Российская Федерация", country::russia}
|
{"Российская Федерация", country::russia}};
|
||||||
};
|
|
||||||
|
|
||||||
const auto it = m.find(str);
|
const auto it = m.find(str);
|
||||||
// TODO(nlohmann) test exceptions
|
// TODO(nlohmann) test exceptions
|
||||||
@@ -225,12 +237,9 @@ static void from_json(const nlohmann::json& j, contact_book& cb)
|
|||||||
|
|
||||||
TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||||
{
|
{
|
||||||
|
|
||||||
// a bit narcissistic maybe :) ?
|
// a bit narcissistic maybe :) ?
|
||||||
const udt::age a
|
const udt::age a{
|
||||||
{
|
23};
|
||||||
23
|
|
||||||
};
|
|
||||||
const udt::name n{"theo"};
|
const udt::name n{"theo"};
|
||||||
const udt::country c{udt::country::france};
|
const udt::country c{udt::country::france};
|
||||||
const udt::person sfinae_addict{a, n, c};
|
const udt::person sfinae_addict{a, n, c};
|
||||||
@@ -252,7 +261,6 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
|||||||
CHECK(
|
CHECK(
|
||||||
json(book) ==
|
json(book) ==
|
||||||
R"({"name":"C++", "contacts" : [{"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"}, {"person" : {"age":42, "country":"中华人民共和国", "name":"王芳"}, "address":"Paris"}]})"_json);
|
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")
|
SECTION("conversion from json via free-functions")
|
||||||
@@ -326,18 +334,18 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace udt
|
namespace udt {
|
||||||
{
|
|
||||||
struct legacy_type
|
struct legacy_type
|
||||||
{
|
{
|
||||||
std::string number{};
|
std::string number{};
|
||||||
legacy_type() = default;
|
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
|
namespace nlohmann {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct adl_serializer<std::shared_ptr<T>>
|
struct adl_serializer<std::shared_ptr<T>>
|
||||||
{
|
{
|
||||||
@@ -433,8 +441,7 @@ TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace nlohmann
|
namespace nlohmann {
|
||||||
{
|
|
||||||
template<>
|
template<>
|
||||||
struct adl_serializer<std::vector<float>>
|
struct adl_serializer<std::vector<float>>
|
||||||
{
|
{
|
||||||
@@ -466,8 +473,7 @@ TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt")
|
|||||||
CHECK((f == std::vector<float>{4.0, 5.0, 6.0}));
|
CHECK((f == std::vector<float>{4.0, 5.0, 6.0}));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace nlohmann
|
namespace nlohmann {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct adl_serializer<std::unique_ptr<T>>
|
struct adl_serializer<std::unique_ptr<T>>
|
||||||
{
|
{
|
||||||
@@ -535,9 +541,11 @@ struct pod_serializer
|
|||||||
{
|
{
|
||||||
// use adl for non-pods, or scalar types
|
// use adl for non-pods, or scalar types
|
||||||
template<
|
template<
|
||||||
typename BasicJsonType, typename U = T,
|
typename BasicJsonType,
|
||||||
|
typename U = T,
|
||||||
typename std::enable_if<
|
typename std::enable_if<
|
||||||
!(std::is_pod<U>::value && std::is_class<U>::value), int >::type = 0 >
|
!(std::is_pod<U>::value && std::is_class<U>::value),
|
||||||
|
int>::type = 0>
|
||||||
static void from_json(const BasicJsonType& j, U& t)
|
static void from_json(const BasicJsonType& j, U& t)
|
||||||
{
|
{
|
||||||
using nlohmann::from_json;
|
using nlohmann::from_json;
|
||||||
@@ -545,9 +553,7 @@ struct pod_serializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// special behaviour for pods
|
// special behaviour for pods
|
||||||
template < typename BasicJsonType, typename 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>
|
||||||
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)
|
static void from_json(const BasicJsonType& j, U& t)
|
||||||
{
|
{
|
||||||
std::uint64_t value = 0;
|
std::uint64_t value = 0;
|
||||||
@@ -571,18 +577,18 @@ struct pod_serializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<
|
template<
|
||||||
typename BasicJsonType, typename U = T,
|
typename BasicJsonType,
|
||||||
|
typename U = T,
|
||||||
typename std::enable_if<
|
typename std::enable_if<
|
||||||
!(std::is_pod<U>::value && std::is_class<U>::value), int >::type = 0 >
|
!(std::is_pod<U>::value && std::is_class<U>::value),
|
||||||
|
int>::type = 0>
|
||||||
static void to_json(BasicJsonType& j, const T& t)
|
static void to_json(BasicJsonType& j, const T& t)
|
||||||
{
|
{
|
||||||
using nlohmann::to_json;
|
using nlohmann::to_json;
|
||||||
to_json(j, t);
|
to_json(j, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename 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>
|
||||||
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
|
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)
|
||||||
@@ -592,8 +598,7 @@ struct pod_serializer
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace udt
|
namespace udt {
|
||||||
{
|
|
||||||
struct small_pod
|
struct small_pod
|
||||||
{
|
{
|
||||||
int begin;
|
int begin;
|
||||||
@@ -605,7 +610,9 @@ struct non_pod
|
|||||||
{
|
{
|
||||||
std::string s{};
|
std::string s{};
|
||||||
non_pod() = default;
|
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>
|
||||||
@@ -640,8 +647,7 @@ static std::ostream& operator<<(std::ostream& os, small_pod l)
|
|||||||
TEST_CASE("custom serializer for pods" * doctest::test_suite("udt"))
|
TEST_CASE("custom serializer for pods" * doctest::test_suite("udt"))
|
||||||
{
|
{
|
||||||
using custom_json =
|
using custom_json =
|
||||||
nlohmann::basic_json<std::map, std::vector, std::string, bool,
|
nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, pod_serializer>;
|
||||||
std::int64_t, std::uint64_t, double, std::allocator, pod_serializer>;
|
|
||||||
|
|
||||||
auto p = udt::small_pod{42, '/', 42};
|
auto p = udt::small_pod{42, '/', 42};
|
||||||
custom_json const j = p;
|
custom_json const j = p;
|
||||||
@@ -775,18 +781,19 @@ TEST_CASE("different basic_json types conversions")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct incomplete;
|
struct incomplete;
|
||||||
|
|
||||||
// std::is_constructible is broken on macOS' libc++
|
// std::is_constructible is broken on macOS' libc++
|
||||||
// use the cppreference implementation
|
// use the cppreference implementation
|
||||||
|
|
||||||
template<typename T, typename = void>
|
template<typename T, typename = void>
|
||||||
struct is_constructible_patched : std::false_type {};
|
struct is_constructible_patched : std::false_type
|
||||||
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type {};
|
struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type
|
||||||
|
{};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context" * doctest::test_suite("udt"))
|
TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context" * doctest::test_suite("udt"))
|
||||||
@@ -794,14 +801,14 @@ TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated
|
|||||||
static_assert(!is_constructible_patched<json, incomplete>::value, "");
|
static_assert(!is_constructible_patched<json, incomplete>::value, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class Evil
|
class Evil
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Evil() = default;
|
Evil() = default;
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Evil(T t) : m_i(sizeof(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
|
||||||
}
|
}
|
||||||
@@ -827,12 +834,12 @@ TEST_CASE("Issue #924")
|
|||||||
|
|
||||||
TEST_CASE("Issue #1237")
|
TEST_CASE("Issue #1237")
|
||||||
{
|
{
|
||||||
struct non_convertible_type {};
|
struct non_convertible_type
|
||||||
|
{};
|
||||||
static_assert(!std::is_convertible<json, non_convertible_type>::value, "");
|
static_assert(!std::is_convertible<json, non_convertible_type>::value, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class no_iterator_type
|
class no_iterator_type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
Loaded 100 of 108 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user