MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / dump

Method dump

Source/external/json.hpp:17991–18258  ·  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 escaped using `escape_string()` - integer numbers are converted imp

Source from the content-addressed store, hash-verified

17989 @param[in] current_indent the current indent level (only used internally)
17990 */
17991 void dump(const BasicJsonType& val,
17992 const bool pretty_print,
17993 const bool ensure_ascii,
17994 const unsigned int indent_step,
17995 const unsigned int current_indent = 0)
17996 {
17997 switch (val.m_type)
17998 {
17999 case value_t::object:
18000 {
18001 if (val.m_value.object->empty())
18002 {
18003 o->write_characters("{}", 2);
18004 return;
18005 }
18006
18007 if (pretty_print)
18008 {
18009 o->write_characters("{\n", 2);
18010
18011 // variable to hold indentation for recursive calls
18012 const auto new_indent = current_indent + indent_step;
18013 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18014 {
18015 indent_string.resize(indent_string.size() * 2, ' ');
18016 }
18017
18018 // first n-1 elements
18019 auto i = val.m_value.object->cbegin();
18020 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
18021 {
18022 o->write_characters(indent_string.c_str(), new_indent);
18023 o->write_character('\"');
18024 dump_escaped(i->first, ensure_ascii);
18025 o->write_characters("\": ", 3);
18026 dump(i->second, true, ensure_ascii, indent_step, new_indent);
18027 o->write_characters(",\n", 2);
18028 }
18029
18030 // last element
18031 JSON_ASSERT(i != val.m_value.object->cend());
18032 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
18033 o->write_characters(indent_string.c_str(), new_indent);
18034 o->write_character('\"');
18035 dump_escaped(i->first, ensure_ascii);
18036 o->write_characters("\": ", 3);
18037 dump(i->second, true, ensure_ascii, indent_step, new_indent);
18038
18039 o->write_character('\n');
18040 o->write_characters(indent_string.c_str(), current_indent);
18041 o->write_character('}');
18042 }
18043 else
18044 {
18045 o->write_character('{');
18046
18047 // first n-1 elements
18048 auto i = val.m_value.object->cbegin();

Callers 6

saveNodeToJsonFileMethod · 0.80
json.hppFile · 0.80
patch_inplaceFunction · 0.80
string to_stringMethod · 0.80

Calls 5

dump_integerFunction · 0.85
dump_floatFunction · 0.85
emptyMethod · 0.80
sizeMethod · 0.80
write_characterMethod · 0.45

Tested by

no test coverage detected