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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 void DictionaryValue::SetStringWithoutPathExpansion( | 475 void DictionaryValue::SetStringWithoutPathExpansion( |
476 const std::string& path, const std::string& in_value) { | 476 const std::string& path, const std::string& in_value) { |
477 SetWithoutPathExpansion(path, new StringValue(in_value)); | 477 SetWithoutPathExpansion(path, new StringValue(in_value)); |
478 } | 478 } |
479 | 479 |
480 void DictionaryValue::SetStringWithoutPathExpansion( | 480 void DictionaryValue::SetStringWithoutPathExpansion( |
481 const std::string& path, const string16& in_value) { | 481 const std::string& path, const string16& in_value) { |
482 SetWithoutPathExpansion(path, new StringValue(in_value)); | 482 SetWithoutPathExpansion(path, new StringValue(in_value)); |
483 } | 483 } |
484 | 484 |
485 bool DictionaryValue::Get(const std::string& path, | 485 bool DictionaryValue::Get(StringPiece path, const Value** out_value) const { |
486 const Value** out_value) const { | |
487 DCHECK(IsStringUTF8(path)); | 486 DCHECK(IsStringUTF8(path)); |
488 std::string current_path(path); | 487 StringPiece current_path(path); |
489 const DictionaryValue* current_dictionary = this; | 488 const DictionaryValue* current_dictionary = this; |
490 for (size_t delimiter_position = current_path.find('.'); | 489 for (size_t delimiter_position = current_path.find('.'); |
491 delimiter_position != std::string::npos; | 490 delimiter_position != std::string::npos; |
492 delimiter_position = current_path.find('.')) { | 491 delimiter_position = current_path.find('.')) { |
493 const DictionaryValue* child_dictionary = NULL; | 492 const DictionaryValue* child_dictionary = NULL; |
494 if (!current_dictionary->GetDictionary( | 493 if (!current_dictionary->GetDictionaryWithoutPathExpansion( |
495 current_path.substr(0, delimiter_position), &child_dictionary)) | 494 current_path.substr(0, delimiter_position).as_string(), |
| 495 &child_dictionary)) { |
496 return false; | 496 return false; |
| 497 } |
497 | 498 |
498 current_dictionary = child_dictionary; | 499 current_dictionary = child_dictionary; |
499 current_path.erase(0, delimiter_position + 1); | 500 current_path = current_path.substr(delimiter_position + 1); |
500 } | 501 } |
501 | 502 |
502 return current_dictionary->GetWithoutPathExpansion(current_path, out_value); | 503 return current_dictionary->GetWithoutPathExpansion(current_path.as_string(), |
| 504 out_value); |
503 } | 505 } |
504 | 506 |
505 bool DictionaryValue::Get(const std::string& path, Value** out_value) { | 507 bool DictionaryValue::Get(StringPiece path, Value** out_value) { |
506 return static_cast<const DictionaryValue&>(*this).Get( | 508 return static_cast<const DictionaryValue&>(*this).Get( |
507 path, | 509 path, |
508 const_cast<const Value**>(out_value)); | 510 const_cast<const Value**>(out_value)); |
509 } | 511 } |
510 | 512 |
511 bool DictionaryValue::GetBoolean(const std::string& path, | 513 bool DictionaryValue::GetBoolean(const std::string& path, |
512 bool* bool_value) const { | 514 bool* bool_value) const { |
513 const Value* value; | 515 const Value* value; |
514 if (!Get(path, &value)) | 516 if (!Get(path, &value)) |
515 return false; | 517 return false; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 return true; | 583 return true; |
582 } | 584 } |
583 | 585 |
584 bool DictionaryValue::GetBinary(const std::string& path, | 586 bool DictionaryValue::GetBinary(const std::string& path, |
585 BinaryValue** out_value) { | 587 BinaryValue** out_value) { |
586 return static_cast<const DictionaryValue&>(*this).GetBinary( | 588 return static_cast<const DictionaryValue&>(*this).GetBinary( |
587 path, | 589 path, |
588 const_cast<const BinaryValue**>(out_value)); | 590 const_cast<const BinaryValue**>(out_value)); |
589 } | 591 } |
590 | 592 |
591 bool DictionaryValue::GetDictionary(const std::string& path, | 593 bool DictionaryValue::GetDictionary(StringPiece path, |
592 const DictionaryValue** out_value) const { | 594 const DictionaryValue** out_value) const { |
593 const Value* value; | 595 const Value* value; |
594 bool result = Get(path, &value); | 596 bool result = Get(path, &value); |
595 if (!result || !value->IsType(TYPE_DICTIONARY)) | 597 if (!result || !value->IsType(TYPE_DICTIONARY)) |
596 return false; | 598 return false; |
597 | 599 |
598 if (out_value) | 600 if (out_value) |
599 *out_value = static_cast<const DictionaryValue*>(value); | 601 *out_value = static_cast<const DictionaryValue*>(value); |
600 | 602 |
601 return true; | 603 return true; |
602 } | 604 } |
603 | 605 |
604 bool DictionaryValue::GetDictionary(const std::string& path, | 606 bool DictionaryValue::GetDictionary(StringPiece path, |
605 DictionaryValue** out_value) { | 607 DictionaryValue** out_value) { |
606 return static_cast<const DictionaryValue&>(*this).GetDictionary( | 608 return static_cast<const DictionaryValue&>(*this).GetDictionary( |
607 path, | 609 path, |
608 const_cast<const DictionaryValue**>(out_value)); | 610 const_cast<const DictionaryValue**>(out_value)); |
609 } | 611 } |
610 | 612 |
611 bool DictionaryValue::GetList(const std::string& path, | 613 bool DictionaryValue::GetList(const std::string& path, |
612 const ListValue** out_value) const { | 614 const ListValue** out_value) const { |
613 const Value* value; | 615 const Value* value; |
614 bool result = Get(path, &value); | 616 bool result = Get(path, &value); |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 ValueDeserializer::~ValueDeserializer() { | 1174 ValueDeserializer::~ValueDeserializer() { |
1173 } | 1175 } |
1174 | 1176 |
1175 std::ostream& operator<<(std::ostream& out, const Value& value) { | 1177 std::ostream& operator<<(std::ostream& out, const Value& value) { |
1176 std::string json; | 1178 std::string json; |
1177 JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json); | 1179 JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
1178 return out << json; | 1180 return out << json; |
1179 } | 1181 } |
1180 | 1182 |
1181 } // namespace base | 1183 } // namespace base |
OLD | NEW |