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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 void DictionaryValue::SetStringWithoutPathExpansion( | 455 void DictionaryValue::SetStringWithoutPathExpansion( |
456 const std::string& path, const std::string& in_value) { | 456 const std::string& path, const std::string& in_value) { |
457 SetWithoutPathExpansion(path, CreateStringValue(in_value)); | 457 SetWithoutPathExpansion(path, CreateStringValue(in_value)); |
458 } | 458 } |
459 | 459 |
460 void DictionaryValue::SetStringWithoutPathExpansion( | 460 void DictionaryValue::SetStringWithoutPathExpansion( |
461 const std::string& path, const string16& in_value) { | 461 const std::string& path, const string16& in_value) { |
462 SetWithoutPathExpansion(path, CreateStringValue(in_value)); | 462 SetWithoutPathExpansion(path, CreateStringValue(in_value)); |
463 } | 463 } |
464 | 464 |
465 bool DictionaryValue::Get( | 465 bool DictionaryValue::Get(const std::string& path, |
466 const std::string& path, const Value** out_value) const { | 466 const Value** out_value) const { |
467 DCHECK(IsStringUTF8(path)); | 467 DCHECK(IsStringUTF8(path)); |
468 // LOG(WARNING) << "\n1\n"; | 468 // LOG(WARNING) << "\n1\n"; |
469 std::string current_path(path); | 469 std::string current_path(path); |
470 const DictionaryValue* current_dictionary = this; | 470 const DictionaryValue* current_dictionary = this; |
471 // LOG(WARNING) << "\n2\n"; | 471 // LOG(WARNING) << "\n2\n"; |
472 for (size_t delimiter_position = current_path.find('.'); | 472 for (size_t delimiter_position = current_path.find('.'); |
473 delimiter_position != std::string::npos; | 473 delimiter_position != std::string::npos; |
474 delimiter_position = current_path.find('.')) { | 474 delimiter_position = current_path.find('.')) { |
475 const DictionaryValue* child_dictionary = NULL; | 475 const DictionaryValue* child_dictionary = NULL; |
476 if (!current_dictionary->GetDictionary( | 476 if (!current_dictionary->GetDictionary( |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
748 | 748 |
749 Value* entry = entry_iterator->second; | 749 Value* entry = entry_iterator->second; |
750 if (out_value) | 750 if (out_value) |
751 out_value->reset(entry); | 751 out_value->reset(entry); |
752 else | 752 else |
753 delete entry; | 753 delete entry; |
754 dictionary_.erase(entry_iterator); | 754 dictionary_.erase(entry_iterator); |
755 return true; | 755 return true; |
756 } | 756 } |
757 | 757 |
758 bool DictionaryValue::RemovePath(const std::string& path, | |
759 scoped_ptr<Value>* out_value) { | |
760 bool result = false; | |
761 size_t delimiter_position = path.find('.'); | |
762 if (delimiter_position == std::string::npos) { | |
763 return RemoveWithoutPathExpansion(path, out_value); | |
764 } else { | |
765 const std::string subdict_path = path.substr(0, delimiter_position); | |
766 DictionaryValue* subdict = NULL; | |
767 if (!GetDictionary(subdict_path, &subdict)) | |
768 return false; | |
769 result = subdict->RemovePath(path.substr(delimiter_position + 1), | |
770 out_value); | |
771 if (result && subdict->empty()) | |
772 Remove(subdict_path, NULL); | |
Mattias Nissler (ping if slow)
2013/11/22 08:03:38
RemoveWithoutPathExpansion for clarity.
gab
2013/11/22 23:24:21
Done.
| |
773 } | |
774 return result; | |
775 } | |
776 | |
758 DictionaryValue* DictionaryValue::DeepCopyWithoutEmptyChildren() const { | 777 DictionaryValue* DictionaryValue::DeepCopyWithoutEmptyChildren() const { |
759 Value* copy = CopyWithoutEmptyChildren(this); | 778 Value* copy = CopyWithoutEmptyChildren(this); |
760 return copy ? static_cast<DictionaryValue*>(copy) : new DictionaryValue; | 779 return copy ? static_cast<DictionaryValue*>(copy) : new DictionaryValue; |
761 } | 780 } |
762 | 781 |
763 void DictionaryValue::MergeDictionary(const DictionaryValue* dictionary) { | 782 void DictionaryValue::MergeDictionary(const DictionaryValue* dictionary) { |
764 for (DictionaryValue::Iterator it(*dictionary); !it.IsAtEnd(); it.Advance()) { | 783 for (DictionaryValue::Iterator it(*dictionary); !it.IsAtEnd(); it.Advance()) { |
765 const Value* merge_value = &it.value(); | 784 const Value* merge_value = &it.value(); |
766 // Check whether we have to merge dictionaries. | 785 // Check whether we have to merge dictionaries. |
767 if (merge_value->IsType(Value::TYPE_DICTIONARY)) { | 786 if (merge_value->IsType(Value::TYPE_DICTIONARY)) { |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1113 | 1132 |
1114 std::ostream& operator<<(std::ostream& out, const Value& value) { | 1133 std::ostream& operator<<(std::ostream& out, const Value& value) { |
1115 std::string json; | 1134 std::string json; |
1116 JSONWriter::WriteWithOptions(&value, | 1135 JSONWriter::WriteWithOptions(&value, |
1117 JSONWriter::OPTIONS_PRETTY_PRINT, | 1136 JSONWriter::OPTIONS_PRETTY_PRINT, |
1118 &json); | 1137 &json); |
1119 return out << json; | 1138 return out << json; |
1120 } | 1139 } |
1121 | 1140 |
1122 } // namespace base | 1141 } // namespace base |
OLD | NEW |