OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // A JSON parser. Converts strings of JSON into a Value object (see | 5 // A JSON parser. Converts strings of JSON into a Value object (see |
6 // base/values.h). | 6 // base/values.h). |
7 // http://www.ietf.org/rfc/rfc4627.txt?number=4627 | 7 // http://www.ietf.org/rfc/rfc4627.txt?number=4627 |
8 // | 8 // |
9 // Known limitations/deviations from the RFC: | 9 // Known limitations/deviations from the RFC: |
10 // - Only knows how to parse ints within the range of a signed 32 bit int and | 10 // - Only knows how to parse ints within the range of a signed 32 bit int and |
11 // decimal numbers within a double. | 11 // decimal numbers within a double. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 BOOL_FALSE, // false | 62 BOOL_FALSE, // false |
63 NULL_TOKEN, // null | 63 NULL_TOKEN, // null |
64 LIST_SEPARATOR, // , | 64 LIST_SEPARATOR, // , |
65 OBJECT_PAIR_SEPARATOR, // : | 65 OBJECT_PAIR_SEPARATOR, // : |
66 END_OF_INPUT, | 66 END_OF_INPUT, |
67 INVALID_TOKEN, | 67 INVALID_TOKEN, |
68 }; | 68 }; |
69 Token(Type t, const wchar_t* b, int len) | 69 Token(Type t, const wchar_t* b, int len) |
70 : type(t), begin(b), length(len) {} | 70 : type(t), begin(b), length(len) {} |
71 | 71 |
| 72 // Get the character that's one past the end of this token. |
| 73 wchar_t NextChar() { |
| 74 return *(begin + length); |
| 75 } |
| 76 |
72 Type type; | 77 Type type; |
73 | 78 |
74 // A pointer into JSONReader::json_pos_ that's the beginning of this token. | 79 // A pointer into JSONReader::json_pos_ that's the beginning of this token. |
75 const wchar_t* begin; | 80 const wchar_t* begin; |
76 | 81 |
77 // End should be one char past the end of the token. | 82 // End should be one char past the end of the token. |
78 int length; | 83 int length; |
79 | |
80 // Get the character that's one past the end of this token. | |
81 wchar_t NextChar() { | |
82 return *(begin + length); | |
83 } | |
84 }; | 84 }; |
85 | 85 |
86 // Error codes during parsing. | 86 // Error codes during parsing. |
87 enum JsonParseError { | 87 enum JsonParseError { |
88 JSON_NO_ERROR = 0, | 88 JSON_NO_ERROR = 0, |
89 JSON_BAD_ROOT_ELEMENT_TYPE, | 89 JSON_BAD_ROOT_ELEMENT_TYPE, |
90 JSON_INVALID_ESCAPE, | 90 JSON_INVALID_ESCAPE, |
91 JSON_SYNTAX_ERROR, | 91 JSON_SYNTAX_ERROR, |
92 JSON_TRAILING_COMMA, | 92 JSON_TRAILING_COMMA, |
93 JSON_TOO_MUCH_NESTING, | 93 JSON_TOO_MUCH_NESTING, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 // Contains the error code for the last call to JsonToValue(), if any. | 212 // Contains the error code for the last call to JsonToValue(), if any. |
213 JsonParseError error_code_; | 213 JsonParseError error_code_; |
214 int error_line_; | 214 int error_line_; |
215 int error_col_; | 215 int error_col_; |
216 }; | 216 }; |
217 | 217 |
218 } // namespace base | 218 } // namespace base |
219 | 219 |
220 #endif // BASE_JSON_JSON_READER_H_ | 220 #endif // BASE_JSON_JSON_READER_H_ |
OLD | NEW |