webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
reader.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 CPPTL_JSON_READER_H_INCLUDED
7 # define CPPTL_JSON_READER_H_INCLUDED
8 
9 #if !defined(JSON_IS_AMALGAMATION)
10 # include "features.h"
11 # include "value.h"
12 #endif // if !defined(JSON_IS_AMALGAMATION)
13 # include <deque>
14 # include <stack>
15 # include <string>
16 
17 namespace Json {
18 
23  {
24  public:
25  typedef char Char;
26  typedef const Char *Location;
27 
31  Reader();
32 
36  Reader( const Features &features );
37 
48  bool parse( const std::string &document,
49  Value &root,
50  bool collectComments = true );
51 
64  bool parse( const char *beginDoc, const char *endDoc,
65  Value &root,
66  bool collectComments = true );
67 
70  bool parse( std::istream &is,
71  Value &root,
72  bool collectComments = true );
73 
80  JSONCPP_DEPRECATED("Use getFormattedErrorMessages instead")
81  std::string getFormatedErrorMessages() const;
82 
88  std::string getFormattedErrorMessages() const;
89 
90  private:
91  enum TokenType
92  {
93  tokenEndOfStream = 0,
94  tokenObjectBegin,
95  tokenObjectEnd,
96  tokenArrayBegin,
97  tokenArrayEnd,
98  tokenString,
99  tokenNumber,
100  tokenTrue,
101  tokenFalse,
102  tokenNull,
103  tokenArraySeparator,
104  tokenMemberSeparator,
105  tokenComment,
106  tokenError
107  };
108 
109  class Token
110  {
111  public:
112  TokenType type_;
113  Location start_;
114  Location end_;
115  };
116 
117  class ErrorInfo
118  {
119  public:
120  Token token_;
121  std::string message_;
122  Location extra_;
123  };
124 
125  typedef std::deque<ErrorInfo> Errors;
126 
127  bool expectToken( TokenType type, Token &token, const char *message );
128  bool readToken( Token &token );
129  void skipSpaces();
130  bool match( Location pattern,
131  int patternLength );
132  bool readComment();
133  bool readCStyleComment();
134  bool readCppStyleComment();
135  bool readString();
136  void readNumber();
137  bool readValue();
138  bool readObject( Token &token );
139  bool readArray( Token &token );
140  bool decodeNumber( Token &token );
141  bool decodeString( Token &token );
142  bool decodeString( Token &token, std::string &decoded );
143  bool decodeDouble( Token &token );
144  bool decodeUnicodeCodePoint( Token &token,
145  Location &current,
146  Location end,
147  unsigned int &unicode );
148  bool decodeUnicodeEscapeSequence( Token &token,
149  Location &current,
150  Location end,
151  unsigned int &unicode );
152  bool addError( const std::string &message,
153  Token &token,
154  Location extra = 0 );
155  bool recoverFromError( TokenType skipUntilToken );
156  bool addErrorAndRecover( const std::string &message,
157  Token &token,
158  TokenType skipUntilToken );
159  void skipUntilSpace();
160  Value &currentValue();
161  Char getNextChar();
162  void getLocationLineAndColumn( Location location,
163  int &line,
164  int &column ) const;
165  std::string getLocationLineAndColumn( Location location ) const;
166  void addComment( Location begin,
167  Location end,
168  CommentPlacement placement );
169  void skipCommentTokens( Token &token );
170 
171  typedef std::stack<Value *> Nodes;
172  Nodes nodes_;
173  Errors errors_;
174  std::string document_;
175  Location begin_;
176  Location end_;
177  Location current_;
178  Location lastValueEnd_;
179  Value *lastValue_;
180  std::string commentsBefore_;
181  Features features_;
182  bool collectComments_;
183  };
184 
209  std::istream& operator>>( std::istream&, Value& );
210 
211 } // namespace Json
212 
213 #endif // CPPTL_JSON_READER_H_INCLUDED
Definition: IWebViewPrivate.idl:301
line
Definition: buildtests.py:37
def root
Definition: pyjsontestrunner.py:60
GLuint GLuint end
Definition: gl2ext.h:323
std::istream & operator>>(std::istream &sin, Value &root)
Read from &#39;sin&#39; into &#39;root&#39;.
Definition: json_reader.cpp:904
char Char
Definition: reader.h:25
Definition: videoengine_unittest.h:62
Definition: WebCryptoAPI.idl:27
Frame decoded
Definition: plotReceiveTrace.m:6
GLint location
Definition: gl2.h:455
CommentPlacement
Definition: value.h:42
const Char * Location
Definition: reader.h:26
def match(pattern, string)
Definition: diff_parser.py:43
JSON (JavaScript Object Notation).
Definition: value.h:26
#define JSONCPP_DEPRECATED(message)
Definition: config.h:72
GenericReader< UTF8<>, UTF8<> > Reader
Reader with UTF8 encoding and default allocator.
Definition: reader.h:1432
EGLenum type
Definition: eglext.h:63
GLsizei const GLchar *const * string
Definition: gl2.h:479
Represents a JSON value.
Definition: value.h:118
bool is(Ref< ArgType > &source)
Definition: Ref.h:220
Unserialize a JSON document into a Value.
Definition: reader.h:22
const
Definition: upload.py:398
std::unique_ptr< ParsedNode > parse(VM *vm, const SourceCode &source, const Identifier &name, JSParserBuiltinMode builtinMode, JSParserStrictMode strictMode, JSParserScriptMode scriptMode, SourceParseMode parseMode, SuperBinding superBinding, ParserError &error, JSTextPosition *positionBeforeLastNewline=nullptr, ConstructorKind defaultConstructorKind=ConstructorKind::None, DerivedContextType derivedContextType=DerivedContextType::None, EvalContextType evalContextType=EvalContextType::None, DebuggerParseData *debuggerParseData=nullptr)
Definition: Parser.h:1887
Definition: FetchRequest.idl:30
#define JSON_API
Definition: config.h:53
Configuration passed to reader and writer. This configuration object can be used to force the Reader ...
Definition: features.h:19
GLuint GLsizei const GLchar * message
Definition: gl2ext.h:137