MCPcopy Create free account
hub / github.com/AllentDan/LibtorchTutorials / dump

Method dump

lesson6-Segmentation/json.hpp:15533–15800  ·  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

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

Callers 4

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

Calls 6

c_strMethod · 0.80
has_subtypeMethod · 0.80
subtypeMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
write_characterMethod · 0.45

Tested by

no test coverage detected