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 <cmath> | 10 #include <cmath> |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 DCHECK(IsStringUTF8(path)); | 390 DCHECK(IsStringUTF8(path)); |
391 DCHECK(in_value); | 391 DCHECK(in_value); |
392 | 392 |
393 StringPiece current_path(path); | 393 StringPiece current_path(path); |
394 DictionaryValue* current_dictionary = this; | 394 DictionaryValue* current_dictionary = this; |
395 for (size_t delimiter_position = current_path.find('.'); | 395 for (size_t delimiter_position = current_path.find('.'); |
396 delimiter_position != StringPiece::npos; | 396 delimiter_position != StringPiece::npos; |
397 delimiter_position = current_path.find('.')) { | 397 delimiter_position = current_path.find('.')) { |
398 // Assume that we're indexing into a dictionary. | 398 // Assume that we're indexing into a dictionary. |
399 StringPiece key = current_path.substr(0, delimiter_position); | 399 StringPiece key = current_path.substr(0, delimiter_position); |
400 DictionaryValue* child_dictionary = NULL; | 400 DictionaryValue* child_dictionary = nullptr; |
401 if (!current_dictionary->GetDictionary(key, &child_dictionary)) { | 401 if (!current_dictionary->GetDictionary(key, &child_dictionary)) { |
402 child_dictionary = new DictionaryValue; | 402 child_dictionary = new DictionaryValue; |
403 current_dictionary->SetWithoutPathExpansion(key, child_dictionary); | 403 current_dictionary->SetWithoutPathExpansion( |
| 404 key, base::WrapUnique(child_dictionary)); |
404 } | 405 } |
405 | 406 |
406 current_dictionary = child_dictionary; | 407 current_dictionary = child_dictionary; |
407 current_path = current_path.substr(delimiter_position + 1); | 408 current_path = current_path.substr(delimiter_position + 1); |
408 } | 409 } |
409 | 410 |
410 current_dictionary->SetWithoutPathExpansion(current_path, | 411 current_dictionary->SetWithoutPathExpansion(current_path, |
411 std::move(in_value)); | 412 std::move(in_value)); |
412 } | 413 } |
413 | 414 |
(...skipping 26 matching lines...) Expand all Loading... |
440 dictionary_[key.as_string()] = std::move(in_value); | 441 dictionary_[key.as_string()] = std::move(in_value); |
441 } | 442 } |
442 | 443 |
443 void DictionaryValue::SetWithoutPathExpansion(StringPiece key, | 444 void DictionaryValue::SetWithoutPathExpansion(StringPiece key, |
444 Value* in_value) { | 445 Value* in_value) { |
445 SetWithoutPathExpansion(key, WrapUnique(in_value)); | 446 SetWithoutPathExpansion(key, WrapUnique(in_value)); |
446 } | 447 } |
447 | 448 |
448 void DictionaryValue::SetBooleanWithoutPathExpansion(StringPiece path, | 449 void DictionaryValue::SetBooleanWithoutPathExpansion(StringPiece path, |
449 bool in_value) { | 450 bool in_value) { |
450 SetWithoutPathExpansion(path, new FundamentalValue(in_value)); | 451 SetWithoutPathExpansion(path, |
| 452 base::MakeUnique<base::FundamentalValue>(in_value)); |
451 } | 453 } |
452 | 454 |
453 void DictionaryValue::SetIntegerWithoutPathExpansion(StringPiece path, | 455 void DictionaryValue::SetIntegerWithoutPathExpansion(StringPiece path, |
454 int in_value) { | 456 int in_value) { |
455 SetWithoutPathExpansion(path, new FundamentalValue(in_value)); | 457 SetWithoutPathExpansion(path, |
| 458 base::MakeUnique<base::FundamentalValue>(in_value)); |
456 } | 459 } |
457 | 460 |
458 void DictionaryValue::SetDoubleWithoutPathExpansion(StringPiece path, | 461 void DictionaryValue::SetDoubleWithoutPathExpansion(StringPiece path, |
459 double in_value) { | 462 double in_value) { |
460 SetWithoutPathExpansion(path, new FundamentalValue(in_value)); | 463 SetWithoutPathExpansion(path, |
| 464 base::MakeUnique<base::FundamentalValue>(in_value)); |
461 } | 465 } |
462 | 466 |
463 void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path, | 467 void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path, |
464 StringPiece in_value) { | 468 StringPiece in_value) { |
465 SetWithoutPathExpansion(path, new StringValue(in_value)); | 469 SetWithoutPathExpansion(path, base::MakeUnique<base::StringValue>(in_value)); |
466 } | 470 } |
467 | 471 |
468 void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path, | 472 void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path, |
469 const string16& in_value) { | 473 const string16& in_value) { |
470 SetWithoutPathExpansion(path, new StringValue(in_value)); | 474 SetWithoutPathExpansion(path, base::MakeUnique<base::StringValue>(in_value)); |
471 } | 475 } |
472 | 476 |
473 bool DictionaryValue::Get(StringPiece path, | 477 bool DictionaryValue::Get(StringPiece path, |
474 const Value** out_value) const { | 478 const Value** out_value) const { |
475 DCHECK(IsStringUTF8(path)); | 479 DCHECK(IsStringUTF8(path)); |
476 StringPiece current_path(path); | 480 StringPiece current_path(path); |
477 const DictionaryValue* current_dictionary = this; | 481 const DictionaryValue* current_dictionary = this; |
478 for (size_t delimiter_position = current_path.find('.'); | 482 for (size_t delimiter_position = current_path.find('.'); |
479 delimiter_position != std::string::npos; | 483 delimiter_position != std::string::npos; |
480 delimiter_position = current_path.find('.')) { | 484 delimiter_position = current_path.find('.')) { |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 // Check whether we have to merge dictionaries. | 792 // Check whether we have to merge dictionaries. |
789 if (merge_value->IsType(Value::TYPE_DICTIONARY)) { | 793 if (merge_value->IsType(Value::TYPE_DICTIONARY)) { |
790 DictionaryValue* sub_dict; | 794 DictionaryValue* sub_dict; |
791 if (GetDictionaryWithoutPathExpansion(it.key(), &sub_dict)) { | 795 if (GetDictionaryWithoutPathExpansion(it.key(), &sub_dict)) { |
792 sub_dict->MergeDictionary( | 796 sub_dict->MergeDictionary( |
793 static_cast<const DictionaryValue*>(merge_value)); | 797 static_cast<const DictionaryValue*>(merge_value)); |
794 continue; | 798 continue; |
795 } | 799 } |
796 } | 800 } |
797 // All other cases: Make a copy and hook it up. | 801 // All other cases: Make a copy and hook it up. |
798 SetWithoutPathExpansion(it.key(), merge_value->DeepCopy()); | 802 SetWithoutPathExpansion(it.key(), |
| 803 base::WrapUnique(merge_value->DeepCopy())); |
799 } | 804 } |
800 } | 805 } |
801 | 806 |
802 void DictionaryValue::Swap(DictionaryValue* other) { | 807 void DictionaryValue::Swap(DictionaryValue* other) { |
803 dictionary_.swap(other->dictionary_); | 808 dictionary_.swap(other->dictionary_); |
804 } | 809 } |
805 | 810 |
806 DictionaryValue::Iterator::Iterator(const DictionaryValue& target) | 811 DictionaryValue::Iterator::Iterator(const DictionaryValue& target) |
807 : target_(target), | 812 : target_(target), |
808 it_(target.dictionary_.begin()) {} | 813 it_(target.dictionary_.begin()) {} |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 ValueDeserializer::~ValueDeserializer() { | 1167 ValueDeserializer::~ValueDeserializer() { |
1163 } | 1168 } |
1164 | 1169 |
1165 std::ostream& operator<<(std::ostream& out, const Value& value) { | 1170 std::ostream& operator<<(std::ostream& out, const Value& value) { |
1166 std::string json; | 1171 std::string json; |
1167 JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json); | 1172 JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
1168 return out << json; | 1173 return out << json; |
1169 } | 1174 } |
1170 | 1175 |
1171 } // namespace base | 1176 } // namespace base |
OLD | NEW |