Refactor: dump_object_key_value
This isn't as clean as I wanted -- there's a lot more context than I realized -- but I think it's still an improvement and will become even moreso later
This commit is contained in:
parent
ef679f8988
commit
5e10e97296
@ -203,6 +203,22 @@ class fancy_serializer
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Iterator>
|
||||
void dump_object_key_value(
|
||||
Iterator i, bool ensure_ascii, unsigned int depth,
|
||||
const fancy_serializer_style* active_style)
|
||||
{
|
||||
const auto new_indent = (depth + 1) * active_style->indent_step;
|
||||
const int newline_len = (active_style->indent_step > 0);
|
||||
|
||||
o->write_characters(indent_string.c_str(), new_indent);
|
||||
o->write_character('\"');
|
||||
prim_serializer.dump_escaped(*o, i->first, ensure_ascii);
|
||||
o->write_characters("\": ", 2 + newline_len);
|
||||
auto new_style = stylizer.get_new_style_or_active(i->first, active_style);
|
||||
dump(i->second, ensure_ascii, depth + 1, new_style);
|
||||
}
|
||||
|
||||
void dump_object(const BasicJsonType& val,
|
||||
bool ensure_ascii,
|
||||
unsigned int depth,
|
||||
@ -234,24 +250,14 @@ class fancy_serializer
|
||||
auto i = val.m_value.object->cbegin();
|
||||
for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
|
||||
{
|
||||
o->write_characters(indent_string.c_str(), new_indent);
|
||||
o->write_character('\"');
|
||||
prim_serializer.dump_escaped(*o, i->first, ensure_ascii);
|
||||
o->write_characters("\": ", 2 + newline_len);
|
||||
auto new_style = stylizer.get_new_style_or_active(i->first, active_style);
|
||||
dump(i->second, ensure_ascii, depth + 1, new_style);
|
||||
dump_object_key_value(i, ensure_ascii, depth, active_style);
|
||||
o->write_characters(",\n", 1 + newline_len);
|
||||
}
|
||||
|
||||
// last element
|
||||
assert(i != val.m_value.object->cend());
|
||||
assert(std::next(i) == val.m_value.object->cend());
|
||||
o->write_characters(indent_string.c_str(), new_indent);
|
||||
o->write_character('\"');
|
||||
prim_serializer.dump_escaped(*o, i->first, ensure_ascii);
|
||||
o->write_characters("\": ", 2 + newline_len);
|
||||
auto new_style = stylizer.get_new_style_or_active(i->first, active_style);
|
||||
dump(i->second, ensure_ascii, depth + 1, new_style);
|
||||
dump_object_key_value(i, ensure_ascii, depth, active_style);
|
||||
|
||||
o->write_characters("\n", newline_len);
|
||||
o->write_characters(indent_string.c_str(), old_indent);
|
||||
|
||||
@ -10273,6 +10273,22 @@ class fancy_serializer
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Iterator>
|
||||
void dump_object_key_value(
|
||||
Iterator i, bool ensure_ascii, unsigned int depth,
|
||||
const fancy_serializer_style* active_style)
|
||||
{
|
||||
const auto new_indent = (depth + 1) * active_style->indent_step;
|
||||
const int newline_len = (active_style->indent_step > 0);
|
||||
|
||||
o->write_characters(indent_string.c_str(), new_indent);
|
||||
o->write_character('\"');
|
||||
prim_serializer.dump_escaped(*o, i->first, ensure_ascii);
|
||||
o->write_characters("\": ", 2 + newline_len);
|
||||
auto new_style = stylizer.get_new_style_or_active(i->first, active_style);
|
||||
dump(i->second, ensure_ascii, depth + 1, new_style);
|
||||
}
|
||||
|
||||
void dump_object(const BasicJsonType& val,
|
||||
bool ensure_ascii,
|
||||
unsigned int depth,
|
||||
@ -10304,24 +10320,14 @@ class fancy_serializer
|
||||
auto i = val.m_value.object->cbegin();
|
||||
for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
|
||||
{
|
||||
o->write_characters(indent_string.c_str(), new_indent);
|
||||
o->write_character('\"');
|
||||
prim_serializer.dump_escaped(*o, i->first, ensure_ascii);
|
||||
o->write_characters("\": ", 2 + newline_len);
|
||||
auto new_style = stylizer.get_new_style_or_active(i->first, active_style);
|
||||
dump(i->second, ensure_ascii, depth + 1, new_style);
|
||||
dump_object_key_value(i, ensure_ascii, depth, active_style);
|
||||
o->write_characters(",\n", 1 + newline_len);
|
||||
}
|
||||
|
||||
// last element
|
||||
assert(i != val.m_value.object->cend());
|
||||
assert(std::next(i) == val.m_value.object->cend());
|
||||
o->write_characters(indent_string.c_str(), new_indent);
|
||||
o->write_character('\"');
|
||||
prim_serializer.dump_escaped(*o, i->first, ensure_ascii);
|
||||
o->write_characters("\": ", 2 + newline_len);
|
||||
auto new_style = stylizer.get_new_style_or_active(i->first, active_style);
|
||||
dump(i->second, ensure_ascii, depth + 1, new_style);
|
||||
dump_object_key_value(i, ensure_ascii, depth, active_style);
|
||||
|
||||
o->write_characters("\n", newline_len);
|
||||
o->write_characters(indent_string.c_str(), old_indent);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user