MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / _stringify_json

Function _stringify_json

exporters/scene_exporter.cpp:123–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123void _stringify_json(String &r_result, const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, bool force_single_precision, HashSet<const void *> &p_markers) {
124 if (p_cur_indent > Variant::MAX_RECURSION_DEPTH) {
125 r_result += "...";
126 ERR_FAIL_MSG("JSON structure is too deep. Bailing.");
127 }
128
129 const char *colon = p_indent.is_empty() ? ":" : ": ";
130 const char *end_statement = p_indent.is_empty() ? "" : "\n";
131
132 switch (p_var.get_type()) {
133 case Variant::NIL:
134 r_result += "null";
135 return;
136 case Variant::BOOL:
137 r_result += p_var.operator bool() ? "true" : "false";
138 return;
139 case Variant::INT:
140 r_result += itos(p_var);
141 return;
142 case Variant::FLOAT: {
143 double num = p_var;
144
145 // Only for exactly 0. If we have approximately 0 let the user decide how much
146 // precision they want.
147 if (num == double(0)) {
148 r_result += "0.0";
149 return;
150 }
151
152 // No NaN in JSON.
153 if (Math::is_nan(num)) {
154 r_result += "null";
155 return;
156 }
157
158 // No Infinity in JSON; use a value that will be parsed as Infinity/-Infinity.
159 if (std::isinf(num)) {
160 if (num < 0.0) {
161 r_result += "-1.0e+511";
162 } else {
163 r_result += "1.0e+511";
164 }
165 return;
166 }
167
168 String num_str;
169 if (force_single_precision || (double)(float)num == num) {
170 r_result += String::num_scientific((float)num);
171 } else {
172 r_result += String::num_scientific(num);
173 }
174 r_result += num_str;
175 return;
176 }
177 case Variant::PACKED_INT32_ARRAY:
178 case Variant::PACKED_INT64_ARRAY:
179 case Variant::PACKED_FLOAT32_ARRAY:
180 case Variant::PACKED_FLOAT64_ARRAY:

Callers 1

stringify_jsonFunction · 0.85

Calls 4

_add_indentFunction · 0.85
get_typeMethod · 0.45
insertMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected