| 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/values.h" | 5 #include "base/values.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool Value::GetAsString(std::string* out_value) const { | 129 bool Value::GetAsString(std::string* out_value) const { |
| 130 return false; | 130 return false; |
| 131 } | 131 } |
| 132 | 132 |
| 133 bool Value::GetAsString(string16* out_value) const { | 133 bool Value::GetAsString(string16* out_value) const { |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool Value::GetAsStringValue(const StringValue** out_value) const { |
| 138 return false; |
| 139 } |
| 140 |
| 137 bool Value::GetAsList(ListValue** out_value) { | 141 bool Value::GetAsList(ListValue** out_value) { |
| 138 return false; | 142 return false; |
| 139 } | 143 } |
| 140 | 144 |
| 141 bool Value::GetAsList(const ListValue** out_value) const { | 145 bool Value::GetAsList(const ListValue** out_value) const { |
| 142 return false; | 146 return false; |
| 143 } | 147 } |
| 144 | 148 |
| 145 bool Value::GetAsDictionary(DictionaryValue** out_value) { | 149 bool Value::GetAsDictionary(DictionaryValue** out_value) { |
| 146 return false; | 150 return false; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 default: | 263 default: |
| 260 NOTREACHED(); | 264 NOTREACHED(); |
| 261 return false; | 265 return false; |
| 262 } | 266 } |
| 263 } | 267 } |
| 264 | 268 |
| 265 ///////////////////// StringValue //////////////////// | 269 ///////////////////// StringValue //////////////////// |
| 266 | 270 |
| 267 StringValue::StringValue(const std::string& in_value) | 271 StringValue::StringValue(const std::string& in_value) |
| 268 : Value(TYPE_STRING), | 272 : Value(TYPE_STRING), |
| 269 value_(in_value) { | 273 value_(new std::string(in_value)) { |
| 270 DCHECK(IsStringUTF8(in_value)); | 274 DCHECK(IsStringUTF8(in_value)); |
| 271 } | 275 } |
| 272 | 276 |
| 273 StringValue::StringValue(const string16& in_value) | 277 StringValue::StringValue(const string16& in_value) |
| 274 : Value(TYPE_STRING), | 278 : Value(TYPE_STRING), |
| 275 value_(UTF16ToUTF8(in_value)) { | 279 value_(new std::string(UTF16ToUTF8(in_value))) {} |
| 276 } | |
| 277 | 280 |
| 278 StringValue::~StringValue() { | 281 StringValue::StringValue(scoped_ptr<std::string> in_value) |
| 279 } | 282 : Value(TYPE_STRING), |
| 283 value_(in_value.Pass()) {} |
| 284 |
| 285 StringValue::~StringValue() {} |
| 280 | 286 |
| 281 bool StringValue::GetAsString(std::string* out_value) const { | 287 bool StringValue::GetAsString(std::string* out_value) const { |
| 282 if (out_value) | 288 if (out_value) |
| 283 *out_value = value_; | 289 *out_value = *value_; |
| 284 return true; | 290 return true; |
| 285 } | 291 } |
| 286 | 292 |
| 287 bool StringValue::GetAsString(string16* out_value) const { | 293 bool StringValue::GetAsString(string16* out_value) const { |
| 288 if (out_value) | 294 if (out_value) |
| 289 *out_value = UTF8ToUTF16(value_); | 295 *out_value = UTF8ToUTF16(*value_); |
| 296 return true; |
| 297 } |
| 298 |
| 299 bool StringValue::GetAsStringValue(const StringValue** out_value) const { |
| 300 if (out_value) |
| 301 *out_value = this; |
| 290 return true; | 302 return true; |
| 291 } | 303 } |
| 292 | 304 |
| 293 StringValue* StringValue::DeepCopy() const { | 305 StringValue* StringValue::DeepCopy() const { |
| 294 return CreateStringValue(value_); | 306 return new StringValue(*value_); |
| 295 } | 307 } |
| 296 | 308 |
| 297 bool StringValue::Equals(const Value* other) const { | 309 bool StringValue::Equals(const Value* other) const { |
| 298 if (other->GetType() != GetType()) | 310 if (other->GetType() != GetType()) |
| 299 return false; | 311 return false; |
| 300 std::string lhs, rhs; | 312 std::string lhs, rhs; |
| 301 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; | 313 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; |
| 302 } | 314 } |
| 303 | 315 |
| 304 ///////////////////// BinaryValue //////////////////// | 316 ///////////////////// BinaryValue //////////////////// |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 | 1144 |
| 1133 std::ostream& operator<<(std::ostream& out, const Value& value) { | 1145 std::ostream& operator<<(std::ostream& out, const Value& value) { |
| 1134 std::string json; | 1146 std::string json; |
| 1135 JSONWriter::WriteWithOptions(&value, | 1147 JSONWriter::WriteWithOptions(&value, |
| 1136 JSONWriter::OPTIONS_PRETTY_PRINT, | 1148 JSONWriter::OPTIONS_PRETTY_PRINT, |
| 1137 &json); | 1149 &json); |
| 1138 return out << json; | 1150 return out << json; |
| 1139 } | 1151 } |
| 1140 | 1152 |
| 1141 } // namespace base | 1153 } // namespace base |
| OLD | NEW |