| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 | 10 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 bool Value::GetAsString(std::string* out_value) const { | 114 bool Value::GetAsString(std::string* out_value) const { |
| 115 return false; | 115 return false; |
| 116 } | 116 } |
| 117 | 117 |
| 118 bool Value::GetAsString(string16* out_value) const { | 118 bool Value::GetAsString(string16* out_value) const { |
| 119 return false; | 119 return false; |
| 120 } | 120 } |
| 121 | 121 |
| 122 #if !defined(WCHAR_T_IS_UTF16) | |
| 123 // TODO(viettrungluu): Deprecated and to be removed: | |
| 124 bool Value::GetAsString(std::wstring* out_value) const { | |
| 125 return false; | |
| 126 } | |
| 127 #endif | |
| 128 | |
| 129 Value* Value::DeepCopy() const { | 122 Value* Value::DeepCopy() const { |
| 130 // This method should only be getting called for null Values--all subclasses | 123 // This method should only be getting called for null Values--all subclasses |
| 131 // need to provide their own implementation;. | 124 // need to provide their own implementation;. |
| 132 DCHECK(IsType(TYPE_NULL)); | 125 DCHECK(IsType(TYPE_NULL)); |
| 133 return CreateNullValue(); | 126 return CreateNullValue(); |
| 134 } | 127 } |
| 135 | 128 |
| 136 bool Value::Equals(const Value* other) const { | 129 bool Value::Equals(const Value* other) const { |
| 137 // This method should only be getting called for null Values--all subclasses | 130 // This method should only be getting called for null Values--all subclasses |
| 138 // need to provide their own implementation;. | 131 // need to provide their own implementation;. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 *out_value = value_; | 240 *out_value = value_; |
| 248 return true; | 241 return true; |
| 249 } | 242 } |
| 250 | 243 |
| 251 bool StringValue::GetAsString(string16* out_value) const { | 244 bool StringValue::GetAsString(string16* out_value) const { |
| 252 if (out_value) | 245 if (out_value) |
| 253 *out_value = UTF8ToUTF16(value_); | 246 *out_value = UTF8ToUTF16(value_); |
| 254 return true; | 247 return true; |
| 255 } | 248 } |
| 256 | 249 |
| 257 #if !defined(WCHAR_T_IS_UTF16) | |
| 258 // TODO(viettrungluu): Deprecated and to be removed: | |
| 259 bool StringValue::GetAsString(std::wstring* out_value) const { | |
| 260 if (out_value) | |
| 261 *out_value = UTF8ToWide(value_); | |
| 262 return true; | |
| 263 } | |
| 264 #endif | |
| 265 | |
| 266 Value* StringValue::DeepCopy() const { | 250 Value* StringValue::DeepCopy() const { |
| 267 return CreateStringValue(value_); | 251 return CreateStringValue(value_); |
| 268 } | 252 } |
| 269 | 253 |
| 270 bool StringValue::Equals(const Value* other) const { | 254 bool StringValue::Equals(const Value* other) const { |
| 271 if (other->GetType() != GetType()) | 255 if (other->GetType() != GetType()) |
| 272 return false; | 256 return false; |
| 273 std::string lhs, rhs; | 257 std::string lhs, rhs; |
| 274 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; | 258 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; |
| 275 } | 259 } |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 return GetInteger(WideToUTF8(path), out_value); | 608 return GetInteger(WideToUTF8(path), out_value); |
| 625 } | 609 } |
| 626 | 610 |
| 627 // TODO(viettrungluu): Deprecated and to be removed: | 611 // TODO(viettrungluu): Deprecated and to be removed: |
| 628 bool DictionaryValue::GetReal(const std::wstring& path, | 612 bool DictionaryValue::GetReal(const std::wstring& path, |
| 629 double* out_value) const { | 613 double* out_value) const { |
| 630 return GetReal(WideToUTF8(path), out_value); | 614 return GetReal(WideToUTF8(path), out_value); |
| 631 } | 615 } |
| 632 | 616 |
| 633 // TODO(viettrungluu): Deprecated and to be removed: | 617 // TODO(viettrungluu): Deprecated and to be removed: |
| 634 bool DictionaryValue::GetString(const std::wstring& path, | |
| 635 std::string* out_value) const { | |
| 636 return GetString(WideToUTF8(path), out_value); | |
| 637 } | |
| 638 | |
| 639 // TODO(viettrungluu): Deprecated and to be removed: | |
| 640 bool DictionaryValue::GetString(const std::wstring& path, | |
| 641 std::wstring* out_value) const { | |
| 642 Value* value; | |
| 643 if (!Get(WideToUTF8(path), &value)) | |
| 644 return false; | |
| 645 | |
| 646 return value->GetAsString(out_value); | |
| 647 } | |
| 648 | |
| 649 // TODO(viettrungluu): Deprecated and to be removed: | |
| 650 bool DictionaryValue::GetBinary(const std::wstring& path, | 618 bool DictionaryValue::GetBinary(const std::wstring& path, |
| 651 BinaryValue** out_value) const { | 619 BinaryValue** out_value) const { |
| 652 return GetBinary(WideToUTF8(path), out_value); | 620 return GetBinary(WideToUTF8(path), out_value); |
| 653 } | 621 } |
| 654 | 622 |
| 655 // TODO(viettrungluu): Deprecated and to be removed: | 623 // TODO(viettrungluu): Deprecated and to be removed: |
| 656 bool DictionaryValue::GetDictionary(const std::wstring& path, | 624 bool DictionaryValue::GetDictionary(const std::wstring& path, |
| 657 DictionaryValue** out_value) const { | 625 DictionaryValue** out_value) const { |
| 658 return GetDictionary(WideToUTF8(path), out_value); | 626 return GetDictionary(WideToUTF8(path), out_value); |
| 659 } | 627 } |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 } | 946 } |
| 979 | 947 |
| 980 bool ListValue::GetString(size_t index, string16* out_value) const { | 948 bool ListValue::GetString(size_t index, string16* out_value) const { |
| 981 Value* value; | 949 Value* value; |
| 982 if (!Get(index, &value)) | 950 if (!Get(index, &value)) |
| 983 return false; | 951 return false; |
| 984 | 952 |
| 985 return value->GetAsString(out_value); | 953 return value->GetAsString(out_value); |
| 986 } | 954 } |
| 987 | 955 |
| 988 #if !defined(WCHAR_T_IS_UTF16) | |
| 989 // TODO(viettrungluu): Deprecated and to be removed: | |
| 990 bool ListValue::GetString(size_t index, std::wstring* out_value) const { | |
| 991 Value* value; | |
| 992 if (!Get(index, &value)) | |
| 993 return false; | |
| 994 | |
| 995 return value->GetAsString(out_value); | |
| 996 } | |
| 997 #endif | |
| 998 | |
| 999 bool ListValue::GetBinary(size_t index, BinaryValue** out_value) const { | 956 bool ListValue::GetBinary(size_t index, BinaryValue** out_value) const { |
| 1000 Value* value; | 957 Value* value; |
| 1001 bool result = Get(index, &value); | 958 bool result = Get(index, &value); |
| 1002 if (!result || !value->IsType(TYPE_BINARY)) | 959 if (!result || !value->IsType(TYPE_BINARY)) |
| 1003 return false; | 960 return false; |
| 1004 | 961 |
| 1005 if (out_value) | 962 if (out_value) |
| 1006 *out_value = static_cast<BinaryValue*>(value); | 963 *out_value = static_cast<BinaryValue*>(value); |
| 1007 | 964 |
| 1008 return true; | 965 return true; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 return false; | 1066 return false; |
| 1110 } | 1067 } |
| 1111 if (lhs_it != end() || rhs_it != other_list->end()) | 1068 if (lhs_it != end() || rhs_it != other_list->end()) |
| 1112 return false; | 1069 return false; |
| 1113 | 1070 |
| 1114 return true; | 1071 return true; |
| 1115 } | 1072 } |
| 1116 | 1073 |
| 1117 ValueSerializer::~ValueSerializer() { | 1074 ValueSerializer::~ValueSerializer() { |
| 1118 } | 1075 } |
| OLD | NEW |