Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(799)

Side by Side Diff: base/json/json_parser.h

Issue 2285933003: Remove more usage of the base::ListValue::Append(Value*) overload. (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/json/json_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_JSON_JSON_PARSER_H_ 5 #ifndef BASE_JSON_JSON_PARSER_H_
6 #define BASE_JSON_JSON_PARSER_H_ 6 #define BASE_JSON_JSON_PARSER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // This does not advance the parser for non-whitespace or comment chars. 154 // This does not advance the parser for non-whitespace or comment chars.
155 Token GetNextToken(); 155 Token GetNextToken();
156 156
157 // Consumes whitespace characters and comments until the next non-that is 157 // Consumes whitespace characters and comments until the next non-that is
158 // encountered. 158 // encountered.
159 void EatWhitespaceAndComments(); 159 void EatWhitespaceAndComments();
160 // Helper function that consumes a comment, assuming that the parser is 160 // Helper function that consumes a comment, assuming that the parser is
161 // currently wound to a '/'. 161 // currently wound to a '/'.
162 bool EatComment(); 162 bool EatComment();
163 163
164 // Calls GetNextToken() and then ParseToken(). Caller owns the result. 164 // Calls GetNextToken() and then ParseToken().
165 Value* ParseNextToken(); 165 std::unique_ptr<Value> ParseNextToken();
166 166
167 // Takes a token that represents the start of a Value ("a structural token" 167 // Takes a token that represents the start of a Value ("a structural token"
168 // in RFC terms) and consumes it, returning the result as an object the 168 // in RFC terms) and consumes it, returning the result as a Value.
169 // caller owns. 169 std::unique_ptr<Value> ParseToken(Token token);
170 Value* ParseToken(Token token);
171 170
172 // Assuming that the parser is currently wound to '{', this parses a JSON 171 // Assuming that the parser is currently wound to '{', this parses a JSON
173 // object into a DictionaryValue. 172 // object into a DictionaryValue.
174 Value* ConsumeDictionary(); 173 std::unique_ptr<Value> ConsumeDictionary();
175 174
176 // Assuming that the parser is wound to '[', this parses a JSON list into a 175 // Assuming that the parser is wound to '[', this parses a JSON list into a
177 // ListValue. 176 // std::unique_ptr<ListValue>.
178 Value* ConsumeList(); 177 std::unique_ptr<Value> ConsumeList();
179 178
180 // Calls through ConsumeStringRaw and wraps it in a value. 179 // Calls through ConsumeStringRaw and wraps it in a value.
181 Value* ConsumeString(); 180 std::unique_ptr<Value> ConsumeString();
182 181
183 // Assuming that the parser is wound to a double quote, this parses a string, 182 // Assuming that the parser is wound to a double quote, this parses a string,
184 // decoding any escape sequences and converts UTF-16 to UTF-8. Returns true on 183 // decoding any escape sequences and converts UTF-16 to UTF-8. Returns true on
185 // success and Swap()s the result into |out|. Returns false on failure with 184 // success and Swap()s the result into |out|. Returns false on failure with
186 // error information set. 185 // error information set.
187 bool ConsumeStringRaw(StringBuilder* out); 186 bool ConsumeStringRaw(StringBuilder* out);
188 // Helper function for ConsumeStringRaw() that consumes the next four or 10 187 // Helper function for ConsumeStringRaw() that consumes the next four or 10
189 // bytes (parser is wound to the first character of a HEX sequence, with the 188 // bytes (parser is wound to the first character of a HEX sequence, with the
190 // potential for consuming another \uXXXX for a surrogate). Returns true on 189 // potential for consuming another \uXXXX for a surrogate). Returns true on
191 // success and places the UTF8 code units in |dest_string|, and false on 190 // success and places the UTF8 code units in |dest_string|, and false on
192 // failure. 191 // failure.
193 bool DecodeUTF16(std::string* dest_string); 192 bool DecodeUTF16(std::string* dest_string);
194 // Helper function for ConsumeStringRaw() that takes a single code point, 193 // Helper function for ConsumeStringRaw() that takes a single code point,
195 // decodes it into UTF-8 units, and appends it to the given builder. The 194 // decodes it into UTF-8 units, and appends it to the given builder. The
196 // point must be valid. 195 // point must be valid.
197 void DecodeUTF8(const int32_t& point, StringBuilder* dest); 196 void DecodeUTF8(const int32_t& point, StringBuilder* dest);
198 197
199 // Assuming that the parser is wound to the start of a valid JSON number, 198 // Assuming that the parser is wound to the start of a valid JSON number,
200 // this parses and converts it to either an int or double value. 199 // this parses and converts it to either an int or double value.
201 Value* ConsumeNumber(); 200 std::unique_ptr<Value> ConsumeNumber();
202 // Helper that reads characters that are ints. Returns true if a number was 201 // Helper that reads characters that are ints. Returns true if a number was
203 // read and false on error. 202 // read and false on error.
204 bool ReadInt(bool allow_leading_zeros); 203 bool ReadInt(bool allow_leading_zeros);
205 204
206 // Consumes the literal values of |true|, |false|, and |null|, assuming the 205 // Consumes the literal values of |true|, |false|, and |null|, assuming the
207 // parser is wound to the first character of any of those. 206 // parser is wound to the first character of any of those.
208 Value* ConsumeLiteral(); 207 std::unique_ptr<Value> ConsumeLiteral();
209 208
210 // Compares two string buffers of a given length. 209 // Compares two string buffers of a given length.
211 static bool StringsAreEqual(const char* left, const char* right, size_t len); 210 static bool StringsAreEqual(const char* left, const char* right, size_t len);
212 211
213 // Sets the error information to |code| at the current column, based on 212 // Sets the error information to |code| at the current column, based on
214 // |index_| and |index_last_line_|, with an optional positive/negative 213 // |index_| and |index_last_line_|, with an optional positive/negative
215 // adjustment by |column_adjust|. 214 // adjustment by |column_adjust|.
216 void ReportError(JSONReader::JsonParseError code, int column_adjust); 215 void ReportError(JSONReader::JsonParseError code, int column_adjust);
217 216
218 // Given the line and column number of an error, formats one of the error 217 // Given the line and column number of an error, formats one of the error
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 FRIEND_TEST_ALL_PREFIXES(JSONParserTest, ConsumeNumbers); 258 FRIEND_TEST_ALL_PREFIXES(JSONParserTest, ConsumeNumbers);
260 FRIEND_TEST_ALL_PREFIXES(JSONParserTest, ErrorMessages); 259 FRIEND_TEST_ALL_PREFIXES(JSONParserTest, ErrorMessages);
261 260
262 DISALLOW_COPY_AND_ASSIGN(JSONParser); 261 DISALLOW_COPY_AND_ASSIGN(JSONParser);
263 }; 262 };
264 263
265 } // namespace internal 264 } // namespace internal
266 } // namespace base 265 } // namespace base
267 266
268 #endif // BASE_JSON_JSON_PARSER_H_ 267 #endif // BASE_JSON_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | base/json/json_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698