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

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

Issue 2516363005: Inline StringValue into base::Value (Closed)
Patch Set: Reimplement old base::Value::GetAsString behavior in json_parser. Created 4 years 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/values.h » ('j') | base/values.cc » ('J')
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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 // Overridden from Value: 145 // Overridden from Value:
146 bool GetAsString(std::string* out_value) const override { 146 bool GetAsString(std::string* out_value) const override {
147 string_piece_.CopyToString(out_value); 147 string_piece_.CopyToString(out_value);
148 return true; 148 return true;
149 } 149 }
150 bool GetAsString(string16* out_value) const override { 150 bool GetAsString(string16* out_value) const override {
151 *out_value = UTF8ToUTF16(string_piece_); 151 *out_value = UTF8ToUTF16(string_piece_);
152 return true; 152 return true;
153 } 153 }
154 // base::Value::GetAsString contains a proper implementation now, so the old
155 // behavior is copied here.
156 // TODO(jdoerrie): Clean this up when StringValue will be removed.
vabr (Chromium) 2016/12/07 10:17:27 nit: It is a good practice to also mention the bug
jdoerrie 2016/12/08 09:59:34 Done.
157 bool GetAsString(const StringValue** out_value) const override {
158 return false;
159 }
154 Value* DeepCopy() const override { return new StringValue(string_piece_); } 160 Value* DeepCopy() const override { return new StringValue(string_piece_); }
155 bool Equals(const Value* other) const override { 161 bool Equals(const Value* other) const override {
156 std::string other_string; 162 std::string other_string;
157 return other->IsType(TYPE_STRING) && other->GetAsString(&other_string) && 163 return other->IsType(TYPE_STRING) && other->GetAsString(&other_string) &&
158 StringPiece(other_string) == string_piece_; 164 StringPiece(other_string) == string_piece_;
159 } 165 }
160 166
161 private: 167 private:
162 // The location in the original input stream. 168 // The location in the original input stream.
163 StringPiece string_piece_; 169 StringPiece string_piece_;
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 const std::string& description) { 995 const std::string& description) {
990 if (line || column) { 996 if (line || column) {
991 return StringPrintf("Line: %i, column: %i, %s", 997 return StringPrintf("Line: %i, column: %i, %s",
992 line, column, description.c_str()); 998 line, column, description.c_str());
993 } 999 }
994 return description; 1000 return description;
995 } 1001 }
996 1002
997 } // namespace internal 1003 } // namespace internal
998 } // namespace base 1004 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/values.h » ('j') | base/values.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698