JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_JSON.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
38class JUCE_API JSON
39{
40public:
41 //==============================================================================
56 static Result parse (const String& text, var& parsedResult);
57
67 static var parse (const String& text);
68
78 static var parse (const File& file);
79
89 static var parse (InputStream& input);
90
91 enum class Spacing
92 {
93 none,
94 singleLine,
95 multiLine,
96 };
97
101 class [[nodiscard]] FormatOptions
102 {
103 public:
105 FormatOptions withSpacing (Spacing x) const { return withMember (*this, &FormatOptions::spacing, x); }
106
110 FormatOptions withMaxDecimalPlaces (int x) const { return withMember (*this, &FormatOptions::maxDecimalPlaces, x); }
111
115 FormatOptions withIndentLevel (int x) const { return withMember (*this, &FormatOptions::indent, x); }
116
118 Spacing getSpacing() const { return spacing; }
119
121 int getMaxDecimalPlaces() const { return maxDecimalPlaces; }
122
124 int getIndentLevel() const { return indent; }
125
126 private:
127 Spacing spacing = Spacing::multiLine;
128 int maxDecimalPlaces = 15;
129 int indent = 0;
130 };
131
132 //==============================================================================
140 static String toString (const var& objectToFormat,
141 bool allOnOneLine = false,
142 int maximumDecimalPlaces = 15);
143
148 static String toString (const var& objectToFormat,
149 const FormatOptions& formatOptions);
150
156 static var fromString (StringRef);
157
165 static void writeToStream (OutputStream& output,
166 const var& objectToFormat,
167 bool allOnOneLine = false,
168 int maximumDecimalPlaces = 15);
169
174 static void writeToStream (OutputStream& output,
175 const var& objectToFormat,
176 const FormatOptions& formatOptions);
177
179 static String escapeString (StringRef);
180
185 static Result parseQuotedString (String::CharPointerType& text, var& result);
186
187private:
188 //==============================================================================
189 JSON() = delete; // This class can't be instantiated - just use its static methods.
190};
191
192} // namespace juce
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
Represents a local file or directory.
Definition juce_File.h:45
The base class for streams that read data.
Allows formatting var objects as JSON with various configurable options.
Definition juce_JSON.h:102
int getIndentLevel() const
Returns the indent level of this Formatter.
Definition juce_JSON.h:124
Spacing getSpacing() const
Returns the spacing used by this Formatter.
Definition juce_JSON.h:118
int getMaxDecimalPlaces() const
Returns the maximum number of decimal places used by this Formatter.
Definition juce_JSON.h:121
FormatOptions withSpacing(Spacing x) const
Returns a copy of this Formatter with the specified spacing.
Definition juce_JSON.h:105
FormatOptions withIndentLevel(int x) const
Returns a copy of this Formatter with the specified indent level.
Definition juce_JSON.h:115
FormatOptions withMaxDecimalPlaces(int x) const
Returns a copy of this Formatter with the specified maximum number of decimal places.
Definition juce_JSON.h:110
Contains static methods for converting JSON-formatted text to and from var objects.
Definition juce_JSON.h:39
The base class for streams that write data to some kind of destination.
Represents the 'success' or 'failure' of an operation, and holds an associated error message to descr...
Definition juce_Result.h:57
A simple class for holding temporary references to a string literal or String.
The JUCE String class!
Definition juce_String.h:53
A variant class, that can be used to hold a range of primitive values.
JUCE Namespace.
Object withMember(Object copy, Member OtherObject::*member, Other &&value)
Copies an object, sets one of the copy's members to the specified value, and then returns the copy.