Chromium Code Reviews| Index: base/json/json_reader.cc |
| diff --git a/base/json/json_reader.cc b/base/json/json_reader.cc |
| index bc7bcd0e5e53fc8e0da9bd7cde18773ad1ce00e0..3aa4490e50986b45072ca94f4df0b2a4cb1a9361 100644 |
| --- a/base/json/json_reader.cc |
| +++ b/base/json/json_reader.cc |
| @@ -21,18 +21,10 @@ const wchar_t kFalseString[] = L"false"; |
| const int kStackLimit = 100; |
| -} // namespace |
| - |
| -namespace base { |
| - |
| -static const JSONReader::Token kInvalidToken(JSONReader::Token::INVALID_TOKEN, |
| - 0, 0); |
| -namespace { |
| - |
| // A helper method for ParseNumberToken. It reads an int from the end of |
| // token. The method returns false if there is no valid integer at the end of |
| // the token. |
| -bool ReadInt(JSONReader::Token& token, bool can_have_leading_zeros) { |
| +bool ReadInt(base::JSONReader::Token& token, bool can_have_leading_zeros) { |
| wchar_t first = token.NextChar(); |
| int len = 0; |
| @@ -56,7 +48,7 @@ bool ReadInt(JSONReader::Token& token, bool can_have_leading_zeros) { |
| // A helper method for ParseStringToken. It reads |digits| hex digits from the |
| // token. If the sequence if digits is not valid (contains other characters), |
| // the method returns false. |
| -bool ReadHexDigits(JSONReader::Token& token, int digits) { |
| +bool ReadHexDigits(base::JSONReader::Token& token, int digits) { |
| for (int i = 1; i <= digits; ++i) { |
| wchar_t c = *(token.begin + token.length + i); |
| if ('\0' == c) |
| @@ -73,6 +65,8 @@ bool ReadHexDigits(JSONReader::Token& token, int digits) { |
| } // namespace |
| +namespace base { |
| + |
| const char* JSONReader::kBadRootElementType = |
| "Root value must be an array or object."; |
| const char* JSONReader::kInvalidEscape = |
| @@ -91,17 +85,22 @@ const char* JSONReader::kUnquotedDictionaryKey = |
| "Dictionary keys must be quoted."; |
| JSONReader::JSONReader() |
| - : start_pos_(NULL), json_pos_(NULL), stack_depth_(0), |
| + : kInvalidToken(new Token(Token::INVALID_TOKEN, 0, 0)), |
|
tfarina
2011/09/01 01:21:07
I'm not convinced this is the best way to do this.
tony
2011/09/01 01:48:11
I think we should just get rid of kInvalidToken an
|
| + start_pos_(NULL), |
| + json_pos_(NULL), |
| + stack_depth_(0), |
| allow_trailing_comma_(false), |
| - error_code_(JSON_NO_ERROR), error_line_(0), error_col_(0) {} |
| + error_code_(JSON_NO_ERROR), |
| + error_line_(0), |
| + error_col_(0) {} |
| -/* static */ |
| +// static |
| Value* JSONReader::Read(const std::string& json, |
| bool allow_trailing_comma) { |
| return ReadAndReturnError(json, allow_trailing_comma, NULL, NULL); |
| } |
| -/* static */ |
| +// static |
| Value* JSONReader::ReadAndReturnError(const std::string& json, |
| bool allow_trailing_comma, |
| int* error_code_out, |
| @@ -119,7 +118,7 @@ Value* JSONReader::ReadAndReturnError(const std::string& json, |
| return NULL; |
| } |
| -/* static */ |
| +// static |
| std::string JSONReader::ErrorCodeToString(JsonParseError error_code) { |
| switch (error_code) { |
| case JSON_NO_ERROR: |
| @@ -194,7 +193,7 @@ Value* JSONReader::JsonToValue(const std::string& json, bool check_root, |
| return NULL; |
| } |
| -/* static */ |
| +// static |
| std::string JSONReader::FormatErrorMessage(int line, int column, |
| const std::string& description) { |
| if (line || column) { |
| @@ -369,14 +368,14 @@ JSONReader::Token JSONReader::ParseNumberToken() { |
| } |
| if (!ReadInt(token, false)) |
| - return kInvalidToken; |
| + return *kInvalidToken; |
| // Optional fraction part |
| c = token.NextChar(); |
| if ('.' == c) { |
| ++token.length; |
| if (!ReadInt(token, true)) |
| - return kInvalidToken; |
| + return *kInvalidToken; |
| c = token.NextChar(); |
| } |
| @@ -389,7 +388,7 @@ JSONReader::Token JSONReader::ParseNumberToken() { |
| c = token.NextChar(); |
| } |
| if (!ReadInt(token, true)) |
| - return kInvalidToken; |
| + return *kInvalidToken; |
| } |
| return token; |
| @@ -422,13 +421,13 @@ JSONReader::Token JSONReader::ParseStringToken() { |
| case 'x': |
| if (!ReadHexDigits(token, 2)) { |
| SetErrorCode(JSON_INVALID_ESCAPE, json_pos_ + token.length); |
| - return kInvalidToken; |
| + return *kInvalidToken; |
| } |
| break; |
| case 'u': |
| if (!ReadHexDigits(token, 4)) { |
| SetErrorCode(JSON_INVALID_ESCAPE, json_pos_ + token.length); |
| - return kInvalidToken; |
| + return *kInvalidToken; |
| } |
| break; |
| case '\\': |
| @@ -443,7 +442,7 @@ JSONReader::Token JSONReader::ParseStringToken() { |
| break; |
| default: |
| SetErrorCode(JSON_INVALID_ESCAPE, json_pos_ + token.length); |
| - return kInvalidToken; |
| + return *kInvalidToken; |
| } |
| } else if ('"' == c) { |
| ++token.length; |
| @@ -452,7 +451,7 @@ JSONReader::Token JSONReader::ParseStringToken() { |
| ++token.length; |
| c = token.NextChar(); |
| } |
| - return kInvalidToken; |
| + return *kInvalidToken; |
| } |
| Value* JSONReader::DecodeString(const Token& token) { |