| 307 | struct JSONFormatter |
| 308 | { |
| 309 | static void write (OutputStream& out, const var& v, |
| 310 | int indentLevel, bool allOnOneLine, int maximumDecimalPlaces) |
| 311 | { |
| 312 | if (v.isString()) |
| 313 | { |
| 314 | out << '"'; |
| 315 | writeString (out, v.toString().getCharPointer()); |
| 316 | out << '"'; |
| 317 | } |
| 318 | else if (v.isVoid()) |
| 319 | { |
| 320 | out << "null"; |
| 321 | } |
| 322 | else if (v.isUndefined()) |
| 323 | { |
| 324 | out << "undefined"; |
| 325 | } |
| 326 | else if (v.isBool()) |
| 327 | { |
| 328 | out << (static_cast<bool> (v) ? "true" : "false"); |
| 329 | } |
| 330 | else if (v.isDouble()) |
| 331 | { |
| 332 | auto d = static_cast<double> (v); |
| 333 | |
| 334 | if (juce_isfinite (d)) |
| 335 | { |
| 336 | out << serialiseDouble (d); |
| 337 | } |
| 338 | else |
| 339 | { |
| 340 | out << "null"; |
| 341 | } |
| 342 | } |
| 343 | else if (v.isArray()) |
| 344 | { |
| 345 | writeArray (out, *v.getArray(), indentLevel, allOnOneLine, maximumDecimalPlaces); |
| 346 | } |
| 347 | else if (v.isObject()) |
| 348 | { |
| 349 | if (auto* object = v.getDynamicObject()) |
| 350 | object->writeAsJSON (out, indentLevel, allOnOneLine, maximumDecimalPlaces); |
| 351 | else |
| 352 | jassertfalse; // Only DynamicObjects can be converted to JSON! |
| 353 | } |
| 354 | else |
| 355 | { |
| 356 | // Can't convert these other types of object to JSON! |
| 357 | jassert (! (v.isMethod() || v.isBinaryData())); |
| 358 | |
| 359 | out << v.toString(); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | static void writeEscapedChar (OutputStream& out, const unsigned short value) |
| 364 | { |
no test coverage detected