MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / write

Method write

JUCE/modules/juce_core/javascript/juce_JSON.cpp:309–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307struct 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 {

Callers 1

writeStringMethod · 0.45

Calls 15

juce_isfiniteFunction · 0.85
serialiseDoubleFunction · 0.85
getDynamicObjectMethod · 0.80
isBinaryDataMethod · 0.80
isStringMethod · 0.45
toStringMethod · 0.45
isVoidMethod · 0.45
isUndefinedMethod · 0.45
isBoolMethod · 0.45
isDoubleMethod · 0.45
isArrayMethod · 0.45
getArrayMethod · 0.45

Tested by

no test coverage detected