"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "third-party/nlohmann_json/json.hpp" between
icinga2-2.11.5.tar.gz and icinga2-2.12.0.tar.gz

About: Icinga 2 is an enterprise grade monitoring system which keeps watch over networks and any conceivable network resource.

json.hpp  (icinga2-2.11.5):json.hpp  (icinga2-2.12.0)
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ __| | __| | | | JSON for Modern C++
| | |__ | | | | | | version 3.5.0 | | |__ | | | | | | version 3.7.3
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>. Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#ifndef NLOHMANN_JSON_HPP #ifndef INCLUDE_NLOHMANN_JSON_HPP_
#define NLOHMANN_JSON_HPP #define INCLUDE_NLOHMANN_JSON_HPP_
#define NLOHMANN_JSON_VERSION_MAJOR 3 #define NLOHMANN_JSON_VERSION_MAJOR 3
#define NLOHMANN_JSON_VERSION_MINOR 5 #define NLOHMANN_JSON_VERSION_MINOR 7
#define NLOHMANN_JSON_VERSION_PATCH 0 #define NLOHMANN_JSON_VERSION_PATCH 3
#include <algorithm> // all_of, find, for_each #include <algorithm> // all_of, find, for_each
#include <cassert> // assert #include <cassert> // assert
#include <ciso646> // and, not, or #include <ciso646> // and, not, or
#include <cstddef> // nullptr_t, ptrdiff_t, size_t #include <cstddef> // nullptr_t, ptrdiff_t, size_t
#include <functional> // hash, less #include <functional> // hash, less
#include <initializer_list> // initializer_list #include <initializer_list> // initializer_list
#include <iosfwd> // istream, ostream #include <iosfwd> // istream, ostream
#include <iterator> // random_access_iterator_tag #include <iterator> // random_access_iterator_tag
#include <memory> // unique_ptr
#include <numeric> // accumulate #include <numeric> // accumulate
#include <string> // string, stoi, to_string #include <string> // string, stoi, to_string
#include <utility> // declval, forward, move, pair, swap #include <utility> // declval, forward, move, pair, swap
#include <vector> // vector
// #include <nlohmann/json_fwd.hpp> // #include <nlohmann/adl_serializer.hpp>
#ifndef NLOHMANN_JSON_FWD_HPP
#define NLOHMANN_JSON_FWD_HPP
#include <cstdint> // int64_t, uint64_t #include <utility>
// #include <nlohmann/detail/conversions/from_json.hpp>
#include <algorithm> // transform
#include <array> // array
#include <ciso646> // and, not
#include <forward_list> // forward_list
#include <iterator> // inserter, front_inserter, end
#include <map> // map #include <map> // map
#include <memory> // allocator
#include <string> // string #include <string> // string
#include <vector> // vector #include <tuple> // tuple, make_tuple
#include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_c
onvertible
#include <unordered_map> // unordered_map
#include <utility> // pair, declval
#include <valarray> // valarray
// #include <nlohmann/detail/exceptions.hpp>
#include <exception> // exception
#include <stdexcept> // runtime_error
#include <string> // to_string
// #include <nlohmann/detail/input/position_t.hpp>
#include <cstddef> // size_t
/*!
@brief namespace for Niels Lohmann
@see https://github.com/nlohmann
@since version 1.0.0
*/
namespace nlohmann namespace nlohmann
{ {
/*! namespace detail
@brief default JSONSerializer template argument {
/// struct to capture the start position of the current token
struct position_t
{
/// the total number of characters read
std::size_t chars_read_total = 0;
/// the number of characters read in the current line
std::size_t chars_read_current_line = 0;
/// the number of lines read
std::size_t lines_read = 0;
This serializer ignores the template arguments and uses ADL /// conversion to size_t to preserve SAX interface
([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) constexpr operator size_t() const
for serialization. {
*/ return chars_read_total;
template<typename T = void, typename SFINAE = void> }
struct adl_serializer; };
template<template<typename U, typename V, typename... Args> class ObjectType = } // namespace detail
std::map, } // namespace nlohmann
template<typename U, typename... Args> class ArrayType = std::vector,
class StringType = std::string, class BooleanType = bool,
class NumberIntegerType = std::int64_t,
class NumberUnsignedType = std::uint64_t,
class NumberFloatType = double,
template<typename U> class AllocatorType = std::allocator,
template<typename T, typename SFINAE = void> class JSONSerializer =
adl_serializer>
class basic_json;
/*! // #include <nlohmann/detail/macro_scope.hpp>
@brief JSON Pointer
A JSON pointer defines a string syntax for identifying a specific value #include <utility> // pair
within a JSON document. It can be used with functions `at` and // #include <nlohmann/thirdparty/hedley/hedley.hpp>
`operator[]`. Furthermore, JSON pointers are the base for JSON patches. /* Hedley - https://nemequ.github.io/hedley
* Created by Evan Nemerson <evan@nemerson.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to
* the public domain worldwide. This software is distributed without
* any warranty.
*
* For details, see <http://creativecommons.org/publicdomain/zero/1.0/>.
* SPDX-License-Identifier: CC0-1.0
*/
#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 11)
#if defined(JSON_HEDLEY_VERSION)
#undef JSON_HEDLEY_VERSION
#endif
#define JSON_HEDLEY_VERSION 11
@sa [RFC 6901](https://tools.ietf.org/html/rfc6901) #if defined(JSON_HEDLEY_STRINGIFY_EX)
#undef JSON_HEDLEY_STRINGIFY_EX
#endif
#define JSON_HEDLEY_STRINGIFY_EX(x) #x
@since version 2.0.0 #if defined(JSON_HEDLEY_STRINGIFY)
*/ #undef JSON_HEDLEY_STRINGIFY
template<typename BasicJsonType> #endif
class json_pointer; #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
/*! #if defined(JSON_HEDLEY_CONCAT_EX)
@brief default JSON class #undef JSON_HEDLEY_CONCAT_EX
#endif
#define JSON_HEDLEY_CONCAT_EX(a,b) a##b
This type is the default specialization of the @ref basic_json class which #if defined(JSON_HEDLEY_CONCAT)
uses the standard template types. #undef JSON_HEDLEY_CONCAT
#endif
#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
@since version 1.0.0 #if defined(JSON_HEDLEY_VERSION_ENCODE)
*/ #undef JSON_HEDLEY_VERSION_ENCODE
using json = basic_json<>; #endif
} // namespace nlohmann #define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) +
((minor) * 1000) + (revision))
#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
#endif #endif
#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
// #include <nlohmann/detail/macro_scope.hpp> #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
#undef JSON_HEDLEY_VERSION_DECODE_MINOR
#endif
#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
#undef JSON_HEDLEY_VERSION_DECODE_REVISION
#endif
#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
#if defined(JSON_HEDLEY_GNUC_VERSION)
#undef JSON_HEDLEY_GNUC_VERSION
#endif
#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
#define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC
_MINOR__, __GNUC_PATCHLEVEL__)
#elif defined(__GNUC__)
#define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC
_MINOR__, 0)
#endif
#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
#undef JSON_HEDLEY_GNUC_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_GNUC_VERSION)
#define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_
VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_MSVC_VERSION)
#undef JSON_HEDLEY_MSVC_VERSION
#endif
#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000)
#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER /
10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
#elif defined(_MSC_FULL_VER)
#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER /
1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
#elif defined(_MSC_VER)
#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100,
_MSC_VER % 100, 0)
#endif
#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
#undef JSON_HEDLEY_MSVC_VERSION_CHECK
#endif
#if !defined(_MSC_VER)
#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >=
((major * 10000000) + (minor * 100000) + (patch)))
#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >=
((major * 1000000) + (minor * 10000) + (patch)))
#else
#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((maj
or * 100) + (minor)))
#endif
#if defined(JSON_HEDLEY_INTEL_VERSION)
#undef JSON_HEDLEY_INTEL_VERSION
#endif
#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE)
#define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILE
R / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
#elif defined(__INTEL_COMPILER)
#define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILE
R / 100, __INTEL_COMPILER % 100, 0)
#endif
#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
#undef JSON_HEDLEY_INTEL_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_INTEL_VERSION)
#define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTE
L_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_PGI_VERSION)
#undef JSON_HEDLEY_PGI_VERSION
#endif
#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__
PGIC_PATCHLEVEL__)
#define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_
MINOR__, __PGIC_PATCHLEVEL__)
#endif
#if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
#undef JSON_HEDLEY_PGI_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_PGI_VERSION)
#define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VE
RSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_SUNPRO_VERSION)
#undef JSON_HEDLEY_SUNPRO_VERSION
#endif
#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C
>> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 1
0) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10)
#elif defined(__SUNPRO_C)
#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >>
8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC
>> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf)
* 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10)
#elif defined(__SUNPRO_CC)
#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >
> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
#endif
#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_SUNPRO_VERSION)
#define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUN
PRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
#endif
#if defined(__EMSCRIPTEN__)
#define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPT
EN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
#endif
#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
#define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY
_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_ARM_VERSION)
#undef JSON_HEDLEY_ARM_VERSION
#endif
#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
#define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VER
SION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSIO
N % 10000) / 100)
#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
#define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION /
1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
#endif
#if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
#undef JSON_HEDLEY_ARM_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_ARM_VERSION)
#define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VE
RSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_IBM_VERSION)
#undef JSON_HEDLEY_IBM_VERSION
#endif
#if defined(__ibmxl__)
#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__
, __ibmxl_release__, __ibmxl_modification__)
#elif defined(__xlC__) && defined(__xlC_ver__)
#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __x
lC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
#elif defined(__xlC__)
#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __x
lC__ & 0xff, 0)
#endif
#if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
#undef JSON_HEDLEY_IBM_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_IBM_VERSION)
#define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VE
RSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_TI_VERSION)
#undef JSON_HEDLEY_TI_VERSION
#endif
#if defined(__TI_COMPILER_VERSION__)
#define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERS
ION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERS
ION__ % 1000))
#endif
#if defined(JSON_HEDLEY_TI_VERSION_CHECK)
#undef JSON_HEDLEY_TI_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_TI_VERSION)
#define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERS
ION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_CRAY_VERSION)
#undef JSON_HEDLEY_CRAY_VERSION
#endif
#if defined(_CRAYC)
#if defined(_RELEASE_PATCHLEVEL)
#define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJ
OR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
#else
#define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJ
OR, _RELEASE_MINOR, 0)
#endif
#endif
#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
#undef JSON_HEDLEY_CRAY_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_CRAY_VERSION)
#define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_
VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_IAR_VERSION)
#undef JSON_HEDLEY_IAR_VERSION
#endif
#if defined(__IAR_SYSTEMS_ICC__)
#if __VER__ > 1000
#define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 10
00000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
#else
#define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(VER / 100, __
VER__ % 100, 0)
#endif
#endif
#if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
#undef JSON_HEDLEY_IAR_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_IAR_VERSION)
#define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VE
RSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_TINYC_VERSION)
#undef JSON_HEDLEY_TINYC_VERSION
#endif
#if defined(__TINYC__)
#define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 100
0, (__TINYC__ / 100) % 10, __TINYC__ % 100)
#endif
#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
#undef JSON_HEDLEY_TINYC_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_TINYC_VERSION)
#define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINY
C_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_DMC_VERSION)
#undef JSON_HEDLEY_DMC_VERSION
#endif
#if defined(__DMC__)
#define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__
DMC__ >> 4) & 0xf, __DMC__ & 0xf)
#endif
#if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
#undef JSON_HEDLEY_DMC_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_DMC_VERSION)
#define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VE
RSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_COMPCERT_VERSION)
#undef JSON_HEDLEY_COMPCERT_VERSION
#endif
#if defined(__COMPCERT_VERSION__)
#define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_V
ERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100
)
#endif
#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_COMPCERT_VERSION)
#define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_C
OMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_PELLES_VERSION)
#undef JSON_HEDLEY_PELLES_VERSION
#endif
#if defined(__POCC__)
#define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100
, __POCC__ % 100, 0)
#endif
#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
#undef JSON_HEDLEY_PELLES_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_PELLES_VERSION)
#define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PEL
LES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_GCC_VERSION)
#undef JSON_HEDLEY_GCC_VERSION
#endif
#if \
defined(JSON_HEDLEY_GNUC_VERSION) && \
!defined(__clang__) && \
!defined(JSON_HEDLEY_INTEL_VERSION) && \
!defined(JSON_HEDLEY_PGI_VERSION) && \
!defined(JSON_HEDLEY_ARM_VERSION) && \
!defined(JSON_HEDLEY_TI_VERSION) && \
!defined(__COMPCERT__)
#define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
#endif
#if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
#undef JSON_HEDLEY_GCC_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_GCC_VERSION)
#define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VE
RSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
#undef JSON_HEDLEY_HAS_ATTRIBUTE
#endif
#if defined(__has_attribute)
#define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
#else
#define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
#endif
#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
#endif
#if defined(__has_attribute)
#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_at
tribute(attribute)
#else
#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HED
LEY_GNUC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
#endif
#if defined(__has_attribute)
#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_att
ribute(attribute)
#else
#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDL
EY_GCC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
#endif
#if \
defined(__has_cpp_attribute) && \
defined(__cplusplus) && \
(!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,
15,0))
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribu
te)
#else
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
#endif
#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
#endif
#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
#elif \
!defined(JSON_HEDLEY_PGI_VERSION) && \
(!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,
15,0)) && \
(!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,
0))
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_A
TTRIBUTE(ns::attribute)
#else
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
#endif
#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
#endif
#if defined(__has_cpp_attribute) && defined(__cplusplus)
#define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __ha
s_cpp_attribute(attribute)
#else
#define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON
_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
#endif
#if defined(__has_cpp_attribute) && defined(__cplusplus)
#define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has
_cpp_attribute(attribute)
#else
#define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_
HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_HAS_BUILTIN)
#undef JSON_HEDLEY_HAS_BUILTIN
#endif
#if defined(__has_builtin)
#define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
#else
#define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
#endif
#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
#endif
#if defined(__has_builtin)
#define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builti
n(builtin)
#else
#define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_
GNUC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
#undef JSON_HEDLEY_GCC_HAS_BUILTIN
#endif
#if defined(__has_builtin)
#define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin
(builtin)
#else
#define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_G
CC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_HAS_FEATURE)
#undef JSON_HEDLEY_HAS_FEATURE
#endif
#if defined(__has_feature)
#define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
#else
#define JSON_HEDLEY_HAS_FEATURE(feature) (0)
#endif
#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
#undef JSON_HEDLEY_GNUC_HAS_FEATURE
#endif
#if defined(__has_feature)
#define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_featur
e(feature)
#else
#define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_
GNUC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
#undef JSON_HEDLEY_GCC_HAS_FEATURE
#endif
#if defined(__has_feature)
#define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature
(feature)
#else
#define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_G
CC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_HAS_EXTENSION)
#undef JSON_HEDLEY_HAS_EXTENSION
#endif
#if defined(__has_extension)
#define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
#else
#define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
#endif
#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
#endif
#if defined(__has_extension)
#define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_ex
tension(extension)
#else
#define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HED
LEY_GNUC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
#undef JSON_HEDLEY_GCC_HAS_EXTENSION
#endif
#if defined(__has_extension)
#define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_ext
ension(extension)
#else
#define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDL
EY_GCC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
#endif
#if defined(__has_declspec_attribute)
#define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribu
te(attribute)
#else
#define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
#endif
#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
#endif
#if defined(__has_declspec_attribute)
#define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch)
__has_declspec_attribute(attribute)
#else
#define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch)
JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
#endif
#if defined(__has_declspec_attribute)
#define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch)
__has_declspec_attribute(attribute)
#else
#define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch)
JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_HAS_WARNING)
#undef JSON_HEDLEY_HAS_WARNING
#endif
#if defined(__has_warning)
#define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
#else
#define JSON_HEDLEY_HAS_WARNING(warning) (0)
#endif
#if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
#undef JSON_HEDLEY_GNUC_HAS_WARNING
#endif
#if defined(__has_warning)
#define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warnin
g(warning)
#else
#define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_
GNUC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_GCC_HAS_WARNING)
#undef JSON_HEDLEY_GCC_HAS_WARNING
#endif
#if defined(__has_warning)
#define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning
(warning)
#else
#define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_G
CC_VERSION_CHECK(major,minor,patch)
#endif
/* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for
HEDLEY INTERNAL USE ONLY. API subject to change without notice. */
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
#endif
#if defined(__cplusplus) && JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
JSON_HEDLEY_DIAGNOSTIC_PUSH \
_Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
xpr \
JSON_HEDLEY_DIAGNOSTIC_POP
#else
# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
#endif
#if \
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
defined(__clang__) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) || \
JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
#define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
#define JSON_HEDLEY_PRAGMA(value) __pragma(value)
#else
#define JSON_HEDLEY_PRAGMA(value)
#endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
#endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
#undef JSON_HEDLEY_DIAGNOSTIC_POP
#endif
#if defined(__clang__)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
#define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
#elif JSON_HEDLEY_TI_VERSION_CHECK(8,1,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
#else
#define JSON_HEDLEY_DIAGNOSTIC_PUSH
#define JSON_HEDLEY_DIAGNOSTIC_POP
#endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
#endif
#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic
ignored \"-Wdeprecated-declarations\"")
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1
478 1786)")
#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 121
5,1444")
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ig
nored \"-Wdeprecated-declarations\"")
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4
996))
#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 129
1,1718")
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(of
f,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(of
f,symdeprecated,symdeprecated2)")
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1
444,Pe1215")
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241
)")
#else
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
#endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
#endif
#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagno
stic ignored \"-Wunknown-pragmas\"")
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disa
ble:161)")
#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppres
s 1675")
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnost
ic ignored \"-Wunknown-pragmas\"")
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disa
ble:4068))
#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppres
s 163")
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppres
s=Pe161")
#else
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
#endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
#endif
#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang
diagnostic ignored \"-Wunknown-attributes\"")
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC d
iagnostic ignored \"-Wdeprecated-declarations\"")
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warni
ng(disable:1292)")
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warni
ng(disable:5030))
#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_
suppress 1097")
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error
_messages(off,attrskipunsup)")
#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_
suppress 1173")
#else
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
#endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
#endif
#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic i
gnored \"-Wcast-qual\"")
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:22
03 2331)")
#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ign
ored \"-Wcast-qual\"")
#else
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
#endif
#if defined(JSON_HEDLEY_DEPRECATED)
#undef JSON_HEDLEY_DEPRECATED
#endif
#if defined(JSON_HEDLEY_DEPRECATED_FOR)
#undef JSON_HEDLEY_DEPRECATED_FOR
#endif
#if defined(__cplusplus) && (__cplusplus >= 201402L)
#define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_C
OMPAT_WRAP_([[deprecated("Since " #since)]])
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTI
C_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)
]])
#elif \
JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,3,0)
#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since "
#since)))
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__depr
ecated__("Since " #since "; use " #replacement)))
#elif \
JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__
))
#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__depr
ecated__))
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0)
#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since
))
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated
("Since " #since "; use " #replacement))
#elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0)
#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated
)
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
#else
#define JSON_HEDLEY_DEPRECATED(since)
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
#endif
#if defined(JSON_HEDLEY_UNAVAILABLE)
#undef JSON_HEDLEY_UNAVAILABLE
#endif
#if \
JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__(
"Not available until " #available_since)))
#else
#define JSON_HEDLEY_UNAVAILABLE(available_since)
#endif
#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
#undef JSON_HEDLEY_WARN_UNUSED_RESULT
#endif
#if defined(__cplusplus) && (__cplusplus >= 201703L)
#define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_
COMPAT_WRAP_([[nodiscard]])
#elif \
JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__
)) || \
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
#define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__
))
#elif defined(_Check_return_) /* SAL */
#define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
#else
#define JSON_HEDLEY_WARN_UNUSED_RESULT
#endif
#if defined(JSON_HEDLEY_SENTINEL)
#undef JSON_HEDLEY_SENTINEL
#endif
#if \
JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0)
#define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)
))
#else
#define JSON_HEDLEY_SENTINEL(position)
#endif
#if defined(JSON_HEDLEY_NO_RETURN)
#undef JSON_HEDLEY_NO_RETURN
#endif
#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_NO_RETURN __noreturn
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define JSON_HEDLEY_NO_RETURN _Noreturn
#elif defined(__cplusplus) && (__cplusplus >= 201103L)
#define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WR
AP_([[noreturn]])
#elif \
JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(18,0,0) || \
(JSON_HEDLEY_TI_VERSION_CHECK(17,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT_
_))
#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
#define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
#define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus)
#define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
#define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
#define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
#else
#define JSON_HEDLEY_NO_RETURN
#endif
#if defined(JSON_HEDLEY_NO_ESCAPE)
#undef JSON_HEDLEY_NO_ESCAPE
#endif
#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
#define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
#else
#define JSON_HEDLEY_NO_ESCAPE
#endif
#if defined(JSON_HEDLEY_UNREACHABLE)
#undef JSON_HEDLEY_UNREACHABLE
#endif
#if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
#undef JSON_HEDLEY_UNREACHABLE_RETURN
#endif
#if \
(JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM
_VERSION))) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5)
#define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
#define JSON_HEDLEY_UNREACHABLE() __assume(0)
#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0)
#if defined(__cplusplus)
#define JSON_HEDLEY_UNREACHABLE() std::_nassert(0)
#else
#define JSON_HEDLEY_UNREACHABLE() _nassert(0)
#endif
#define JSON_HEDLEY_UNREACHABLE_RETURN(value) return value
#elif defined(EXIT_FAILURE)
#define JSON_HEDLEY_UNREACHABLE() abort()
#else
#define JSON_HEDLEY_UNREACHABLE()
#define JSON_HEDLEY_UNREACHABLE_RETURN(value) return value
#endif
#if !defined(JSON_HEDLEY_UNREACHABLE_RETURN)
#define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
#endif
#if defined(JSON_HEDLEY_ASSUME)
#undef JSON_HEDLEY_ASSUME
#endif
#if \
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_ASSUME(expr) __assume(expr)
#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
#define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0)
#if defined(__cplusplus)
#define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
#else
#define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
#endif
#elif \
(JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && !defined(JSON_HEDLEY_ARM_
VERSION)) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5)
#define JSON_HEDLEY_ASSUME(expr) ((void) ((expr) ? 1 : (__builtin_unreachabl
e(), 1)))
#else
#define JSON_HEDLEY_ASSUME(expr) ((void) (expr))
#endif
JSON_HEDLEY_DIAGNOSTIC_PUSH
#if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
#pragma clang diagnostic ignored "-Wpedantic"
#endif
#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#endif
#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wvariadic-macros"
#elif defined(JSON_HEDLEY_GCC_VERSION)
#pragma GCC diagnostic ignored "-Wvariadic-macros"
#endif
#endif
#if defined(JSON_HEDLEY_NON_NULL)
#undef JSON_HEDLEY_NON_NULL
#endif
#if \
JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
#define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
#else
#define JSON_HEDLEY_NON_NULL(...)
#endif
JSON_HEDLEY_DIAGNOSTIC_POP
#if defined(JSON_HEDLEY_PRINTF_FORMAT)
#undef JSON_HEDLEY_PRINTF_FORMAT
#endif
#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defi
ned(__USE_MINGW_ANSI_STDIO)
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((
__format__(ms_printf, string_idx, first_to_check)))
#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && def
ined(__USE_MINGW_ANSI_STDIO)
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((
__format__(gnu_printf, string_idx, first_to_check)))
#elif \
JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__
))
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((
__format__(__printf__, string_idx, first_to_check)))
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vafo
rmat(printf,string_idx,first_to_check))
#else
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
#endif
#if defined(JSON_HEDLEY_CONSTEXPR)
#undef JSON_HEDLEY_CONSTEXPR
#endif
#if defined(__cplusplus)
#if __cplusplus >= 201103L
#define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPA
T_WRAP_(constexpr)
#endif
#endif
#if !defined(JSON_HEDLEY_CONSTEXPR)
#define JSON_HEDLEY_CONSTEXPR
#endif
#if defined(JSON_HEDLEY_PREDICT)
#undef JSON_HEDLEY_PREDICT
#endif
#if defined(JSON_HEDLEY_LIKELY)
#undef JSON_HEDLEY_LIKELY
#endif
#if defined(JSON_HEDLEY_UNLIKELY)
#undef JSON_HEDLEY_UNLIKELY
#endif
#if defined(JSON_HEDLEY_UNPREDICTABLE)
#undef JSON_HEDLEY_UNPREDICTABLE
#endif
#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
#define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable(!!(expr))
#endif
#if \
JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) || \
JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0)
# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_pr
obability(expr, value, probability)
# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_prob
ability(!!(expr), 1, probability)
# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_pro
bability(!!(expr), 0, probability)
# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
#if !defined(JSON_HEDLEY_BUILTIN_UNPREDICTABLE)
#define JSON_HEDLEY_BUILTIN_UNPREDICTABLE(expr) __builtin_expect_with_probab
ility(!!(expr), 1, 0.5)
#endif
#elif \
JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(6,1,0) || \
JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27)
# define JSON_HEDLEY_PREDICT(expr, expected, probability) \
(((probability) >= 0.9) ? __builtin_expect(!!(expr), (expected)) : (((void)
(expected)), !!(expr)))
# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
(__extension__ ({ \
JSON_HEDLEY_CONSTEXPR double hedley_probability_ = (probability); \
((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley
_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
}))
# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
(__extension__ ({ \
JSON_HEDLEY_CONSTEXPR double hedley_probability_ = (probability); \
((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley
_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
}))
# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
#else
# define JSON_HEDLEY_PREDICT(expr, expected, probability) (((void) (expected)),
!!(expr))
# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
# define JSON_HEDLEY_LIKELY(expr) (!!(expr))
# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
#endif
#if !defined(JSON_HEDLEY_UNPREDICTABLE)
#define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
#endif
#if defined(JSON_HEDLEY_MALLOC)
#undef JSON_HEDLEY_MALLOC
#endif
#if \
JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__
))
#define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
#define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0)
#define JSON_HEDLEY_MALLOC __declspec(restrict)
#else
#define JSON_HEDLEY_MALLOC
#endif
#if defined(JSON_HEDLEY_PURE)
#undef JSON_HEDLEY_PURE
#endif
#if \
JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__
)) || \
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
#define JSON_HEDLEY_PURE __attribute__((__pure__))
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
#define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus)
#define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
#else
#define JSON_HEDLEY_PURE
#endif
#if defined(JSON_HEDLEY_CONST)
#undef JSON_HEDLEY_CONST
#endif
#if \
JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__
)) || \
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
#define JSON_HEDLEY_CONST __attribute__((__const__))
#elif \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
#define JSON_HEDLEY_CONST _Pragma("no_side_effect")
#else
#define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
#endif
#if defined(JSON_HEDLEY_RESTRICT)
#undef JSON_HEDLEY_RESTRICT
#endif
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cpl
usplus)
#define JSON_HEDLEY_RESTRICT restrict
#elif \
JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
defined(__clang__)
#define JSON_HEDLEY_RESTRICT __restrict
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
#define JSON_HEDLEY_RESTRICT _Restrict
#else
#define JSON_HEDLEY_RESTRICT
#endif
#if defined(JSON_HEDLEY_INLINE)
#undef JSON_HEDLEY_INLINE
#endif
#if \
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
(defined(__cplusplus) && (__cplusplus >= 199711L))
#define JSON_HEDLEY_INLINE inline
#elif \
defined(JSON_HEDLEY_GCC_VERSION) || \
JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
#define JSON_HEDLEY_INLINE __inline__
#elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_INLINE __inline
#else
#define JSON_HEDLEY_INLINE
#endif
#if defined(JSON_HEDLEY_ALWAYS_INLINE)
#undef JSON_HEDLEY_ALWAYS_INLINE
#endif
#if \
JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__
))
#define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HE
DLEY_INLINE
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0)
#define JSON_HEDLEY_ALWAYS_INLINE __forceinline
#elif JSON_HEDLEY_TI_VERSION_CHECK(7,0,0) && defined(__cplusplus)
#define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
#else
#define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
#endif
#if defined(JSON_HEDLEY_NEVER_INLINE)
#undef JSON_HEDLEY_NEVER_INLINE
#endif
#if \
JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__
))
#define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
#define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus)
#define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
#define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
#else
#define JSON_HEDLEY_NEVER_INLINE
#endif
#if defined(JSON_HEDLEY_PRIVATE)
#undef JSON_HEDLEY_PRIVATE
#endif
#if defined(JSON_HEDLEY_PUBLIC)
#undef JSON_HEDLEY_PUBLIC
#endif
#if defined(JSON_HEDLEY_IMPORT)
#undef JSON_HEDLEY_IMPORT
#endif
#if defined(_WIN32) || defined(__CYGWIN__)
#define JSON_HEDLEY_PRIVATE
#define JSON_HEDLEY_PUBLIC __declspec(dllexport)
#define JSON_HEDLEY_IMPORT __declspec(dllimport)
#else
#if \
JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_EABI__) && defined(
__TI_GNU_ATTRIBUTE_SUPPORT__))
#define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
#define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
#else
#define JSON_HEDLEY_PRIVATE
#define JSON_HEDLEY_PUBLIC
#endif
#define JSON_HEDLEY_IMPORT extern
#endif
#if defined(JSON_HEDLEY_NO_THROW)
#undef JSON_HEDLEY_NO_THROW
#endif
#if \
JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
#elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
#define JSON_HEDLEY_NO_THROW __declspec(nothrow)
#else
#define JSON_HEDLEY_NO_THROW
#endif
#if defined(JSON_HEDLEY_FALL_THROUGH)
#undef JSON_HEDLEY_FALL_THROUGH
#endif
#if JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(fallthrough,7,0,0) && !defined(JSON_HEDLEY_PG
I_VERSION)
#define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
#define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT
_WRAP_([[clang::fallthrough]])
#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
#define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT
_WRAP_([[fallthrough]])
#elif defined(__fallthrough) /* SAL */
#define JSON_HEDLEY_FALL_THROUGH __fallthrough
#else
#define JSON_HEDLEY_FALL_THROUGH
#endif
#if defined(JSON_HEDLEY_RETURNS_NON_NULL)
#undef JSON_HEDLEY_RETURNS_NON_NULL
#endif
#if \
JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
#define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
#elif defined(_Ret_notnull_) /* SAL */
#define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
#else
#define JSON_HEDLEY_RETURNS_NON_NULL
#endif
#if defined(JSON_HEDLEY_ARRAY_PARAM)
#undef JSON_HEDLEY_ARRAY_PARAM
#endif
#if \
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
!defined(__STDC_NO_VLA__) && \
!defined(__cplusplus) && \
!defined(JSON_HEDLEY_PGI_VERSION) && \
!defined(JSON_HEDLEY_TINYC_VERSION)
#define JSON_HEDLEY_ARRAY_PARAM(name) (name)
#else
#define JSON_HEDLEY_ARRAY_PARAM(name)
#endif
#if defined(JSON_HEDLEY_IS_CONSTANT)
#undef JSON_HEDLEY_IS_CONSTANT
#endif
#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
#endif
/* JSON_HEDLEY_IS_CONSTEXPR_ is for
HEDLEY INTERNAL USE ONLY. API subject to change without notice. */
#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
#undef JSON_HEDLEY_IS_CONSTEXPR_
#endif
#if \
JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(6,1,0) || \
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0)
#define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
#endif
#if !defined(__cplusplus)
# if \
JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
#if defined(__INTPTR_TYPE__)
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeo
f__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
#else
#include <stdint.h>
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeo
f__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
#endif
# elif \
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && !defined(J
SON_HEDLEY_SUNPRO_VERSION) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
#if defined(__INTPTR_TYPE__)
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYP
E__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
#else
#include <stdint.h>
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) *
0) : (int*) 0), int*: 1, void*: 0)
#endif
# elif \
defined(JSON_HEDLEY_GCC_VERSION) || \
defined(JSON_HEDLEY_INTEL_VERSION) || \
defined(JSON_HEDLEY_TINYC_VERSION) || \
defined(JSON_HEDLEY_TI_VERSION) || \
defined(__clang__)
# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
sizeof(void) != \
sizeof(*( \
1 ? \
((void*) ((expr) * 0L) ) : \
((struct { char v[sizeof(void) * 2]; } *) 1) \
) \
) \
)
# endif
#endif
#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
#if !defined(JSON_HEDLEY_IS_CONSTANT)
#define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
#endif
#define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr)
? (expr) : (-1))
#else
#if !defined(JSON_HEDLEY_IS_CONSTANT)
#define JSON_HEDLEY_IS_CONSTANT(expr) (0)
#endif
#define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
#endif
#if defined(JSON_HEDLEY_BEGIN_C_DECLS)
#undef JSON_HEDLEY_BEGIN_C_DECLS
#endif
#if defined(JSON_HEDLEY_END_C_DECLS)
#undef JSON_HEDLEY_END_C_DECLS
#endif
#if defined(JSON_HEDLEY_C_DECL)
#undef JSON_HEDLEY_C_DECL
#endif
#if defined(__cplusplus)
#define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
#define JSON_HEDLEY_END_C_DECLS }
#define JSON_HEDLEY_C_DECL extern "C"
#else
#define JSON_HEDLEY_BEGIN_C_DECLS
#define JSON_HEDLEY_END_C_DECLS
#define JSON_HEDLEY_C_DECL
#endif
#if defined(JSON_HEDLEY_STATIC_ASSERT)
#undef JSON_HEDLEY_STATIC_ASSERT
#endif
#if \
!defined(__cplusplus) && ( \
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
JSON_HEDLEY_HAS_FEATURE(c_static_assert) || \
JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
defined(_Static_assert) \
)
# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
#elif \
(defined(__cplusplus) && (__cplusplus >= 201103L)) || \
JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
(defined(__cplusplus) && JSON_HEDLEY_TI_VERSION_CHECK(8,3,0))
# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABL
E_CPP98_COMPAT_WRAP_(static_assert(expr, message))
#else
# define JSON_HEDLEY_STATIC_ASSERT(expr, message)
#endif
#if defined(JSON_HEDLEY_CONST_CAST)
#undef JSON_HEDLEY_CONST_CAST
#endif
#if defined(__cplusplus)
# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
#elif \
JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
JSON_HEDLEY_DIAGNOSTIC_PUSH \
JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
((T) (expr)); \
JSON_HEDLEY_DIAGNOSTIC_POP \
}))
#else
# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
#endif
#if defined(JSON_HEDLEY_REINTERPRET_CAST)
#undef JSON_HEDLEY_REINTERPRET_CAST
#endif
#if defined(__cplusplus)
#define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
#else
#define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (*((T*) &(expr)))
#endif
#if defined(JSON_HEDLEY_STATIC_CAST)
#undef JSON_HEDLEY_STATIC_CAST
#endif
#if defined(__cplusplus)
#define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
#else
#define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
#endif
#if defined(JSON_HEDLEY_CPP_CAST)
#undef JSON_HEDLEY_CPP_CAST
#endif
#if defined(__cplusplus)
#define JSON_HEDLEY_CPP_CAST(T, expr) static_cast<T>(expr)
#else
#define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
#endif
#if defined(JSON_HEDLEY_NULL)
#undef JSON_HEDLEY_NULL
#endif
#if defined(__cplusplus)
#if __cplusplus >= 201103L
#define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRA
P_(nullptr)
#elif defined(NULL)
#define JSON_HEDLEY_NULL NULL
#else
#define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
#endif
#elif defined(NULL)
#define JSON_HEDLEY_NULL NULL
#else
#define JSON_HEDLEY_NULL ((void*) 0)
#endif
#if defined(JSON_HEDLEY_MESSAGE)
#undef JSON_HEDLEY_MESSAGE
#endif
#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
# define JSON_HEDLEY_MESSAGE(msg) \
JSON_HEDLEY_DIAGNOSTIC_PUSH \
JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
JSON_HEDLEY_PRAGMA(message msg) \
JSON_HEDLEY_DIAGNOSTIC_POP
#elif \
JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
#else
# define JSON_HEDLEY_MESSAGE(msg)
#endif
#if defined(JSON_HEDLEY_WARNING)
#undef JSON_HEDLEY_WARNING
#endif
#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
# define JSON_HEDLEY_WARNING(msg) \
JSON_HEDLEY_DIAGNOSTIC_PUSH \
JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
JSON_HEDLEY_PRAGMA(clang warning msg) \
JSON_HEDLEY_DIAGNOSTIC_POP
#elif \
JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0)
# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
#else
# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
#endif
#if defined(JSON_HEDLEY_REQUIRE)
#undef JSON_HEDLEY_REQUIRE
#endif
#if defined(JSON_HEDLEY_REQUIRE_MSG)
#undef JSON_HEDLEY_REQUIRE_MSG
#endif
#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
# define JSON_HEDLEY_REQUIRE(expr) \
JSON_HEDLEY_DIAGNOSTIC_PUSH \
_Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
__attribute__((diagnose_if(!(expr), #expr, "error"))) \
JSON_HEDLEY_DIAGNOSTIC_POP
# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
JSON_HEDLEY_DIAGNOSTIC_PUSH \
_Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
__attribute__((diagnose_if(!(expr), msg, "error"))) \
JSON_HEDLEY_DIAGNOSTIC_POP
# else
# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr,
"error")))
# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr)
, msg, "error")))
# endif
#else
# define JSON_HEDLEY_REQUIRE(expr)
# define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
#endif
#if defined(JSON_HEDLEY_FLAGS)
#undef JSON_HEDLEY_FLAGS
#endif
#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum)
#define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
#endif
#if defined(JSON_HEDLEY_FLAGS_CAST)
#undef JSON_HEDLEY_FLAGS_CAST
#endif
#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
JSON_HEDLEY_DIAGNOSTIC_PUSH \
_Pragma("warning(disable:188)") \
((T) (expr)); \
JSON_HEDLEY_DIAGNOSTIC_POP \
}))
#else
# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
#endif
#if defined(JSON_HEDLEY_EMPTY_BASES)
#undef JSON_HEDLEY_EMPTY_BASES
#endif
#if JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHEC
K(20,0,0)
#define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
#else
#define JSON_HEDLEY_EMPTY_BASES
#endif
/* Remaining macros are deprecated. */
#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
#endif
#if defined(__clang__)
#define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
#else
#define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDL
EY_GCC_VERSION_CHECK(major,minor,patch)
#endif
#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
#endif
#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(att
ribute)
#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
#endif
#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRI
BUTE(attribute)
#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
#endif
#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
#undef JSON_HEDLEY_CLANG_HAS_FEATURE
#endif
#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
#endif
#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(ext
ension)
#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
#endif
#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECL
SPEC_ATTRIBUTE(attribute)
#if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
#undef JSON_HEDLEY_CLANG_HAS_WARNING
#endif
#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
#endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */
// This file contains all internal macro definitions // This file contains all internal macro definitions
// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of the m // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of the m
// exclude unsupported compilers // exclude unsupported compilers
#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
#if defined(__clang__) #if defined(__clang__)
#if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchleve l__) < 30400 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchleve l__) < 30400
#error "unsupported Clang version - see https://github.com/nlohmann/ json#supported-compilers" #error "unsupported Clang version - see https://github.com/nlohmann/ json#supported-compilers"
#endif #endif
#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40 800 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40 800
#error "unsupported GCC version - see https://github.com/nlohmann/js on#supported-compilers" #error "unsupported GCC version - see https://github.com/nlohmann/js on#supported-compilers"
#endif #endif
#endif #endif
#endif #endif
// C++ language standard detection
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) &&
_HAS_CXX17 == 1) // fix for issue #464
#define JSON_HAS_CPP_17
#define JSON_HAS_CPP_14
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) &
& _HAS_CXX14 == 1)
#define JSON_HAS_CPP_14
#endif
// disable float-equal warnings on GCC/clang // disable float-equal warnings on GCC/clang
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal" #pragma GCC diagnostic ignored "-Wfloat-equal"
#endif #endif
// disable documentation warnings on clang // disable documentation warnings on clang
#if defined(__clang__) #if defined(__clang__)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdocumentation" #pragma GCC diagnostic ignored "-Wdocumentation"
#endif #endif
// allow for portable deprecation warnings
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
#define JSON_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define JSON_DEPRECATED __declspec(deprecated)
#else
#define JSON_DEPRECATED
#endif
// allow to disable exceptions // allow to disable exceptions
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
#define JSON_THROW(exception) throw exception #define JSON_THROW(exception) throw exception
#define JSON_TRY try #define JSON_TRY try
#define JSON_CATCH(exception) catch(exception) #define JSON_CATCH(exception) catch(exception)
#define JSON_INTERNAL_CATCH(exception) catch(exception) #define JSON_INTERNAL_CATCH(exception) catch(exception)
#else #else
#include <cstdlib>
#define JSON_THROW(exception) std::abort() #define JSON_THROW(exception) std::abort()
#define JSON_TRY if(true) #define JSON_TRY if(true)
#define JSON_CATCH(exception) if(false) #define JSON_CATCH(exception) if(false)
#define JSON_INTERNAL_CATCH(exception) if(false) #define JSON_INTERNAL_CATCH(exception) if(false)
#endif #endif
// override exception macros // override exception macros
#if defined(JSON_THROW_USER) #if defined(JSON_THROW_USER)
#undef JSON_THROW #undef JSON_THROW
#define JSON_THROW JSON_THROW_USER #define JSON_THROW JSON_THROW_USER
skipping to change at line 187 skipping to change at line 1774
#undef JSON_CATCH #undef JSON_CATCH
#define JSON_CATCH JSON_CATCH_USER #define JSON_CATCH JSON_CATCH_USER
#undef JSON_INTERNAL_CATCH #undef JSON_INTERNAL_CATCH
#define JSON_INTERNAL_CATCH JSON_CATCH_USER #define JSON_INTERNAL_CATCH JSON_CATCH_USER
#endif #endif
#if defined(JSON_INTERNAL_CATCH_USER) #if defined(JSON_INTERNAL_CATCH_USER)
#undef JSON_INTERNAL_CATCH #undef JSON_INTERNAL_CATCH
#define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
#endif #endif
// manual branch prediction
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
#define JSON_LIKELY(x) __builtin_expect(!!(x), 1)
#define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
#else
#define JSON_LIKELY(x) x
#define JSON_UNLIKELY(x) x
#endif
// C++ language standard detection
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) &&
_HAS_CXX17 == 1) // fix for issue #464
#define JSON_HAS_CPP_17
#define JSON_HAS_CPP_14
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) &
& _HAS_CXX14 == 1)
#define JSON_HAS_CPP_14
#endif
/*! /*!
@brief macro to briefly define a mapping between an enum and JSON @brief macro to briefly define a mapping between an enum and JSON
@def NLOHMANN_JSON_SERIALIZE_ENUM @def NLOHMANN_JSON_SERIALIZE_ENUM
@since version 3.4.0 @since version 3.4.0
*/ */
#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...)
\ \
template<typename BasicJsonType> template<typename BasicJsonType>
\ \
inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) inline void to_json(BasicJsonType& j, const ENUM_TYPE& e)
\ \
{ {
\ \
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an en static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an en
um!"); \ um!"); \
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 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej
_pair) -> bool \ _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;
\ \
} }
\ \
template<typename BasicJsonType> template<typename BasicJsonType>
\ \
inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) inline void from_json(const BasicJsonType& j, ENUM_TYPE& e)
\ \
{ {
\ \
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an en static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an en
um!"); \ um!"); \
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 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& e
_pair) -> bool \ j_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;
\ \
} }
// Ugly macros to avoid uglier copy-paste when specializing basic_json. They // Ugly macros to avoid uglier copy-paste when specializing basic_json. They
// may be removed in the future once the class is split. // may be removed in the future once the class is split.
#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 ArrayType, \
class StringType, class BooleanType, class NumberIntegerType, \ class StringType, class BooleanType, class NumberIntegerType, \
class NumberUnsignedType, class NumberFloatType, \ class NumberUnsignedType, class NumberFloatType, \
template<typename> class AllocatorType, \ template<typename> class AllocatorType, \
template<typename, typename = void> class JSONSerializer> template<typename, typename = void> class JSONSerializer>
#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, \ NumberIntegerType, NumberUnsignedType, NumberFloatType, \
AllocatorType, JSONSerializer> AllocatorType, JSONSerializer>
namespace nlohmann
{
namespace detail
{
////////////////
// exceptions //
////////////////
/*!
@brief general exception of the @ref basic_json class
This class is an extension of `std::exception` objects with a member @a id for
exception ids. It is used as the base class for all exceptions thrown by the
@ref basic_json class. This class can hence be used as "wildcard" to catch
exceptions.
Subclasses:
- @ref parse_error for exceptions indicating a parse error
- @ref invalid_iterator for exceptions indicating errors with iterators
- @ref type_error for exceptions indicating executing a member function with
a wrong type
- @ref out_of_range for exceptions indicating access out of the defined range
- @ref other_error for exceptions indicating other library errors
@internal
@note To have nothrow-copy-constructible exceptions, we internally use
`std::runtime_error` which can cope with arbitrary-length error messages.
Intermediate strings are built with static functions and then passed to
the actual constructor.
@endinternal
@liveexample{The following code shows how arbitrary library exceptions can be
caught.,exception}
@since version 3.0.0
*/
class exception : public std::exception
{
public:
/// returns the explanatory string
JSON_HEDLEY_RETURNS_NON_NULL
const char* what() const noexcept override
{
return m.what();
}
/// the id of the exception
const int id;
protected:
JSON_HEDLEY_NON_NULL(3)
exception(int id_, const char* what_arg) : id(id_), m(what_arg) {}
static std::string name(const std::string& ename, int id_)
{
return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
}
private:
/// an exception object as storage for error messages
std::runtime_error m;
};
/*!
@brief exception indicating a parse error
This exception is thrown by the library when a parse error occurs. Parse errors
can occur during the deserialization of JSON text, CBOR, MessagePack, as well
as when using JSON Patch.
Member @a byte holds the byte index of the last read character in the input
file.
Exceptions have ids 1xx.
name / id | example message | description
------------------------------ | --------------- | -------------------------
json.exception.parse_error.101 | parse error at 2: unexpected end of input; expe
cted string literal | This error indicates a syntax error while deserializing a
JSON text. The error message describes that an unexpected token (character) was
encountered, and the member @a byte indicates the error position.
json.exception.parse_error.102 | parse error at 14: missing or wrong low surroga
te | JSON uses the `\uxxxx` format to describe Unicode characters. Code points a
bove above 0xFFFF are split into two `\uxxxx` entries ("surrogate pairs"). This
error indicates that the surrogate pair is incomplete or contains an invalid cod
e point.
json.exception.parse_error.103 | parse error: code points above 0x10FFFF are inv
alid | Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF a
re invalid.
json.exception.parse_error.104 | parse error: JSON patch must be an array of obj
ects | [RFC 6902](https://tools.ietf.org/html/rfc6902) requires a JSON Patch doc
ument to be a JSON document that represents an array of objects.
json.exception.parse_error.105 | parse error: operation must have string member
'op' | An operation of a JSON Patch document must contain exactly one "op" membe
r, whose value indicates the operation to perform. Its value must be one of "add
", "remove", "replace", "move", "copy", or "test"; other values are errors.
json.exception.parse_error.106 | parse error: array index '01' must not begin wi
th '0' | An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/htm
l/rfc6901)) may be `0` or any number without a leading `0`.
json.exception.parse_error.107 | parse error: JSON pointer must be empty or begi
n with '/' - was: 'foo' | A JSON Pointer must be a Unicode string containing a s
equence of zero or more reference tokens, each prefixed by a `/` character.
json.exception.parse_error.108 | parse error: escape character '~' must be follo
wed with '0' or '1' | In a JSON Pointer, only `~0` and `~1` are valid escape seq
uences.
json.exception.parse_error.109 | parse error: array index 'one' is not a number
| A JSON Pointer array index must be a number.
json.exception.parse_error.110 | parse error at 1: cannot read 2 bytes from vect
or | When parsing CBOR or MessagePack, the byte vector ends before the complete
value has been read.
json.exception.parse_error.112 | parse error at 1: error reading CBOR; last byte
: 0xF8 | Not all types of CBOR or MessagePack are supported. This exception occu
rs if an unsupported byte was read.
json.exception.parse_error.113 | parse error at 2: expected a CBOR string; last
byte: 0x98 | While parsing a map key, a value that is not a string has been read
.
json.exception.parse_error.114 | parse error: Unsupported BSON record type 0x0F
| The parsing of the corresponding BSON record type is not implemented (yet).
@note For an input with n bytes, 1 is the index of the first character and n+1
is the index of the terminating null byte or the end of file. This also
holds true when reading a byte vector (CBOR or MessagePack).
@liveexample{The following code shows how a `parse_error` exception can be
caught.,parse_error}
@sa - @ref exception for the base class of the library exceptions
@sa - @ref invalid_iterator for exceptions indicating errors with iterators
@sa - @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa - @ref out_of_range for exceptions indicating access out of the defined rang
e
@sa - @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class parse_error : public exception
{
public:
/*!
@brief create a parse error exception
@param[in] id_ the id of the exception
@param[in] pos the position where the error occurred (or with
chars_read_total=0 if the position cannot be
determined)
@param[in] what_arg the explanatory string
@return parse_error object
*/
static parse_error create(int id_, const position_t& pos, const std::string&
what_arg)
{
std::string w = exception::name("parse_error", id_) + "parse error" +
position_string(pos) + ": " + what_arg;
return parse_error(id_, pos.chars_read_total, w.c_str());
}
static parse_error create(int id_, std::size_t byte_, const std::string& wha
t_arg)
{
std::string w = exception::name("parse_error", id_) + "parse error" +
(byte_ != 0 ? (" at byte " + std::to_string(byte_)) : ""
) +
": " + what_arg;
return parse_error(id_, byte_, w.c_str());
}
/*!
@brief byte index of the parse error
The byte index of the last read character in the input file.
@note For an input with n bytes, 1 is the index of the first character and
n+1 is the index of the terminating null byte or the end of file.
This also holds true when reading a byte vector (CBOR or MessagePack).
*/
const std::size_t byte;
private:
parse_error(int id_, std::size_t byte_, const char* what_arg)
: exception(id_, what_arg), byte(byte_) {}
static std::string position_string(const position_t& pos)
{
return " at line " + std::to_string(pos.lines_read + 1) +
", column " + std::to_string(pos.chars_read_current_line);
}
};
/*!
@brief exception indicating errors with iterators
This exception is thrown if iterators passed to a library function do not match
the expected semantics.
Exceptions have ids 2xx.
name / id | example message | description
----------------------------------- | --------------- | ------------------------
-
json.exception.invalid_iterator.201 | iterators are not compatible | The iterato
rs passed to constructor @ref basic_json(InputIT first, InputIT last) are not co
mpatible, meaning they do not belong to the same container. Therefore, the range
(@a first, @a last) is invalid.
json.exception.invalid_iterator.202 | iterator does not fit current value | In a
n erase or insert function, the passed iterator @a pos does not belong to the JS
ON value for which the function was called. It hence does not define a valid pos
ition for the deletion/insertion.
json.exception.invalid_iterator.203 | iterators do not fit current value | Eithe
r iterator passed to function @ref erase(IteratorType first, IteratorType last)
does not belong to the JSON value from which values shall be erased. It hence do
es not define a valid range to delete values from.
json.exception.invalid_iterator.204 | iterators out of range | When an iterator
range for a primitive type (number, boolean, or string) is passed to a construct
or or an erase function, this range has to be exactly (@ref begin(), @ref end())
, because this is the only way the single stored value is expressed. All other r
anges are invalid.
json.exception.invalid_iterator.205 | iterator out of range | When an iterator f
or a primitive type (number, boolean, or string) is passed to an erase function,
the iterator has to be the @ref begin() iterator, because it is the only way to
address the stored value. All other iterators are invalid.
json.exception.invalid_iterator.206 | cannot construct with iterators from null
| The iterators passed to constructor @ref basic_json(InputIT first, InputIT las
t) belong to a JSON null value and hence to not define a valid range.
json.exception.invalid_iterator.207 | cannot use key() for non-object iterators
| The key() member function can only be used on iterators belonging to a JSON ob
ject, because other types do not have a concept of a key.
json.exception.invalid_iterator.208 | cannot use operator[] for object iterators
| The operator[] to specify a concrete offset cannot be used on iterators belon
ging to a JSON object, because JSON objects are unordered.
json.exception.invalid_iterator.209 | cannot use offsets with object iterators |
The offset operators (+, -, +=, -=) cannot be used on iterators belonging to a
JSON object, because JSON objects are unordered.
json.exception.invalid_iterator.210 | iterators do not fit | The iterator range
passed to the insert function are not compatible, meaning they do not belong to
the same container. Therefore, the range (@a first, @a last) is invalid.
json.exception.invalid_iterator.211 | passed iterators may not belong to contain
er | The iterator range passed to the insert function must not be a subrange of
the container to insert to.
json.exception.invalid_iterator.212 | cannot compare iterators of different cont
ainers | When two iterators are compared, they must belong to the same container
.
json.exception.invalid_iterator.213 | cannot compare order of object iterators |
The order of object iterators cannot be compared, because JSON objects are unor
dered.
json.exception.invalid_iterator.214 | cannot get value | Cannot get value for it
erator: Either the iterator belongs to a null value or it is an iterator to a pr
imitive type (number, boolean, or string), but the iterator is different to @ref
begin().
@liveexample{The following code shows how an `invalid_iterator` exception can be
caught.,invalid_iterator}
@sa - @ref exception for the base class of the library exceptions
@sa - @ref parse_error for exceptions indicating a parse error
@sa - @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa - @ref out_of_range for exceptions indicating access out of the defined rang
e
@sa - @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class invalid_iterator : public exception
{
public:
static invalid_iterator create(int id_, const std::string& what_arg)
{
std::string w = exception::name("invalid_iterator", id_) + what_arg;
return invalid_iterator(id_, w.c_str());
}
private:
JSON_HEDLEY_NON_NULL(3)
invalid_iterator(int id_, const char* what_arg)
: exception(id_, what_arg) {}
};
/*!
@brief exception indicating executing a member function with a wrong type
This exception is thrown in case of a type error; that is, a library function is
executed on a JSON value whose type does not match the expected semantics.
Exceptions have ids 3xx.
name / id | example message | description
----------------------------- | --------------- | -------------------------
json.exception.type_error.301 | cannot create object from initializer list | To
create an object from an initializer list, the initializer list must consist onl
y of a list of pairs whose first element is a string. When this constraint is vi
olated, an array is created instead.
json.exception.type_error.302 | type must be object, but is array | During impli
cit or explicit value conversion, the JSON type must be compatible to the target
type. For instance, a JSON string can only be converted into string types, but
not into numbers or boolean types.
json.exception.type_error.303 | incompatible ReferenceType for get_ref, actual t
ype is object | To retrieve a reference to a value stored in a @ref basic_json o
bject with @ref get_ref, the type of the reference must match the value type. Fo
r instance, for a JSON array, the @a ReferenceType must be @ref array_t &.
json.exception.type_error.304 | cannot use at() with string | The @ref at() memb
er functions can only be executed for certain JSON types.
json.exception.type_error.305 | cannot use operator[] with string | The @ref ope
rator[] member functions can only be executed for certain JSON types.
json.exception.type_error.306 | cannot use value() with string | The @ref value(
) member functions can only be executed for certain JSON types.
json.exception.type_error.307 | cannot use erase() with string | The @ref erase(
) member functions can only be executed for certain JSON types.
json.exception.type_error.308 | cannot use push_back() with string | The @ref pu
sh_back() and @ref operator+= member functions can only be executed for certain
JSON types.
json.exception.type_error.309 | cannot use insert() with | The @ref insert() mem
ber functions can only be executed for certain JSON types.
json.exception.type_error.310 | cannot use swap() with number | The @ref swap()
member functions can only be executed for certain JSON types.
json.exception.type_error.311 | cannot use emplace_back() with string | The @ref
emplace_back() member function can only be executed for certain JSON types.
json.exception.type_error.312 | cannot use update() with string | The @ref updat
e() member functions can only be executed for certain JSON types.
json.exception.type_error.313 | invalid value to unflatten | The @ref unflatten
function converts an object whose keys are JSON Pointers back into an arbitrary
nested JSON value. The JSON Pointers must not overlap, because then the resultin
g value would not be well defined.
json.exception.type_error.314 | only objects can be unflattened | The @ref unfla
tten function only works for an object whose keys are JSON Pointers.
json.exception.type_error.315 | values in object must be primitive | The @ref un
flatten function only works for an object whose keys are JSON Pointers and whose
values are primitive.
json.exception.type_error.316 | invalid UTF-8 byte at index 10: 0x7E | The @ref
dump function only works with UTF-8 encoded strings; that is, if you assign a `s
td::string` to a JSON value, make sure it is UTF-8 encoded. |
json.exception.type_error.317 | JSON value cannot be serialized to requested for
mat | The dynamic type of the object cannot be represented in the requested seri
alization format (e.g. a raw `true` or `null` JSON object cannot be serialized t
o BSON) |
@liveexample{The following code shows how a `type_error` exception can be
caught.,type_error}
@sa - @ref exception for the base class of the library exceptions
@sa - @ref parse_error for exceptions indicating a parse error
@sa - @ref invalid_iterator for exceptions indicating errors with iterators
@sa - @ref out_of_range for exceptions indicating access out of the defined rang
e
@sa - @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class type_error : public exception
{
public:
static type_error create(int id_, const std::string& what_arg)
{
std::string w = exception::name("type_error", id_) + what_arg;
return type_error(id_, w.c_str());
}
private:
JSON_HEDLEY_NON_NULL(3)
type_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
};
/*!
@brief exception indicating access out of the defined range
This exception is thrown in case a library function is called on an input
parameter that exceeds the expected range, for instance in case of array
indices or nonexisting object keys.
Exceptions have ids 4xx.
name / id | example message | description
------------------------------- | --------------- | -------------------------
json.exception.out_of_range.401 | array index 3 is out of range | The provided a
rray index @a i is larger than @a size-1.
json.exception.out_of_range.402 | array index '-' (3) is out of range | The spec
ial array index `-` in a JSON Pointer never describes a valid element of the arr
ay, but the index past the end. That is, it can only be used to add elements at
this position, but not to read it.
json.exception.out_of_range.403 | key 'foo' not found | The provided key was not
found in the JSON object.
json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference
token in a JSON Pointer could not be resolved.
json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch op
erations 'remove' and 'add' can not be applied to the root element of the JSON v
alue.
json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed n
umber could not be stored as without changing it to NaN or INF.
json.exception.out_of_range.407 | number overflow serializing '92233720368547758
08' | UBJSON and BSON only support integer numbers up to 9223372036854775807. |
json.exception.out_of_range.408 | excessive array size: 8658170730974374167 | Th
e size (following `#`) of an UBJSON array or object exceeds the maximal capacity
. |
json.exception.out_of_range.409 | BSON key cannot contain code point U+0000 (at
byte 2) | Key identifiers to be serialized to BSON cannot contain code point U+0
000, since the key is stored as zero-terminated c-string |
@liveexample{The following code shows how an `out_of_range` exception can be
caught.,out_of_range}
@sa - @ref exception for the base class of the library exceptions
@sa - @ref parse_error for exceptions indicating a parse error
@sa - @ref invalid_iterator for exceptions indicating errors with iterators
@sa - @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa - @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class out_of_range : public exception
{
public:
static out_of_range create(int id_, const std::string& what_arg)
{
std::string w = exception::name("out_of_range", id_) + what_arg;
return out_of_range(id_, w.c_str());
}
private:
JSON_HEDLEY_NON_NULL(3)
out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {}
};
/*!
@brief exception indicating other library errors
This exception is thrown in case of errors that cannot be classified with the
other exception types.
Exceptions have ids 5xx.
name / id | example message | description
------------------------------ | --------------- | -------------------------
json.exception.other_error.501 | unsuccessful: {"op":"test","path":"/baz", "valu
e":"bar"} | A JSON Patch operation 'test' failed. The unsuccessful operation is
also printed.
@sa - @ref exception for the base class of the library exceptions
@sa - @ref parse_error for exceptions indicating a parse error
@sa - @ref invalid_iterator for exceptions indicating errors with iterators
@sa - @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa - @ref out_of_range for exceptions indicating access out of the defined rang
e
@liveexample{The following code shows how an `other_error` exception can be
caught.,other_error}
@since version 3.0.0
*/
class other_error : public exception
{
public:
static other_error create(int id_, const std::string& what_arg)
{
std::string w = exception::name("other_error", id_) + what_arg;
return other_error(id_, w.c_str());
}
private:
JSON_HEDLEY_NON_NULL(3)
other_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
};
} // namespace detail
} // namespace nlohmann
// #include <nlohmann/detail/macro_scope.hpp>
// #include <nlohmann/detail/meta/cpp_future.hpp> // #include <nlohmann/detail/meta/cpp_future.hpp>
#include <ciso646> // not #include <ciso646> // not
#include <cstddef> // size_t #include <cstddef> // size_t
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type #include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
namespace nlohmann namespace nlohmann
{ {
namespace detail namespace detail
{ {
skipping to change at line 322 skipping to change at line 2242
} // namespace detail } // namespace detail
} // namespace nlohmann } // namespace nlohmann
// #include <nlohmann/detail/meta/type_traits.hpp> // #include <nlohmann/detail/meta/type_traits.hpp>
#include <ciso646> // not #include <ciso646> // not
#include <limits> // numeric_limits #include <limits> // numeric_limits
#include <type_traits> // false_type, is_constructible, is_integral, is_same, tr ue_type #include <type_traits> // false_type, is_constructible, is_integral, is_same, tr ue_type
#include <utility> // declval #include <utility> // declval
// #include <nlohmann/json_fwd.hpp>
// #include <nlohmann/detail/iterators/iterator_traits.hpp> // #include <nlohmann/detail/iterators/iterator_traits.hpp>
#include <iterator> // random_access_iterator_tag #include <iterator> // random_access_iterator_tag
// #include <nlohmann/detail/meta/void_t.hpp> // #include <nlohmann/detail/meta/void_t.hpp>
namespace nlohmann namespace nlohmann
{ {
namespace detail namespace detail
{ {
skipping to change at line 386 skipping to change at line 2304
template <typename T> template <typename T>
struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>> struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
{ {
using iterator_category = std::random_access_iterator_tag; using iterator_category = std::random_access_iterator_tag;
using value_type = T; using value_type = T;
using difference_type = ptrdiff_t; using difference_type = ptrdiff_t;
using pointer = T*; using pointer = T*;
using reference = T&; using reference = T&;
}; };
} } // namespace detail
} } // namespace nlohmann
// #include <nlohmann/detail/macro_scope.hpp>
// #include <nlohmann/detail/meta/cpp_future.hpp> // #include <nlohmann/detail/meta/cpp_future.hpp>
// #include <nlohmann/detail/meta/detected.hpp> // #include <nlohmann/detail/meta/detected.hpp>
#include <type_traits> #include <type_traits>
// #include <nlohmann/detail/meta/void_t.hpp> // #include <nlohmann/detail/meta/void_t.hpp>
// http://en.cppreference.com/w/cpp/experimental/is_detected // http://en.cppreference.com/w/cpp/experimental/is_detected
namespace nlohmann namespace nlohmann
{ {
namespace detail namespace detail
{ {
struct nonesuch struct nonesuch
{ {
nonesuch() = delete; nonesuch() = delete;
~nonesuch() = delete; ~nonesuch() = delete;
nonesuch(nonesuch const&) = delete; nonesuch(nonesuch const&) = delete;
nonesuch(nonesuch const&&) = delete;
void operator=(nonesuch const&) = delete; void operator=(nonesuch const&) = delete;
void operator=(nonesuch&&) = delete;
}; };
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
{ {
using value_t = std::false_type; using value_t = std::false_type;
using type = Default; using type = Default;
skipping to change at line 448 skipping to change at line 2370
template <class Expected, template <class...> class Op, class... Args> template <class Expected, template <class...> class Op, class... Args>
using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>; using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
template <class To, template <class...> class Op, class... Args> template <class To, template <class...> class Op, class... Args>
using is_detected_convertible = using is_detected_convertible =
std::is_convertible<detected_t<Op, Args...>, To>; std::is_convertible<detected_t<Op, Args...>, To>;
} // namespace detail } // namespace detail
} // namespace nlohmann } // namespace nlohmann
// #include <nlohmann/detail/macro_scope.hpp> // #include <nlohmann/json_fwd.hpp>
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
#include <cstdint> // int64_t, uint64_t
#include <map> // map
#include <memory> // allocator
#include <string> // string
#include <vector> // vector
/*!
@brief namespace for Niels Lohmann
@see https://github.com/nlohmann
@since version 1.0.0
*/
namespace nlohmann
{
/*!
@brief default JSONSerializer template argument
This serializer ignores the template arguments and uses ADL
([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl))
for serialization.
*/
template<typename T = void, typename SFINAE = void>
struct adl_serializer;
template<template<typename U, typename V, typename... Args> class ObjectType =
std::map,
template<typename U, typename... Args> class ArrayType = std::vector,
class StringType = std::string, class BooleanType = bool,
class NumberIntegerType = std::int64_t,
class NumberUnsignedType = std::uint64_t,
class NumberFloatType = double,
template<typename U> class AllocatorType = std::allocator,
template<typename T, typename SFINAE = void> class JSONSerializer =
adl_serializer>
class basic_json;
/*!
@brief JSON Pointer
A JSON pointer defines a string syntax for identifying a specific value
within a JSON document. It can be used with functions `at` and
`operator[]`. Furthermore, JSON pointers are the base for JSON patches.
@sa [RFC 6901](https://tools.ietf.org/html/rfc6901)
@since version 2.0.0
*/
template<typename BasicJsonType>
class json_pointer;
/*!
@brief default JSON class
This type is the default specialization of the @ref basic_json class which
uses the standard template types.
@since version 1.0.0
*/
using json = basic_json<>;
} // namespace nlohmann
#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_
namespace nlohmann namespace nlohmann
{ {
/*! /*!
@brief detail namespace with internal helper functions @brief detail namespace with internal helper functions
This namespace collects functions that should not be exposed, This namespace collects functions that should not be exposed,
implementations of some @ref basic_json methods, and meta-programming helpers. implementations of some @ref basic_json methods, and meta-programming helpers.
@since version 2.1.0 @since version 2.1.0
skipping to change at line 630 skipping to change at line 2616
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 and enable_if_t<is_detected<mapped_type_t, ConstructibleObjectType>::value and
is_detected<key_type_t, ConstructibleObjectType>::value >> is_detected<key_type_t, ConstructibleObjectType>::value >>
{ {
using object_t = typename BasicJsonType::object_t; using object_t = typename BasicJsonType::object_t;
static constexpr bool value = static constexpr bool value =
(std::is_constructible<typename ConstructibleObjectType::key_type, typen (std::is_default_constructible<ConstructibleObjectType>::value and
ame object_t::key_type>::value and (std::is_move_assignable<ConstructibleObjectType>::value or
std::is_same<typename object_t::mapped_type, typename ConstructibleObje std::is_copy_assignable<ConstructibleObjectType>::value) and
ctType::mapped_type>::value) or (std::is_constructible<typename ConstructibleObjectType::key_type,
(has_from_json<BasicJsonType, typename ConstructibleObjectType::mapped_t typename object_t::key_type>::value and
ype>::value or std::is_same <
has_non_default_from_json<BasicJsonType, typename ConstructibleObjectTy typename object_t::mapped_type,
pe::mapped_type >::value); typename ConstructibleObjectType::mapped_type >::value)) or
(has_from_json<BasicJsonType,
typename ConstructibleObjectType::mapped_type>::value or
has_non_default_from_json <
BasicJsonType,
typename ConstructibleObjectType::mapped_type >::value);
}; };
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,
typename = void> typename = void>
struct is_compatible_string_type_impl : std::false_type {}; struct is_compatible_string_type_impl : std::false_type {};
skipping to change at line 716 skipping to change at line 2711
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<not std::is_same<ConstructibleArrayType, enable_if_t<not std::is_same<ConstructibleArrayType,
typename BasicJsonType::value_type>::value and typename BasicJsonType::value_type>::value and
is_detected<value_type_t, ConstructibleArrayType>::value and std::is_default_constructible<ConstructibleArrayType>::value and
is_detected<iterator_t, ConstructibleArrayType>::value and (std::is_move_assignable<ConstructibleArrayType>::value or
is_complete_type< std::is_copy_assignable<ConstructibleArrayType>::value) and
detected_t<value_type_t, ConstructibleArrayType>>::value >> is_detected<value_type_t, ConstructibleArrayType>::value and
is_detected<iterator_t, ConstructibleArrayType>::value and
is_complete_type<
detected_t<value_type_t, ConstructibleArrayType>>::value >>
{ {
static constexpr bool value = static constexpr bool value =
// This is needed because json_reverse_iterator has a ::iterator type, // This is needed because json_reverse_iterator has a ::iterator type,
// furthermore, std::back_insert_iterator (and other iterators) have a b // furthermore, std::back_insert_iterator (and other iterators) have a
ase class `iterator`... // base class `iterator`... Therefore it is detected as a
// Therefore it is detected as a ConstructibleArrayType. // ConstructibleArrayType. The real fix would be to have an Iterable
// The real fix would be to have an Iterable concept. // concept.
not is_iterator_traits < not is_iterator_traits<iterator_traits<ConstructibleArrayType>>::value a
iterator_traits<ConstructibleArrayType >>::value and nd
(std::is_same<typename ConstructibleArrayType::value_type, typename Basi (std::is_same<typename ConstructibleArrayType::value_type,
cJsonType::array_t::value_type>::value or typename BasicJsonType::array_t::value_type>::value or
has_from_json<BasicJsonType, has_from_json<BasicJsonType,
typename ConstructibleArrayType::value_type>::value or typename ConstructibleArrayType::value_type>::value or
has_non_default_from_json < has_non_default_from_json <
BasicJsonType, typename ConstructibleArrayType::value_type >::value); BasicJsonType, typename ConstructibleArrayType::value_type >::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> {} ;
skipping to change at line 782 skipping to change at line 2781
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 =
has_to_json<BasicJsonType, CompatibleType>::value; has_to_json<BasicJsonType, CompatibleType>::value;
}; };
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> {};
} // namespace detail
} // namespace nlohmann
// #include <nlohmann/detail/exceptions.hpp>
#include <exception> // exception
#include <stdexcept> // runtime_error
#include <string> // to_string
// #include <nlohmann/detail/input/position_t.hpp>
#include <cstddef> // size_t
namespace nlohmann
{
namespace detail
{
/// struct to capture the start position of the current token
struct position_t
{
/// the total number of characters read
std::size_t chars_read_total = 0;
/// the number of characters read in the current line
std::size_t chars_read_current_line = 0;
/// the number of lines read
std::size_t lines_read = 0;
/// conversion to size_t to preserve SAX interface
constexpr operator size_t() const
{
return chars_read_total;
}
};
}
}
namespace nlohmann
{
namespace detail
{
////////////////
// exceptions //
////////////////
/*!
@brief general exception of the @ref basic_json class
This class is an extension of `std::exception` objects with a member @a id for
exception ids. It is used as the base class for all exceptions thrown by the
@ref basic_json class. This class can hence be used as "wildcard" to catch
exceptions.
Subclasses:
- @ref parse_error for exceptions indicating a parse error
- @ref invalid_iterator for exceptions indicating errors with iterators
- @ref type_error for exceptions indicating executing a member function with
a wrong type
- @ref out_of_range for exceptions indicating access out of the defined range
- @ref other_error for exceptions indicating other library errors
@internal
@note To have nothrow-copy-constructible exceptions, we internally use
`std::runtime_error` which can cope with arbitrary-length error messages.
Intermediate strings are built with static functions and then passed to
the actual constructor.
@endinternal
@liveexample{The following code shows how arbitrary library exceptions can be
caught.,exception}
@since version 3.0.0
*/
class exception : public std::exception
{
public:
/// returns the explanatory string
const char* what() const noexcept override
{
return m.what();
}
/// the id of the exception
const int id;
protected:
exception(int id_, const char* what_arg) : id(id_), m(what_arg) {}
static std::string name(const std::string& ename, int id_)
{
return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
}
private:
/// an exception object as storage for error messages
std::runtime_error m;
};
/*!
@brief exception indicating a parse error
This exception is thrown by the library when a parse error occurs. Parse errors
can occur during the deserialization of JSON text, CBOR, MessagePack, as well
as when using JSON Patch.
Member @a byte holds the byte index of the last read character in the input
file.
Exceptions have ids 1xx.
name / id | example message | description
json.exception.parse_error.101 | parse error at 2: unexpected end of input; expe
cted string literal | This error indicates a syntax error while deserializing a
JSON text. The error message describes that an unexpected token (character) was
encountered, and the member @a byte indicates the error position.
json.exception.parse_error.102 | parse error at 14: missing or wrong low surroga
te | JSON uses the `\uxxxx` format to describe Unicode characters. Code points a
bove above 0xFFFF are split into two `\uxxxx` entries ("surrogate pairs"). This
error indicates that the surrogate pair is incomplete or contains an invalid cod
e point.
json.exception.parse_error.103 | parse error: code points above 0x10FFFF are inv
alid | Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF a
re invalid.
json.exception.parse_error.104 | parse error: JSON patch must be an array of obj
ects | [RFC 6902](https://tools.ietf.org/html/rfc6902) requires a JSON Patch doc
ument to be a JSON document that represents an array of objects.
json.exception.parse_error.105 | parse error: operation must have string member
'op' | An operation of a JSON Patch document must contain exactly one "op" membe
r, whose value indicates the operation to perform. Its value must be one of "add
", "remove", "replace", "move", "copy", or "test"; other values are errors.
json.exception.parse_error.106 | parse error: array index '01' must not begin wi
th '0' | An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/htm
l/rfc6901)) may be `0` or any number without a leading `0`.
json.exception.parse_error.107 | parse error: JSON pointer must be empty or begi
n with '/' - was: 'foo' | A JSON Pointer must be a Unicode string containing a s
equence of zero or more reference tokens, each prefixed by a `/` character.
json.exception.parse_error.108 | parse error: escape character '~' must be follo
wed with '0' or '1' | In a JSON Pointer, only `~0` and `~1` are valid escape seq
uences.
json.exception.parse_error.109 | parse error: array index 'one' is not a number
| A JSON Pointer array index must be a number.
json.exception.parse_error.110 | parse error at 1: cannot read 2 bytes from vect
or | When parsing CBOR or MessagePack, the byte vector ends before the complete
value has been read.
json.exception.parse_error.112 | parse error at 1: error reading CBOR; last byte
: 0xF8 | Not all types of CBOR or MessagePack are supported. This exception occu
rs if an unsupported byte was read.
json.exception.parse_error.113 | parse error at 2: expected a CBOR string; last
byte: 0x98 | While parsing a map key, a value that is not a string has been read
.
json.exception.parse_error.114 | parse error: Unsupported BSON record type 0x0F
| The parsing of the corresponding BSON record type is not implemented (yet).
@note For an input with n bytes, 1 is the index of the first character and n+1
is the index of the terminating null byte or the end of file. This also
holds true when reading a byte vector (CBOR or MessagePack).
@liveexample{The following code shows how a `parse_error` exception can be
caught.,parse_error}
@sa @ref exception for the base class of the library exceptions
@sa @ref invalid_iterator for exceptions indicating errors with iterators
@sa @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa @ref out_of_range for exceptions indicating access out of the defined range
@sa @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class parse_error : public exception
{
public:
/*!
@brief create a parse error exception
@param[in] id_ the id of the exception
@param[in] position the position where the error occurred (or with
chars_read_total=0 if the position cannot be
determined)
@param[in] what_arg the explanatory string
@return parse_error object
*/
static parse_error create(int id_, const position_t& pos, const std::string&
what_arg)
{
std::string w = exception::name("parse_error", id_) + "parse error" +
position_string(pos) + ": " + what_arg;
return parse_error(id_, pos.chars_read_total, w.c_str());
}
static parse_error create(int id_, std::size_t byte_, const std::string& wha
t_arg)
{
std::string w = exception::name("parse_error", id_) + "parse error" +
(byte_ != 0 ? (" at byte " + std::to_string(byte_)) : ""
) +
": " + what_arg;
return parse_error(id_, byte_, w.c_str());
}
/*!
@brief byte index of the parse error
The byte index of the last read character in the input file.
@note For an input with n bytes, 1 is the index of the first character and
n+1 is the index of the terminating null byte or the end of file.
This also holds true when reading a byte vector (CBOR or MessagePack).
*/
const std::size_t byte;
private:
parse_error(int id_, std::size_t byte_, const char* what_arg)
: exception(id_, what_arg), byte(byte_) {}
static std::string position_string(const position_t& pos)
{
return " at line " + std::to_string(pos.lines_read + 1) +
", column " + std::to_string(pos.chars_read_current_line);
}
};
/*!
@brief exception indicating errors with iterators
This exception is thrown if iterators passed to a library function do not match
the expected semantics.
Exceptions have ids 2xx.
name / id | example message | description
json.exception.invalid_iterator.201 | iterators are not compatible | The iterato
rs passed to constructor @ref basic_json(InputIT first, InputIT last) are not co
mpatible, meaning they do not belong to the same container. Therefore, the range
(@a first, @a last) is invalid.
json.exception.invalid_iterator.202 | iterator does not fit current value | In a
n erase or insert function, the passed iterator @a pos does not belong to the JS
ON value for which the function was called. It hence does not define a valid pos
ition for the deletion/insertion.
json.exception.invalid_iterator.203 | iterators do not fit current value | Eithe
r iterator passed to function @ref erase(IteratorType first, IteratorType last)
does not belong to the JSON value from which values shall be erased. It hence do
es not define a valid range to delete values from.
json.exception.invalid_iterator.204 | iterators out of range | When an iterator
range for a primitive type (number, boolean, or string) is passed to a construct
or or an erase function, this range has to be exactly (@ref begin(), @ref end())
, because this is the only way the single stored value is expressed. All other r
anges are invalid.
json.exception.invalid_iterator.205 | iterator out of range | When an iterator f
or a primitive type (number, boolean, or string) is passed to an erase function,
the iterator has to be the @ref begin() iterator, because it is the only way to
address the stored value. All other iterators are invalid.
json.exception.invalid_iterator.206 | cannot construct with iterators from null
| The iterators passed to constructor @ref basic_json(InputIT first, InputIT las
t) belong to a JSON null value and hence to not define a valid range.
json.exception.invalid_iterator.207 | cannot use key() for non-object iterators
| The key() member function can only be used on iterators belonging to a JSON ob
ject, because other types do not have a concept of a key.
json.exception.invalid_iterator.208 | cannot use operator[] for object iterators
| The operator[] to specify a concrete offset cannot be used on iterators belon
ging to a JSON object, because JSON objects are unordered.
json.exception.invalid_iterator.209 | cannot use offsets with object iterators |
The offset operators (+, -, +=, -=) cannot be used on iterators belonging to a
JSON object, because JSON objects are unordered.
json.exception.invalid_iterator.210 | iterators do not fit | The iterator range
passed to the insert function are not compatible, meaning they do not belong to
the same container. Therefore, the range (@a first, @a last) is invalid.
json.exception.invalid_iterator.211 | passed iterators may not belong to contain
er | The iterator range passed to the insert function must not be a subrange of
the container to insert to.
json.exception.invalid_iterator.212 | cannot compare iterators of different cont
ainers | When two iterators are compared, they must belong to the same container
.
json.exception.invalid_iterator.213 | cannot compare order of object iterators |
The order of object iterators cannot be compared, because JSON objects are unor
dered.
json.exception.invalid_iterator.214 | cannot get value | Cannot get value for it
erator: Either the iterator belongs to a null value or it is an iterator to a pr
imitive type (number, boolean, or string), but the iterator is different to @ref
begin().
@liveexample{The following code shows how an `invalid_iterator` exception can be
caught.,invalid_iterator}
@sa @ref exception for the base class of the library exceptions
@sa @ref parse_error for exceptions indicating a parse error
@sa @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa @ref out_of_range for exceptions indicating access out of the defined range
@sa @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class invalid_iterator : public exception
{
public:
static invalid_iterator create(int id_, const std::string& what_arg)
{
std::string w = exception::name("invalid_iterator", id_) + what_arg;
return invalid_iterator(id_, w.c_str());
}
private:
invalid_iterator(int id_, const char* what_arg)
: exception(id_, what_arg) {}
};
/*!
@brief exception indicating executing a member function with a wrong type
This exception is thrown in case of a type error; that is, a library function is
executed on a JSON value whose type does not match the expected semantics.
Exceptions have ids 3xx. // https://en.cppreference.com/w/cpp/types/conjunction
template<class...> struct conjunction : std::true_type { };
template<class B1> struct conjunction<B1> : B1 { };
template<class B1, class... Bn>
struct conjunction<B1, Bn...>
: std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
name / id | example message | description template <typename T1, typename T2>
json.exception.type_error.301 | cannot create object from initializer list | To struct is_constructible_tuple : std::false_type {};
create an object from an initializer list, the initializer list must consist onl
y of a list of pairs whose first element is a string. When this constraint is vi
olated, an array is created instead.
json.exception.type_error.302 | type must be object, but is array | During impli
cit or explicit value conversion, the JSON type must be compatible to the target
type. For instance, a JSON string can only be converted into string types, but
not into numbers or boolean types.
json.exception.type_error.303 | incompatible ReferenceType for get_ref, actual t
ype is object | To retrieve a reference to a value stored in a @ref basic_json o
bject with @ref get_ref, the type of the reference must match the value type. Fo
r instance, for a JSON array, the @a ReferenceType must be @ref array_t&.
json.exception.type_error.304 | cannot use at() with string | The @ref at() memb
er functions can only be executed for certain JSON types.
json.exception.type_error.305 | cannot use operator[] with string | The @ref ope
rator[] member functions can only be executed for certain JSON types.
json.exception.type_error.306 | cannot use value() with string | The @ref value(
) member functions can only be executed for certain JSON types.
json.exception.type_error.307 | cannot use erase() with string | The @ref erase(
) member functions can only be executed for certain JSON types.
json.exception.type_error.308 | cannot use push_back() with string | The @ref pu
sh_back() and @ref operator+= member functions can only be executed for certain
JSON types.
json.exception.type_error.309 | cannot use insert() with | The @ref insert() mem
ber functions can only be executed for certain JSON types.
json.exception.type_error.310 | cannot use swap() with number | The @ref swap()
member functions can only be executed for certain JSON types.
json.exception.type_error.311 | cannot use emplace_back() with string | The @ref
emplace_back() member function can only be executed for certain JSON types.
json.exception.type_error.312 | cannot use update() with string | The @ref updat
e() member functions can only be executed for certain JSON types.
json.exception.type_error.313 | invalid value to unflatten | The @ref unflatten
function converts an object whose keys are JSON Pointers back into an arbitrary
nested JSON value. The JSON Pointers must not overlap, because then the resultin
g value would not be well defined.
json.exception.type_error.314 | only objects can be unflattened | The @ref unfla
tten function only works for an object whose keys are JSON Pointers.
json.exception.type_error.315 | values in object must be primitive | The @ref un
flatten function only works for an object whose keys are JSON Pointers and whose
values are primitive.
json.exception.type_error.316 | invalid UTF-8 byte at index 10: 0x7E | The @ref
dump function only works with UTF-8 encoded strings; that is, if you assign a `s
td::string` to a JSON value, make sure it is UTF-8 encoded. |
json.exception.type_error.317 | JSON value cannot be serialized to requested for
mat | The dynamic type of the object cannot be represented in the requested seri
alization format (e.g. a raw `true` or `null` JSON object cannot be serialized t
o BSON) |
@liveexample{The following code shows how a `type_error` exception can be
caught.,type_error}
@sa @ref exception for the base class of the library exceptions
@sa @ref parse_error for exceptions indicating a parse error
@sa @ref invalid_iterator for exceptions indicating errors with iterators
@sa @ref out_of_range for exceptions indicating access out of the defined range
@sa @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class type_error : public exception
{
public:
static type_error create(int id_, const std::string& what_arg)
{
std::string w = exception::name("type_error", id_) + what_arg;
return type_error(id_, w.c_str());
}
private:
type_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
};
/*!
@brief exception indicating access out of the defined range
This exception is thrown in case a library function is called on an input
parameter that exceeds the expected range, for instance in case of array
indices or nonexisting object keys.
Exceptions have ids 4xx.
name / id | example message | description
json.exception.out_of_range.401 | array index 3 is out of range | The provided a
rray index @a i is larger than @a size-1.
json.exception.out_of_range.402 | array index '-' (3) is out of range | The spec
ial array index `-` in a JSON Pointer never describes a valid element of the arr
ay, but the index past the end. That is, it can only be used to add elements at
this position, but not to read it.
json.exception.out_of_range.403 | key 'foo' not found | The provided key was not
found in the JSON object.
json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference
token in a JSON Pointer could not be resolved.
json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch op
erations 'remove' and 'add' can not be applied to the root element of the JSON v
alue.
json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed n
umber could not be stored as without changing it to NaN or INF.
json.exception.out_of_range.407 | number overflow serializing '92233720368547758
08' | UBJSON and BSON only support integer numbers up to 9223372036854775807. |
json.exception.out_of_range.408 | excessive array size: 8658170730974374167 | Th
e size (following `#`) of an UBJSON array or object exceeds the maximal capacity
. |
json.exception.out_of_range.409 | BSON key cannot contain code point U+0000 (at
byte 2) | Key identifiers to be serialized to BSON cannot contain code point U+0
000, since the key is stored as zero-terminated c-string |
@liveexample{The following code shows how an `out_of_range` exception can be
caught.,out_of_range}
@sa @ref exception for the base class of the library exceptions
@sa @ref parse_error for exceptions indicating a parse error
@sa @ref invalid_iterator for exceptions indicating errors with iterators
@sa @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class out_of_range : public exception
{
public:
static out_of_range create(int id_, const std::string& what_arg)
{
std::string w = exception::name("out_of_range", id_) + what_arg;
return out_of_range(id_, w.c_str());
}
private:
out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {}
};
/*!
@brief exception indicating other library errors
This exception is thrown in case of errors that cannot be classified with the template <typename T1, typename... Args>
other exception types. struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<std::is_con
structible<T1, Args>...> {};
Exceptions have ids 5xx.
name / id | example message | description
json.exception.other_error.501 | unsuccessful: {"op":"test","path":"/baz", "valu
e":"bar"} | A JSON Patch operation 'test' failed. The unsuccessful operation is
also printed.
@sa @ref exception for the base class of the library exceptions
@sa @ref parse_error for exceptions indicating a parse error
@sa @ref invalid_iterator for exceptions indicating errors with iterators
@sa @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa @ref out_of_range for exceptions indicating access out of the defined range
@liveexample{The following code shows how an `other_error` exception can be
caught.,other_error}
@since version 3.0.0
*/
class other_error : public exception
{
public:
static other_error create(int id_, const std::string& what_arg)
{
std::string w = exception::name("other_error", id_) + what_arg;
return other_error(id_, w.c_str());
}
private:
other_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
};
} // namespace detail } // namespace detail
} // namespace nlohmann } // namespace nlohmann
// #include <nlohmann/detail/value_t.hpp> // #include <nlohmann/detail/value_t.hpp>
#include <array> // array #include <array> // array
#include <ciso646> // and #include <ciso646> // and
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstdint> // uint8_t #include <cstdint> // uint8_t
#include <string> // string
namespace nlohmann namespace nlohmann
{ {
namespace detail namespace detail
{ {
/////////////////////////// ///////////////////////////
// JSON type enumeration // // JSON type enumeration //
/////////////////////////// ///////////////////////////
/*! /*!
skipping to change at line 1238 skipping to change at line 2875
} }
}; };
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);
return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index]; return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index];
} }
} // namespace detail } // namespace detail
} // namespace nlohmann } // namespace nlohmann
// #include <nlohmann/detail/conversions/from_json.hpp>
#include <algorithm> // transform
#include <array> // array
#include <ciso646> // and, not
#include <forward_list> // forward_list
#include <iterator> // inserter, front_inserter, end
#include <map> // map
#include <string> // string
#include <tuple> // tuple, make_tuple
#include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_c
onvertible
#include <unordered_map> // unordered_map
#include <utility> // pair, declval
#include <valarray> // valarray
// #include <nlohmann/detail/exceptions.hpp>
// #include <nlohmann/detail/macro_scope.hpp>
// #include <nlohmann/detail/meta/cpp_future.hpp>
// #include <nlohmann/detail/meta/type_traits.hpp>
// #include <nlohmann/detail/value_t.hpp>
namespace nlohmann namespace nlohmann
{ {
namespace detail namespace detail
{ {
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json(const BasicJsonType& j, typename std::nullptr_t& n) void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
{ {
if (JSON_UNLIKELY(not j.is_null())) if (JSON_HEDLEY_UNLIKELY(not j.is_null()))
{ {
JSON_THROW(type_error::create(302, "type must be null, but is " + std::s tring(j.type_name()))); JSON_THROW(type_error::create(302, "type must be null, but is " + std::s tring(j.type_name())));
} }
n = nullptr; n = nullptr;
} }
// 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 and enable_if_t<std::is_arithmetic<ArithmeticType>::value and
not std::is_same<ArithmeticType, typename BasicJsonType::bo olean_t>::value, not std::is_same<ArithmeticType, typename BasicJsonType::bo olean_t>::value,
skipping to change at line 1310 skipping to change at line 2922
} }
default: default:
JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name())));
} }
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b) void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
{ {
if (JSON_UNLIKELY(not j.is_boolean())) if (JSON_HEDLEY_UNLIKELY(not j.is_boolean()))
{ {
JSON_THROW(type_error::create(302, "type must be boolean, but is " + std ::string(j.type_name()))); JSON_THROW(type_error::create(302, "type must be boolean, but is " + std ::string(j.type_name())));
} }
b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>(); b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s) void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
{ {
if (JSON_UNLIKELY(not j.is_string())) if (JSON_HEDLEY_UNLIKELY(not j.is_string()))
{ {
JSON_THROW(type_error::create(302, "type must be string, but is " + std: :string(j.type_name()))); JSON_THROW(type_error::create(302, "type must be string, but is " + std: :string(j.type_name())));
} }
s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
} }
template < template <
typename BasicJsonType, typename ConstructibleStringType, typename BasicJsonType, typename ConstructibleStringType,
enable_if_t < enable_if_t <
is_constructible_string_type<BasicJsonType, ConstructibleStringType>::va lue and is_constructible_string_type<BasicJsonType, ConstructibleStringType>::va lue and
not std::is_same<typename BasicJsonType::string_t, not std::is_same<typename BasicJsonType::string_t,
ConstructibleStringType>::value, ConstructibleStringType>::value,
int > = 0 > int > = 0 >
void from_json(const BasicJsonType& j, ConstructibleStringType& s) void from_json(const BasicJsonType& j, ConstructibleStringType& s)
{ {
if (JSON_UNLIKELY(not j.is_string())) if (JSON_HEDLEY_UNLIKELY(not j.is_string()))
{ {
JSON_THROW(type_error::create(302, "type must be string, but is " + std: :string(j.type_name()))); JSON_THROW(type_error::create(302, "type must be string, but is " + std: :string(j.type_name())));
} }
s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& v al) void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& v al)
{ {
skipping to change at line 1376 skipping to change at line 2988
typename std::underlying_type<EnumType>::type val; typename std::underlying_type<EnumType>::type val;
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
e = static_cast<EnumType>(val); e = static_cast<EnumType>(val);
} }
// 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<std::is_convertible<BasicJsonType, T>::value, int> = 0> enable_if_t<std::is_convertible<BasicJsonType, T>::value, int> = 0>
void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l) void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
{ {
if (JSON_UNLIKELY(not j.is_array())) if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std:: string(j.type_name()))); JSON_THROW(type_error::create(302, "type must be array, but is " + std:: string(j.type_name())));
} }
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<std::is_convertible<BasicJsonType, T>::value, int> = 0> enable_if_t<std::is_convertible<BasicJsonType, T>::value, int> = 0>
void from_json(const BasicJsonType& j, std::valarray<T>& l) void from_json(const BasicJsonType& j, std::valarray<T>& l)
{ {
if (JSON_UNLIKELY(not j.is_array())) if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std:: string(j.type_name()))); JSON_THROW(type_error::create(302, "type must be array, but is " + std:: string(j.type_name())));
} }
l.resize(j.size()); l.resize(j.size());
std::copy(j.m_value.array->begin(), j.m_value.array->end(), std::begin(l)); std::copy(j.begin(), j.end(), std::begin(l));
}
template <typename BasicJsonType, typename T, std::size_t N>
auto from_json(const BasicJsonType& j, T (&arr)[N])
-> decltype(j.template get<T>(), void())
{
for (std::size_t i = 0; i < N; ++i)
{
arr[i] = j.at(i).template get<T>();
}
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_ t& arr, priority_tag<3> /*unused*/) void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_ t& arr, priority_tag<3> /*unused*/)
{ {
arr = *j.template get_ptr<const typename BasicJsonType::array_t*>(); arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
} }
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,
skipping to change at line 1426 skipping to change at line 3049
template<typename BasicJsonType, typename ConstructibleArrayType> template<typename BasicJsonType, typename ConstructibleArrayType>
auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, p riority_tag<1> /*unused*/) auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, p riority_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())
{ {
using std::end; using std::end;
arr.reserve(j.size()); ConstructibleArrayType ret;
ret.reserve(j.size());
std::transform(j.begin(), j.end(), std::transform(j.begin(), j.end(),
std::inserter(arr, end(arr)), [](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>();
}); });
arr = std::move(ret);
} }
template <typename BasicJsonType, typename ConstructibleArrayType> template <typename BasicJsonType, typename ConstructibleArrayType>
void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr,
priority_tag<0> /*unused*/) priority_tag<0> /*unused*/)
{ {
using std::end; using std::end;
ConstructibleArrayType ret;
std::transform( std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)), j.begin(), j.end(), std::inserter(ret, end(ret)),
[](const BasicJsonType & i) [](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>();
}); });
arr = std::move(ret);
} }
template <typename BasicJsonType, typename ConstructibleArrayType, template <typename BasicJsonType, typename ConstructibleArrayType,
enable_if_t < enable_if_t <
is_constructible_array_type<BasicJsonType, ConstructibleArrayType> ::value and is_constructible_array_type<BasicJsonType, ConstructibleArrayType> ::value and
not is_constructible_object_type<BasicJsonType, ConstructibleArray Type>::value and not is_constructible_object_type<BasicJsonType, ConstructibleArray Type>::value and
not is_constructible_string_type<BasicJsonType, ConstructibleArray Type>::value and not is_constructible_string_type<BasicJsonType, ConstructibleArray Type>::value and
not is_basic_json<ConstructibleArrayType>::value, not is_basic_json<ConstructibleArrayType>::value,
int > = 0 > 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>(),
void()) void())
{ {
if (JSON_UNLIKELY(not j.is_array())) if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + JSON_THROW(type_error::create(302, "type must be array, but is " +
std::string(j.type_name()))); std::string(j.type_name())));
} }
from_json_array_impl(j, arr, priority_tag<3> {}); from_json_array_impl(j, arr, priority_tag<3> {});
} }
template<typename BasicJsonType, typename ConstructibleObjectType, template<typename BasicJsonType, typename ConstructibleObjectType,
enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleOb jectType>::value, int> = 0> enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleOb jectType>::value, int> = 0>
void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
{ {
if (JSON_UNLIKELY(not j.is_object())) if (JSON_HEDLEY_UNLIKELY(not j.is_object()))
{ {
JSON_THROW(type_error::create(302, "type must be object, but is " + std: :string(j.type_name()))); JSON_THROW(type_error::create(302, "type must be object, but is " + std: :string(j.type_name())));
} }
ConstructibleObjectType ret;
auto inner_object = j.template get_ptr<const typename BasicJsonType::object_ t*>(); 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(obj, obj.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 ConstructibleO bjectType::mapped_type>()); return value_type(p.first, p.second.template get<typename ConstructibleO bjectType::mapped_type>());
}); });
obj = std::move(ret);
} }
// overload for arithmetic types, not chosen for basic_json template arguments // overload for arithmetic types, not chosen for basic_json template arguments
// (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 < enable_if_t <
std::is_arithmetic<ArithmeticType>::value and std::is_arithmetic<ArithmeticType>::value and
not std::is_same<ArithmeticType, typename BasicJsonType::number_uns igned_t>::value and not std::is_same<ArithmeticType, typename BasicJsonType::number_uns igned_t>::value and
skipping to change at line 1559 skipping to change at line 3188
void from_json(const BasicJsonType& j, std::tuple<Args...>& t) void from_json(const BasicJsonType& j, std::tuple<Args...>& t)
{ {
from_json_tuple_impl(j, t, index_sequence_for<Args...> {}); from_json_tuple_impl(j, t, index_sequence_for<Args...> {});
} }
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<not std::is_constructible< typename = enable_if_t<not std::is_constructible<
typename BasicJsonType::string_t, Key>::val ue>> typename BasicJsonType::string_t, Key>::val ue>>
void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m) void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
{ {
if (JSON_UNLIKELY(not j.is_array())) if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std:: string(j.type_name()))); JSON_THROW(type_error::create(302, "type must be array, but is " + std:: string(j.type_name())));
} }
m.clear();
for (const auto& p : j) for (const auto& p : j)
{ {
if (JSON_UNLIKELY(not p.is_array())) if (JSON_HEDLEY_UNLIKELY(not p.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + s td::string(p.type_name()))); JSON_THROW(type_error::create(302, "type must be array, but is " + s td::string(p.type_name())));
} }
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>()); m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
} }
} }
template <typename BasicJsonType, typename Key, typename Value, typename Hash, t ypename KeyEqual, typename Allocator, template <typename BasicJsonType, typename Key, typename Value, typename Hash, t ypename KeyEqual, typename Allocator,
typename = enable_if_t<not std::is_constructible< typename = enable_if_t<not std::is_constructible<
typename BasicJsonType::string_t, Key>::val ue>> typename BasicJsonType::string_t, Key>::val ue>>
void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE qual, Allocator>& m) void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE qual, Allocator>& m)
{ {
if (JSON_UNLIKELY(not j.is_array())) if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std:: string(j.type_name()))); JSON_THROW(type_error::create(302, "type must be array, but is " + std:: string(j.type_name())));
} }
m.clear();
for (const auto& p : j) for (const auto& p : j)
{ {
if (JSON_UNLIKELY(not p.is_array())) if (JSON_HEDLEY_UNLIKELY(not p.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + s td::string(p.type_name()))); JSON_THROW(type_error::create(302, "type must be array, but is " + s td::string(p.type_name())));
} }
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>()); m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
} }
} }
struct from_json_fn struct from_json_fn
{ {
template<typename BasicJsonType, typename T> template<typename BasicJsonType, typename T>
skipping to change at line 1611 skipping to change at line 3242
}; };
} // namespace detail } // namespace detail
/// namespace to hold default `from_json` function /// namespace to hold default `from_json` function
/// to see why this is required: /// to see why this is required:
/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html /// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html
namespace namespace
{ {
constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::va lue; constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::va lue;
} // namespace } // namespace
} // namespace nlohmann } // namespace nlohmann
// #include <nlohmann/detail/conversions/to_json.hpp> // #include <nlohmann/detail/conversions/to_json.hpp>
#include <algorithm> // copy
#include <ciso646> // or, and, not #include <ciso646> // or, and, not
#include <iterator> // begin, end #include <iterator> // begin, end
#include <string> // string
#include <tuple> // tuple, get #include <tuple> // tuple, get
#include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type #include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type
#include <utility> // move, forward, declval, pair #include <utility> // move, forward, declval, pair
#include <valarray> // valarray #include <valarray> // valarray
#include <vector> // vector #include <vector> // vector
// #include <nlohmann/detail/meta/cpp_future.hpp>
// #include <nlohmann/detail/meta/type_traits.hpp>
// #include <nlohmann/detail/value_t.hpp>
// #include <nlohmann/detail/iterators/iteration_proxy.hpp> // #include <nlohmann/detail/iterators/iteration_proxy.hpp>
#include <cstddef> // size_t #include <cstddef> // size_t
#include <string> // string, to_string
#include <iterator> // input_iterator_tag #include <iterator> // input_iterator_tag
#include <string> // string, to_string
#include <tuple> // tuple_size, get, tuple_element #include <tuple> // tuple_size, get, tuple_element
// #include <nlohmann/detail/value_t.hpp>
// #include <nlohmann/detail/meta/type_traits.hpp> // #include <nlohmann/detail/meta/type_traits.hpp>
// #include <nlohmann/detail/value_t.hpp>
namespace nlohmann namespace nlohmann
{ {
namespace detail namespace detail
{ {
template<typename string_type>
void int_to_string( string_type& target, std::size_t value )
{
target = std::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;
using value_type = iteration_proxy_value; using value_type = iteration_proxy_value;
using pointer = value_type * ; using pointer = value_type * ;
using reference = value_type & ; using reference = value_type & ;
using iterator_category = std::input_iterator_tag; using iterator_category = std::input_iterator_tag;
using string_type = typename std::remove_cv< typename std::remove_reference< decltype( std::declval<IteratorType>().key() ) >::type >::type;
private: private:
/// the iterator /// the iterator
IteratorType anchor; IteratorType anchor;
/// an index for arrays (used to create key names) /// an index for arrays (used to create key names)
std::size_t array_index = 0; std::size_t array_index = 0;
/// last stringified array index /// last stringified array index
mutable std::size_t array_index_last = 0; mutable std::size_t array_index_last = 0;
/// a string representation of the array index /// a string representation of the array index
mutable std::string array_index_str = "0"; mutable string_type array_index_str = "0";
/// an empty string (to return a reference for primitive values) /// an empty string (to return a reference for primitive values)
const std::string empty_str = ""; const string_type empty_str = "";
public: public:
explicit iteration_proxy_value(IteratorType it) noexcept : anchor(it) {} explicit iteration_proxy_value(IteratorType it) noexcept : anchor(it) {}
/// dereference operator (needed for range-based for) /// dereference operator (needed for range-based for)
iteration_proxy_value& operator*() iteration_proxy_value& operator*()
{ {
return *this; return *this;
} }
/// increment operator (needed for range-based for) /// increment operator (needed for range-based for)
iteration_proxy_value& operator++() iteration_proxy_value& operator++()
{ {
++anchor; ++anchor;
++array_index; ++array_index;
return *this; return *this;
} }
/// equality operator (needed for InputIterator) /// equality operator (needed for InputIterator)
bool operator==(const iteration_proxy_value& o) const noexcept bool operator==(const iteration_proxy_value& o) const
{ {
return anchor == o.anchor; return anchor == o.anchor;
} }
/// inequality operator (needed for range-based for) /// inequality operator (needed for range-based for)
bool operator!=(const iteration_proxy_value& o) const noexcept bool operator!=(const iteration_proxy_value& o) const
{ {
return anchor != o.anchor; return anchor != o.anchor;
} }
/// return key of the iterator /// return key of the iterator
const std::string& key() const const string_type& key() const
{ {
assert(anchor.m_object != nullptr); assert(anchor.m_object != nullptr);
switch (anchor.m_object->type()) switch (anchor.m_object->type())
{ {
// use integer array index as key // use integer array index as key
case value_t::array: case value_t::array:
{ {
if (array_index != array_index_last) if (array_index != array_index_last)
{ {
array_index_str = std::to_string(array_index); int_to_string( array_index_str, array_index );
array_index_last = array_index; array_index_last = array_index;
} }
return array_index_str; return array_index_str;
} }
// use key from the object // use key from the object
case value_t::object: case value_t::object:
return anchor.key(); return anchor.key();
// use an empty key for all primitive types // use an empty key for all primitive types
skipping to change at line 1779 skipping to change at line 3412
} }
} // namespace detail } // namespace detail
} // namespace nlohmann } // namespace nlohmann
// The Addition to the STD Namespace is required to add // The Addition to the STD Namespace is required to add
// 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__)
// Fix: https://github.com/nlohmann/json/issues/1401
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmismatched-tags"
#endif
template <typename IteratorType> template <typename IteratorType>
class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
: 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 >> class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
{ {
public: public:
using type = decltype( using type = decltype(
get<N>(std::declval < get<N>(std::declval <
::nlohmann::detail::iteration_proxy_value<IteratorTy pe >> ())); ::nlohmann::detail::iteration_proxy_value<IteratorTy pe >> ()));
}; };
} #if defined(__clang__)
#pragma clang diagnostic pop
#endif
} // namespace std
// #include <nlohmann/detail/meta/cpp_future.hpp>
// #include <nlohmann/detail/meta/type_traits.hpp>
// #include <nlohmann/detail/value_t.hpp>
namespace nlohmann namespace nlohmann
{ {
namespace detail namespace detail
{ {
////////////////// //////////////////
// constructors // // constructors //
////////////////// //////////////////
template<value_t> struct external_constructor; template<value_t> struct external_constructor;
skipping to change at line 1932 skipping to change at line 3579
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_type = value_t::array; j.m_type = value_t::array;
j.m_value = value_t::array; j.m_value = value_t::array;
j.m_value.array->resize(arr.size()); j.m_value.array->resize(arr.size());
std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin()); if (arr.size() > 0)
{
std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
}
j.assert_invariant(); j.assert_invariant();
} }
}; };
template<> template<>
struct external_constructor<value_t::object> struct external_constructor<value_t::object>
{ {
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::object _t& obj) static void construct(BasicJsonType& j, const typename BasicJsonType::object _t& obj)
{ {
skipping to change at line 2077 skipping to change at line 3727
template < template <
typename BasicJsonType, typename T, std::size_t N, typename BasicJsonType, typename T, std::size_t N,
enable_if_t<not std::is_constructible<typename BasicJsonType::string_t, enable_if_t<not std::is_constructible<typename BasicJsonType::string_t,
const T(&)[N]>::value, const T(&)[N]>::value,
int> = 0 > int> = 0 >
void to_json(BasicJsonType& j, const T(&arr)[N]) void to_json(BasicJsonType& j, const T(&arr)[N])
{ {
external_constructor<value_t::array>::construct(j, arr); external_constructor<value_t::array>::construct(j, arr);
} }
template<typename BasicJsonType, typename... Args> template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::
void to_json(BasicJsonType& j, const std::pair<Args...>& p) is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType
, T2>::value, int > = 0 >
void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
{ {
j = { p.first, p.second }; j = { p.first, p.second };
} }
// for https://github.com/nlohmann/json/pull/1134 // 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 BasicJsonT ype::iterator>>::value, int> = 0> enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonT ype::iterator>>::value, int> = 0>
void to_json(BasicJsonType& j, const T& b) void to_json(BasicJsonType& j, const T& b)
{ {
j = { {b.key(), b.value()} }; j = { {b.key(), b.value()} };
} }
template<typename BasicJsonType, typename Tuple, std::size_t... Idx> template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/) void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
{ {
j = { std::get<Idx>(t)... }; j = { std::get<Idx>(t)... };
} }
template<typename BasicJsonType, typename... Args> template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<
void to_json(BasicJsonType& j, const std::tuple<Args...>& t) BasicJsonType, T>::value, int > = 0>
void to_json(BasicJsonType& j, const T& t)
{ {
to_json_tuple_impl(j, t, index_sequence_for<Args...> {}); to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
} }
struct to_json_fn struct to_json_fn
{ {
template<typename BasicJsonType, typename T> template<typename BasicJsonType, typename T>
auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j , std::forward<T>(val)))) auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j , std::forward<T>(val))))
-> decltype(to_json(j, std::forward<T>(val)), void()) -> decltype(to_json(j, std::forward<T>(val)), void())
{ {
return to_json(j, std::forward<T>(val)); return to_json(j, std::forward<T>(val));
} }
}; };
} // namespace detail } // namespace detail
/// namespace to hold default `to_json` function /// namespace to hold default `to_json` function
namespace namespace
{ {
constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value; constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
} // namespace } // namespace
} // namespace nlohmann
namespace nlohmann
{
template<typename, typename>
struct adl_serializer
{
/*!
@brief convert a JSON value to any value type
This function is usually called by the `get()` function of the
@ref basic_json class (either explicit or via conversion operators).
@param[in] j JSON value to read from
@param[in,out] val value to write to
*/
template<typename BasicJsonType, typename ValueType>
static auto from_json(BasicJsonType&& j, ValueType& val) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void
())
{
::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
}
/*!
@brief convert any value type to a JSON value
This function is usually called by the constructors of the @ref basic_json
class.
@param[in,out] j JSON value to write to
@param[in] val value to read from
*/
template <typename BasicJsonType, typename ValueType>
static auto to_json(BasicJsonType& j, ValueType&& val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<ValueType>(val)), void())
{
::nlohmann::to_json(j, std::forward<ValueType>(val));
}
};
} // namespace nlohmann } // namespace nlohmann
// #include <nlohmann/detail/conversions/from_json.hpp>
// #include <nlohmann/detail/conversions/to_json.hpp>
// #include <nlohmann/detail/exceptions.hpp>
// #include <nlohmann/detail/input/binary_reader.hpp>
#include <algorithm> // generate_n
#include <array> // array
#include <cassert> // assert
#include <cmath> // ldexp
#include <cstddef> // size_t
#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
#include <cstdio> // snprintf
#include <cstring> // memcpy
#include <iterator> // back_inserter
#include <limits> // numeric_limits
#include <string> // char_traits, string
#include <utility> // make_pair, move
// #include <nlohmann/detail/exceptions.hpp>
// #include <nlohmann/detail/input/input_adapters.hpp> // #include <nlohmann/detail/input/input_adapters.hpp>
#include <array> // array
#include <cassert> // assert #include <cassert> // assert
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstdio> //FILE *
#include <cstring> // strlen #include <cstring> // strlen
#include <istream> // istream #include <istream> // istream
#include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next #include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next
#include <memory> // shared_ptr, make_shared, addressof #include <memory> // shared_ptr, make_shared, addressof
#include <numeric> // accumulate #include <numeric> // accumulate
#include <string> // string, char_traits #include <string> // string, char_traits
#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove _pointer #include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove _pointer
#include <utility> // pair, declval #include <utility> // pair, declval
#include <cstdio> //FILE *
// #include <nlohmann/detail/iterators/iterator_traits.hpp>
// #include <nlohmann/detail/macro_scope.hpp> // #include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann namespace nlohmann
{ {
namespace detail namespace detail
{ {
/// the supported input formats /// the supported input formats
enum class input_format_t { json, cbor, msgpack, ubjson, bson }; enum class input_format_t { json, cbor, msgpack, ubjson, bson };
skipping to change at line 2176 skipping to change at line 3895
/// a type to simplify interfaces /// a type to simplify interfaces
using input_adapter_t = std::shared_ptr<input_adapter_protocol>; using input_adapter_t = std::shared_ptr<input_adapter_protocol>;
/*! /*!
Input adapter for stdio file access. This adapter read only 1 byte and do not us e any Input adapter for stdio file access. This adapter read only 1 byte and do not us e any
buffer. This adapter is a very low level adapter. buffer. This adapter is a very low level adapter.
*/ */
class file_input_adapter : public input_adapter_protocol class file_input_adapter : public input_adapter_protocol
{ {
public: public:
JSON_HEDLEY_NON_NULL(2)
explicit file_input_adapter(std::FILE* f) noexcept explicit file_input_adapter(std::FILE* f) noexcept
: m_file(f) : m_file(f)
{} {}
// make class move-only
file_input_adapter(const file_input_adapter&) = delete;
file_input_adapter(file_input_adapter&&) = default;
file_input_adapter& operator=(const file_input_adapter&) = delete;
file_input_adapter& operator=(file_input_adapter&&) = default;
~file_input_adapter() override = default;
std::char_traits<char>::int_type get_character() noexcept override std::char_traits<char>::int_type get_character() noexcept override
{ {
return std::fgetc(m_file); return std::fgetc(m_file);
} }
private: private:
/// the file pointer to read from /// the file pointer to read from
std::FILE* m_file; std::FILE* m_file;
}; };
/*! /*!
Input adapter for a (caching) istream. Ignores a UFT Byte Order Mark at Input adapter for a (caching) istream. Ignores a UFT Byte Order Mark at
beginning of input. Does not support changing the underlying std::streambuf beginning of input. Does not support changing the underlying std::streambuf
in mid-input. Maintains underlying std::istream and std::streambuf to support in mid-input. Maintains underlying std::istream and std::streambuf to support
subsequent use of standard std::istream operations to process any input subsequent use of standard std::istream operations to process any input
skipping to change at line 2243 skipping to change at line 3971
/// the associated input stream /// the associated input stream
std::istream& is; std::istream& is;
std::streambuf& sb; std::streambuf& sb;
}; };
/// input adapter for buffer input /// input adapter for buffer input
class input_buffer_adapter : public input_adapter_protocol class input_buffer_adapter : public input_adapter_protocol
{ {
public: public:
input_buffer_adapter(const char* b, const std::size_t l) noexcept input_buffer_adapter(const char* b, const std::size_t l) noexcept
: cursor(b), limit(b + l) : cursor(b), limit(b == nullptr ? nullptr : (b + l))
{} {}
// delete because of pointer members // delete because of pointer members
input_buffer_adapter(const input_buffer_adapter&) = delete; input_buffer_adapter(const input_buffer_adapter&) = delete;
input_buffer_adapter& operator=(input_buffer_adapter&) = delete; input_buffer_adapter& operator=(input_buffer_adapter&) = delete;
input_buffer_adapter(input_buffer_adapter&&) = delete; input_buffer_adapter(input_buffer_adapter&&) = delete;
input_buffer_adapter& operator=(input_buffer_adapter&&) = delete; input_buffer_adapter& operator=(input_buffer_adapter&&) = delete;
~input_buffer_adapter() override = default; ~input_buffer_adapter() override = default;
std::char_traits<char>::int_type get_character() noexcept override std::char_traits<char>::int_type get_character() noexcept override
{ {
if (JSON_LIKELY(cursor < limit)) if (JSON_HEDLEY_LIKELY(cursor < limit))
{ {
assert(cursor != nullptr and limit != nullptr);
return std::char_traits<char>::to_int_type(*(cursor++)); return std::char_traits<char>::to_int_type(*(cursor++));
} }
return std::char_traits<char>::eof(); return std::char_traits<char>::eof();
} }
private: private:
/// pointer to the current character /// pointer to the current character
const char* cursor; const char* cursor;
/// pointer past the last character /// pointer past the last character
const char* const limit; const char* const limit;
}; };
template<typename WideStringType, size_t T> template<typename WideStringType, size_t T>
struct wide_string_input_helper struct wide_string_input_helper
{ {
// UTF-32 // UTF-32
static void fill_buffer(const WideStringType& str, size_t& current_wchar, st static void fill_buffer(const WideStringType& str,
d::array<std::char_traits<char>::int_type, 4>& utf8_bytes, size_t& utf8_bytes_in size_t& current_wchar,
dex, size_t& utf8_bytes_filled) std::array<std::char_traits<char>::int_type, 4>& utf
8_bytes,
size_t& utf8_bytes_index,
size_t& utf8_bytes_filled)
{ {
utf8_bytes_index = 0; utf8_bytes_index = 0;
if (current_wchar == str.size()) if (current_wchar == str.size())
{ {
utf8_bytes[0] = std::char_traits<char>::eof(); utf8_bytes[0] = std::char_traits<char>::eof();
utf8_bytes_filled = 1; utf8_bytes_filled = 1;
} }
else else
{ {
// get the current character // get the current character
const auto wc = static_cast<int>(str[current_wchar++]); const auto wc = static_cast<unsigned int>(str[current_wchar++]);
// UTF-32 to UTF-8 encoding // UTF-32 to UTF-8 encoding
if (wc < 0x80) if (wc < 0x80)
{ {
utf8_bytes[0] = wc; utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc );
utf8_bytes_filled = 1; utf8_bytes_filled = 1;
} }
else if (wc <= 0x7FF) else if (wc <= 0x7FF)
{ {
utf8_bytes[0] = 0xC0 | ((wc >> 6) & 0x1F); utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0x
utf8_bytes[1] = 0x80 | (wc & 0x3F); C0u | ((wc >> 6u) & 0x1Fu));
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x
80u | (wc & 0x3Fu));
utf8_bytes_filled = 2; utf8_bytes_filled = 2;
} }
else if (wc <= 0xFFFF) else if (wc <= 0xFFFF)
{ {
utf8_bytes[0] = 0xE0 | ((wc >> 12) & 0x0F); utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0x
utf8_bytes[1] = 0x80 | ((wc >> 6) & 0x3F); E0u | ((wc >> 12u) & 0x0Fu));
utf8_bytes[2] = 0x80 | (wc & 0x3F); utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x
80u | ((wc >> 6u) & 0x3Fu));
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x
80u | (wc & 0x3Fu));
utf8_bytes_filled = 3; utf8_bytes_filled = 3;
} }
else if (wc <= 0x10FFFF) else if (wc <= 0x10FFFF)
{ {
utf8_bytes[0] = 0xF0 | ((wc >> 18) & 0x07); utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0x
utf8_bytes[1] = 0x80 | ((wc >> 12) & 0x3F); F0u | ((wc >> 18u) & 0x07u));
utf8_bytes[2] = 0x80 | ((wc >> 6) & 0x3F); utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x
utf8_bytes[3] = 0x80 | (wc & 0x3F); 80u | ((wc >> 12u) & 0x3Fu));
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x
80u | ((wc >> 6u) & 0x3Fu));
utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x
80u | (wc & 0x3Fu));
utf8_bytes_filled = 4; utf8_bytes_filled = 4;
} }
else else
{ {
// unknown character // unknown character
utf8_bytes[0] = wc; utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc );
utf8_bytes_filled = 1; utf8_bytes_filled = 1;
} }
} }
} }
}; };
template<typename WideStringType> template<typename WideStringType>
struct wide_string_input_helper<WideStringType, 2> struct wide_string_input_helper<WideStringType, 2>
{ {
// UTF-16 // UTF-16
static void fill_buffer(const WideStringType& str, size_t& current_wchar, st static void fill_buffer(const WideStringType& str,
d::array<std::char_traits<char>::int_type, 4>& utf8_bytes, size_t& utf8_bytes_in size_t& current_wchar,
dex, size_t& utf8_bytes_filled) std::array<std::char_traits<char>::int_type, 4>& utf
8_bytes,
size_t& utf8_bytes_index,
size_t& utf8_bytes_filled)
{ {
utf8_bytes_index = 0; utf8_bytes_index = 0;
if (current_wchar == str.size()) if (current_wchar == str.size())
{ {
utf8_bytes[0] = std::char_traits<char>::eof(); utf8_bytes[0] = std::char_traits<char>::eof();
utf8_bytes_filled = 1; utf8_bytes_filled = 1;
} }
else else
{ {
// get the current character // get the current character
const auto wc = static_cast<int>(str[current_wchar++]); const auto wc = static_cast<unsigned int>(str[current_wchar++]);
// UTF-16 to UTF-8 encoding // UTF-16 to UTF-8 encoding
if (wc < 0x80) if (wc < 0x80)
{ {
utf8_bytes[0] = wc; utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc );
utf8_bytes_filled = 1; utf8_bytes_filled = 1;
} }
else if (wc <= 0x7FF) else if (wc <= 0x7FF)
{ {
utf8_bytes[0] = 0xC0 | ((wc >> 6)); utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0x
utf8_bytes[1] = 0x80 | (wc & 0x3F); C0u | ((wc >> 6u)));
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x
80u | (wc & 0x3Fu));
utf8_bytes_filled = 2; utf8_bytes_filled = 2;
} }
else if (0xD800 > wc or wc >= 0xE000) else if (0xD800 > wc or wc >= 0xE000)
{ {
utf8_bytes[0] = 0xE0 | ((wc >> 12)); utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0x
utf8_bytes[1] = 0x80 | ((wc >> 6) & 0x3F); E0u | ((wc >> 12u)));
utf8_bytes[2] = 0x80 | (wc & 0x3F); utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x
80u | ((wc >> 6u) & 0x3Fu));
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x
80u | (wc & 0x3Fu));
utf8_bytes_filled = 3; utf8_bytes_filled = 3;
} }
else else
{ {
if (current_wchar < str.size()) if (current_wchar < str.size())
{ {
const auto wc2 = static_cast<int>(str[current_wchar++]); const auto wc2 = static_cast<unsigned int>(str[current_wchar
const int charcode = 0x10000 + (((wc & 0x3FF) << 10) | (wc2 ++]);
& 0x3FF)); const auto charcode = 0x10000u + (((wc & 0x3FFu) << 10u) | (
utf8_bytes[0] = 0xf0 | (charcode >> 18); wc2 & 0x3FFu));
utf8_bytes[1] = 0x80 | ((charcode >> 12) & 0x3F); utf8_bytes[0] = static_cast<std::char_traits<char>::int_type
utf8_bytes[2] = 0x80 | ((charcode >> 6) & 0x3F); >(0xF0u | (charcode >> 18u));
utf8_bytes[3] = 0x80 | (charcode & 0x3F); utf8_bytes[1] = static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
utf8_bytes[3] = static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
utf8_bytes_filled = 4; utf8_bytes_filled = 4;
} }
else else
{ {
// unknown character // unknown character
++current_wchar; ++current_wchar;
utf8_bytes[0] = wc; utf8_bytes[0] = static_cast<std::char_traits<char>::int_type >(wc);
utf8_bytes_filled = 1; utf8_bytes_filled = 1;
} }
} }
} }
} }
}; };
template<typename WideStringType> template<typename WideStringType>
class wide_string_input_adapter : public input_adapter_protocol class wide_string_input_adapter : public input_adapter_protocol
{ {
public: public:
explicit wide_string_input_adapter(const WideStringType& w) noexcept explicit wide_string_input_adapter(const WideStringType& w) noexcept
: str(w) : str(w)
{} {}
std::char_traits<char>::int_type get_character() noexcept override std::char_traits<char>::int_type get_character() noexcept override
{ {
// check if buffer needs to be filled // check if buffer needs to be filled
if (utf8_bytes_index == utf8_bytes_filled) if (utf8_bytes_index == utf8_bytes_filled)
{ {
fill_buffer<sizeof(typename WideStringType::value_type)>(); fill_buffer<sizeof(typename WideStringType::value_type)>();
skipping to change at line 2437 skipping to change at line 4174
/// index to the utf8_codes array for the next valid byte /// index to the utf8_codes array for the next valid byte
std::size_t utf8_bytes_index = 0; std::size_t utf8_bytes_index = 0;
/// number of valid bytes in the utf8_codes array /// number of valid bytes in the utf8_codes array
std::size_t utf8_bytes_filled = 0; std::size_t utf8_bytes_filled = 0;
}; };
class input_adapter class input_adapter
{ {
public: public:
// native support // native support
JSON_HEDLEY_NON_NULL(2)
input_adapter(std::FILE* file) input_adapter(std::FILE* file)
: ia(std::make_shared<file_input_adapter>(file)) {} : ia(std::make_shared<file_input_adapter>(file)) {}
/// input adapter for input stream /// input adapter for input stream
input_adapter(std::istream& i) input_adapter(std::istream& i)
: ia(std::make_shared<input_stream_adapter>(i)) {} : ia(std::make_shared<input_stream_adapter>(i)) {}
/// input adapter for input stream /// input adapter for input stream
input_adapter(std::istream&& i) input_adapter(std::istream&& i)
: ia(std::make_shared<input_stream_adapter>(i)) {} : ia(std::make_shared<input_stream_adapter>(i)) {}
skipping to change at line 2505 skipping to change at line 4243
}).first; }).first;
assert(is_contiguous); assert(is_contiguous);
#endif #endif
// assertion to check that each element is 1 byte long // assertion to check that each element is 1 byte long
static_assert( static_assert(
sizeof(typename iterator_traits<IteratorType>::value_type) == 1, sizeof(typename iterator_traits<IteratorType>::value_type) == 1,
"each element in the iterator range must have the size of 1 byte"); "each element in the iterator range must have the size of 1 byte");
const auto len = static_cast<size_t>(std::distance(first, last)); const auto len = static_cast<size_t>(std::distance(first, last));
if (JSON_LIKELY(len > 0)) if (JSON_HEDLEY_LIKELY(len > 0))
{ {
// there is at least one element: use the address of first // there is at least one element: use the address of first
ia = std::make_shared<input_buffer_adapter>(reinterpret_cast<const c har*>(&(*first)), len); ia = std::make_shared<input_buffer_adapter>(reinterpret_cast<const c har*>(&(*first)), len);
} }
else else
{ {
// the address of first cannot be used: use nullptr // the address of first cannot be used: use nullptr
ia = std::make_shared<input_buffer_adapter>(nullptr, len); ia = std::make_shared<input_buffer_adapter>(nullptr, len);
} }
} }
skipping to change at line 2542 skipping to change at line 4280
return ia; return ia;
} }
private: private:
/// the actual adapter /// the actual adapter
input_adapter_t ia = nullptr; input_adapter_t ia = nullptr;
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann } // namespace nlohmann
// #include <nlohmann/detail/input/json_sax.hpp>
#include <cassert> // assert
#include <cstddef>
#include <string> // string
#include <utility> // move
#include <vector> // vector
// #include <nlohmann/detail/exceptions.hpp>
// #include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann
{
/*!
@brief SAX interface
This class describes the SAX interface used by @ref nlohmann::json::sax_parse.
Each function is called in different situations while the input is parsed. The
boolean return value informs the parser whether to continue processing the
input.
*/
template<typename BasicJsonType>
struct json_sax
{
/// type for (signed) integers
using number_integer_t = typename BasicJsonType::number_integer_t;
/// type for unsigned integers
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
/// type for floating-point numbers
using number_float_t = typename BasicJsonType::number_float_t;
/// type for strings
using string_t = typename BasicJsonType::string_t;
/*!
@brief a null value was read
@return whether parsing should proceed
*/
virtual bool null() = 0;
/*!
@brief a boolean value was read
@param[in] val boolean value
@return whether parsing should proceed
*/
virtual bool boolean(bool val) = 0;
/*!
@brief an integer number was read
@param[in] val integer value
@return whether parsing should proceed
*/
virtual bool number_integer(number_integer_t val) = 0;
/*!
@brief an unsigned integer number was read
@param[in] val unsigned integer value
@return whether parsing should proceed
*/
virtual bool number_unsigned(number_unsigned_t val) = 0;
/*!
@brief an floating-point number was read
@param[in] val floating-point value
@param[in] s raw token value
@return whether parsing should proceed
*/
virtual bool number_float(number_float_t val, const string_t& s) = 0;
/*!
@brief a string was read
@param[in] val string value
@return whether parsing should proceed
@note It is safe to move the passed string.
*/
virtual bool string(string_t& val) = 0;
/*!
@brief the beginning of an object was read
@param[in] elements number of object elements or -1 if unknown
@return whether parsing should proceed
@note binary formats may report the number of elements
*/
virtual bool start_object(std::size_t elements) = 0;
/*!
@brief an object key was read
@param[in] val object key
@return whether parsing should proceed
@note It is safe to move the passed string.
*/
virtual bool key(string_t& val) = 0;
/*!
@brief the end of an object was read
@return whether parsing should proceed
*/
virtual bool end_object() = 0;
/*!
@brief the beginning of an array was read
@param[in] elements number of array elements or -1 if unknown
@return whether parsing should proceed
@note binary formats may report the number of elements
*/
virtual bool start_array(std::size_t elements) = 0;
/*!
@brief the end of an array was read
@return whether parsing should proceed
*/
virtual bool end_array() = 0;
/*!
@brief a parse error occurred
@param[in] position the position in the input where the error occurs
@param[in] last_token the last read token
@param[in] ex an exception object describing the error
@return whether parsing should proceed (must return false)
*/
virtual bool parse_error(std::size_t position,
const std::string& last_token,
const detail::exception& ex) = 0;
virtual ~json_sax() = default;
};
namespace detail
{
/*!
@brief SAX implementation to create a JSON value from SAX events
This class implements the @ref json_sax interface and processes the SAX events
to create a JSON value which makes it basically a DOM parser. The structure or
hierarchy of the JSON value is managed by the stack `ref_stack` which contains
a pointer to the respective array or object for each recursion depth.
After successful parsing, the value that is passed by reference to the
constructor contains the parsed value.
@tparam BasicJsonType the JSON type
*/
template<typename BasicJsonType>
class json_sax_dom_parser
{
public:
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
/*!
@param[in, out] r reference to a JSON value that is manipulated while
parsing
@param[in] allow_exceptions_ whether parse errors yield exceptions
*/
explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_
= true)
: root(r), allow_exceptions(allow_exceptions_)
{}
// make class move-only
json_sax_dom_parser(const json_sax_dom_parser&) = delete;
json_sax_dom_parser(json_sax_dom_parser&&) = default;
json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete;
json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default;
~json_sax_dom_parser() = default;
bool null()
{
handle_value(nullptr);
return true;
}
bool boolean(bool val)
{
handle_value(val);
return true;
}
bool number_integer(number_integer_t val)
{
handle_value(val);
return true;
}
bool number_unsigned(number_unsigned_t val)
{
handle_value(val);
return true;
}
bool number_float(number_float_t val, const string_t& /*unused*/)
{
handle_value(val);
return true;
}
bool string(string_t& val)
{
handle_value(val);
return true;
}
bool start_object(std::size_t len)
{
ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back
()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_
string(len)));
}
return true;
}
bool key(string_t& val)
{
// add null at given key and store the reference for later
object_element = &(ref_stack.back()->m_value.object->operator[](val));
return true;
}
bool end_object()
{
ref_stack.pop_back();
return true;
}
bool start_array(std::size_t len)
{
ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back
()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_s
tring(len)));
}
return true;
}
bool end_array()
{
ref_stack.pop_back();
return true;
}
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,
const detail::exception& ex)
{
errored = true;
if (allow_exceptions)
{
// determine the proper exception type from the id
switch ((ex.id / 100) % 100)
{
case 1:
JSON_THROW(*static_cast<const detail::parse_error*>(&ex));
case 4:
JSON_THROW(*static_cast<const detail::out_of_range*>(&ex));
// LCOV_EXCL_START
case 2:
JSON_THROW(*static_cast<const detail::invalid_iterator*>(&ex
));
case 3:
JSON_THROW(*static_cast<const detail::type_error*>(&ex));
case 5:
JSON_THROW(*static_cast<const detail::other_error*>(&ex));
default:
assert(false);
// LCOV_EXCL_STOP
}
}
return false;
}
constexpr bool is_errored() const
{
return errored;
}
private:
/*!
@invariant If the ref stack is empty, then the passed value will be the new
root.
@invariant If the ref stack contains a value, then it is an array or an
object to which we can add elements
*/
template<typename Value>
JSON_HEDLEY_RETURNS_NON_NULL
BasicJsonType* handle_value(Value&& v)
{
if (ref_stack.empty())
{
root = BasicJsonType(std::forward<Value>(v));
return &root;
}
assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
if (ref_stack.back()->is_array())
{
ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v)
);
return &(ref_stack.back()->m_value.array->back());
}
assert(ref_stack.back()->is_object());
assert(object_element);
*object_element = BasicJsonType(std::forward<Value>(v));
return object_element;
}
/// the parsed JSON value
BasicJsonType& root;
/// stack to model hierarchy of values
std::vector<BasicJsonType*> ref_stack {};
/// helper to hold the reference for the next object element
BasicJsonType* object_element = nullptr;
/// whether a syntax error occurred
bool errored = false;
/// whether to throw exceptions in case of errors
const bool allow_exceptions = true;
};
template<typename BasicJsonType>
class json_sax_dom_callback_parser
{
public:
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using parser_callback_t = typename BasicJsonType::parser_callback_t;
using parse_event_t = typename BasicJsonType::parse_event_t;
json_sax_dom_callback_parser(BasicJsonType& r,
const parser_callback_t cb,
const bool allow_exceptions_ = true)
: root(r), callback(cb), allow_exceptions(allow_exceptions_)
{
keep_stack.push_back(true);
}
// make class move-only
json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete;
json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default;
json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&)
= delete;
json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = de
fault;
~json_sax_dom_callback_parser() = default;
bool null()
{
handle_value(nullptr);
return true;
}
bool boolean(bool val)
{
handle_value(val);
return true;
}
bool number_integer(number_integer_t val)
{
handle_value(val);
return true;
}
bool number_unsigned(number_unsigned_t val)
{
handle_value(val);
return true;
}
bool number_float(number_float_t val, const string_t& /*unused*/)
{
handle_value(val);
return true;
}
bool string(string_t& val)
{
handle_value(val);
return true;
}
bool start_object(std::size_t len)
{
// check callback for object start
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_eve
nt_t::object_start, discarded);
keep_stack.push_back(keep);
auto val = handle_value(BasicJsonType::value_t::object, true);
ref_stack.push_back(val.second);
// check object limit
if (ref_stack.back() and JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and
len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408, "excessive object size: " + std
::to_string(len)));
}
return true;
}
bool key(string_t& val)
{
BasicJsonType k = BasicJsonType(val);
// check callback for key
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_eve
nt_t::key, k);
key_keep_stack.push_back(keep);
// add discarded value at given key and store the reference for later
if (keep and ref_stack.back())
{
object_element = &(ref_stack.back()->m_value.object->operator[](val)
= discarded);
}
return true;
}
bool end_object()
{
if (ref_stack.back() and not callback(static_cast<int>(ref_stack.size())
- 1, parse_event_t::object_end, *ref_stack.back()))
{
// discard object
*ref_stack.back() = discarded;
}
assert(not ref_stack.empty());
assert(not keep_stack.empty());
ref_stack.pop_back();
keep_stack.pop_back();
if (not ref_stack.empty() and ref_stack.back() and ref_stack.back()->is_
object())
{
// remove discarded value
for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->en
d(); ++it)
{
if (it->is_discarded())
{
ref_stack.back()->erase(it);
break;
}
}
}
return true;
}
bool start_array(std::size_t len)
{
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_eve
nt_t::array_start, discarded);
keep_stack.push_back(keep);
auto val = handle_value(BasicJsonType::value_t::array, true);
ref_stack.push_back(val.second);
// check array limit
if (ref_stack.back() and JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and
len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408, "excessive array size: " + std:
:to_string(len)));
}
return true;
}
bool end_array()
{
bool keep = true;
if (ref_stack.back())
{
keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_
t::array_end, *ref_stack.back());
if (not keep)
{
// discard array
*ref_stack.back() = discarded;
}
}
assert(not ref_stack.empty());
assert(not keep_stack.empty());
ref_stack.pop_back();
keep_stack.pop_back();
// remove discarded value
if (not keep and not ref_stack.empty() and ref_stack.back()->is_array())
{
ref_stack.back()->m_value.array->pop_back();
}
return true;
}
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,
const detail::exception& ex)
{
errored = true;
if (allow_exceptions)
{
// determine the proper exception type from the id
switch ((ex.id / 100) % 100)
{
case 1:
JSON_THROW(*static_cast<const detail::parse_error*>(&ex));
case 4:
JSON_THROW(*static_cast<const detail::out_of_range*>(&ex));
// LCOV_EXCL_START
case 2:
JSON_THROW(*static_cast<const detail::invalid_iterator*>(&ex
));
case 3:
JSON_THROW(*static_cast<const detail::type_error*>(&ex));
case 5:
JSON_THROW(*static_cast<const detail::other_error*>(&ex));
default:
assert(false);
// LCOV_EXCL_STOP
}
}
return false;
}
constexpr bool is_errored() const
{
return errored;
}
private:
/*!
@param[in] v value to add to the JSON value we build during parsing
@param[in] skip_callback whether we should skip calling the callback
function; this is required after start_array() and
start_object() SAX events, because otherwise we would call the
callback function with an empty array or object, respectively.
@invariant If the ref stack is empty, then the passed value will be the new
root.
@invariant If the ref stack contains a value, then it is an array or an
object to which we can add elements
@return pair of boolean (whether value should be kept) and pointer (to the
passed value in the ref_stack hierarchy; nullptr if not kept)
*/
template<typename Value>
std::pair<bool, BasicJsonType*> handle_value(Value&& v, const bool skip_call
back = false)
{
assert(not keep_stack.empty());
// do not handle this value if we know it would be added to a discarded
// container
if (not keep_stack.back())
{
return {false, nullptr};
}
// create value
auto value = BasicJsonType(std::forward<Value>(v));
// check callback
const bool keep = skip_callback or callback(static_cast<int>(ref_stack.s
ize()), parse_event_t::value, value);
// do not handle this value if we just learnt it shall be discarded
if (not keep)
{
return {false, nullptr};
}
if (ref_stack.empty())
{
root = std::move(value);
return {true, &root};
}
// skip this value if we already decided to skip the parent
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
if (not ref_stack.back())
{
return {false, nullptr};
}
// we now only expect arrays and objects
assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
// array
if (ref_stack.back()->is_array())
{
ref_stack.back()->m_value.array->push_back(std::move(value));
return {true, &(ref_stack.back()->m_value.array->back())};
}
// object
assert(ref_stack.back()->is_object());
// check if we should store an element for the current key
assert(not key_keep_stack.empty());
const bool store_element = key_keep_stack.back();
key_keep_stack.pop_back();
if (not store_element)
{
return {false, nullptr};
}
assert(object_element);
*object_element = std::move(value);
return {true, object_element};
}
/// the parsed JSON value
BasicJsonType& root;
/// stack to model hierarchy of values
std::vector<BasicJsonType*> ref_stack {};
/// stack to manage which values to keep
std::vector<bool> keep_stack {};
/// stack to manage which object keys to keep
std::vector<bool> key_keep_stack {};
/// helper to hold the reference for the next object element
BasicJsonType* object_element = nullptr;
/// whether a syntax error occurred
bool errored = false;
/// callback function
const parser_callback_t callback = nullptr;
/// whether to throw exceptions in case of errors
const bool allow_exceptions = true;
/// a discarded value for the callback
BasicJsonType discarded = BasicJsonType::value_t::discarded;
};
template<typename BasicJsonType>
class json_sax_acceptor
{
public:
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
bool null()
{
return true;
}
bool boolean(bool /*unused*/)
{
return true;
}
bool number_integer(number_integer_t /*unused*/)
{
return true;
}
bool number_unsigned(number_unsigned_t /*unused*/)
{
return true;
}
bool number_float(number_float_t /*unused*/, const string_t& /*unused*/)
{
return true;
}
bool string(string_t& /*unused*/)
{
return true;
}
bool start_object(std::size_t /*unused*/ = std::size_t(-1))
{
return true;
}
bool key(string_t& /*unused*/)
{
return true;
}
bool end_object()
{
return true;
}
bool start_array(std::size_t /*unused*/ = std::size_t(-1))
{
return true;
}
bool end_array()
{
return true;
}
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, cons
t detail::exception& /*unused*/)
{
return false;
}
};
} // namespace detail
} // namespace nlohmann
// #include <nlohmann/detail/macro_scope.hpp>
// #include <nlohmann/detail/meta/is_sax.hpp>
#include <cstdint> // size_t
#include <utility> // declval
#include <string> // string
// #include <nlohmann/detail/meta/detected.hpp>
// #include <nlohmann/detail/meta/type_traits.hpp>
namespace nlohmann
{
namespace detail
{
template <typename T>
using null_function_t = decltype(std::declval<T&>().null());
template <typename T>
using boolean_function_t =
decltype(std::declval<T&>().boolean(std::declval<bool>()));
template <typename T, typename Integer>
using number_integer_function_t =
decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
template <typename T, typename Unsigned>
using number_unsigned_function_t =
decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
template <typename T, typename Float, typename String>
using number_float_function_t = decltype(std::declval<T&>().number_float(
std::declval<Float>(), std::declval<const St
ring&>()));
template <typename T, typename String>
using string_function_t =
decltype(std::declval<T&>().string(std::declval<String&>()));
template <typename T>
using start_object_function_t =
decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
template <typename T, typename String>
using key_function_t =
decltype(std::declval<T&>().key(std::declval<String&>()));
template <typename T>
using end_object_function_t = decltype(std::declval<T&>().end_object());
template <typename T>
using start_array_function_t =
decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
template <typename T>
using end_array_function_t = decltype(std::declval<T&>().end_array());
template <typename T, typename Exception>
using parse_error_function_t = decltype(std::declval<T&>().parse_error(
std::declval<std::size_t>(), std::declval<const std::string&>(),
std::declval<const Exception&>()));
template <typename SAX, typename BasicJsonType>
struct is_sax
{
private:
static_assert(is_basic_json<BasicJsonType>::value,
"BasicJsonType must be of type basic_json<...>");
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using exception_t = typename BasicJsonType::exception;
public:
static constexpr bool value =
is_detected_exact<bool, null_function_t, SAX>::value &&
is_detected_exact<bool, boolean_function_t, SAX>::value &&
is_detected_exact<bool, number_integer_function_t, SAX,
number_integer_t>::value &&
is_detected_exact<bool, number_unsigned_function_t, SAX,
number_unsigned_t>::value &&
is_detected_exact<bool, number_float_function_t, SAX, number_float_t,
string_t>::value &&
is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
is_detected_exact<bool, start_object_function_t, SAX>::value &&
is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
is_detected_exact<bool, end_object_function_t, SAX>::value &&
is_detected_exact<bool, start_array_function_t, SAX>::value &&
is_detected_exact<bool, end_array_function_t, SAX>::value &&
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value
;
};
template <typename SAX, typename BasicJsonType>
struct is_sax_static_asserts
{
private:
static_assert(is_basic_json<BasicJsonType>::value,
"BasicJsonType must be of type basic_json<...>");
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using exception_t = typename BasicJsonType::exception;
public:
static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
"Missing/invalid function: bool null()");
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
"Missing/invalid function: bool boolean(bool)");
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
"Missing/invalid function: bool boolean(bool)");
static_assert(
is_detected_exact<bool, number_integer_function_t, SAX,
number_integer_t>::value,
"Missing/invalid function: bool number_integer(number_integer_t)");
static_assert(
is_detected_exact<bool, number_unsigned_function_t, SAX,
number_unsigned_t>::value,
"Missing/invalid function: bool number_unsigned(number_unsigned_t)");
static_assert(is_detected_exact<bool, number_float_function_t, SAX,
number_float_t, string_t>::value,
"Missing/invalid function: bool number_float(number_float_t, c
onst string_t&)");
static_assert(
is_detected_exact<bool, string_function_t, SAX, string_t>::value,
"Missing/invalid function: bool string(string_t&)");
static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
"Missing/invalid function: bool start_object(std::size_t)");
static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
"Missing/invalid function: bool key(string_t&)");
static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
"Missing/invalid function: bool end_object()");
static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
"Missing/invalid function: bool start_array(std::size_t)");
static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
"Missing/invalid function: bool end_array()");
static_assert(
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value
,
"Missing/invalid function: bool parse_error(std::size_t, const "
"std::string&, const exception&)");
};
} // namespace detail
} // namespace nlohmann
// #include <nlohmann/detail/value_t.hpp>
namespace nlohmann
{
namespace detail
{
///////////////////
// binary reader //
///////////////////
/*!
@brief deserialization of CBOR, MessagePack, and UBJSON values
*/
template<typename BasicJsonType, typename SAX = json_sax_dom_parser<BasicJsonTyp
e>>
class binary_reader
{
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using json_sax_t = SAX;
public:
/*!
@brief create a binary reader
@param[in] adapter input adapter to read from
*/
explicit binary_reader(input_adapter_t adapter) : ia(std::move(adapter))
{
(void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
assert(ia);
}
// make class move-only
binary_reader(const binary_reader&) = delete;
binary_reader(binary_reader&&) = default;
binary_reader& operator=(const binary_reader&) = delete;
binary_reader& operator=(binary_reader&&) = default;
~binary_reader() = default;
/*!
@param[in] format the binary format to parse
@param[in] sax_ a SAX event processor
@param[in] strict whether to expect the input to be consumed completed
@return
*/
JSON_HEDLEY_NON_NULL(3)
bool sax_parse(const input_format_t format,
json_sax_t* sax_,
const bool strict = true)
{
sax = sax_;
bool result = false;
switch (format)
{
case input_format_t::bson:
result = parse_bson_internal();
break;
case input_format_t::cbor:
result = parse_cbor_internal();
break;
case input_format_t::msgpack:
result = parse_msgpack_internal();
break;
case input_format_t::ubjson:
result = parse_ubjson_internal();
break;
default: // LCOV_EXCL_LINE
assert(false); // LCOV_EXCL_LINE
}
// strict mode: next byte must be EOF
if (result and strict)
{
if (format == input_format_t::ubjson)
{
get_ignore_noop();
}
else
{
get();
}
if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char>::eof()))
{
return sax->parse_error(chars_read, get_token_string(),
parse_error::create(110, chars_read, exc
eption_message(format, "expected end of input; last byte: 0x" + get_token_string
(), "value")));
}
}
return result;
}
/*!
@brief determine system byte order
@return true if and only if system's byte order is little endian
@note from http://stackoverflow.com/a/1001328/266378
*/
static constexpr bool little_endianess(int num = 1) noexcept
{
return *reinterpret_cast<char*>(&num) == 1;
}
private:
//////////
// BSON //
//////////
/*!
@brief Reads in a BSON-object and passes it to the SAX-parser.
@return whether a valid BSON-value was passed to the SAX parser
*/
bool parse_bson_internal()
{
std::int32_t document_size;
get_number<std::int32_t, true>(input_format_t::bson, document_size);
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(not parse_bson_element_list(/*is_array*/false))
)
{
return false;
}
return sax->end_object();
}
/*!
@brief Parses a C-style string from the BSON input.
@param[in, out] result A reference to the string variable where the read
string is to be stored.
@return `true` if the \x00-byte indicating the end of the string was
encountered before the EOF; false` indicates an unexpected EOF.
*/
bool get_bson_cstr(string_t& result)
{
auto out = std::back_inserter(result);
while (true)
{
get();
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::bson, "cst
ring")))
{
return false;
}
if (current == 0x00)
{
return true;
}
*out++ = static_cast<char>(current);
}
return true;
}
/*!
@brief Parses a zero-terminated string of length @a len from the BSON
input.
@param[in] len The length (including the zero-byte at the end) of the
string to be read.
@param[in, out] result A reference to the string variable where the read
string is to be stored.
@tparam NumberType The type of the length @a len
@pre len >= 1
@return `true` if the string was successfully parsed
*/
template<typename NumberType>
bool get_bson_string(const NumberType len, string_t& result)
{
if (JSON_HEDLEY_UNLIKELY(len < 1))
{
auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(
112, chars_read, exception_message(input_format_t::bson, "string length must be
at least 1, is " + std::to_string(len), "string")));
}
return get_string(input_format_t::bson, len - static_cast<NumberType>(1)
, result) and get() != std::char_traits<char>::eof();
}
/*!
@brief Read a BSON document element of the given @a element_type.
@param[in] element_type The BSON element type, c.f. http://bsonspec.org/spec
.html
@param[in] element_type_parse_position The position in the input stream,
where the `element_type` was read.
@warning Not all BSON element types are supported yet. An unsupported
@a element_type will give rise to a parse_error.114:
Unsupported BSON record type 0x...
@return whether a valid BSON-object/array was passed to the SAX parser
*/
bool parse_bson_element_internal(const int element_type,
const std::size_t element_type_parse_positi
on)
{
switch (element_type)
{
case 0x01: // double
{
double number;
return get_number<double, true>(input_format_t::bson, number) an
d sax->number_float(static_cast<number_float_t>(number), "");
}
case 0x02: // string
{
std::int32_t len;
string_t value;
return get_number<std::int32_t, true>(input_format_t::bson, len)
and get_bson_string(len, value) and sax->string(value);
}
case 0x03: // object
{
return parse_bson_internal();
}
case 0x04: // array
{
return parse_bson_array();
}
case 0x08: // boolean
{
return sax->boolean(get() != 0);
}
case 0x0A: // null
{
return sax->null();
}
case 0x10: // int32
{
std::int32_t value;
return get_number<std::int32_t, true>(input_format_t::bson, valu
e) and sax->number_integer(value);
}
case 0x12: // int64
{
std::int64_t value;
return get_number<std::int64_t, true>(input_format_t::bson, valu
e) and sax->number_integer(value);
}
default: // anything else not supported (yet)
{
std::array<char, 3> cr{{}};
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsi
gned char>(element_type));
return sax->parse_error(element_type_parse_position, std::string
(cr.data()), parse_error::create(114, element_type_parse_position, "Unsupported
BSON record type 0x" + std::string(cr.data())));
}
}
}
/*!
@brief Read a BSON element list (as specified in the BSON-spec)
The same binary layout is used for objects and arrays, hence it must be
indicated with the argument @a is_array which one is expected
(true --> array, false --> object).
@param[in] is_array Determines if the element list being read is to be
treated as an object (@a is_array == false), or as an
array (@a is_array == true).
@return whether a valid BSON-object/array was passed to the SAX parser
*/
bool parse_bson_element_list(const bool is_array)
{
string_t key;
while (int element_type = get())
{
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::bson, "ele
ment list")))
{
return false;
}
const std::size_t element_type_parse_position = chars_read;
if (JSON_HEDLEY_UNLIKELY(not get_bson_cstr(key)))
{
return false;
}
if (not is_array and not sax->key(key))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(not parse_bson_element_internal(element_typ
e, element_type_parse_position)))
{
return false;
}
// get_bson_cstr only appends
key.clear();
}
return true;
}
/*!
@brief Reads an array from the BSON input and passes it to the SAX-parser.
@return whether a valid BSON-array was passed to the SAX parser
*/
bool parse_bson_array()
{
std::int32_t document_size;
get_number<std::int32_t, true>(input_format_t::bson, document_size);
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(not parse_bson_element_list(/*is_array*/true)))
{
return false;
}
return sax->end_array();
}
//////////
// CBOR //
//////////
/*!
@param[in] get_char whether a new character should be retrieved from the
input (true, default) or whether the last read
character should be considered instead
@return whether a valid CBOR value was passed to the SAX parser
*/
bool parse_cbor_internal(const bool get_char = true)
{
switch (get_char ? get() : current)
{
// EOF
case std::char_traits<char>::eof():
return unexpect_eof(input_format_t::cbor, "value");
// Integer 0x00..0x17 (0..23)
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
case 0x07:
case 0x08:
case 0x09:
case 0x0A:
case 0x0B:
case 0x0C:
case 0x0D:
case 0x0E:
case 0x0F:
case 0x10:
case 0x11:
case 0x12:
case 0x13:
case 0x14:
case 0x15:
case 0x16:
case 0x17:
return sax->number_unsigned(static_cast<number_unsigned_t>(curre
nt));
case 0x18: // Unsigned integer (one-byte uint8_t follows)
{
std::uint8_t number;
return get_number(input_format_t::cbor, number) and sax->number_
unsigned(number);
}
case 0x19: // Unsigned integer (two-byte uint16_t follows)
{
std::uint16_t number;
return get_number(input_format_t::cbor, number) and sax->number_
unsigned(number);
}
case 0x1A: // Unsigned integer (four-byte uint32_t follows)
{
std::uint32_t number;
return get_number(input_format_t::cbor, number) and sax->number_
unsigned(number);
}
case 0x1B: // Unsigned integer (eight-byte uint64_t follows)
{
std::uint64_t number;
return get_number(input_format_t::cbor, number) and sax->number_
unsigned(number);
}
// Negative integer -1-0x00..-1-0x17 (-1..-24)
case 0x20:
case 0x21:
case 0x22:
case 0x23:
case 0x24:
case 0x25:
case 0x26:
case 0x27:
case 0x28:
case 0x29:
case 0x2A:
case 0x2B:
case 0x2C:
case 0x2D:
case 0x2E:
case 0x2F:
case 0x30:
case 0x31:
case 0x32:
case 0x33:
case 0x34:
case 0x35:
case 0x36:
case 0x37:
return sax->number_integer(static_cast<std::int8_t>(0x20 - 1 - c
urrent));
case 0x38: // Negative integer (one-byte uint8_t follows)
{
std::uint8_t number;
return get_number(input_format_t::cbor, number) and sax->number_
integer(static_cast<number_integer_t>(-1) - number);
}
case 0x39: // Negative integer -1-n (two-byte uint16_t follows)
{
std::uint16_t number;
return get_number(input_format_t::cbor, number) and sax->number_
integer(static_cast<number_integer_t>(-1) - number);
}
case 0x3A: // Negative integer -1-n (four-byte uint32_t follows)
{
std::uint32_t number;
return get_number(input_format_t::cbor, number) and sax->number_
integer(static_cast<number_integer_t>(-1) - number);
}
case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows)
{
std::uint64_t number;
return get_number(input_format_t::cbor, number) and sax->number_
integer(static_cast<number_integer_t>(-1)
- static_cast<number_integer_t>(number));
}
// UTF-8 string (0x00..0x17 bytes follow)
case 0x60:
case 0x61:
case 0x62:
case 0x63:
case 0x64:
case 0x65:
case 0x66:
case 0x67:
case 0x68:
case 0x69:
case 0x6A:
case 0x6B:
case 0x6C:
case 0x6D:
case 0x6E:
case 0x6F:
case 0x70:
case 0x71:
case 0x72:
case 0x73:
case 0x74:
case 0x75:
case 0x76:
case 0x77:
case 0x78: // UTF-8 string (one-byte uint8_t for n follows)
case 0x79: // UTF-8 string (two-byte uint16_t for n follow)
case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)
case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)
case 0x7F: // UTF-8 string (indefinite length)
{
string_t s;
return get_cbor_string(s) and sax->string(s);
}
// array (0x00..0x17 data items follow)
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
return get_cbor_array(static_cast<std::size_t>(static_cast<unsig
ned int>(current) & 0x1Fu));
case 0x98: // array (one-byte uint8_t for n follows)
{
std::uint8_t len;
return get_number(input_format_t::cbor, len) and get_cbor_array(
static_cast<std::size_t>(len));
}
case 0x99: // array (two-byte uint16_t for n follow)
{
std::uint16_t len;
return get_number(input_format_t::cbor, len) and get_cbor_array(
static_cast<std::size_t>(len));
}
case 0x9A: // array (four-byte uint32_t for n follow)
{
std::uint32_t len;
return get_number(input_format_t::cbor, len) and get_cbor_array(
static_cast<std::size_t>(len));
}
case 0x9B: // array (eight-byte uint64_t for n follow)
{
std::uint64_t len;
return get_number(input_format_t::cbor, len) and get_cbor_array(
static_cast<std::size_t>(len));
}
case 0x9F: // array (indefinite length)
return get_cbor_array(std::size_t(-1));
// map (0x00..0x17 pairs of data items follow)
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
return get_cbor_object(static_cast<std::size_t>(static_cast<unsi
gned int>(current) & 0x1Fu));
case 0xB8: // map (one-byte uint8_t for n follows)
{
std::uint8_t len;
return get_number(input_format_t::cbor, len) and get_cbor_object
(static_cast<std::size_t>(len));
}
case 0xB9: // map (two-byte uint16_t for n follow)
{
std::uint16_t len;
return get_number(input_format_t::cbor, len) and get_cbor_object
(static_cast<std::size_t>(len));
}
case 0xBA: // map (four-byte uint32_t for n follow)
{
std::uint32_t len;
return get_number(input_format_t::cbor, len) and get_cbor_object
(static_cast<std::size_t>(len));
}
case 0xBB: // map (eight-byte uint64_t for n follow)
{
std::uint64_t len;
return get_number(input_format_t::cbor, len) and get_cbor_object
(static_cast<std::size_t>(len));
}
case 0xBF: // map (indefinite length)
return get_cbor_object(std::size_t(-1));
case 0xF4: // false
return sax->boolean(false);
case 0xF5: // true
return sax->boolean(true);
case 0xF6: // null
return sax->null();
case 0xF9: // Half-Precision Float (two-byte IEEE 754)
{
const int byte1_raw = get();
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor,
"number")))
{
return false;
}
const int byte2_raw = get();
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor,
"number")))
{
return false;
}
const auto byte1 = static_cast<unsigned char>(byte1_raw);
const auto byte2 = static_cast<unsigned char>(byte2_raw);
// code from RFC 7049, Appendix D, Figure 3:
// As half-precision floating-point numbers were only added
// to IEEE 754 in 2008, today's programming platforms often
// still only have limited support for them. It is very
// easy to include at least decoding support for them even
// without such support. An example of a small decoder for
// half-precision floating-point numbers in the C language
// is shown in Fig. 3.
const auto half = static_cast<unsigned int>((byte1 << 8u) + byte
2);
const double val = [&half]
{
const int exp = (half >> 10u) & 0x1Fu;
const unsigned int mant = half & 0x3FFu;
assert(0 <= exp and exp <= 32);
assert(mant <= 1024);
switch (exp)
{
case 0:
return std::ldexp(mant, -24);
case 31:
return (mant == 0)
? std::numeric_limits<double>::infinity()
: std::numeric_limits<double>::quiet_NaN();
default:
return std::ldexp(mant + 1024, exp - 25);
}
}();
return sax->number_float((half & 0x8000u) != 0
? static_cast<number_float_t>(-val)
: static_cast<number_float_t>(val), "")
;
}
case 0xFA: // Single-Precision Float (four-byte IEEE 754)
{
float number;
return get_number(input_format_t::cbor, number) and sax->number_
float(static_cast<number_float_t>(number), "");
}
case 0xFB: // Double-Precision Float (eight-byte IEEE 754)
{
double number;
return get_number(input_format_t::cbor, number) and sax->number_
float(static_cast<number_float_t>(number), "");
}
default: // anything else (0xFF is handled inside the other types)
{
auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::cre
ate(112, chars_read, exception_message(input_format_t::cbor, "invalid byte: 0x"
+ last_token, "value")));
}
}
}
/*!
@brief reads a CBOR string
This function first reads starting bytes to determine the expected
string length and then copies this number of bytes into a string.
Additionally, CBOR's strings with indefinite lengths are supported.
@param[out] result created string
@return whether string creation completed
*/
bool get_cbor_string(string_t& result)
{
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "string"
)))
{
return false;
}
switch (current)
{
// UTF-8 string (0x00..0x17 bytes follow)
case 0x60:
case 0x61:
case 0x62:
case 0x63:
case 0x64:
case 0x65:
case 0x66:
case 0x67:
case 0x68:
case 0x69:
case 0x6A:
case 0x6B:
case 0x6C:
case 0x6D:
case 0x6E:
case 0x6F:
case 0x70:
case 0x71:
case 0x72:
case 0x73:
case 0x74:
case 0x75:
case 0x76:
case 0x77:
{
return get_string(input_format_t::cbor, static_cast<unsigned int
>(current) & 0x1Fu, result);
}
case 0x78: // UTF-8 string (one-byte uint8_t for n follows)
{
std::uint8_t len;
return get_number(input_format_t::cbor, len) and get_string(inpu
t_format_t::cbor, len, result);
}
case 0x79: // UTF-8 string (two-byte uint16_t for n follow)
{
std::uint16_t len;
return get_number(input_format_t::cbor, len) and get_string(inpu
t_format_t::cbor, len, result);
}
case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)
{
std::uint32_t len;
return get_number(input_format_t::cbor, len) and get_string(inpu
t_format_t::cbor, len, result);
}
case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)
{
std::uint64_t len;
return get_number(input_format_t::cbor, len) and get_string(inpu
t_format_t::cbor, len, result);
}
case 0x7F: // UTF-8 string (indefinite length)
{
while (get() != 0xFF)
{
string_t chunk;
if (not get_cbor_string(chunk))
{
return false;
}
result.append(chunk);
}
return true;
}
default:
{
auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::cre
ate(113, chars_read, exception_message(input_format_t::cbor, "expected length sp
ecification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x" + last_
token, "string")));
}
}
}
/*!
@param[in] len the length of the array or std::size_t(-1) for an
array of indefinite size
@return whether array creation completed
*/
bool get_cbor_array(const std::size_t len)
{
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(len)))
{
return false;
}
if (len != std::size_t(-1))
{
for (std::size_t i = 0; i < len; ++i)
{
if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
{
return false;
}
}
}
else
{
while (get() != 0xFF)
{
if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal(false)))
{
return false;
}
}
}
return sax->end_array();
}
/*!
@param[in] len the length of the object or std::size_t(-1) for an
object of indefinite size
@return whether object creation completed
*/
bool get_cbor_object(const std::size_t len)
{
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(len)))
{
return false;
}
string_t key;
if (len != std::size_t(-1))
{
for (std::size_t i = 0; i < len; ++i)
{
get();
if (JSON_HEDLEY_UNLIKELY(not get_cbor_string(key) or not sax->ke
y(key)))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
{
return false;
}
key.clear();
}
}
else
{
while (get() != 0xFF)
{
if (JSON_HEDLEY_UNLIKELY(not get_cbor_string(key) or not sax->ke
y(key)))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
{
return false;
}
key.clear();
}
}
return sax->end_object();
}
/////////////
// MsgPack //
/////////////
/*!
@return whether a valid MessagePack value was passed to the SAX parser
*/
bool parse_msgpack_internal()
{
switch (get())
{
// EOF
case std::char_traits<char>::eof():
return unexpect_eof(input_format_t::msgpack, "value");
// positive fixint
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
case 0x07:
case 0x08:
case 0x09:
case 0x0A:
case 0x0B:
case 0x0C:
case 0x0D:
case 0x0E:
case 0x0F:
case 0x10:
case 0x11:
case 0x12:
case 0x13:
case 0x14:
case 0x15:
case 0x16:
case 0x17:
case 0x18:
case 0x19:
case 0x1A:
case 0x1B:
case 0x1C:
case 0x1D:
case 0x1E:
case 0x1F:
case 0x20:
case 0x21:
case 0x22:
case 0x23:
case 0x24:
case 0x25:
case 0x26:
case 0x27:
case 0x28:
case 0x29:
case 0x2A:
case 0x2B:
case 0x2C:
case 0x2D:
case 0x2E:
case 0x2F:
case 0x30:
case 0x31:
case 0x32:
case 0x33:
case 0x34:
case 0x35:
case 0x36:
case 0x37:
case 0x38:
case 0x39:
case 0x3A:
case 0x3B:
case 0x3C:
case 0x3D:
case 0x3E:
case 0x3F:
case 0x40:
case 0x41:
case 0x42:
case 0x43:
case 0x44:
case 0x45:
case 0x46:
case 0x47:
case 0x48:
case 0x49:
case 0x4A:
case 0x4B:
case 0x4C:
case 0x4D:
case 0x4E:
case 0x4F:
case 0x50:
case 0x51:
case 0x52:
case 0x53:
case 0x54:
case 0x55:
case 0x56:
case 0x57:
case 0x58:
case 0x59:
case 0x5A:
case 0x5B:
case 0x5C:
case 0x5D:
case 0x5E:
case 0x5F:
case 0x60:
case 0x61:
case 0x62:
case 0x63:
case 0x64:
case 0x65:
case 0x66:
case 0x67:
case 0x68:
case 0x69:
case 0x6A:
case 0x6B:
case 0x6C:
case 0x6D:
case 0x6E:
case 0x6F:
case 0x70:
case 0x71:
case 0x72:
case 0x73:
case 0x74:
case 0x75:
case 0x76:
case 0x77:
case 0x78:
case 0x79:
case 0x7A:
case 0x7B:
case 0x7C:
case 0x7D:
case 0x7E:
case 0x7F:
return sax->number_unsigned(static_cast<number_unsigned_t>(curre
nt));
// fixmap
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
return get_msgpack_object(static_cast<std::size_t>(static_cast<u
nsigned int>(current) & 0x0Fu));
// fixarray
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
return get_msgpack_array(static_cast<std::size_t>(static_cast<un
signed int>(current) & 0x0Fu));
// fixstr
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF:
case 0xD9: // str 8
case 0xDA: // str 16
case 0xDB: // str 32
{
string_t s;
return get_msgpack_string(s) and sax->string(s);
}
case 0xC0: // nil
return sax->null();
case 0xC2: // false
return sax->boolean(false);
case 0xC3: // true
return sax->boolean(true);
case 0xCA: // float 32
{
float number;
return get_number(input_format_t::msgpack, number) and sax->numb
er_float(static_cast<number_float_t>(number), "");
}
case 0xCB: // float 64
{
double number;
return get_number(input_format_t::msgpack, number) and sax->numb
er_float(static_cast<number_float_t>(number), "");
}
case 0xCC: // uint 8
{
std::uint8_t number;
return get_number(input_format_t::msgpack, number) and sax->numb
er_unsigned(number);
}
case 0xCD: // uint 16
{
std::uint16_t number;
return get_number(input_format_t::msgpack, number) and sax->numb
er_unsigned(number);
}
case 0xCE: // uint 32
{
std::uint32_t number;
return get_number(input_format_t::msgpack, number) and sax->numb
er_unsigned(number);
}
case 0xCF: // uint 64
{
std::uint64_t number;
return get_number(input_format_t::msgpack, number) and sax->numb
er_unsigned(number);
}
case 0xD0: // int 8
{
std::int8_t number;
return get_number(input_format_t::msgpack, number) and sax->numb
er_integer(number);
}
case 0xD1: // int 16
{
std::int16_t number;
return get_number(input_format_t::msgpack, number) and sax->numb
er_integer(number);
}
case 0xD2: // int 32
{
std::int32_t number;
return get_number(input_format_t::msgpack, number) and sax->numb
er_integer(number);
}
case 0xD3: // int 64
{
std::int64_t number;
return get_number(input_format_t::msgpack, number) and sax->numb
er_integer(number);
}
case 0xDC: // array 16
{
std::uint16_t len;
return get_number(input_format_t::msgpack, len) and get_msgpack_
array(static_cast<std::size_t>(len));
}
case 0xDD: // array 32
{
std::uint32_t len;
return get_number(input_format_t::msgpack, len) and get_msgpack_
array(static_cast<std::size_t>(len));
}
case 0xDE: // map 16
{
std::uint16_t len;
return get_number(input_format_t::msgpack, len) and get_msgpack_
object(static_cast<std::size_t>(len));
}
case 0xDF: // map 32
{
std::uint32_t len;
return get_number(input_format_t::msgpack, len) and get_msgpack_
object(static_cast<std::size_t>(len));
}
// negative fixint
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4:
case 0xF5:
case 0xF6:
case 0xF7:
case 0xF8:
case 0xF9:
case 0xFA:
case 0xFB:
case 0xFC:
case 0xFD:
case 0xFE:
case 0xFF:
return sax->number_integer(static_cast<std::int8_t>(current));
default: // anything else
{
auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::cre
ate(112, chars_read, exception_message(input_format_t::msgpack, "invalid byte: 0
x" + last_token, "value")));
}
}
}
/*!
@brief reads a MessagePack string
This function first reads starting bytes to determine the expected
string length and then copies this number of bytes into a string.
@param[out] result created string
@return whether string creation completed
*/
bool get_msgpack_string(string_t& result)
{
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::msgpack, "stri
ng")))
{
return false;
}
switch (current)
{
// fixstr
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF:
{
return get_string(input_format_t::msgpack, static_cast<unsigned
int>(current) & 0x1Fu, result);
}
case 0xD9: // str 8
{
std::uint8_t len;
return get_number(input_format_t::msgpack, len) and get_string(i
nput_format_t::msgpack, len, result);
}
case 0xDA: // str 16
{
std::uint16_t len;
return get_number(input_format_t::msgpack, len) and get_string(i
nput_format_t::msgpack, len, result);
}
case 0xDB: // str 32
{
std::uint32_t len;
return get_number(input_format_t::msgpack, len) and get_string(i
nput_format_t::msgpack, len, result);
}
default:
{
auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::cre
ate(113, chars_read, exception_message(input_format_t::msgpack, "expected length
specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x" + last_token, "string")));
}
}
}
/*!
@param[in] len the length of the array
@return whether array creation completed
*/
bool get_msgpack_array(const std::size_t len)
{
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(len)))
{
return false;
}
for (std::size_t i = 0; i < len; ++i)
{
if (JSON_HEDLEY_UNLIKELY(not parse_msgpack_internal()))
{
return false;
}
}
return sax->end_array();
}
/*!
@param[in] len the length of the object
@return whether object creation completed
*/
bool get_msgpack_object(const std::size_t len)
{
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(len)))
{
return false;
}
string_t key;
for (std::size_t i = 0; i < len; ++i)
{
get();
if (JSON_HEDLEY_UNLIKELY(not get_msgpack_string(key) or not sax->key
(key)))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(not parse_msgpack_internal()))
{
return false;
}
key.clear();
}
return sax->end_object();
}
////////////
// UBJSON //
////////////
/*!
@param[in] get_char whether a new character should be retrieved from the
input (true, default) or whether the last read
character should be considered instead
@return whether a valid UBJSON value was passed to the SAX parser
*/
bool parse_ubjson_internal(const bool get_char = true)
{
return get_ubjson_value(get_char ? get_ignore_noop() : current);
}
/*!
@brief reads a UBJSON string
This function is either called after reading the 'S' byte explicitly
indicating a string, or in case of an object key where the 'S' byte can be
left out.
@param[out] result created string
@param[in] get_char whether a new character should be retrieved from the
input (true, default) or whether the last read
character should be considered instead
@return whether string creation completed
*/
bool get_ubjson_string(string_t& result, const bool get_char = true)
{
if (get_char)
{
get(); // TODO(niels): may we ignore N here?
}
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "value
")))
{
return false;
}
switch (current)
{
case 'U':
{
std::uint8_t len;
return get_number(input_format_t::ubjson, len) and get_string(in
put_format_t::ubjson, len, result);
}
case 'i':
{
std::int8_t len;
return get_number(input_format_t::ubjson, len) and get_string(in
put_format_t::ubjson, len, result);
}
case 'I':
{
std::int16_t len;
return get_number(input_format_t::ubjson, len) and get_string(in
put_format_t::ubjson, len, result);
}
case 'l':
{
std::int32_t len;
return get_number(input_format_t::ubjson, len) and get_string(in
put_format_t::ubjson, len, result);
}
case 'L':
{
std::int64_t len;
return get_number(input_format_t::ubjson, len) and get_string(in
put_format_t::ubjson, len, result);
}
default:
auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::cre
ate(113, chars_read, exception_message(input_format_t::ubjson, "expected length
type specification (U, i, I, l, L); last byte: 0x" + last_token, "string")));
}
}
/*!
@param[out] result determined size
@return whether size determination completed
*/
bool get_ubjson_size_value(std::size_t& result)
{
switch (get_ignore_noop())
{
case 'U':
{
std::uint8_t number;
if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson,
number)))
{
return false;
}
result = static_cast<std::size_t>(number);
return true;
}
case 'i':
{
std::int8_t number;
if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson,
number)))
{
return false;
}
result = static_cast<std::size_t>(number);
return true;
}
case 'I':
{
std::int16_t number;
if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson,
number)))
{
return false;
}
result = static_cast<std::size_t>(number);
return true;
}
case 'l':
{
std::int32_t number;
if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson,
number)))
{
return false;
}
result = static_cast<std::size_t>(number);
return true;
}
case 'L':
{
std::int64_t number;
if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson,
number)))
{
return false;
}
result = static_cast<std::size_t>(number);
return true;
}
default:
{
auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::cre
ate(113, chars_read, exception_message(input_format_t::ubjson, "expected length
type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token, "size
")));
}
}
}
/*!
@brief determine the type and size for a container
In the optimized UBJSON format, a type and a size can be provided to allow
for a more compact representation.
@param[out] result pair of the size and the type
@return whether pair creation completed
*/
bool get_ubjson_size_type(std::pair<std::size_t, int>& result)
{
result.first = string_t::npos; // size
result.second = 0; // type
get_ignore_noop();
if (current == '$')
{
result.second = get(); // must not ignore 'N', because 'N' maybe th
e type
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "t
ype")))
{
return false;
}
get_ignore_noop();
if (JSON_HEDLEY_UNLIKELY(current != '#'))
{
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson
, "value")))
{
return false;
}
auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::cre
ate(112, chars_read, exception_message(input_format_t::ubjson, "expected '#' aft
er type information; last byte: 0x" + last_token, "size")));
}
return get_ubjson_size_value(result.first);
}
if (current == '#')
{
return get_ubjson_size_value(result.first);
}
return true;
}
/*!
@param prefix the previously read or set type prefix
@return whether value creation completed
*/
bool get_ubjson_value(const int prefix)
{
switch (prefix)
{
case std::char_traits<char>::eof(): // EOF
return unexpect_eof(input_format_t::ubjson, "value");
case 'T': // true
return sax->boolean(true);
case 'F': // false
return sax->boolean(false);
case 'Z': // null
return sax->null();
case 'U':
{
std::uint8_t number;
return get_number(input_format_t::ubjson, number) and sax->numbe
r_unsigned(number);
}
case 'i':
{
std::int8_t number;
return get_number(input_format_t::ubjson, number) and sax->numbe
r_integer(number);
}
case 'I':
{
std::int16_t number;
return get_number(input_format_t::ubjson, number) and sax->numbe
r_integer(number);
}
case 'l':
{
std::int32_t number;
return get_number(input_format_t::ubjson, number) and sax->numbe
r_integer(number);
}
case 'L':
{
std::int64_t number;
return get_number(input_format_t::ubjson, number) and sax->numbe
r_integer(number);
}
case 'd':
{
float number;
return get_number(input_format_t::ubjson, number) and sax->numbe
r_float(static_cast<number_float_t>(number), "");
}
case 'D':
{
double number;
return get_number(input_format_t::ubjson, number) and sax->numbe
r_float(static_cast<number_float_t>(number), "");
}
case 'C': // char
{
get();
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson
, "char")))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(current > 127))
{
auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error:
:create(113, chars_read, exception_message(input_format_t::ubjson, "byte after '
C' must be in range 0x00..0x7F; last byte: 0x" + last_token, "char")));
}
string_t s(1, static_cast<char>(current));
return sax->string(s);
}
case 'S': // string
{
string_t s;
return get_ubjson_string(s) and sax->string(s);
}
case '[': // array
return get_ubjson_array();
case '{': // object
return get_ubjson_object();
default: // anything else
{
auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::cre
ate(112, chars_read, exception_message(input_format_t::ubjson, "invalid byte: 0x
" + last_token, "value")));
}
}
}
/*!
@return whether array creation completed
*/
bool get_ubjson_array()
{
std::pair<std::size_t, int> size_and_type;
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type)))
{
return false;
}
if (size_and_type.first != string_t::npos)
{
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(size_and_type.first)))
{
return false;
}
if (size_and_type.second != 0)
{
if (size_and_type.second != 'N')
{
for (std::size_t i = 0; i < size_and_type.first; ++i)
{
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_value(size_and_t
ype.second)))
{
return false;
}
}
}
}
else
{
for (std::size_t i = 0; i < size_and_type.first; ++i)
{
if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
{
return false;
}
}
}
}
else
{
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
{
return false;
}
while (current != ']')
{
if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal(false)))
{
return false;
}
get_ignore_noop();
}
}
return sax->end_array();
}
/*!
@return whether object creation completed
*/
bool get_ubjson_object()
{
std::pair<std::size_t, int> size_and_type;
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type)))
{
return false;
}
string_t key;
if (size_and_type.first != string_t::npos)
{
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(size_and_type.first))
)
{
return false;
}
if (size_and_type.second != 0)
{
for (std::size_t i = 0; i < size_and_type.first; ++i)
{
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or not s
ax->key(key)))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_value(size_and_type.
second)))
{
return false;
}
key.clear();
}
}
else
{
for (std::size_t i = 0; i < size_and_type.first; ++i)
{
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or not s
ax->key(key)))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
{
return false;
}
key.clear();
}
}
}
else
{
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
{
return false;
}
while (current != '}')
{
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key, false) or no
t sax->key(key)))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
{
return false;
}
get_ignore_noop();
key.clear();
}
}
return sax->end_object();
}
///////////////////////
// Utility functions //
///////////////////////
/*!
@brief get next character from the input
This function provides the interface to the used input adapter. It does
not throw in case the input reached EOF, but returns a -'ve valued
`std::char_traits<char>::eof()` in that case.
@return character read from the input
*/
int get()
{
++chars_read;
return current = ia->get_character();
}
/*!
@return character read from the input after ignoring all 'N' entries
*/
int get_ignore_noop()
{
do
{
get();
}
while (current == 'N');
return current;
}
/*
@brief read a number from the input
@tparam NumberType the type of the number
@param[in] format the current format (for diagnostics)
@param[out] result number of type @a NumberType
@return whether conversion completed
@note This function needs to respect the system's endianess, because
bytes in CBOR, MessagePack, and UBJSON are stored in network order
(big endian) and therefore need reordering on little endian systems.
*/
template<typename NumberType, bool InputIsLittleEndian = false>
bool get_number(const input_format_t format, NumberType& result)
{
// step 1: read input into array with system's byte order
std::array<std::uint8_t, sizeof(NumberType)> vec;
for (std::size_t i = 0; i < sizeof(NumberType); ++i)
{
get();
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(format, "number")))
{
return false;
}
// reverse byte order prior to conversion if necessary
if (is_little_endian != InputIsLittleEndian)
{
vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(curr
ent);
}
else
{
vec[i] = static_cast<std::uint8_t>(current); // LCOV_EXCL_LINE
}
}
// step 2: convert array into number of type T and return
std::memcpy(&result, vec.data(), sizeof(NumberType));
return true;
}
/*!
@brief create a string by reading characters from the input
@tparam NumberType the type of the number
@param[in] format the current format (for diagnostics)
@param[in] len number of characters to read
@param[out] result string created by reading @a len bytes
@return whether string creation completed
@note We can not reserve @a len bytes for the result, because @a len
may be too large. Usually, @ref unexpect_eof() detects the end of
the input before we run out of string memory.
*/
template<typename NumberType>
bool get_string(const input_format_t format,
const NumberType len,
string_t& result)
{
bool success = true;
std::generate_n(std::back_inserter(result), len, [this, &success, &forma
t]()
{
get();
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(format, "string")))
{
success = false;
}
return static_cast<char>(current);
});
return success;
}
/*!
@param[in] format the current format (for diagnostics)
@param[in] context further context information (for diagnostics)
@return whether the last read character is not EOF
*/
JSON_HEDLEY_NON_NULL(3)
bool unexpect_eof(const input_format_t format, const char* context) const
{
if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char>::eof()))
{
return sax->parse_error(chars_read, "<end of file>",
parse_error::create(110, chars_read, excepti
on_message(format, "unexpected end of input", context)));
}
return true;
}
/*!
@return a string representation of the last read byte
*/
std::string get_token_string() const
{
std::array<char, 3> cr{{}};
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned cha
r>(current));
return std::string{cr.data()};
}
/*!
@param[in] format the current format
@param[in] detail a detailed error message
@param[in] context further context information
@return a message string to use in the parse_error exceptions
*/
std::string exception_message(const input_format_t format,
const std::string& detail,
const std::string& context) const
{
std::string error_msg = "syntax error while parsing ";
switch (format)
{
case input_format_t::cbor:
error_msg += "CBOR";
break;
case input_format_t::msgpack:
error_msg += "MessagePack";
break;
case input_format_t::ubjson:
error_msg += "UBJSON";
break;
case input_format_t::bson:
error_msg += "BSON";
break;
default: // LCOV_EXCL_LINE
assert(false); // LCOV_EXCL_LINE
}
return error_msg + " " + context + ": " + detail;
}
private:
/// input adapter
input_adapter_t ia = nullptr;
/// the current character
int current = std::char_traits<char>::eof();
/// the number of characters read
std::size_t chars_read = 0;
/// whether we can assume little endianess
const bool is_little_endian = little_endianess();
/// the SAX parser
json_sax_t* sax = nullptr;
};
} // namespace detail
} // namespace nlohmann
// #include <nlohmann/detail/input/input_adapters.hpp>
// #include <nlohmann/detail/input/lexer.hpp> // #include <nlohmann/detail/input/lexer.hpp>
#include <array> // array
#include <clocale> // localeconv #include <clocale> // localeconv
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull
#include <cstdio> // snprintf #include <cstdio> // snprintf
#include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull
#include <initializer_list> // initializer_list #include <initializer_list> // initializer_list
#include <string> // char_traits, string #include <string> // char_traits, string
#include <utility> // move
#include <vector> // vector #include <vector> // vector
// #include <nlohmann/detail/macro_scope.hpp>
// #include <nlohmann/detail/input/input_adapters.hpp> // #include <nlohmann/detail/input/input_adapters.hpp>
// #include <nlohmann/detail/input/position_t.hpp> // #include <nlohmann/detail/input/position_t.hpp>
// #include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann namespace nlohmann
{ {
namespace detail namespace detail
{ {
/////////// ///////////
// lexer // // lexer //
/////////// ///////////
/*! /*!
@brief lexical analysis @brief lexical analysis
skipping to change at line 2603 skipping to change at line 7157
end_array, ///< the character for array end `]` end_array, ///< the character for array end `]`
end_object, ///< the character for object end `}` end_object, ///< the character for object end `}`
name_separator, ///< the name separator `:` name_separator, ///< the name separator `:`
value_separator, ///< the value separator `,` value_separator, ///< the value separator `,`
parse_error, ///< indicating a parse error parse_error, ///< indicating a parse error
end_of_input, ///< indicating the end of the input buffer end_of_input, ///< indicating the end of the input buffer
literal_or_value ///< a literal or the begin of a value (only for diagn ostics) literal_or_value ///< a literal or the begin of a value (only for diagn ostics)
}; };
/// return name of values of type token_type (only used for errors) /// return name of values of type token_type (only used for errors)
JSON_HEDLEY_RETURNS_NON_NULL
JSON_HEDLEY_CONST
static const char* token_type_name(const token_type t) noexcept static const char* token_type_name(const token_type t) noexcept
{ {
switch (t) switch (t)
{ {
case token_type::uninitialized: case token_type::uninitialized:
return "<uninitialized>"; return "<uninitialized>";
case token_type::literal_true: case token_type::literal_true:
return "true literal"; return "true literal";
case token_type::literal_false: case token_type::literal_false:
return "false literal"; return "false literal";
skipping to change at line 2662 skipping to change at line 7218
lexer& operator=(lexer&) = delete; lexer& operator=(lexer&) = delete;
lexer& operator=(lexer&&) = delete; lexer& operator=(lexer&&) = delete;
~lexer() = default; ~lexer() = default;
private: private:
///////////////////// /////////////////////
// locales // locales
///////////////////// /////////////////////
/// return the locale-dependent decimal point /// return the locale-dependent decimal point
JSON_HEDLEY_PURE
static char get_decimal_point() noexcept static char get_decimal_point() noexcept
{ {
const auto loc = localeconv(); const auto loc = localeconv();
assert(loc != nullptr); assert(loc != nullptr);
return (loc->decimal_point == nullptr) ? '.' : *(loc->decimal_point); return (loc->decimal_point == nullptr) ? '.' : *(loc->decimal_point);
} }
///////////////////// /////////////////////
// scan functions // scan functions
///////////////////// /////////////////////
skipping to change at line 2694 skipping to change at line 7251
@return codepoint (0x0000..0xFFFF) or -1 in case of an error (e.g. EOF or @return codepoint (0x0000..0xFFFF) or -1 in case of an error (e.g. EOF or
non-hex character) non-hex character)
*/ */
int get_codepoint() int get_codepoint()
{ {
// this function only makes sense after reading `\u` // this function only makes sense after reading `\u`
assert(current == 'u'); assert(current == 'u');
int codepoint = 0; int codepoint = 0;
const auto factors = { 12, 8, 4, 0 }; const auto factors = { 12u, 8u, 4u, 0u };
for (const auto factor : factors) for (const auto factor : factors)
{ {
get(); get();
if (current >= '0' and current <= '9') if (current >= '0' and current <= '9')
{ {
codepoint += ((current - 0x30) << factor); codepoint += static_cast<int>((static_cast<unsigned int>(current ) - 0x30u) << factor);
} }
else if (current >= 'A' and current <= 'F') else if (current >= 'A' and current <= 'F')
{ {
codepoint += ((current - 0x37) << factor); codepoint += static_cast<int>((static_cast<unsigned int>(current ) - 0x37u) << factor);
} }
else if (current >= 'a' and current <= 'f') else if (current >= 'a' and current <= 'f')
{ {
codepoint += ((current - 0x57) << factor); codepoint += static_cast<int>((static_cast<unsigned int>(current ) - 0x57u) << factor);
} }
else else
{ {
return -1; return -1;
} }
} }
assert(0x0000 <= codepoint and codepoint <= 0xFFFF); assert(0x0000 <= codepoint and codepoint <= 0xFFFF);
return codepoint; return codepoint;
} }
skipping to change at line 2744 skipping to change at line 7301
@return true if and only if no range violation was detected @return true if and only if no range violation was detected
*/ */
bool next_byte_in_range(std::initializer_list<int> ranges) bool next_byte_in_range(std::initializer_list<int> ranges)
{ {
assert(ranges.size() == 2 or ranges.size() == 4 or ranges.size() == 6); assert(ranges.size() == 2 or ranges.size() == 4 or ranges.size() == 6);
add(current); add(current);
for (auto range = ranges.begin(); range != ranges.end(); ++range) for (auto range = ranges.begin(); range != ranges.end(); ++range)
{ {
get(); get();
if (JSON_LIKELY(*range <= current and current <= *(++range))) if (JSON_HEDLEY_LIKELY(*range <= current and current <= *(++range)))
{ {
add(current); add(current);
} }
else else
{ {
error_message = "invalid string: ill-formed UTF-8 byte"; error_message = "invalid string: ill-formed UTF-8 byte";
return false; return false;
} }
} }
skipping to change at line 2843 skipping to change at line 7400
case 't': case 't':
add('\t'); add('\t');
break; break;
// unicode escapes // unicode escapes
case 'u': case 'u':
{ {
const int codepoint1 = get_codepoint(); const int codepoint1 = get_codepoint();
int codepoint = codepoint1; // start with codepoint1 int codepoint = codepoint1; // start with codepoint1
if (JSON_UNLIKELY(codepoint1 == -1)) if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
{ {
error_message = "invalid string: '\\u' must be f ollowed by 4 hex digits"; error_message = "invalid string: '\\u' must be f ollowed by 4 hex digits";
return token_type::parse_error; return token_type::parse_error;
} }
// check if code point is a high surrogate // check if code point is a high surrogate
if (0xD800 <= codepoint1 and codepoint1 <= 0xDBFF) if (0xD800 <= codepoint1 and codepoint1 <= 0xDBFF)
{ {
// expect next \uxxxx entry // expect next \uxxxx entry
if (JSON_LIKELY(get() == '\\' and get() == 'u')) if (JSON_HEDLEY_LIKELY(get() == '\\' and get() = = 'u'))
{ {
const int codepoint2 = get_codepoint(); const int codepoint2 = get_codepoint();
if (JSON_UNLIKELY(codepoint2 == -1)) if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
{ {
error_message = "invalid string: '\\u' m ust be followed by 4 hex digits"; error_message = "invalid string: '\\u' m ust be followed by 4 hex digits";
return token_type::parse_error; return token_type::parse_error;
} }
// check if codepoint2 is a low surrogate // check if codepoint2 is a low surrogate
if (JSON_LIKELY(0xDC00 <= codepoint2 and cod epoint2 <= 0xDFFF)) if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 and codepoint2 <= 0xDFFF))
{ {
// overwrite codepoint // overwrite codepoint
codepoint = codepoint = static_cast<int>(
// high surrogate occupies the most // high surrogate occupi
significant 22 bits es the most significant 22 bits
(codepoint1 << 10) (static_cast<unsigned in
// low surrogate occupies the least t>(codepoint1) << 10u)
significant 15 bits // low surrogate occupie
+ codepoint2 s the least significant 15 bits
// there is still the 0xD800, 0xDC00 + static_cast<unsigned i
and 0x10000 noise nt>(codepoint2)
// in the result so we have to subtr // there is still the 0x
act with: D800, 0xDC00 and 0x10000 noise
// (0xD800 << 10) + DC00 - 0x10000 = // in the result so we h
0x35FDC00 ave to subtract with:
- 0x35FDC00; // (0xD800 << 10) + DC00
- 0x10000 = 0x35FDC00
- 0x35FDC00u);
} }
else else
{ {
error_message = "invalid string: surroga te U+DC00..U+DFFF must be followed by U+DC00..U+DFFF"; error_message = "invalid string: surroga te U+DC00..U+DFFF must be followed by U+DC00..U+DFFF";
return token_type::parse_error; return token_type::parse_error;
} }
} }
else else
{ {
error_message = "invalid string: surrogate U +DC00..U+DFFF must be followed by U+DC00..U+DFFF"; error_message = "invalid string: surrogate U +DC00..U+DFFF must be followed by U+DC00..U+DFFF";
return token_type::parse_error; return token_type::parse_error;
} }
} }
else else
{ {
if (JSON_UNLIKELY(0xDC00 <= codepoint1 and codep oint1 <= 0xDFFF)) if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 an d codepoint1 <= 0xDFFF))
{ {
error_message = "invalid string: surrogate U +DC00..U+DFFF must follow U+D800..U+DBFF"; error_message = "invalid string: surrogate U +DC00..U+DFFF must follow U+D800..U+DBFF";
return token_type::parse_error; return token_type::parse_error;
} }
} }
// result of the above calculation yields a proper c odepoint // result of the above calculation yields a proper c odepoint
assert(0x00 <= codepoint and codepoint <= 0x10FFFF); assert(0x00 <= codepoint and codepoint <= 0x10FFFF);
// translate codepoint into bytes // translate codepoint into bytes
if (codepoint < 0x80) if (codepoint < 0x80)
{ {
// 1-byte characters: 0xxxxxxx (ASCII) // 1-byte characters: 0xxxxxxx (ASCII)
add(codepoint); add(codepoint);
} }
else if (codepoint <= 0x7FF) else if (codepoint <= 0x7FF)
{ {
// 2-byte characters: 110xxxxx 10xxxxxx // 2-byte characters: 110xxxxx 10xxxxxx
add(0xC0 | (codepoint >> 6)); add(static_cast<int>(0xC0u | (static_cast<unsign
add(0x80 | (codepoint & 0x3F)); ed int>(codepoint) >> 6u)));
add(static_cast<int>(0x80u | (static_cast<unsign
ed int>(codepoint) & 0x3Fu)));
} }
else if (codepoint <= 0xFFFF) else if (codepoint <= 0xFFFF)
{ {
// 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
add(0xE0 | (codepoint >> 12)); add(static_cast<int>(0xE0u | (static_cast<unsign
add(0x80 | ((codepoint >> 6) & 0x3F)); ed int>(codepoint) >> 12u)));
add(0x80 | (codepoint & 0x3F)); add(static_cast<int>(0x80u | ((static_cast<unsig
ned int>(codepoint) >> 6u) & 0x3Fu)));
add(static_cast<int>(0x80u | (static_cast<unsign
ed int>(codepoint) & 0x3Fu)));
} }
else else
{ {
// 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx