Commit 363880a4 authored by GitHub Actions's avatar GitHub Actions
Browse files

Upstream release v3.1.2

parent a2b994bc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ include(FetchContent)

FetchContent_Declare(json
  GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohman_json
  GIT_TAG v3.1.1)
  GIT_TAG v3.1.2)

FetchContent_GetProperties(json)
if(NOT json_POPULATED)
+204 −94
Original line number Diff line number Diff line
/*
    __ _____ _____ _____
 __|  |   __|     |   | |  JSON for Modern C++
|  |  |__   |  |  | | | |  version 3.1.1
|  |  |__   |  |  | | | |  version 3.1.2
|_____|_____|_____|_|___|  https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@@ -31,7 +31,7 @@ SOFTWARE.
#define NLOHMANN_JSON_VERSION_MAJOR 3
#define NLOHMANN_JSON_VERSION_MINOR 1
#define NLOHMANN_JSON_VERSION_PATCH 1
#define NLOHMANN_JSON_VERSION_PATCH 2
#include <algorithm> // all_of, find, for_each
#include <cassert> // assert
@@ -466,7 +466,7 @@ struct is_compatible_complete_type
{
    static constexpr bool value =
        not std::is_base_of<std::istream, CompatibleCompleteType>::value and
        not std::is_same<BasicJsonType, CompatibleCompleteType>::value and
        not is_basic_json<CompatibleCompleteType>::value and
        not is_basic_json_nested_type<BasicJsonType, CompatibleCompleteType>::value and
        has_to_json<BasicJsonType, CompatibleCompleteType>::value;
};
@@ -1871,6 +1871,7 @@ class lexer
    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;
  public:
    /// token types for the parser
@@ -2969,7 +2970,7 @@ scan_number_done:
    }
    /// return current string value (implicitly resets the token; useful only once)
    std::string move_string()
    string_t&& move_string()
    {
        return std::move(token_buffer);
    }
@@ -3099,7 +3100,7 @@ scan_number_done:
    std::vector<char> token_string {};
    /// buffer for variable-length tokens (numbers, strings)
    std::string token_buffer {};
    string_t token_buffer {};
    /// a description of occurred lexer errors
    const char* error_message = "";
@@ -3155,6 +3156,7 @@ class parser
    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 lexer_t = lexer<BasicJsonType>;
    using token_type = typename lexer_t::token_type;
@@ -3298,7 +3300,7 @@ class parser
                }
                // parse values
                std::string key;
                string_t key;
                BasicJsonType value;
                while (true)
                {
@@ -3526,6 +3528,7 @@ class parser
        if (keep and callback and not callback(depth, parse_event_t::value, result))
        {
            result.m_value.destroy(result.m_type);
            result.m_type = value_t::discarded;
        }
    }
@@ -4776,11 +4779,11 @@ class output_stream_adapter : public output_adapter_protocol<CharType>
};
/// output adapter for basic_string
template<typename CharType>
template<typename CharType, typename StringType = std::basic_string<CharType>>
class output_string_adapter : public output_adapter_protocol<CharType>
{
  public:
    explicit output_string_adapter(std::basic_string<CharType>& s) : str(s) {}
    explicit output_string_adapter(StringType& s) : str(s) {}
    void write_character(CharType c) override
    {
@@ -4793,10 +4796,10 @@ class output_string_adapter : public output_adapter_protocol<CharType>
    }
  private:
    std::basic_string<CharType>& str;
    StringType& str;
};
template<typename CharType>
template<typename CharType, typename StringType = std::basic_string<CharType>>
class output_adapter
{
  public:
@@ -4806,8 +4809,8 @@ class output_adapter
    output_adapter(std::basic_ostream<CharType>& s)
        : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
    output_adapter(std::basic_string<CharType>& s)
        : oa(std::make_shared<output_string_adapter<CharType>>(s)) {}
    output_adapter(StringType& s)
        : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
    operator output_adapter_t<CharType>()
    {
@@ -6909,11 +6912,11 @@ class binary_writer
        oa->write_characters(vec.data(), sizeof(NumberType));
    }
    template<typename NumberType>
    // UBJSON: write number (floating point)
    template<typename NumberType, typename std::enable_if<
                 std::is_floating_point<NumberType>::value, int>::type = 0>
    void write_number_with_ubjson_prefix(const NumberType n,
                                         const bool add_prefix)
    {
        if (std::is_floating_point<NumberType>::value)
    {
        if (add_prefix)
        {
@@ -6921,9 +6924,14 @@ class binary_writer
        }
        write_number(n);
    }
        else if (std::is_unsigned<NumberType>::value)
    // UBJSON: write number (unsigned integer)
    template<typename NumberType, typename std::enable_if<
                 std::is_unsigned<NumberType>::value, int>::type = 0>
    void write_number_with_ubjson_prefix(const NumberType n,
                                         const bool add_prefix)
    {
            if (n <= (std::numeric_limits<int8_t>::max)())
        if (n <= static_cast<uint64_t>((std::numeric_limits<int8_t>::max)()))
        {
            if (add_prefix)
            {
@@ -6939,7 +6947,7 @@ class binary_writer
            }
            write_number(static_cast<uint8_t>(n));
        }
            else if (n <= (std::numeric_limits<int16_t>::max)())
        else if (n <= static_cast<uint64_t>((std::numeric_limits<int16_t>::max)()))
        {
            if (add_prefix)
            {
@@ -6947,7 +6955,7 @@ class binary_writer
            }
            write_number(static_cast<int16_t>(n));
        }
            else if (n <= (std::numeric_limits<int32_t>::max)())
        else if (n <= static_cast<uint64_t>((std::numeric_limits<int32_t>::max)()))
        {
            if (add_prefix)
            {
@@ -6955,7 +6963,7 @@ class binary_writer
            }
            write_number(static_cast<int32_t>(n));
        }
            else if (n <= (std::numeric_limits<int64_t>::max)())
        else if (n <= static_cast<uint64_t>((std::numeric_limits<int64_t>::max)()))
        {
            if (add_prefix)
            {
@@ -6968,7 +6976,13 @@ class binary_writer
            JSON_THROW(out_of_range::create(407, "number overflow serializing " + std::to_string(n)));
        }
    }
        else
    // UBJSON: write number (signed integer)
    template<typename NumberType, typename std::enable_if<
                 std::is_signed<NumberType>::value and
                 not std::is_floating_point<NumberType>::value, int>::type = 0>
    void write_number_with_ubjson_prefix(const NumberType n,
                                         const bool add_prefix)
    {
        if ((std::numeric_limits<int8_t>::min)() <= n and n <= (std::numeric_limits<int8_t>::max)())
        {
@@ -6978,7 +6992,7 @@ class binary_writer
            }
            write_number(static_cast<int8_t>(n));
        }
            else if ((std::numeric_limits<uint8_t>::min)() <= n and n <= (std::numeric_limits<uint8_t>::max)())
        else if (static_cast<int64_t>((std::numeric_limits<uint8_t>::min)()) <= n and n <= static_cast<int64_t>((std::numeric_limits<uint8_t>::max)()))
        {
            if (add_prefix)
            {
@@ -7017,7 +7031,6 @@ class binary_writer
        }
        // LCOV_EXCL_STOP
    }
    }
    /*!
    @brief determine the type prefix of container values
@@ -10535,7 +10548,7 @@ class basic_json
                    object = nullptr;  // silence warning, see #821
                    if (JSON_UNLIKELY(t == value_t::null))
                    {
                        JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.1.1")); // LCOV_EXCL_LINE
                        JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.1.2")); // LCOV_EXCL_LINE
                    }
                    break;
                }
@@ -10805,6 +10818,7 @@ class basic_json
    - @a CompatibleType is not derived from `std::istream`,
    - @a CompatibleType is not @ref basic_json (to avoid hijacking copy/move
         constructors),
    - @a CompatibleType is not a different @ref basic_json type (i.e. with different template arguments)
    - @a CompatibleType is not a @ref basic_json nested type (e.g.,
         @ref json_pointer, @ref iterator, etc ...)
    - @ref @ref json_serializer<U> has a
@@ -10840,6 +10854,78 @@ class basic_json
        assert_invariant();
    }
    /*!
    @brief create a JSON value from an existing one
    This is a constructor for existing @ref basic_json types.
    It does not hijack copy/move constructors, since the parameter has different
    template arguments than the current ones.
    The constructor tries to convert the internal @ref m_value of the parameter.
    @tparam BasicJsonType a type such that:
    - @a BasicJsonType is a @ref basic_json type.
    - @a BasicJsonType has different template arguments than @ref basic_json_t.
    @param[in] val the @ref basic_json value to be converted.
    @complexity Usually linear in the size of the passed @a val, also
                depending on the implementation of the called `to_json()`
                method.
    @exceptionsafety Depends on the called constructor. For types directly
    supported by the library (i.e., all types for which no `to_json()` function
    was provided), strong guarantee holds: if an exception is thrown, there are
    no changes to any JSON value.
    @since version 3.1.2
    */
    template <typename BasicJsonType,
              detail::enable_if_t<
                  detail::is_basic_json<BasicJsonType>::value and not std::is_same<basic_json, BasicJsonType>::value, int> = 0>
    basic_json(const BasicJsonType& val)
    {
        using other_boolean_t = typename BasicJsonType::boolean_t;
        using other_number_float_t = typename BasicJsonType::number_float_t;
        using other_number_integer_t = typename BasicJsonType::number_integer_t;
        using other_number_unsigned_t = typename BasicJsonType::number_unsigned_t;
        using other_string_t = typename BasicJsonType::string_t;
        using other_object_t = typename BasicJsonType::object_t;
        using other_array_t = typename BasicJsonType::array_t;
        switch (val.type())
        {
            case value_t::boolean:
                JSONSerializer<other_boolean_t>::to_json(*this, val.template get<other_boolean_t>());
                break;
            case value_t::number_float:
                JSONSerializer<other_number_float_t>::to_json(*this, val.template get<other_number_float_t>());
                break;
            case value_t::number_integer:
                JSONSerializer<other_number_integer_t>::to_json(*this, val.template get<other_number_integer_t>());
                break;
            case value_t::number_unsigned:
                JSONSerializer<other_number_unsigned_t>::to_json(*this, val.template get<other_number_unsigned_t>());
                break;
            case value_t::string:
                JSONSerializer<other_string_t>::to_json(*this, val.template get_ref<const other_string_t&>());
                break;
            case value_t::object:
                JSONSerializer<other_object_t>::to_json(*this, val.template get_ref<const other_object_t&>());
                break;
            case value_t::array:
                JSONSerializer<other_array_t>::to_json(*this, val.template get_ref<const other_array_t&>());
                break;
            case value_t::null:
                *this = nullptr;
                break;
            case value_t::discarded:
                m_type = value_t::discarded;
                break;
        }
        assert_invariant();
    }
    /*!
    @brief create a container (array or object) from an initializer list
@@ -11472,7 +11558,7 @@ class basic_json
                  const bool ensure_ascii = false) const
    {
        string_t result;
        serializer s(detail::output_adapter<char>(result), indent_char);
        serializer s(detail::output_adapter<char, string_t>(result), indent_char);
        if (indent >= 0)
        {
@@ -12012,6 +12098,29 @@ class basic_json
        return *this;
    }
    /*!
    @brief get special-case overload
    This overloads converts the current @ref basic_json in a different
    @ref basic_json type
    @tparam BasicJsonType == @ref basic_json
    @return a copy of *this, converted into @tparam BasicJsonType
    @complexity Depending on the implementation of the called `from_json()`
                method.
    @since version 3.1.2
    */
    template<typename BasicJsonType, detail::enable_if_t<
                 not std::is_same<BasicJsonType, basic_json>::value and
                 detail::is_basic_json<BasicJsonType>::value, int> = 0>
    BasicJsonType get() const
    {
        return *this;
    }
    /*!
    @brief get a value (explicit)
@@ -12053,7 +12162,7 @@ class basic_json
    */
    template<typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>,
             detail::enable_if_t <
                 not std::is_same<basic_json_t, ValueType>::value and
                 not detail::is_basic_json<ValueType>::value and
                 detail::has_from_json<basic_json_t, ValueType>::value and
                 not detail::has_non_default_from_json<basic_json_t, ValueType>::value,
                 int> = 0>
@@ -12319,7 +12428,8 @@ class basic_json
    template < typename ValueType, typename std::enable_if <
                   not std::is_pointer<ValueType>::value and
                   not std::is_same<ValueType, detail::json_ref<basic_json>>::value and
                   not std::is_same<ValueType, typename string_t::value_type>::value
                   not std::is_same<ValueType, typename string_t::value_type>::value and
                   not detail::is_basic_json<ValueType>::value
#ifndef _MSC_VER  // fix for issue #167 operator<< ambiguity under VS2015
                   and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
#endif
@@ -14777,7 +14887,7 @@ class basic_json
        // passed iterators must belong to objects
        if (JSON_UNLIKELY(not first.m_object->is_object()
                          or not first.m_object->is_object()))
                          or not last.m_object->is_object()))
        {
            JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects"));
        }