mirror of
https://github.com/nlohmann/json.git
synced 2026-09-11 02:38:00 +00:00
Move pretty_print, ensure_ascii and indent_step into the serializer
None of these change over the life of a serializer, unlike current_indent and depth, which do change on every recursive call. They are now captured once in the constructor - matching indent_char and error_handler - instead of being threaded through dump(), dump_internal(), dump_iteratively(), dump_value() and dump_escaped() on every call. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -1343,15 +1343,18 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
const error_handler_t error_handler = error_handler_t::strict) const
|
||||
{
|
||||
string_t result;
|
||||
serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
|
||||
|
||||
if (indent >= 0)
|
||||
{
|
||||
s.dump(*this, true, ensure_ascii, static_cast<std::size_t>(indent));
|
||||
serializer s(detail::output_adapter<char, string_t>(result), indent_char,
|
||||
true, ensure_ascii, static_cast<std::size_t>(indent), error_handler);
|
||||
s.dump(*this);
|
||||
}
|
||||
else
|
||||
{
|
||||
s.dump(*this, false, ensure_ascii, 0);
|
||||
serializer s(detail::output_adapter<char, string_t>(result), indent_char,
|
||||
false, ensure_ascii, 0, error_handler);
|
||||
s.dump(*this);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -4080,8 +4083,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
o.width(0);
|
||||
|
||||
// do the actual serialization
|
||||
serializer s(detail::output_adapter<char>(o), o.fill());
|
||||
s.dump(j, pretty_print, false, static_cast<unsigned int>(indentation));
|
||||
serializer s(detail::output_adapter<char>(o), o.fill(),
|
||||
pretty_print, false, static_cast<std::size_t>(indentation));
|
||||
s.dump(j);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user