MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / dump

Method dump

extern/json/json.hpp:18029–18296  ·  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 numb

Source from the content-addressed store, hash-verified

18027 @param[in] current_indent the current indent level (only used internally)
18028 */
18029 void dump(const BasicJsonType& val,
18030 const bool pretty_print,
18031 const bool ensure_ascii,
18032 const unsigned int indent_step,
18033 const unsigned int current_indent = 0)
18034 {
18035 switch (val.m_type)
18036 {
18037 case value_t::object:
18038 {
18039 if (val.m_value.object->empty())
18040 {
18041 o->write_characters("{}", 2);
18042 return;
18043 }
18044
18045 if (pretty_print)
18046 {
18047 o->write_characters("{\n", 2);
18048
18049 // variable to hold indentation for recursive calls
18050 const auto new_indent = current_indent + indent_step;
18051 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18052 {
18053 indent_string.resize(indent_string.size() * 2, ' ');
18054 }
18055
18056 // first n-1 elements
18057 auto i = val.m_value.object->cbegin();
18058 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
18059 {
18060 o->write_characters(indent_string.c_str(), new_indent);
18061 o->write_character('\"');
18062 dump_escaped(i->first, ensure_ascii);
18063 o->write_characters("\": ", 3);
18064 dump(i->second, true, ensure_ascii, indent_step, new_indent);
18065 o->write_characters(",\n", 2);
18066 }
18067
18068 // last element
18069 JSON_ASSERT(i != val.m_value.object->cend());
18070 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
18071 o->write_characters(indent_string.c_str(), new_indent);
18072 o->write_character('\"');
18073 dump_escaped(i->first, ensure_ascii);
18074 o->write_characters("\": ", 3);
18075 dump(i->second, true, ensure_ascii, indent_step, new_indent);
18076
18077 o->write_character('\n');
18078 o->write_characters(indent_string.c_str(), current_indent);
18079 o->write_character('}');
18080 }
18081 else
18082 {
18083 o->write_character('{');
18084
18085 // first n-1 elements
18086 auto i = val.m_value.object->cbegin();

Callers 4

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

Calls 9

dump_integerFunction · 0.85
dump_floatFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
cbeginMethod · 0.45
c_strMethod · 0.45
write_characterMethod · 0.45
cendMethod · 0.45

Tested by

no test coverage detected