summaryrefslogtreecommitdiffstats
path: root/base/json/json_reader.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/json/json_reader.cc')
-rw-r--r--base/json/json_reader.cc44
1 files changed, 21 insertions, 23 deletions
diff --git a/base/json/json_reader.cc b/base/json/json_reader.cc
index bc7bcd0..d3d712a 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) {