OpenShot Audio Library | OpenShotAudio  0.6.0
juce_JSON.h
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 
23 namespace juce
24 {
25 
26 //==============================================================================
38 class JUCE_API JSON
39 {
40 public:
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 
187 private:
188  //==============================================================================
189  JSON() = delete; // This class can't be instantiated - just use its static methods.
190 };
191 
192 } // namespace juce
int getIndentLevel() const
Definition: juce_JSON.h:124
Spacing getSpacing() const
Definition: juce_JSON.h:118
int getMaxDecimalPlaces() const
Definition: juce_JSON.h:121
FormatOptions withSpacing(Spacing x) const
Definition: juce_JSON.h:105
FormatOptions withIndentLevel(int x) const
Definition: juce_JSON.h:115
FormatOptions withMaxDecimalPlaces(int x) const
Definition: juce_JSON.h:110