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

Unified Diff: base/json/json_reader.cc

Issue 7756022: base/json: Get rid of static initializer in JSONReader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add CreateInvalidToken() Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/json/json_reader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/json/json_reader.cc
diff --git a/base/json/json_reader.cc b/base/json/json_reader.cc
index bc7bcd0e5e53fc8e0da9bd7cde18773ad1ce00e0..d3d712a5b74540e13c63b16b7b568a0f1510914a 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,21 @@ const char* JSONReader::kUnquotedDictionaryKey =
"Dictionary keys must be quoted.";
JSONReader::JSONReader()
- : start_pos_(NULL), json_pos_(NULL), stack_depth_(0),
+ : 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 +117,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 +192,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 +367,14 @@ JSONReader::Token JSONReader::ParseNumberToken() {
}
if (!ReadInt(token, false))
- return kInvalidToken;
+ return Token::CreateInvalidToken();
// Optional fraction part
c = token.NextChar();
if ('.' == c) {
++token.length;
if (!ReadInt(token, true))
- return kInvalidToken;
+ return Token::CreateInvalidToken();
c = token.NextChar();
}
@@ -389,7 +387,7 @@ JSONReader::Token JSONReader::ParseNumberToken() {
c = token.NextChar();
}
if (!ReadInt(token, true))
- return kInvalidToken;
+ return Token::CreateInvalidToken();
}
return token;
@@ -422,13 +420,13 @@ JSONReader::Token JSONReader::ParseStringToken() {
case 'x':
if (!ReadHexDigits(token, 2)) {
SetErrorCode(JSON_INVALID_ESCAPE, json_pos_ + token.length);
- return kInvalidToken;
+ return Token::CreateInvalidToken();
}
break;
case 'u':
if (!ReadHexDigits(token, 4)) {
SetErrorCode(JSON_INVALID_ESCAPE, json_pos_ + token.length);
- return kInvalidToken;
+ return Token::CreateInvalidToken();
}
break;
case '\\':
@@ -443,7 +441,7 @@ JSONReader::Token JSONReader::ParseStringToken() {
break;
default:
SetErrorCode(JSON_INVALID_ESCAPE, json_pos_ + token.length);
- return kInvalidToken;
+ return Token::CreateInvalidToken();
}
} else if ('"' == c) {
++token.length;
@@ -452,7 +450,7 @@ JSONReader::Token JSONReader::ParseStringToken() {
++token.length;
c = token.NextChar();
}
- return kInvalidToken;
+ return Token::CreateInvalidToken();
}
Value* JSONReader::DecodeString(const Token& token) {
« no previous file with comments | « base/json/json_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698