diff options
Diffstat (limited to 'third_party/chromium/base/json/json_parser.cc')
-rw-r--r-- | third_party/chromium/base/json/json_parser.cc | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/third_party/chromium/base/json/json_parser.cc b/third_party/chromium/base/json/json_parser.cc index 708965a..011272f 100644 --- a/third_party/chromium/base/json/json_parser.cc +++ b/third_party/chromium/base/json/json_parser.cc @@ -187,9 +187,9 @@ class StackMarker { JSONParser::JSONParser(int options) : options_(options), - start_pos_(NULL), - pos_(NULL), - end_pos_(NULL), + start_pos_(nullptr), + pos_(nullptr), + end_pos_(nullptr), index_(0), stack_depth_(0), line_number_(0), @@ -208,7 +208,7 @@ std::unique_ptr<Value> JSONParser::Parse(StringPiece input) { // be used, so do not bother copying the input because StringPiece will not // be used anywhere. if (!(options_ & JSON_DETACHABLE_CHILDREN)) { - input_copy = WrapUnique(new std::string(input.as_string())); + input_copy = MakeUnique<std::string>(input.as_string()); start_pos_ = input_copy->data(); } else { start_pos_ = input.data(); @@ -250,12 +250,14 @@ std::unique_ptr<Value> JSONParser::Parse(StringPiece input) { // hidden root. if (!(options_ & JSON_DETACHABLE_CHILDREN)) { if (root->IsType(Value::TYPE_DICTIONARY)) { - return WrapUnique(new DictionaryHiddenRootValue(std::move(input_copy), - std::move(root))); - } else if (root->IsType(Value::TYPE_LIST)) { - return WrapUnique( - new ListHiddenRootValue(std::move(input_copy), std::move(root))); - } else if (root->IsType(Value::TYPE_STRING)) { + return MakeUnique<DictionaryHiddenRootValue>(std::move(input_copy), + std::move(root)); + } + if (root->IsType(Value::TYPE_LIST)) { + return MakeUnique<ListHiddenRootValue>(std::move(input_copy), + std::move(root)); + } + if (root->IsType(Value::TYPE_STRING)) { // A string type could be a JSONStringValue, but because there's no // corresponding HiddenRootValue, the memory will be lost. Deep copy to // preserve it. @@ -286,16 +288,12 @@ int JSONParser::error_column() const { // StringBuilder /////////////////////////////////////////////////////////////// -JSONParser::StringBuilder::StringBuilder() - : pos_(NULL), - length_(0), - string_(NULL) { -} +JSONParser::StringBuilder::StringBuilder() : StringBuilder(nullptr) {} JSONParser::StringBuilder::StringBuilder(const char* pos) : pos_(pos), length_(0), - string_(NULL) { + string_(nullptr) { } void JSONParser::StringBuilder::Swap(StringBuilder* other) { @@ -484,20 +482,20 @@ Value* JSONParser::ParseToken(Token token) { return ConsumeLiteral(); default: ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); - return NULL; + return nullptr; } } Value* JSONParser::ConsumeDictionary() { if (*pos_ != '{') { ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); - return NULL; + return nullptr; } StackMarker depth_check(&stack_depth_); if (depth_check.IsTooDeep()) { ReportError(JSONReader::JSON_TOO_MUCH_NESTING, 1); - return NULL; + return nullptr; } std::unique_ptr<DictionaryValue> dict(new DictionaryValue); @@ -507,13 +505,13 @@ Value* JSONParser::ConsumeDictionary() { while (token != T_OBJECT_END) { if (token != T_STRING) { ReportError(JSONReader::JSON_UNQUOTED_DICTIONARY_KEY, 1); - return NULL; + return nullptr; } // First consume the key. StringBuilder key; if (!ConsumeStringRaw(&key)) { - return NULL; + return nullptr; } // Read the separator. @@ -521,7 +519,7 @@ Value* JSONParser::ConsumeDictionary() { token = GetNextToken(); if (token != T_OBJECT_PAIR_SEPARATOR) { ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); - return NULL; + return nullptr; } // The next token is the value. Ownership transfers to |dict|. @@ -529,7 +527,7 @@ Value* JSONParser::ConsumeDictionary() { Value* value = ParseNextToken(); if (!value) { // ReportError from deeper level. - return NULL; + return nullptr; } dict->SetWithoutPathExpansion(key.AsString(), value); @@ -541,11 +539,11 @@ Value* JSONParser::ConsumeDictionary() { token = GetNextToken(); if (token == T_OBJECT_END && !(options_ & JSON_ALLOW_TRAILING_COMMAS)) { ReportError(JSONReader::JSON_TRAILING_COMMA, 1); - return NULL; + return nullptr; } } else if (token != T_OBJECT_END) { ReportError(JSONReader::JSON_SYNTAX_ERROR, 0); - return NULL; + return nullptr; } } @@ -555,13 +553,13 @@ Value* JSONParser::ConsumeDictionary() { Value* JSONParser::ConsumeList() { if (*pos_ != '[') { ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); - return NULL; + return nullptr; } StackMarker depth_check(&stack_depth_); if (depth_check.IsTooDeep()) { ReportError(JSONReader::JSON_TOO_MUCH_NESTING, 1); - return NULL; + return nullptr; } std::unique_ptr<ListValue> list(new ListValue); @@ -572,7 +570,7 @@ Value* JSONParser::ConsumeList() { Value* item = ParseToken(token); if (!item) { // ReportError from deeper level. - return NULL; + return nullptr; } list->Append(item); @@ -584,11 +582,11 @@ Value* JSONParser::ConsumeList() { token = GetNextToken(); if (token == T_ARRAY_END && !(options_ & JSON_ALLOW_TRAILING_COMMAS)) { ReportError(JSONReader::JSON_TRAILING_COMMA, 1); - return NULL; + return nullptr; } } else if (token != T_ARRAY_END) { ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); - return NULL; + return nullptr; } } @@ -598,17 +596,16 @@ Value* JSONParser::ConsumeList() { Value* JSONParser::ConsumeString() { StringBuilder string; if (!ConsumeStringRaw(&string)) - return NULL; + return nullptr; // Create the Value representation, using a hidden root, if configured // to do so, and if the string can be represented by StringPiece. - if (string.CanBeStringPiece() && !(options_ & JSON_DETACHABLE_CHILDREN)) { + if (string.CanBeStringPiece() && !(options_ & JSON_DETACHABLE_CHILDREN)) return new JSONStringValue(string.AsStringPiece()); - } else { - if (string.CanBeStringPiece()) - string.Convert(); - return new StringValue(string.AsString()); - } + + if (string.CanBeStringPiece()) + string.Convert(); + return new StringValue(string.AsString()); } bool JSONParser::ConsumeStringRaw(StringBuilder* out) { @@ -633,11 +630,23 @@ bool JSONParser::ConsumeStringRaw(StringBuilder* out) { return false; } - // If this character is an escape sequence... - if (next_char == '\\') { - // The input string will be adjusted (either by combining the two - // characters of an encoded escape sequence, or with a UTF conversion), - // so using StringPiece isn't possible -- force a conversion. + if (next_char == '"') { + --index_; // Rewind by one because of CBU8_NEXT. + out->Swap(&string); + return true; + } + + // If this character is not an escape sequence... + if (next_char != '\\') { + if (next_char < kExtendedASCIIStart) + string.Append(static_cast<char>(next_char)); + else + DecodeUTF8(next_char, &string); + } else { + // And if it is an escape sequence, the input string will be adjusted + // (either by combining the two characters of an encoded escape sequence, + // or with a UTF conversion), so using StringPiece isn't possible -- force + // a conversion. string.Convert(); if (!CanConsume(1)) { @@ -719,15 +728,6 @@ bool JSONParser::ConsumeStringRaw(StringBuilder* out) { ReportError(JSONReader::JSON_INVALID_ESCAPE, 0); return false; } - } else if (next_char == '"') { - --index_; // Rewind by one because of CBU8_NEXT. - out->Swap(&string); - return true; - } else { - if (next_char < kExtendedASCIIStart) - string.Append(static_cast<char>(next_char)); - else - DecodeUTF8(next_char, &string); } } @@ -832,7 +832,7 @@ Value* JSONParser::ConsumeNumber() { if (!ReadInt(false)) { ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); - return NULL; + return nullptr; } end_index = index_; @@ -840,12 +840,12 @@ Value* JSONParser::ConsumeNumber() { if (*pos_ == '.') { if (!CanConsume(1)) { ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); - return NULL; + return nullptr; } NextChar(); if (!ReadInt(true)) { ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); - return NULL; + return nullptr; } end_index = index_; } @@ -857,7 +857,7 @@ Value* JSONParser::ConsumeNumber() { NextChar(); if (!ReadInt(true)) { ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); - return NULL; + return nullptr; } end_index = index_; } @@ -877,7 +877,7 @@ Value* JSONParser::ConsumeNumber() { break; default: ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); - return NULL; + return nullptr; } pos_ = exit_pos; @@ -895,7 +895,7 @@ Value* JSONParser::ConsumeNumber() { return new FundamentalValue(num_double); } - return NULL; + return nullptr; } bool JSONParser::ReadInt(bool allow_leading_zeros) { @@ -925,7 +925,7 @@ Value* JSONParser::ConsumeLiteral() { if (!CanConsume(kTrueLen - 1) || !StringsAreEqual(pos_, kTrueLiteral, kTrueLen)) { ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); - return NULL; + return nullptr; } NextNChars(kTrueLen - 1); return new FundamentalValue(true); @@ -936,7 +936,7 @@ Value* JSONParser::ConsumeLiteral() { if (!CanConsume(kFalseLen - 1) || !StringsAreEqual(pos_, kFalseLiteral, kFalseLen)) { ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); - return NULL; + return nullptr; } NextNChars(kFalseLen - 1); return new FundamentalValue(false); @@ -947,14 +947,14 @@ Value* JSONParser::ConsumeLiteral() { if (!CanConsume(kNullLen - 1) || !StringsAreEqual(pos_, kNullLiteral, kNullLen)) { ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); - return NULL; + return nullptr; } NextNChars(kNullLen - 1); return Value::CreateNullValue().release(); } default: ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); - return NULL; + return nullptr; } } |