mirror of
https://github.com/nlohmann/json.git
synced 2026-10-16 11:17:13 +00:00
Merge remote-tracking branch 'origin/develop' into claude/fix-issue-3989-db7e45
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
7 files changed
+62
-65
No files matched your search
@@ -5263,7 +5263,7 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSON_HEDLEY_NEVER_INLINE
|
JSON_HEDLEY_NEVER_INLINE
|
||||||
bool bson_unsupported_type_error(const std::size_t position, const char element_type)
|
bool bson_unsupported_type_error(const std::size_t position, const char_int_type element_type)
|
||||||
{
|
{
|
||||||
const std::string cr_str = hex_byte(static_cast<std::uint8_t>(element_type));
|
const std::string cr_str = hex_byte(static_cast<std::uint8_t>(element_type));
|
||||||
return report_error(position, cr_str,
|
return report_error(position, cr_str,
|
||||||
|
|||||||
@@ -1077,7 +1077,7 @@ class json_pointer
|
|||||||
std::size_t token_count = 0;
|
std::size_t token_count = 0;
|
||||||
for (std::size_t i = 0; i < size; ++i)
|
for (std::size_t i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
token_count += (reference_string[i] == '/') ? 1 : 0;
|
token_count += static_cast<std::size_t>(reference_string[i] == '/');
|
||||||
}
|
}
|
||||||
result.reserve(token_count);
|
result.reserve(token_count);
|
||||||
|
|
||||||
|
|||||||
@@ -17,18 +17,7 @@ NLOHMANN_JSON_NAMESPACE_BEGIN
|
|||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
/*!
|
/// append @a s to @a out, escaped like @ref escape does
|
||||||
* @brief string escaping as described in RFC 6901 (Sect. 4)
|
|
||||||
* @param[in] s string to escape
|
|
||||||
* @return escaped string
|
|
||||||
*
|
|
||||||
* Note the order of escaping "~" to "~0" and "/" to "~1" is important.
|
|
||||||
*
|
|
||||||
* The string is rebuilt in a single pass, appending whole runs between the
|
|
||||||
* characters that need escaping, while repeated replace() calls would move
|
|
||||||
* the tail of the string once per escaped character. @ref escape_into appends
|
|
||||||
* the escaped string to an existing one.
|
|
||||||
*/
|
|
||||||
template<typename StringType>
|
template<typename StringType>
|
||||||
inline void escape_into(StringType& out, const StringType& s)
|
inline void escape_into(StringType& out, const StringType& s)
|
||||||
{
|
{
|
||||||
@@ -47,6 +36,18 @@ inline void escape_into(StringType& out, const StringType& s)
|
|||||||
out.append(s.data() + run, size - run);
|
out.append(s.data() + run, size - run);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief string escaping as described in RFC 6901 (Sect. 4)
|
||||||
|
* @param[in] s string to escape
|
||||||
|
* @return escaped string
|
||||||
|
*
|
||||||
|
* Note the order of escaping "~" to "~0" and "/" to "~1" is important.
|
||||||
|
*
|
||||||
|
* The string is rebuilt in a single pass, appending whole runs between the
|
||||||
|
* characters that need escaping, while repeated replace() calls would move
|
||||||
|
* the tail of the string once per escaped character. @ref escape_into appends
|
||||||
|
* the escaped string to an existing one.
|
||||||
|
*/
|
||||||
template<typename StringType>
|
template<typename StringType>
|
||||||
inline StringType escape(const StringType& s)
|
inline StringType escape(const StringType& s)
|
||||||
{
|
{
|
||||||
|
|||||||
+26
-26
@@ -943,30 +943,30 @@ public:
|
|||||||
free_container(v);
|
free_container(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy the tree below top without recursing per nesting level and
|
// Destroy the tree below top without recursing per nesting level and
|
||||||
// without any heap allocation: a heap-allocated flattening
|
// without any heap allocation: a heap-allocated flattening
|
||||||
// stack (the previous implementation) can itself throw
|
// stack (the previous implementation) can itself throw
|
||||||
// bad_alloc, which would escape this noexcept destructor and
|
// bad_alloc, which would escape this noexcept destructor and
|
||||||
// terminate the program (#5135).
|
// terminate the program (#5135).
|
||||||
//
|
//
|
||||||
// Instead, walk down a chain of children (always the one
|
// Instead, walk down a chain of children (always the one
|
||||||
// walk_child() picks), reversing links as we go: cur is the
|
// walk_child() picks), reversing links as we go: cur is the
|
||||||
// container currently being emptied, and prev is its parent
|
// container currently being emptied, and prev is its parent
|
||||||
// (value_t::null when there is none). Each parent's
|
// (value_t::null when there is none). Each parent's
|
||||||
// walk_child() slot doubles as storage for that parent's own
|
// walk_child() slot doubles as storage for that parent's own
|
||||||
// parent link while we are below it, so no extra memory is
|
// parent link while we are below it, so no extra memory is
|
||||||
// needed; the parent is not modified meanwhile, so
|
// needed; the parent is not modified meanwhile, so
|
||||||
// walk_child() finds that same slot again on the way up. We
|
// walk_child() finds that same slot again on the way up. We
|
||||||
// only ever remove a child once it is a scalar or an empty
|
// only ever remove a child once it is a scalar or an empty
|
||||||
// array/object, which neither allocates nor recurses more
|
// array/object, which neither allocates nor recurses more
|
||||||
// than one level deep.
|
// than one level deep.
|
||||||
//
|
//
|
||||||
// This json_value is not itself a basic_json, so the
|
// This json_value is not itself a basic_json, so the
|
||||||
// top-level container is first moved into a local stand-in
|
// top-level container is first moved into a local stand-in
|
||||||
// ("cur"); a default-constructed basic_json has a null
|
// ("cur"); a default-constructed basic_json has a null
|
||||||
// pointer in its m_value (see data::m_value's initializer),
|
// pointer in its m_value (see data::m_value's initializer),
|
||||||
// so swapping it with *this leaves this union's own pointer
|
// so swapping it with *this leaves this union's own pointer
|
||||||
// null, and it is never looked at or freed a second time.
|
// null, and it is never looked at or freed a second time.
|
||||||
static void destroy_walk(basic_json& top) noexcept
|
static void destroy_walk(basic_json& top) noexcept
|
||||||
{
|
{
|
||||||
basic_json cur;
|
basic_json cur;
|
||||||
@@ -3058,14 +3058,14 @@ public:
|
|||||||
JSON_THROW(std::length_error(detail::concat("array index ", std::to_string(idx), " exceeds size_type")));
|
JSON_THROW(std::length_error(detail::concat("array index ", std::to_string(idx), " exceeds size_type")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @throw out_of_range.401
|
/// @throw out_of_range.401 always, as @a idx is out of range of @a j
|
||||||
JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE
|
JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE
|
||||||
static void throw_array_index_out_of_range(size_type idx, const basic_json& j)
|
static void throw_array_index_out_of_range(size_type idx, const basic_json& j)
|
||||||
{
|
{
|
||||||
JSON_THROW(out_of_range::create(detail::exception_id::array_index_out_of_range, detail::concat("array index ", std::to_string(idx), " is out of range"), &j));
|
JSON_THROW(out_of_range::create(detail::exception_id::array_index_out_of_range, detail::concat("array index ", std::to_string(idx), " is out of range"), &j));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @throw out_of_range.403
|
/// @throw out_of_range.403 always, as @a key is not found in @a j
|
||||||
template<typename KeyType>
|
template<typename KeyType>
|
||||||
JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE
|
JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE
|
||||||
static void throw_key_not_found(const KeyType& key, const basic_json& j)
|
static void throw_key_not_found(const KeyType& key, const basic_json& j)
|
||||||
|
|||||||
Generated
+17
-16
@@ -3463,18 +3463,7 @@ NLOHMANN_JSON_NAMESPACE_BEGIN
|
|||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
/*!
|
/// append @a s to @a out, escaped like @ref escape does
|
||||||
* @brief string escaping as described in RFC 6901 (Sect. 4)
|
|
||||||
* @param[in] s string to escape
|
|
||||||
* @return escaped string
|
|
||||||
*
|
|
||||||
* Note the order of escaping "~" to "~0" and "/" to "~1" is important.
|
|
||||||
*
|
|
||||||
* The string is rebuilt in a single pass, appending whole runs between the
|
|
||||||
* characters that need escaping, while repeated replace() calls would move
|
|
||||||
* the tail of the string once per escaped character. @ref escape_into appends
|
|
||||||
* the escaped string to an existing one.
|
|
||||||
*/
|
|
||||||
template<typename StringType>
|
template<typename StringType>
|
||||||
inline void escape_into(StringType& out, const StringType& s)
|
inline void escape_into(StringType& out, const StringType& s)
|
||||||
{
|
{
|
||||||
@@ -3493,6 +3482,18 @@ inline void escape_into(StringType& out, const StringType& s)
|
|||||||
out.append(s.data() + run, size - run);
|
out.append(s.data() + run, size - run);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief string escaping as described in RFC 6901 (Sect. 4)
|
||||||
|
* @param[in] s string to escape
|
||||||
|
* @return escaped string
|
||||||
|
*
|
||||||
|
* Note the order of escaping "~" to "~0" and "/" to "~1" is important.
|
||||||
|
*
|
||||||
|
* The string is rebuilt in a single pass, appending whole runs between the
|
||||||
|
* characters that need escaping, while repeated replace() calls would move
|
||||||
|
* the tail of the string once per escaped character. @ref escape_into appends
|
||||||
|
* the escaped string to an existing one.
|
||||||
|
*/
|
||||||
template<typename StringType>
|
template<typename StringType>
|
||||||
inline StringType escape(const StringType& s)
|
inline StringType escape(const StringType& s)
|
||||||
{
|
{
|
||||||
@@ -20663,7 +20664,7 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSON_HEDLEY_NEVER_INLINE
|
JSON_HEDLEY_NEVER_INLINE
|
||||||
bool bson_unsupported_type_error(const std::size_t position, const char element_type)
|
bool bson_unsupported_type_error(const std::size_t position, const char_int_type element_type)
|
||||||
{
|
{
|
||||||
const std::string cr_str = hex_byte(static_cast<std::uint8_t>(element_type));
|
const std::string cr_str = hex_byte(static_cast<std::uint8_t>(element_type));
|
||||||
return report_error(position, cr_str,
|
return report_error(position, cr_str,
|
||||||
@@ -24332,7 +24333,7 @@ class json_pointer
|
|||||||
std::size_t token_count = 0;
|
std::size_t token_count = 0;
|
||||||
for (std::size_t i = 0; i < size; ++i)
|
for (std::size_t i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
token_count += (reference_string[i] == '/') ? 1 : 0;
|
token_count += static_cast<std::size_t>(reference_string[i] == '/');
|
||||||
}
|
}
|
||||||
result.reserve(token_count);
|
result.reserve(token_count);
|
||||||
|
|
||||||
@@ -35404,14 +35405,14 @@ public:
|
|||||||
JSON_THROW(std::length_error(detail::concat("array index ", std::to_string(idx), " exceeds size_type")));
|
JSON_THROW(std::length_error(detail::concat("array index ", std::to_string(idx), " exceeds size_type")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @throw out_of_range.401
|
/// @throw out_of_range.401 always, as @a idx is out of range of @a j
|
||||||
JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE
|
JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE
|
||||||
static void throw_array_index_out_of_range(size_type idx, const basic_json& j)
|
static void throw_array_index_out_of_range(size_type idx, const basic_json& j)
|
||||||
{
|
{
|
||||||
JSON_THROW(out_of_range::create(detail::exception_id::array_index_out_of_range, detail::concat("array index ", std::to_string(idx), " is out of range"), &j));
|
JSON_THROW(out_of_range::create(detail::exception_id::array_index_out_of_range, detail::concat("array index ", std::to_string(idx), " is out of range"), &j));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @throw out_of_range.403
|
/// @throw out_of_range.403 always, as @a key is not found in @a j
|
||||||
template<typename KeyType>
|
template<typename KeyType>
|
||||||
JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE
|
JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE
|
||||||
static void throw_key_not_found(const KeyType& key, const basic_json& j)
|
static void throw_key_not_found(const KeyType& key, const basic_json& j)
|
||||||
|
|||||||
@@ -733,7 +733,7 @@ TEST_CASE_TEMPLATE("Parent pointers stay consistent", J, json, ordered_json)
|
|||||||
TEST_CASE_TEMPLATE("update() and merge_patch() keep parent pointers and diagnostic paths", J, json, ordered_json)
|
TEST_CASE_TEMPLATE("update() and merge_patch() keep parent pointers and diagnostic paths", J, json, ordered_json)
|
||||||
{
|
{
|
||||||
// enough keys to make the vector behind ordered_json reallocate several times
|
// enough keys to make the vector behind ordered_json reallocate several times
|
||||||
const auto make_object = [](int first, int last)
|
const auto make_object = [](int first, int last) -> J
|
||||||
{
|
{
|
||||||
J o = J::object();
|
J o = J::object();
|
||||||
for (int i = first; i < last; ++i)
|
for (int i = first; i < last; ++i)
|
||||||
|
|||||||
@@ -39,20 +39,15 @@ struct tracked
|
|||||||
std::string payload;
|
std::string payload;
|
||||||
bool moved_from = false;
|
bool moved_from = false;
|
||||||
|
|
||||||
explicit tracked(std::string p) : payload(std::move(p)) {}
|
explicit tracked(std::string p) noexcept : payload(std::move(p)) {}
|
||||||
tracked(const tracked&) = default;
|
tracked(const tracked&) = default;
|
||||||
tracked& operator=(const tracked&) = default;
|
tracked& operator=(const tracked&) = default;
|
||||||
tracked(tracked&& other) noexcept : payload(std::move(other.payload)), moved_from(other.moved_from)
|
tracked(tracked&& other) noexcept : payload(std::move(other.payload)), moved_from(other.moved_from)
|
||||||
{
|
{
|
||||||
other.moved_from = true;
|
other.moved_from = true;
|
||||||
}
|
}
|
||||||
tracked& operator=(tracked&& other) noexcept
|
// not needed by the tests (and an unused definition fails -Wunneeded-member-function)
|
||||||
{
|
tracked& operator=(tracked&&) = delete;
|
||||||
payload = std::move(other.payload);
|
|
||||||
moved_from = other.moved_from;
|
|
||||||
other.moved_from = true;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
~tracked() = default;
|
~tracked() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user