webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
writer.h
Go to the documentation of this file.
1 // Copyright 2007-2010 Baptiste Lepilleur
2 // Distributed under MIT license, or public domain if desired and
3 // recognized in your jurisdiction.
4 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
5 
6 #ifndef JSON_WRITER_H_INCLUDED
7 # define JSON_WRITER_H_INCLUDED
8 
9 #if !defined(JSON_IS_AMALGAMATION)
10 # include "value.h"
11 #endif // if !defined(JSON_IS_AMALGAMATION)
12 # include <vector>
13 # include <string>
14 
15 namespace Json {
16 
17  class Value;
18 
22  {
23  public:
24  virtual ~Writer();
25 
26  virtual std::string write( const Value &root ) = 0;
27  };
28 
35  class JSON_API FastWriter : public Writer
36  {
37  public:
38  FastWriter();
39  virtual ~FastWriter(){}
40 
41  void enableYAMLCompatibility();
42 
43  public: // overridden from Writer
44  virtual std::string write( const Value &root );
45 
46  private:
47  void writeValue( const Value &value );
48 
49  std::string document_;
50  bool yamlCompatiblityEnabled_;
51  };
52 
72  {
73  public:
74  StyledWriter();
75  virtual ~StyledWriter(){}
76 
77  public: // overridden from Writer
82  virtual std::string write( const Value &root );
83 
84  private:
85  void writeValue( const Value &value );
86  void writeArrayValue( const Value &value );
87  bool isMultineArray( const Value &value );
88  void pushValue( const std::string &value );
89  void writeIndent();
90  void writeWithIndent( const std::string &value );
91  void indent();
92  void unindent();
93  void writeCommentBeforeValue( const Value &root );
94  void writeCommentAfterValueOnSameLine( const Value &root );
95  bool hasCommentForValue( const Value &value );
96  static std::string normalizeEOL( const std::string &text );
97 
98  typedef std::vector<std::string> ChildValues;
99 
100  ChildValues childValues_;
101  std::string document_;
102  std::string indentString_;
103  int rightMargin_;
104  int indentSize_;
105  bool addChildValues_;
106  };
107 
129  {
130  public:
131  StyledStreamWriter( std::string indentation="\t" );
133 
134  public:
140  void write( std::ostream &out, const Value &root );
141 
142  private:
143  void writeValue( const Value &value );
144  void writeArrayValue( const Value &value );
145  bool isMultineArray( const Value &value );
146  void pushValue( const std::string &value );
147  void writeIndent();
148  void writeWithIndent( const std::string &value );
149  void indent();
150  void unindent();
151  void writeCommentBeforeValue( const Value &root );
152  void writeCommentAfterValueOnSameLine( const Value &root );
153  bool hasCommentForValue( const Value &value );
154  static std::string normalizeEOL( const std::string &text );
155 
156  typedef std::vector<std::string> ChildValues;
157 
158  ChildValues childValues_;
159  std::ostream* document_;
160  std::string indentString_;
161  int rightMargin_;
162  std::string indentation_;
163  bool addChildValues_;
164  };
165 
166 # if defined(JSON_HAS_INT64)
169 # endif // if defined(JSON_HAS_INT64)
172  std::string JSON_API valueToString( double value );
173  std::string JSON_API valueToString( bool value );
174  std::string JSON_API valueToQuotedString( const char *value );
175 
178  std::ostream& operator<<( std::ostream&, const Value &root );
179 
180 } // namespace Json
181 
182 
183 
184 #endif // JSON_WRITER_H_INCLUDED
void write(TextStream &, const RenderObject &, int indent=0, RenderAsTextBehavior=RenderAsTextBehaviorNormal)
Definition: RenderTreeAsText.cpp:529
Outputs a Value in JSON format without formatting (not human friendly).
Definition: writer.h:35
Int64 LargestInt
Definition: config.h:91
Writes a Value in JSON format in a human friendly way.
Definition: writer.h:71
Definition: XMLHttpRequest.idl:39
virtual ~FastWriter()
Definition: writer.h:39
def root
Definition: pyjsontestrunner.py:60
std::string JSON_API valueToQuotedString(const char *value)
Definition: json_writer.cpp:119
~StyledStreamWriter()
Definition: writer.h:132
std::string JSON_API valueToString(Int value)
UInt64 LargestUInt
Definition: config.h:92
int int * out
Definition: gcc-loops.cpp:206
EGLAttrib * value
Definition: eglext.h:120
JSON (JavaScript Object Notation).
Definition: value.h:26
GLsizei const GLchar *const * string
Definition: gl2.h:479
Abstract class for writers.
Definition: writer.h:21
Represents a JSON value.
Definition: value.h:118
unsigned int UInt
Definition: config.h:77
Writes a Value in JSON format in a human friendly way, to a stream rather than to a string...
Definition: writer.h:128
virtual ~StyledWriter()
Definition: writer.h:75
#define JSON_API
Definition: config.h:53
int Int
Definition: config.h:76
std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
Definition: json_writer.cpp:833
void writeIndent(TextStream &, int indent)
Definition: TextStream.cpp:187