| OLD | NEW |
| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 // A variant on StringValue that uses StringPiece instead of copying the string | 137 // A variant on StringValue that uses StringPiece instead of copying the string |
| 138 // into the Value. This can only be stored in a child of hidden root (above), | 138 // into the Value. This can only be stored in a child of hidden root (above), |
| 139 // otherwise the referenced string will not be guaranteed to outlive it. | 139 // otherwise the referenced string will not be guaranteed to outlive it. |
| 140 class JSONStringValue : public Value { | 140 class JSONStringValue : public Value { |
| 141 public: | 141 public: |
| 142 explicit JSONStringValue(StringPiece piece) | 142 explicit JSONStringValue(StringPiece piece) |
| 143 : Value(Type::STRING), string_piece_(piece) {} | 143 : Value(Type::STRING), string_piece_(piece) {} |
| 144 | 144 |
| 145 ~JSONStringValue() override { |
| 146 // Ugly hack that prevents ~Value() from trying to destroy string_value_. |
| 147 // TODO(crbug.com/646113): Clean this up when StringValue will be removed. |
| 148 type_ = Type::NONE; |
| 149 } |
| 150 |
| 145 // Overridden from Value: | 151 // Overridden from Value: |
| 146 bool GetAsString(std::string* out_value) const override { | 152 bool GetAsString(std::string* out_value) const override { |
| 147 string_piece_.CopyToString(out_value); | 153 string_piece_.CopyToString(out_value); |
| 148 return true; | 154 return true; |
| 149 } | 155 } |
| 150 bool GetAsString(string16* out_value) const override { | 156 bool GetAsString(string16* out_value) const override { |
| 151 *out_value = UTF8ToUTF16(string_piece_); | 157 *out_value = UTF8ToUTF16(string_piece_); |
| 152 return true; | 158 return true; |
| 153 } | 159 } |
| 160 // base::Value::GetAsString contains a proper implementation now, so the old |
| 161 // behavior is copied here. |
| 162 // TODO(crbug.com/646113): Clean this up when StringValue will be removed. |
| 163 bool GetAsString(const StringValue** out_value) const override { |
| 164 return false; |
| 165 } |
| 154 Value* DeepCopy() const override { return new StringValue(string_piece_); } | 166 Value* DeepCopy() const override { return new StringValue(string_piece_); } |
| 155 bool Equals(const Value* other) const override { | 167 bool Equals(const Value* other) const override { |
| 156 std::string other_string; | 168 std::string other_string; |
| 157 return other->IsType(Type::STRING) && other->GetAsString(&other_string) && | 169 return other->IsType(Type::STRING) && other->GetAsString(&other_string) && |
| 158 StringPiece(other_string) == string_piece_; | 170 StringPiece(other_string) == string_piece_; |
| 159 } | 171 } |
| 160 | 172 |
| 161 private: | 173 private: |
| 162 // The location in the original input stream. | 174 // The location in the original input stream. |
| 163 StringPiece string_piece_; | 175 StringPiece string_piece_; |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 const std::string& description) { | 1001 const std::string& description) { |
| 990 if (line || column) { | 1002 if (line || column) { |
| 991 return StringPrintf("Line: %i, column: %i, %s", | 1003 return StringPrintf("Line: %i, column: %i, %s", |
| 992 line, column, description.c_str()); | 1004 line, column, description.c_str()); |
| 993 } | 1005 } |
| 994 return description; | 1006 return description; |
| 995 } | 1007 } |
| 996 | 1008 |
| 997 } // namespace internal | 1009 } // namespace internal |
| 998 } // namespace base | 1010 } // namespace base |
| OLD | NEW |