mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
JSON: Add new JSON::Formatter for configuring JSON output
This also fixes an issue where MIDI CI header data could contain spaces, which is not allowed according to the spec.
This commit is contained in:
parent
06855ed05d
commit
224c4f706b
12 changed files with 203 additions and 96 deletions
|
|
@ -94,37 +94,47 @@ std::unique_ptr<DynamicObject> DynamicObject::clone() const
|
|||
return result;
|
||||
}
|
||||
|
||||
void DynamicObject::writeAsJSON (OutputStream& out, const int indentLevel, const bool allOnOneLine, int maximumDecimalPlaces)
|
||||
void DynamicObject::writeAsJSON (OutputStream& out, const JSON::FormatOptions& format)
|
||||
{
|
||||
out << '{';
|
||||
if (! allOnOneLine)
|
||||
if (format.getSpacing() == JSON::Spacing::multiLine)
|
||||
out << newLine;
|
||||
|
||||
const int numValues = properties.size();
|
||||
|
||||
for (int i = 0; i < numValues; ++i)
|
||||
{
|
||||
if (! allOnOneLine)
|
||||
JSONFormatter::writeSpaces (out, indentLevel + JSONFormatter::indentSize);
|
||||
if (format.getSpacing() == JSON::Spacing::multiLine)
|
||||
JSONFormatter::writeSpaces (out, format.getIndentLevel() + JSONFormatter::indentSize);
|
||||
|
||||
out << '"';
|
||||
JSONFormatter::writeString (out, properties.getName (i));
|
||||
out << "\": ";
|
||||
JSONFormatter::write (out, properties.getValueAt (i), indentLevel + JSONFormatter::indentSize, allOnOneLine, maximumDecimalPlaces);
|
||||
out << "\":";
|
||||
|
||||
if (format.getSpacing() != JSON::Spacing::none)
|
||||
out << ' ';
|
||||
|
||||
JSON::writeToStream (out,
|
||||
properties.getValueAt (i),
|
||||
format.withIndentLevel (format.getIndentLevel() + JSONFormatter::indentSize));
|
||||
|
||||
if (i < numValues - 1)
|
||||
{
|
||||
if (allOnOneLine)
|
||||
out << ", ";
|
||||
else
|
||||
out << ',' << newLine;
|
||||
out << ",";
|
||||
|
||||
switch (format.getSpacing())
|
||||
{
|
||||
case JSON::Spacing::none: break;
|
||||
case JSON::Spacing::singleLine: out << ' '; break;
|
||||
case JSON::Spacing::multiLine: out << newLine; break;
|
||||
}
|
||||
}
|
||||
else if (! allOnOneLine)
|
||||
else if (format.getSpacing() == JSON::Spacing::multiLine)
|
||||
out << newLine;
|
||||
}
|
||||
|
||||
if (! allOnOneLine)
|
||||
JSONFormatter::writeSpaces (out, indentLevel);
|
||||
if (format.getSpacing() == JSON::Spacing::multiLine)
|
||||
JSONFormatter::writeSpaces (out, format.getIndentLevel());
|
||||
|
||||
out << '}';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ public:
|
|||
never need to call it directly, but it's virtual so that custom object types
|
||||
can stringify themselves appropriately.
|
||||
*/
|
||||
virtual void writeAsJSON (OutputStream&, int indentLevel, bool allOnOneLine, int maximumDecimalPlaces);
|
||||
virtual void writeAsJSON (OutputStream&, const JSON::FormatOptions&);
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue