Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bce35d7f7e |
No files matched your search
@@ -28,7 +28,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ jobs:
|
|||||||
security-events: write
|
security-events: write
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ jobs:
|
|||||||
target: [ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind]
|
target: [ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind]
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -436,7 +436,7 @@ jobs:
|
|||||||
runs-on: ubuntu-26.04
|
runs-on: ubuntu-26.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -459,7 +459,7 @@ jobs:
|
|||||||
target: [ci_test_examples, ci_test_build_documentation, ci_test_documentation_mermaid]
|
target: [ci_test_examples, ci_test_build_documentation, ci_test_documentation_mermaid]
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -64,10 +64,6 @@ so the result can be larger than the value by a factor of its nesting depth (see
|
|||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
Once the output reaches 512 characters, the result reserves 1 MiB, and four times as much whenever that is not enough,
|
|
||||||
up to 64 MiB. This saves copies and page faults while the string grows, but the returned string can have a much larger
|
|
||||||
`capacity()` than `size()`. Call `shrink_to_fit()` on a result that is kept for long.
|
|
||||||
|
|
||||||
Floating-point numbers are written with the fewest digits that read back as the same value (for `#!cpp double`; see
|
Floating-point numbers are written with the fewest digits that read back as the same value (for `#!cpp double`; see
|
||||||
[number handling](../../features/types/number_handling.md#number-serialization)).
|
[number handling](../../features/types/number_handling.md#number-serialization)).
|
||||||
|
|
||||||
@@ -110,4 +106,3 @@ Binary values are serialized as an object containing two keys:
|
|||||||
- Error handler `keep` added in version 3.13.0.
|
- Error handler `keep` added in version 3.13.0.
|
||||||
- Doubles are written with the shortest digits (Żmij instead of Grisu2) since version 3.13.0; about 0.1% of doubles are
|
- Doubles are written with the shortest digits (Żmij instead of Grisu2) since version 3.13.0; about 0.1% of doubles are
|
||||||
written differently, most of them with fewer digits.
|
written differently, most of them with fewer digits.
|
||||||
- The result reserves capacity for outputs of 512 characters or more since version 3.13.0.
|
|
||||||
@@ -25,7 +25,6 @@
|
|||||||
#endif // JSON_NO_IO
|
#endif // JSON_NO_IO
|
||||||
|
|
||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
#include <nlohmann/detail/meta/cpp_future.hpp>
|
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail
|
||||||
@@ -401,68 +400,6 @@ class output_string_adapter : public output_adapter_protocol<CharType>
|
|||||||
StringType& str;
|
StringType& str;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief output adapter for the string that basic_json::dump() returns
|
|
||||||
|
|
||||||
A string that grows by appending reallocates and copies its contents each time
|
|
||||||
it doubles, and with glibc every new big block is fresh memory that faults in
|
|
||||||
page by page. Once a single write of at least 512 characters arrives (a full
|
|
||||||
flush of the serializer's buffer or a long string, so the output is at least
|
|
||||||
that big), this adapter reserves 1 MiB, and four times as much whenever that is
|
|
||||||
not enough, until 64 MiB; beyond that the string grows by itself. Smaller
|
|
||||||
outputs never reserve. The capacity is tracked here, as StringType::capacity()
|
|
||||||
is not required; a StringType without reserve() just appends.
|
|
||||||
*/
|
|
||||||
template<typename CharType, typename StringType>
|
|
||||||
class output_dump_string_adapter : public output_adapter_protocol<CharType>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit output_dump_string_adapter(StringType& s) noexcept
|
|
||||||
: str(s)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void write_character(CharType c) override
|
|
||||||
{
|
|
||||||
str.push_back(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_characters(const CharType* s, std::size_t length) override
|
|
||||||
{
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(length >= 512))
|
|
||||||
{
|
|
||||||
grow(str.size() + length);
|
|
||||||
}
|
|
||||||
str.append(s, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void grow(const std::size_t needed)
|
|
||||||
{
|
|
||||||
const std::size_t first_reserve = 1048576; // 1 MiB
|
|
||||||
const std::size_t last_reserve = 64 * first_reserve;
|
|
||||||
if (needed > reserved && reserved < last_reserve)
|
|
||||||
{
|
|
||||||
const std::size_t next = reserved == 0 ? first_reserve : reserved * 4;
|
|
||||||
reserved = (std::max)(needed, next);
|
|
||||||
reserve_string(str, reserved, priority_tag<1> {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename String>
|
|
||||||
static auto reserve_string(String& string, std::size_t n, priority_tag<1> /*unused*/)
|
|
||||||
-> decltype(string.reserve(n), void())
|
|
||||||
{
|
|
||||||
string.reserve(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename String>
|
|
||||||
static void reserve_string(String& /*string*/, std::size_t /*n*/, priority_tag<0> /*unused*/) noexcept
|
|
||||||
{}
|
|
||||||
|
|
||||||
StringType& str;
|
|
||||||
std::size_t reserved = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// @brief output sink forwarding to a type-erased output adapter
|
/// @brief output sink forwarding to a type-erased output adapter
|
||||||
///
|
///
|
||||||
/// Wraps the polymorphic output_adapter_t so the same binary_writer template can
|
/// Wraps the polymorphic output_adapter_t so the same binary_writer template can
|
||||||
|
|||||||
@@ -2766,7 +2766,7 @@ public:
|
|||||||
const error_handler_t error_handler = error_handler_t::strict) const
|
const error_handler_t error_handler = error_handler_t::strict) const
|
||||||
{
|
{
|
||||||
string_t result;
|
string_t result;
|
||||||
detail::output_dump_string_adapter<char, string_t> string_adapter(result);
|
detail::output_string_adapter<char, string_t> string_adapter(result);
|
||||||
|
|
||||||
if (indent >= 0)
|
if (indent >= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Generated
+1
-65
@@ -29739,8 +29739,6 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
|
|
||||||
// #include <nlohmann/detail/macro_scope.hpp>
|
// #include <nlohmann/detail/macro_scope.hpp>
|
||||||
|
|
||||||
// #include <nlohmann/detail/meta/cpp_future.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail
|
||||||
@@ -30116,68 +30114,6 @@ class output_string_adapter : public output_adapter_protocol<CharType>
|
|||||||
StringType& str;
|
StringType& str;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief output adapter for the string that basic_json::dump() returns
|
|
||||||
|
|
||||||
A string that grows by appending reallocates and copies its contents each time
|
|
||||||
it doubles, and with glibc every new big block is fresh memory that faults in
|
|
||||||
page by page. Once a single write of at least 512 characters arrives (a full
|
|
||||||
flush of the serializer's buffer or a long string, so the output is at least
|
|
||||||
that big), this adapter reserves 1 MiB, and four times as much whenever that is
|
|
||||||
not enough, until 64 MiB; beyond that the string grows by itself. Smaller
|
|
||||||
outputs never reserve. The capacity is tracked here, as StringType::capacity()
|
|
||||||
is not required; a StringType without reserve() just appends.
|
|
||||||
*/
|
|
||||||
template<typename CharType, typename StringType>
|
|
||||||
class output_dump_string_adapter : public output_adapter_protocol<CharType>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit output_dump_string_adapter(StringType& s) noexcept
|
|
||||||
: str(s)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void write_character(CharType c) override
|
|
||||||
{
|
|
||||||
str.push_back(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_characters(const CharType* s, std::size_t length) override
|
|
||||||
{
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(length >= 512))
|
|
||||||
{
|
|
||||||
grow(str.size() + length);
|
|
||||||
}
|
|
||||||
str.append(s, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void grow(const std::size_t needed)
|
|
||||||
{
|
|
||||||
const std::size_t first_reserve = 1048576; // 1 MiB
|
|
||||||
const std::size_t last_reserve = 64 * first_reserve;
|
|
||||||
if (needed > reserved && reserved < last_reserve)
|
|
||||||
{
|
|
||||||
const std::size_t next = reserved == 0 ? first_reserve : reserved * 4;
|
|
||||||
reserved = (std::max)(needed, next);
|
|
||||||
reserve_string(str, reserved, priority_tag<1> {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename String>
|
|
||||||
static auto reserve_string(String& string, std::size_t n, priority_tag<1> /*unused*/)
|
|
||||||
-> decltype(string.reserve(n), void())
|
|
||||||
{
|
|
||||||
string.reserve(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename String>
|
|
||||||
static void reserve_string(String& /*string*/, std::size_t /*n*/, priority_tag<0> /*unused*/) noexcept
|
|
||||||
{}
|
|
||||||
|
|
||||||
StringType& str;
|
|
||||||
std::size_t reserved = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// @brief output sink forwarding to a type-erased output adapter
|
/// @brief output sink forwarding to a type-erased output adapter
|
||||||
///
|
///
|
||||||
/// Wraps the polymorphic output_adapter_t so the same binary_writer template can
|
/// Wraps the polymorphic output_adapter_t so the same binary_writer template can
|
||||||
@@ -43036,7 +42972,7 @@ public:
|
|||||||
const error_handler_t error_handler = error_handler_t::strict) const
|
const error_handler_t error_handler = error_handler_t::strict) const
|
||||||
{
|
{
|
||||||
string_t result;
|
string_t result;
|
||||||
detail::output_dump_string_adapter<char, string_t> string_adapter(result);
|
detail::output_string_adapter<char, string_t> string_adapter(result);
|
||||||
|
|
||||||
if (indent >= 0)
|
if (indent >= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -484,22 +484,6 @@ TEST_CASE("alternative string type")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("alternative string type with a big dump")
|
|
||||||
{
|
|
||||||
// dump() reserves capacity in the result once the output is big
|
|
||||||
alt_json j = alt_json::array();
|
|
||||||
nlohmann::json reference = nlohmann::json::array();
|
|
||||||
for (int i = 0; i < 300000; ++i)
|
|
||||||
{
|
|
||||||
j.push_back(i);
|
|
||||||
reference.push_back(i);
|
|
||||||
}
|
|
||||||
j.push_back(alt_string(600, 'x'));
|
|
||||||
reference.push_back(std::string(600, 'x'));
|
|
||||||
const std::string expected = reference.dump(2);
|
|
||||||
CHECK(j.dump(2) == expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("alternative string type with json_view")
|
TEST_CASE("alternative string type with json_view")
|
||||||
{
|
{
|
||||||
// regression test for #5994: basic_json_view::dump() called
|
// regression test for #5994: basic_json_view::dump() called
|
||||||
|
|||||||
@@ -800,30 +800,6 @@ class failing_adapter : public nlohmann::detail::output_adapter_protocol<char>
|
|||||||
} // namespace
|
} // namespace
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
// a string type with only what the adapter of dump() needs, and no reserve()
|
|
||||||
struct appending_string
|
|
||||||
{
|
|
||||||
std::string str;
|
|
||||||
|
|
||||||
std::size_t size() const noexcept
|
|
||||||
{
|
|
||||||
return str.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
void push_back(char c)
|
|
||||||
{
|
|
||||||
str.push_back(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
void append(const char* s, std::size_t length)
|
|
||||||
{
|
|
||||||
str.append(s, length);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
TEST_CASE("output adapters")
|
TEST_CASE("output adapters")
|
||||||
{
|
{
|
||||||
SECTION("writing a single character")
|
SECTION("writing a single character")
|
||||||
@@ -849,18 +825,6 @@ TEST_CASE("output adapters")
|
|||||||
CHECK(as_string == "ef");
|
CHECK(as_string == "ef");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("the adapter of dump() with a string type without reserve()")
|
|
||||||
{
|
|
||||||
// dump() reserves capacity for big outputs only if the string type
|
|
||||||
// has reserve(); without it, the adapter just appends
|
|
||||||
appending_string as_string {std::string()};
|
|
||||||
nlohmann::detail::output_dump_string_adapter<char, appending_string> dump_adapter(as_string);
|
|
||||||
dump_adapter.write_character('g');
|
|
||||||
const std::string block(600, 'h');
|
|
||||||
dump_adapter.write_characters(block.data(), block.size());
|
|
||||||
CHECK(as_string.str == "g" + block);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !defined(JSON_NOEXCEPTION)
|
#if !defined(JSON_NOEXCEPTION)
|
||||||
SECTION("a sink that is destroyed with characters left over")
|
SECTION("a sink that is destroyed with characters left over")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1717,45 +1717,3 @@ TEST_CASE("runs of multi-byte characters are escaped like the reference under en
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("dump() of outputs around the sizes where the result reserves capacity")
|
|
||||||
{
|
|
||||||
// the result reserves 1 MiB from the first write of at least 512
|
|
||||||
// characters, and four times as much whenever that is not enough; the
|
|
||||||
// output must not depend on it
|
|
||||||
const std::size_t mib = 1048576;
|
|
||||||
for (const std::size_t length :
|
|
||||||
{
|
|
||||||
std::size_t{0}, std::size_t{1}, std::size_t{509}, std::size_t{510}, std::size_t{511}, std::size_t{512},
|
|
||||||
std::size_t{513}, std::size_t{1023}, std::size_t{1024}, mib - 3, mib - 2, mib - 1, mib, mib + 1,
|
|
||||||
(4 * mib) - 2, (4 * mib) + 1
|
|
||||||
})
|
|
||||||
{
|
|
||||||
CAPTURE(length)
|
|
||||||
const std::string s(length, 'x');
|
|
||||||
const json j = s;
|
|
||||||
CHECK(j.dump() == "\"" + s + "\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
// many writes of the serializer's buffer, compact and indented
|
|
||||||
for (const std::size_t count :
|
|
||||||
{
|
|
||||||
std::size_t{0}, std::size_t{1}, std::size_t{100}, std::size_t{200000}
|
|
||||||
})
|
|
||||||
{
|
|
||||||
CAPTURE(count)
|
|
||||||
json j = json::array();
|
|
||||||
std::string compact = "[";
|
|
||||||
std::string indented = "[";
|
|
||||||
for (std::size_t i = 0; i < count; ++i)
|
|
||||||
{
|
|
||||||
j.push_back(i);
|
|
||||||
compact += (i == 0 ? "" : ",") + std::to_string(i);
|
|
||||||
indented += (i == 0 ? "\n " : ",\n ") + std::to_string(i);
|
|
||||||
}
|
|
||||||
compact += "]";
|
|
||||||
indented += count == 0 ? "]" : "\n]";
|
|
||||||
CHECK(j.dump() == compact);
|
|
||||||
CHECK(j.dump(1) == indented);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user