MCPcopy Create free account
hub / github.com/MihailRis/voxelcore / stringifyValue

Function stringifyValue

src/coders/json.cpp:49–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47);
48
49void stringifyValue(
50 const Value& value,
51 std::stringstream& ss,
52 int indent,
53 const std::string& indentstr,
54 bool nice
55) {
56 if (auto map = std::get_if<Map_sptr>(&value)) {
57 stringifyObj(map->get(), ss, indent, indentstr, nice);
58 }
59 else if (auto listptr = std::get_if<List_sptr>(&value)) {
60 auto list = *listptr;
61 if (list->size() == 0) {
62 ss << "[]";
63 return;
64 }
65 ss << '[';
66 for (uint i = 0; i < list->size(); i++) {
67 Value& value = list->get(i);
68 if (i > 0 || nice) {
69 newline(ss, nice, indent, indentstr);
70 }
71 stringifyValue(value, ss, indent+1, indentstr, nice);
72 if (i + 1 < list->size()) {
73 ss << ',';
74 }
75 }
76 if (nice) {
77 newline(ss, true, indent - 1, indentstr);
78 }
79 ss << ']';
80 } else if (auto flag = std::get_if<bool>(&value)) {
81 ss << (*flag ? "true" : "false");
82 } else if (auto num = std::get_if<number_t>(&value)) {
83 ss << std::setprecision(15) << *num;
84 } else if (auto num = std::get_if<integer_t>(&value)) {
85 ss << *num;
86 } else if (auto str = std::get_if<std::string>(&value)) {
87 ss << util::escape(*str);
88 } else {
89 ss << "null";
90 }
91}
92
93void stringifyObj(
94 const Map* obj,

Callers 2

stringifyObjFunction · 0.85
stringifyMethod · 0.85

Calls 4

stringifyObjFunction · 0.85
newlineFunction · 0.70
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected