OLD | NEW |
1 // Copyright (c) 2011 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 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 STRING, | 57 STRING, |
58 NUMBER, | 58 NUMBER, |
59 BOOL_TRUE, // true | 59 BOOL_TRUE, // true |
60 BOOL_FALSE, // false | 60 BOOL_FALSE, // false |
61 NULL_TOKEN, // null | 61 NULL_TOKEN, // null |
62 LIST_SEPARATOR, // , | 62 LIST_SEPARATOR, // , |
63 OBJECT_PAIR_SEPARATOR, // : | 63 OBJECT_PAIR_SEPARATOR, // : |
64 END_OF_INPUT, | 64 END_OF_INPUT, |
65 INVALID_TOKEN, | 65 INVALID_TOKEN, |
66 }; | 66 }; |
| 67 |
67 Token(Type t, const wchar_t* b, int len) | 68 Token(Type t, const wchar_t* b, int len) |
68 : type(t), begin(b), length(len) {} | 69 : type(t), begin(b), length(len) {} |
69 | 70 |
70 // Get the character that's one past the end of this token. | 71 // Get the character that's one past the end of this token. |
71 wchar_t NextChar() { | 72 wchar_t NextChar() { |
72 return *(begin + length); | 73 return *(begin + length); |
73 } | 74 } |
74 | 75 |
| 76 static Token CreateInvalidToken() { |
| 77 return Token(INVALID_TOKEN, 0, 0); |
| 78 } |
| 79 |
75 Type type; | 80 Type type; |
76 | 81 |
77 // A pointer into JSONReader::json_pos_ that's the beginning of this token. | 82 // A pointer into JSONReader::json_pos_ that's the beginning of this token. |
78 const wchar_t* begin; | 83 const wchar_t* begin; |
79 | 84 |
80 // End should be one char past the end of the token. | 85 // End should be one char past the end of the token. |
81 int length; | 86 int length; |
82 }; | 87 }; |
83 | 88 |
84 // Error codes during parsing. | 89 // Error codes during parsing. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 JsonParseError error_code_; | 214 JsonParseError error_code_; |
210 int error_line_; | 215 int error_line_; |
211 int error_col_; | 216 int error_col_; |
212 | 217 |
213 DISALLOW_COPY_AND_ASSIGN(JSONReader); | 218 DISALLOW_COPY_AND_ASSIGN(JSONReader); |
214 }; | 219 }; |
215 | 220 |
216 } // namespace base | 221 } // namespace base |
217 | 222 |
218 #endif // BASE_JSON_JSON_READER_H_ | 223 #endif // BASE_JSON_JSON_READER_H_ |
OLD | NEW |