MCPcopy Create free account
hub / github.com/boostorg/json / pretty_print

Function pretty_print

example/pretty.cpp:46–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46void
47pretty_print( std::ostream& os, json::value const& jv, std::string* indent = nullptr )
48{
49 std::string indent_;
50 if(! indent)
51 indent = &indent_;
52 switch(jv.kind())
53 {
54 case json::kind::object:
55 {
56 os << "{\n";
57 indent->append(4, ' ');
58 auto const& obj = jv.get_object();
59 if(! obj.empty())
60 {
61 auto it = obj.begin();
62 for(;;)
63 {
64 os << *indent << json::serialize(it->key()) << " : ";
65 pretty_print(os, it->value(), indent);
66 if(++it == obj.end())
67 break;
68 os << ",\n";
69 }
70 }
71 os << "\n";
72 indent->resize(indent->size() - 4);
73 os << *indent << "}";
74 break;
75 }
76
77 case json::kind::array:
78 {
79 os << "[\n";
80 indent->append(4, ' ');
81 auto const& arr = jv.get_array();
82 if(! arr.empty())
83 {
84 auto it = arr.begin();
85 for(;;)
86 {
87 os << *indent;
88 pretty_print( os, *it, indent);
89 if(++it == arr.end())
90 break;
91 os << ",\n";
92 }
93 }
94 os << "\n";
95 indent->resize(indent->size() - 4);
96 os << *indent << "]";
97 break;
98 }
99
100 case json::kind::string:
101 {
102 os << json::serialize(jv.get_string());
103 break;

Callers 1

mainFunction · 0.85

Calls 11

serializeFunction · 0.85
kindMethod · 0.80
keyMethod · 0.80
valueMethod · 0.80
resizeMethod · 0.80
get_boolMethod · 0.80
appendMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected