MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / dump

Method dump

native/thirdpart/json/json.hpp:13837–14030  ·  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

13835 @param[in] current_indent the current indent level (only used internally)
13836 */
13837 void dump(const BasicJsonType& val, const bool pretty_print,
13838 const bool ensure_ascii,
13839 const unsigned int indent_step,
13840 const unsigned int current_indent = 0)
13841 {
13842 switch (val.m_type)
13843 {
13844 case value_t::object:
13845 {
13846 if (val.m_value.object->empty())
13847 {
13848 o->write_characters("{}", 2);
13849 return;
13850 }
13851
13852 if (pretty_print)
13853 {
13854 o->write_characters("{\n", 2);
13855
13856 // variable to hold indentation for recursive calls
13857 const auto new_indent = current_indent + indent_step;
13858 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
13859 {
13860 indent_string.resize(indent_string.size() * 2, ' ');
13861 }
13862
13863 // first n-1 elements
13864 auto i = val.m_value.object->cbegin();
13865 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
13866 {
13867 o->write_characters(indent_string.c_str(), new_indent);
13868 o->write_character('\"');
13869 dump_escaped(i->first, ensure_ascii);
13870 o->write_characters("\": ", 3);
13871 dump(i->second, true, ensure_ascii, indent_step, new_indent);
13872 o->write_characters(",\n", 2);
13873 }
13874
13875 // last element
13876 assert(i != val.m_value.object->cend());
13877 assert(std::next(i) == val.m_value.object->cend());
13878 o->write_characters(indent_string.c_str(), new_indent);
13879 o->write_character('\"');
13880 dump_escaped(i->first, ensure_ascii);
13881 o->write_characters("\": ", 3);
13882 dump(i->second, true, ensure_ascii, indent_step, new_indent);
13883
13884 o->write_character('\n');
13885 o->write_characters(indent_string.c_str(), current_indent);
13886 o->write_character('}');
13887 }
13888 else
13889 {
13890 o->write_character('{');
13891
13892 // first n-1 elements
13893 auto i = val.m_value.object->cbegin();
13894 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)

Callers 5

toStringMethod · 0.45
json.hppFile · 0.45
patchFunction · 0.45
string to_stringMethod · 0.45
operator()Method · 0.45

Calls 6

emptyMethod · 0.80
sizeMethod · 0.45
cbeginMethod · 0.45
c_strMethod · 0.45
write_characterMethod · 0.45
cendMethod · 0.45

Tested by

no test coverage detected