mirror of
https://github.com/nlohmann/json.git
synced 2026-06-18 18:34:17 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3249b180cc | |||
| 61f0d683e0 | |||
| b3effb609c |
@@ -128,7 +128,8 @@ class serializer
|
|||||||
const auto new_indent = current_indent + indent_step;
|
const auto new_indent = current_indent + indent_step;
|
||||||
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
||||||
{
|
{
|
||||||
indent_string.resize(indent_string.size() * 2, ' ');
|
indent_string.resize((std::max)(indent_string.size() * 2, static_cast<std::size_t>(new_indent)), indent_char);
|
||||||
|
JSON_ASSERT(indent_string.size() >= new_indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// first n-1 elements
|
// first n-1 elements
|
||||||
@@ -201,7 +202,8 @@ class serializer
|
|||||||
const auto new_indent = current_indent + indent_step;
|
const auto new_indent = current_indent + indent_step;
|
||||||
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
||||||
{
|
{
|
||||||
indent_string.resize(indent_string.size() * 2, ' ');
|
indent_string.resize((std::max)(indent_string.size() * 2, static_cast<std::size_t>(new_indent)), indent_char);
|
||||||
|
JSON_ASSERT(indent_string.size() >= new_indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// first n-1 elements
|
// first n-1 elements
|
||||||
@@ -262,7 +264,8 @@ class serializer
|
|||||||
const auto new_indent = current_indent + indent_step;
|
const auto new_indent = current_indent + indent_step;
|
||||||
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
||||||
{
|
{
|
||||||
indent_string.resize(indent_string.size() * 2, ' ');
|
indent_string.resize((std::max)(indent_string.size() * 2, static_cast<std::size_t>(new_indent)), indent_char);
|
||||||
|
JSON_ASSERT(indent_string.size() >= new_indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
o->write_characters(indent_string.c_str(), new_indent);
|
o->write_characters(indent_string.c_str(), new_indent);
|
||||||
|
|||||||
@@ -19302,7 +19302,8 @@ class serializer
|
|||||||
const auto new_indent = current_indent + indent_step;
|
const auto new_indent = current_indent + indent_step;
|
||||||
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
||||||
{
|
{
|
||||||
indent_string.resize(indent_string.size() * 2, ' ');
|
indent_string.resize((std::max)(indent_string.size() * 2, static_cast<std::size_t>(new_indent)), indent_char);
|
||||||
|
JSON_ASSERT(indent_string.size() >= new_indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// first n-1 elements
|
// first n-1 elements
|
||||||
@@ -19375,7 +19376,8 @@ class serializer
|
|||||||
const auto new_indent = current_indent + indent_step;
|
const auto new_indent = current_indent + indent_step;
|
||||||
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
||||||
{
|
{
|
||||||
indent_string.resize(indent_string.size() * 2, ' ');
|
indent_string.resize((std::max)(indent_string.size() * 2, static_cast<std::size_t>(new_indent)), indent_char);
|
||||||
|
JSON_ASSERT(indent_string.size() >= new_indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// first n-1 elements
|
// first n-1 elements
|
||||||
@@ -19436,7 +19438,8 @@ class serializer
|
|||||||
const auto new_indent = current_indent + indent_step;
|
const auto new_indent = current_indent + indent_step;
|
||||||
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
||||||
{
|
{
|
||||||
indent_string.resize(indent_string.size() * 2, ' ');
|
indent_string.resize((std::max)(indent_string.size() * 2, static_cast<std::size_t>(new_indent)), indent_char);
|
||||||
|
JSON_ASSERT(indent_string.size() >= new_indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
o->write_characters(indent_string.c_str(), new_indent);
|
o->write_characters(indent_string.c_str(), new_indent);
|
||||||
|
|||||||
@@ -245,6 +245,41 @@ TEST_CASE("object inspection")
|
|||||||
CHECK(binary.dump(1024).size() == 2086);
|
CHECK(binary.dump(1024).size() == 2086);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("indentation and resize")
|
||||||
|
{
|
||||||
|
SECTION("array")
|
||||||
|
{
|
||||||
|
const auto j_array = json::parse("[[[[[[]]]]]]");
|
||||||
|
// check right size after indentation triggering a resize
|
||||||
|
CHECK(j_array.dump(1024).size() == 25622);
|
||||||
|
// check if right indentation symbol is used
|
||||||
|
CHECK(j_array.dump(1024, '\t')[4096] == '\t');
|
||||||
|
// check resize is large enough
|
||||||
|
CHECK(j_array.dump(10000).size() == 250022);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("object")
|
||||||
|
{
|
||||||
|
const auto j_object = json::parse(R"({"":{"":{"":{"":{"":{}}}}}})");
|
||||||
|
// check right size after indentation triggering a resize
|
||||||
|
CHECK(j_object.dump(1024).size() == 25642);
|
||||||
|
// check if right indentation symbol is used
|
||||||
|
CHECK(j_object.dump(1024, '\t')[4096] == '\t');
|
||||||
|
// check resize is large enough
|
||||||
|
CHECK(j_object.dump(10000).size() == 250042);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("binary")
|
||||||
|
{
|
||||||
|
const auto j_binary = json::binary({1, 2, 3}, 128);
|
||||||
|
// check right size after indentation triggering a resize
|
||||||
|
CHECK(j_binary.dump(1024).size() == 2086);
|
||||||
|
CHECK(j_binary.dump(1024, '\t')[1024] == '\t');
|
||||||
|
// check resize is large enough
|
||||||
|
CHECK(j_binary.dump(10000).size() == 20038);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("dump and floating-point numbers")
|
SECTION("dump and floating-point numbers")
|
||||||
{
|
{
|
||||||
auto s = json(42.23).dump();
|
auto s = json(42.23).dump();
|
||||||
|
|||||||
Reference in New Issue
Block a user