| 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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 ++lhs_it; | 371 ++lhs_it; |
| 372 ++rhs_it; | 372 ++rhs_it; |
| 373 } | 373 } |
| 374 if (lhs_it != end_keys() || rhs_it != other_dict->end_keys()) | 374 if (lhs_it != end_keys() || rhs_it != other_dict->end_keys()) |
| 375 return false; | 375 return false; |
| 376 | 376 |
| 377 return true; | 377 return true; |
| 378 } | 378 } |
| 379 | 379 |
| 380 bool DictionaryValue::HasKey(const std::string& key) const { | 380 bool DictionaryValue::HasKey(const std::string& key) const { |
| 381 DCHECK(IsStringUTF8(key)); |
| 381 ValueMap::const_iterator current_entry = dictionary_.find(key); | 382 ValueMap::const_iterator current_entry = dictionary_.find(key); |
| 382 DCHECK((current_entry == dictionary_.end()) || current_entry->second); | 383 DCHECK((current_entry == dictionary_.end()) || current_entry->second); |
| 383 return current_entry != dictionary_.end(); | 384 return current_entry != dictionary_.end(); |
| 384 } | 385 } |
| 385 | 386 |
| 386 // TODO(viettrungluu): Deprecated and to be removed: | 387 // TODO(viettrungluu): Deprecated and to be removed: |
| 387 bool DictionaryValue::HasKeyASCII(const std::string& key) const { | 388 bool DictionaryValue::HasKeyASCII(const std::string& key) const { |
| 388 return HasKey(key); | 389 return HasKey(key); |
| 389 } | 390 } |
| 390 | 391 |
| 391 // TODO(viettrungluu): Deprecated and to be removed: | 392 // TODO(viettrungluu): Deprecated and to be removed: |
| 392 bool DictionaryValue::HasKey(const std::wstring& key) const { | 393 bool DictionaryValue::HasKey(const std::wstring& key) const { |
| 393 return HasKey(WideToUTF8(key)); | 394 return HasKey(WideToUTF8(key)); |
| 394 } | 395 } |
| 395 | 396 |
| 396 void DictionaryValue::Clear() { | 397 void DictionaryValue::Clear() { |
| 397 ValueMap::iterator dict_iterator = dictionary_.begin(); | 398 ValueMap::iterator dict_iterator = dictionary_.begin(); |
| 398 while (dict_iterator != dictionary_.end()) { | 399 while (dict_iterator != dictionary_.end()) { |
| 399 delete dict_iterator->second; | 400 delete dict_iterator->second; |
| 400 ++dict_iterator; | 401 ++dict_iterator; |
| 401 } | 402 } |
| 402 | 403 |
| 403 dictionary_.clear(); | 404 dictionary_.clear(); |
| 404 } | 405 } |
| 405 | 406 |
| 406 void DictionaryValue::Set(const std::string& path, Value* in_value) { | 407 void DictionaryValue::Set(const std::string& path, Value* in_value) { |
| 408 DCHECK(IsStringUTF8(path)); |
| 407 DCHECK(in_value); | 409 DCHECK(in_value); |
| 408 | 410 |
| 409 std::string current_path(path); | 411 std::string current_path(path); |
| 410 DictionaryValue* current_dictionary = this; | 412 DictionaryValue* current_dictionary = this; |
| 411 for (size_t delimiter_position = current_path.find('.'); | 413 for (size_t delimiter_position = current_path.find('.'); |
| 412 delimiter_position != std::string::npos; | 414 delimiter_position != std::string::npos; |
| 413 delimiter_position = current_path.find('.')) { | 415 delimiter_position = current_path.find('.')) { |
| 414 // Assume that we're indexing into a dictionary. | 416 // Assume that we're indexing into a dictionary. |
| 415 std::string key(current_path, 0, delimiter_position); | 417 std::string key(current_path, 0, delimiter_position); |
| 416 DictionaryValue* child_dictionary = NULL; | 418 DictionaryValue* child_dictionary = NULL; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 dictionary_[key] = in_value; | 502 dictionary_[key] = in_value; |
| 501 } | 503 } |
| 502 | 504 |
| 503 // TODO(viettrungluu): Deprecated and to be removed: | 505 // TODO(viettrungluu): Deprecated and to be removed: |
| 504 void DictionaryValue::SetWithoutPathExpansion(const std::wstring& key, | 506 void DictionaryValue::SetWithoutPathExpansion(const std::wstring& key, |
| 505 Value* in_value) { | 507 Value* in_value) { |
| 506 SetWithoutPathExpansion(WideToUTF8(key), in_value); | 508 SetWithoutPathExpansion(WideToUTF8(key), in_value); |
| 507 } | 509 } |
| 508 | 510 |
| 509 bool DictionaryValue::Get(const std::string& path, Value** out_value) const { | 511 bool DictionaryValue::Get(const std::string& path, Value** out_value) const { |
| 512 DCHECK(IsStringUTF8(path)); |
| 510 std::string current_path(path); | 513 std::string current_path(path); |
| 511 const DictionaryValue* current_dictionary = this; | 514 const DictionaryValue* current_dictionary = this; |
| 512 for (size_t delimiter_position = current_path.find('.'); | 515 for (size_t delimiter_position = current_path.find('.'); |
| 513 delimiter_position != std::string::npos; | 516 delimiter_position != std::string::npos; |
| 514 delimiter_position = current_path.find('.')) { | 517 delimiter_position = current_path.find('.')) { |
| 515 DictionaryValue* child_dictionary = NULL; | 518 DictionaryValue* child_dictionary = NULL; |
| 516 if (!current_dictionary->GetDictionary( | 519 if (!current_dictionary->GetDictionary( |
| 517 current_path.substr(0, delimiter_position), &child_dictionary)) | 520 current_path.substr(0, delimiter_position), &child_dictionary)) |
| 518 return false; | 521 return false; |
| 519 | 522 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 } | 678 } |
| 676 | 679 |
| 677 // TODO(viettrungluu): Deprecated and to be removed: | 680 // TODO(viettrungluu): Deprecated and to be removed: |
| 678 bool DictionaryValue::GetList(const std::wstring& path, | 681 bool DictionaryValue::GetList(const std::wstring& path, |
| 679 ListValue** out_value) const { | 682 ListValue** out_value) const { |
| 680 return GetList(WideToUTF8(path), out_value); | 683 return GetList(WideToUTF8(path), out_value); |
| 681 } | 684 } |
| 682 | 685 |
| 683 bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, | 686 bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, |
| 684 Value** out_value) const { | 687 Value** out_value) const { |
| 688 DCHECK(IsStringUTF8(key)); |
| 685 ValueMap::const_iterator entry_iterator = dictionary_.find(key); | 689 ValueMap::const_iterator entry_iterator = dictionary_.find(key); |
| 686 if (entry_iterator == dictionary_.end()) | 690 if (entry_iterator == dictionary_.end()) |
| 687 return false; | 691 return false; |
| 688 | 692 |
| 689 Value* entry = entry_iterator->second; | 693 Value* entry = entry_iterator->second; |
| 690 if (out_value) | 694 if (out_value) |
| 691 *out_value = entry; | 695 *out_value = entry; |
| 692 return true; | 696 return true; |
| 693 } | 697 } |
| 694 | 698 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 return GetDictionaryWithoutPathExpansion(WideToUTF8(key), out_value); | 789 return GetDictionaryWithoutPathExpansion(WideToUTF8(key), out_value); |
| 786 } | 790 } |
| 787 | 791 |
| 788 // TODO(viettrungluu): Deprecated and to be removed: | 792 // TODO(viettrungluu): Deprecated and to be removed: |
| 789 bool DictionaryValue::GetListWithoutPathExpansion(const std::wstring& key, | 793 bool DictionaryValue::GetListWithoutPathExpansion(const std::wstring& key, |
| 790 ListValue** out_value) const { | 794 ListValue** out_value) const { |
| 791 return GetListWithoutPathExpansion(WideToUTF8(key), out_value); | 795 return GetListWithoutPathExpansion(WideToUTF8(key), out_value); |
| 792 } | 796 } |
| 793 | 797 |
| 794 bool DictionaryValue::Remove(const std::string& path, Value** out_value) { | 798 bool DictionaryValue::Remove(const std::string& path, Value** out_value) { |
| 799 DCHECK(IsStringUTF8(path)); |
| 795 std::string current_path(path); | 800 std::string current_path(path); |
| 796 DictionaryValue* current_dictionary = this; | 801 DictionaryValue* current_dictionary = this; |
| 797 size_t delimiter_position = current_path.rfind('.'); | 802 size_t delimiter_position = current_path.rfind('.'); |
| 798 if (delimiter_position != std::string::npos) { | 803 if (delimiter_position != std::string::npos) { |
| 799 if (!GetDictionary(current_path.substr(0, delimiter_position), | 804 if (!GetDictionary(current_path.substr(0, delimiter_position), |
| 800 ¤t_dictionary)) | 805 ¤t_dictionary)) |
| 801 return false; | 806 return false; |
| 802 current_path.erase(0, delimiter_position + 1); | 807 current_path.erase(0, delimiter_position + 1); |
| 803 } | 808 } |
| 804 | 809 |
| 805 return current_dictionary->RemoveWithoutPathExpansion(current_path, | 810 return current_dictionary->RemoveWithoutPathExpansion(current_path, |
| 806 out_value); | 811 out_value); |
| 807 } | 812 } |
| 808 | 813 |
| 809 // TODO(viettrungluu): Deprecated and to be removed: | 814 // TODO(viettrungluu): Deprecated and to be removed: |
| 810 bool DictionaryValue::Remove(const std::wstring& path, Value** out_value) { | 815 bool DictionaryValue::Remove(const std::wstring& path, Value** out_value) { |
| 811 return Remove(WideToUTF8(path), out_value); | 816 return Remove(WideToUTF8(path), out_value); |
| 812 } | 817 } |
| 813 | 818 |
| 814 bool DictionaryValue::RemoveWithoutPathExpansion(const std::string& key, | 819 bool DictionaryValue::RemoveWithoutPathExpansion(const std::string& key, |
| 815 Value** out_value) { | 820 Value** out_value) { |
| 821 DCHECK(IsStringUTF8(key)); |
| 816 ValueMap::iterator entry_iterator = dictionary_.find(key); | 822 ValueMap::iterator entry_iterator = dictionary_.find(key); |
| 817 if (entry_iterator == dictionary_.end()) | 823 if (entry_iterator == dictionary_.end()) |
| 818 return false; | 824 return false; |
| 819 | 825 |
| 820 Value* entry = entry_iterator->second; | 826 Value* entry = entry_iterator->second; |
| 821 if (out_value) | 827 if (out_value) |
| 822 *out_value = entry; | 828 *out_value = entry; |
| 823 else | 829 else |
| 824 delete entry; | 830 delete entry; |
| 825 dictionary_.erase(entry_iterator); | 831 dictionary_.erase(entry_iterator); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 return false; | 1177 return false; |
| 1172 } | 1178 } |
| 1173 if (lhs_it != end() || rhs_it != other_list->end()) | 1179 if (lhs_it != end() || rhs_it != other_list->end()) |
| 1174 return false; | 1180 return false; |
| 1175 | 1181 |
| 1176 return true; | 1182 return true; |
| 1177 } | 1183 } |
| 1178 | 1184 |
| 1179 ValueSerializer::~ValueSerializer() { | 1185 ValueSerializer::~ValueSerializer() { |
| 1180 } | 1186 } |
| OLD | NEW |