1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-22 15:21:52 +03:00

implemented an indentation character #520

An optional parameter for dump() allows to set the character to use for
indentation (default: space). In case a JSON value is serialized to an
output stream, its fill character is used (and can be set with
std::setfill).
This commit is contained in:
Niels Lohmann
2017-05-07 19:27:40 +02:00
parent fba1bcdd0b
commit 962da00171
10 changed files with 76 additions and 16 deletions

View File

@ -51,6 +51,15 @@ TEST_CASE("serialization")
CHECK(ss.str() ==
"[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
}
SECTION("given fill")
{
std::stringstream ss;
json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
ss << std::setw(1) << std::setfill('\t') << j;
CHECK(ss.str() ==
"[\n\t\"foo\",\n\t1,\n\t2,\n\t3,\n\tfalse,\n\t{\n\t\t\"one\": 1\n\t}\n]");
}
}
SECTION("operator>>")
@ -72,5 +81,16 @@ TEST_CASE("serialization")
CHECK(ss.str() ==
"[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
}
SECTION("given fill")
{
std::stringstream ss;
json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
ss.width(1);
ss.fill('\t');
j >> ss;
CHECK(ss.str() ==
"[\n\t\"foo\",\n\t1,\n\t2,\n\t3,\n\tfalse,\n\t{\n\t\t\"one\": 1\n\t}\n]");
}
}
}