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

Side by Side Diff: base/json/json_parser.cc

Issue 2516363005: Inline StringValue into base::Value (Closed)
Patch Set: Rebase and Nits. Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/test/values_test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/json/json_parser.h" 5 #include "base/json/json_parser.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 }; 137 };
138 138
139 // A variant on StringValue that uses StringPiece instead of copying the string 139 // A variant on StringValue that uses StringPiece instead of copying the string
140 // into the Value. This can only be stored in a child of hidden root (above), 140 // into the Value. This can only be stored in a child of hidden root (above),
141 // otherwise the referenced string will not be guaranteed to outlive it. 141 // otherwise the referenced string will not be guaranteed to outlive it.
142 class JSONStringValue : public Value { 142 class JSONStringValue : public Value {
143 public: 143 public:
144 explicit JSONStringValue(StringPiece piece) 144 explicit JSONStringValue(StringPiece piece)
145 : Value(Type::STRING), string_piece_(piece) {} 145 : Value(Type::STRING), string_piece_(piece) {}
146 146
147 ~JSONStringValue() override {
148 // Ugly hack that prevents ~Value() from trying to destroy string_value_.
149 // TODO(crbug.com/646113): Clean this up when StringValue will be removed.
150 type_ = Type::NONE;
151 }
152
147 // Overridden from Value: 153 // Overridden from Value:
148 bool GetAsString(std::string* out_value) const override { 154 bool GetAsString(std::string* out_value) const override {
149 string_piece_.CopyToString(out_value); 155 string_piece_.CopyToString(out_value);
150 return true; 156 return true;
151 } 157 }
152 bool GetAsString(string16* out_value) const override { 158 bool GetAsString(string16* out_value) const override {
153 *out_value = UTF8ToUTF16(string_piece_); 159 *out_value = UTF8ToUTF16(string_piece_);
154 return true; 160 return true;
155 } 161 }
162 // base::Value::GetAsString contains a proper implementation now, so the old
163 // behavior is copied here.
164 // TODO(crbug.com/646113): Clean this up when StringValue will be removed.
165 bool GetAsString(const StringValue** out_value) const override {
166 return false;
167 }
156 bool GetAsString(StringPiece* out_value) const override { 168 bool GetAsString(StringPiece* out_value) const override {
157 *out_value = string_piece_; 169 *out_value = string_piece_;
158 return true; 170 return true;
159 } 171 }
160 Value* DeepCopy() const override { return new StringValue(string_piece_); } 172 Value* DeepCopy() const override { return new StringValue(string_piece_); }
161 bool Equals(const Value* other) const override { 173 bool Equals(const Value* other) const override {
162 std::string other_string; 174 std::string other_string;
163 return other->IsType(Type::STRING) && other->GetAsString(&other_string) && 175 return other->IsType(Type::STRING) && other->GetAsString(&other_string) &&
164 StringPiece(other_string) == string_piece_; 176 StringPiece(other_string) == string_piece_;
165 } 177 }
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 const std::string& description) { 1007 const std::string& description) {
996 if (line || column) { 1008 if (line || column) {
997 return StringPrintf("Line: %i, column: %i, %s", 1009 return StringPrintf("Line: %i, column: %i, %s",
998 line, column, description.c_str()); 1010 line, column, description.c_str());
999 } 1011 }
1000 return description; 1012 return description;
1001 } 1013 }
1002 1014
1003 } // namespace internal 1015 } // namespace internal
1004 } // namespace base 1016 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/test/values_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698