MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / dump

Method dump

Source/Utils/json.hpp:15532–15799  ·  view source on GitHub ↗

! @brief internal implementation of the serialization function This function is called by the public member function dump and organizes the serialization internally. The indentation level is propagated as additional parameter. In case of arrays and objects, the function is called recursively. - strings and object keys are es

Source from the content-addressed store, hash-verified

15530 @param[in] current_indent the current indent level (only used internally)
15531 */
15532 void dump(const BasicJsonType& val,
15533 const bool pretty_print,
15534 const bool ensure_ascii,
15535 const unsigned int indent_step,
15536 const unsigned int current_indent = 0)
15537 {
15538 switch (val.m_type)
15539 {
15540 case value_t::object:
15541 {
15542 if (val.m_value.object->empty())
15543 {
15544 o->write_characters("{}", 2);
15545 return;
15546 }
15547
15548 if (pretty_print)
15549 {
15550 o->write_characters("{\n", 2);
15551
15552 // variable to hold indentation for recursive calls
15553 const auto new_indent = current_indent + indent_step;
15554 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
15555 {
15556 indent_string.resize(indent_string.size() * 2, ' ');
15557 }
15558
15559 // first n-1 elements
15560 auto i = val.m_value.object->cbegin();
15561 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
15562 {
15563 o->write_characters(indent_string.c_str(), new_indent);
15564 o->write_character('\"');
15565 dump_escaped(i->first, ensure_ascii);
15566 o->write_characters("\": ", 3);
15567 dump(i->second, true, ensure_ascii, indent_step, new_indent);
15568 o->write_characters(",\n", 2);
15569 }
15570
15571 // last element
15572 JSON_ASSERT(i != val.m_value.object->cend());
15573 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
15574 o->write_characters(indent_string.c_str(), new_indent);
15575 o->write_character('\"');
15576 dump_escaped(i->first, ensure_ascii);
15577 o->write_characters("\": ", 3);
15578 dump(i->second, true, ensure_ascii, indent_step, new_indent);
15579
15580 o->write_character('\n');
15581 o->write_characters(indent_string.c_str(), current_indent);
15582 o->write_character('}');
15583 }
15584 else
15585 {
15586 o->write_character('{');
15587
15588 // first n-1 elements
15589 auto i = val.m_value.object->cbegin();

Callers 7

ToJsonMethod · 0.80
ToJsonMethod · 0.80
SaveCampaignMethod · 0.80
json.hppFile · 0.80
patchFunction · 0.80
string to_stringMethod · 0.80

Calls 7

resizeMethod · 0.80
has_subtypeMethod · 0.80
subtypeMethod · 0.80
emptyMethod · 0.45
write_charactersMethod · 0.45
sizeMethod · 0.45
write_characterMethod · 0.45

Tested by

no test coverage detected