MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / dump

Method dump

dependencies/json/json.hpp:15607–15874  ·  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

15605 @param[in] current_indent the current indent level (only used internally)
15606 */
15607 void dump(const BasicJsonType& val,
15608 const bool pretty_print,
15609 const bool ensure_ascii,
15610 const unsigned int indent_step,
15611 const unsigned int current_indent = 0)
15612 {
15613 switch (val.m_type)
15614 {
15615 case value_t::object:
15616 {
15617 if (val.m_value.object->empty())
15618 {
15619 o->write_characters("{}", 2);
15620 return;
15621 }
15622
15623 if (pretty_print)
15624 {
15625 o->write_characters("{\n", 2);
15626
15627 // variable to hold indentation for recursive calls
15628 const auto new_indent = current_indent + indent_step;
15629 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
15630 {
15631 indent_string.resize(indent_string.size() * 2, ' ');
15632 }
15633
15634 // first n-1 elements
15635 auto i = val.m_value.object->cbegin();
15636 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
15637 {
15638 o->write_characters(indent_string.c_str(), new_indent);
15639 o->write_character('\"');
15640 dump_escaped(i->first, ensure_ascii);
15641 o->write_characters("\": ", 3);
15642 dump(i->second, true, ensure_ascii, indent_step, new_indent);
15643 o->write_characters(",\n", 2);
15644 }
15645
15646 // last element
15647 JSON_ASSERT(i != val.m_value.object->cend());
15648 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
15649 o->write_characters(indent_string.c_str(), new_indent);
15650 o->write_character('\"');
15651 dump_escaped(i->first, ensure_ascii);
15652 o->write_characters("\": ", 3);
15653 dump(i->second, true, ensure_ascii, indent_step, new_indent);
15654
15655 o->write_character('\n');
15656 o->write_characters(indent_string.c_str(), current_indent);
15657 o->write_character('}');
15658 }
15659 else
15660 {
15661 o->write_character('{');
15662
15663 // first n-1 elements
15664 auto i = val.m_value.object->cbegin();

Callers 5

SaveSettingsMethod · 0.45
json.hppFile · 0.45
patchFunction · 0.45
string to_stringMethod · 0.45

Calls 7

dump_integerFunction · 0.70
dump_floatFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45
write_characterMethod · 0.45
has_subtypeMethod · 0.45
subtypeMethod · 0.45

Tested by

no test coverage detected