JsonCpp project page JsonCpp home page

reader.h
Go to the documentation of this file.
1#ifndef CPPTL_JSON_READER_H_INCLUDED
2# define CPPTL_JSON_READER_H_INCLUDED
3
4# include "json/features.h"
5# include "json/value.h"
6# include <deque>
7# include <stack>
8# include <string>
9# include <iostream>
10
11namespace Json {
12
17 {
18 public:
19 typedef char Char;
20 typedef const Char *Location;
21
25 Reader();
26
30 Reader( const Features &features );
31
42 bool parse( const std::string &document,
43 Value &root,
44 bool collectComments = true );
45
56 bool parse( const char *beginDoc, const char *endDoc,
57 Value &root,
58 bool collectComments = true );
59
62 bool parse( std::istream &is,
63 Value &root,
64 bool collectComments = true );
65
71 std::string getFormatedErrorMessages() const;
72
73 private:
74 enum TokenType
75 {
76 tokenEndOfStream = 0,
77 tokenObjectBegin,
78 tokenObjectEnd,
79 tokenArrayBegin,
80 tokenArrayEnd,
81 tokenString,
82 tokenNumber,
83 tokenTrue,
84 tokenFalse,
85 tokenNull,
86 tokenArraySeparator,
87 tokenMemberSeparator,
88 tokenComment,
89 tokenError
90 };
91
92 class Token
93 {
94 public:
95 TokenType type_;
96 Location start_;
97 Location end_;
98 };
99
100 class ErrorInfo
101 {
102 public:
103 Token token_;
104 std::string message_;
105 Location extra_;
106 };
107
108 typedef std::deque<ErrorInfo> Errors;
109
110 bool expectToken( TokenType type, Token &token, const char *message );
111 bool readToken( Token &token );
112 void skipSpaces();
113 bool match( Location pattern,
114 int patternLength );
115 bool readComment();
116 bool readCStyleComment();
117 bool readCppStyleComment();
118 bool readString();
119 void readNumber();
120 bool readValue();
121 bool readObject( Token &token );
122 bool readArray( Token &token );
123 bool decodeNumber( Token &token );
124 bool decodeString( Token &token );
125 bool decodeString( Token &token, std::string &decoded );
126 bool decodeDouble( Token &token );
127 bool decodeUnicodeCodePoint( Token &token,
128 Location &current,
129 Location end,
130 unsigned int &unicode );
131 bool decodeUnicodeEscapeSequence( Token &token,
132 Location &current,
133 Location end,
134 unsigned int &unicode );
135 bool addError( const std::string &message,
136 Token &token,
137 Location extra = 0 );
138 bool recoverFromError( TokenType skipUntilToken );
139 bool addErrorAndRecover( const std::string &message,
140 Token &token,
141 TokenType skipUntilToken );
142 void skipUntilSpace();
143 Value &currentValue();
144 Char getNextChar();
145 void getLocationLineAndColumn( Location location,
146 int &line,
147 int &column ) const;
148 std::string getLocationLineAndColumn( Location location ) const;
149 void addComment( Location begin,
150 Location end,
151 CommentPlacement placement );
152 void skipCommentTokens( Token &token );
153
154 typedef std::stack<Value *> Nodes;
155 Nodes nodes_;
156 Errors errors_;
157 std::string document_;
158 Location begin_;
159 Location end_;
160 Location current_;
161 Location lastValueEnd_;
162 Value *lastValue_;
163 std::string commentsBefore_;
164 Features features_;
165 bool collectComments_;
166 };
167
192 std::istream& operator>>( std::istream&, Value& );
193
194} // namespace Json
195
196#endif // CPPTL_JSON_READER_H_INCLUDED
Configuration passed to reader and writer.
Definition: features.h:13
Unserialize a JSON document into a Value.
Definition: reader.h:17
char Char
Definition: reader.h:19
const Char * Location
Definition: reader.h:20
Represents a JSON value.
Definition: value.h:112
#define JSON_API
Definition: config.h:40
JSON (JavaScript Object Notation).
Definition: features.h:6
std::istream & operator>>(std::istream &, Value &)
Read from 'sin' into 'root'.

SourceForge Logo hosts this site. Send comments to:
Json-cpp Developers