diff options
-rw-r--r-- | base/values.cc | 18 | ||||
-rw-r--r-- | base/values.h | 9 |
2 files changed, 15 insertions, 12 deletions
diff --git a/base/values.cc b/base/values.cc index 4534d27..55947a4 100644 --- a/base/values.cc +++ b/base/values.cc @@ -482,27 +482,29 @@ void DictionaryValue::SetStringWithoutPathExpansion( SetWithoutPathExpansion(path, new StringValue(in_value)); } -bool DictionaryValue::Get(const std::string& path, +bool DictionaryValue::Get(StringPiece path, const Value** out_value) const { DCHECK(IsStringUTF8(path)); - std::string current_path(path); + StringPiece current_path(path); const DictionaryValue* current_dictionary = this; for (size_t delimiter_position = current_path.find('.'); delimiter_position != std::string::npos; delimiter_position = current_path.find('.')) { const DictionaryValue* child_dictionary = NULL; if (!current_dictionary->GetDictionary( - current_path.substr(0, delimiter_position), &child_dictionary)) + current_path.substr(0, delimiter_position), &child_dictionary)) { return false; + } current_dictionary = child_dictionary; - current_path.erase(0, delimiter_position + 1); + current_path = current_path.substr(delimiter_position + 1); } - return current_dictionary->GetWithoutPathExpansion(current_path, out_value); + return current_dictionary->GetWithoutPathExpansion(current_path.as_string(), + out_value); } -bool DictionaryValue::Get(const std::string& path, Value** out_value) { +bool DictionaryValue::Get(StringPiece path, Value** out_value) { return static_cast<const DictionaryValue&>(*this).Get( path, const_cast<const Value**>(out_value)); @@ -588,7 +590,7 @@ bool DictionaryValue::GetBinary(const std::string& path, const_cast<const BinaryValue**>(out_value)); } -bool DictionaryValue::GetDictionary(const std::string& path, +bool DictionaryValue::GetDictionary(StringPiece path, const DictionaryValue** out_value) const { const Value* value; bool result = Get(path, &value); @@ -601,7 +603,7 @@ bool DictionaryValue::GetDictionary(const std::string& path, return true; } -bool DictionaryValue::GetDictionary(const std::string& path, +bool DictionaryValue::GetDictionary(StringPiece path, DictionaryValue** out_value) { return static_cast<const DictionaryValue&>(*this).GetDictionary( path, diff --git a/base/values.h b/base/values.h index 7feef9d..8756deb 100644 --- a/base/values.h +++ b/base/values.h @@ -30,6 +30,7 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/strings/string16.h" +#include "base/strings/string_piece.h" namespace base { @@ -270,8 +271,8 @@ class BASE_EXPORT DictionaryValue : public Value { // Otherwise, it will return false and |out_value| will be untouched. // Note that the dictionary always owns the value that's returned. // |out_value| is optional and will only be set if non-NULL. - bool Get(const std::string& path, const Value** out_value) const; - bool Get(const std::string& path, Value** out_value); + bool Get(StringPiece path, const Value** out_value) const; + bool Get(StringPiece path, Value** out_value); // These are convenience forms of Get(). The value will be retrieved // and the return value will be true if the path is valid and the value at @@ -287,9 +288,9 @@ class BASE_EXPORT DictionaryValue : public Value { bool GetStringASCII(const std::string& path, std::string* out_value) const; bool GetBinary(const std::string& path, const BinaryValue** out_value) const; bool GetBinary(const std::string& path, BinaryValue** out_value); - bool GetDictionary(const std::string& path, + bool GetDictionary(StringPiece path, const DictionaryValue** out_value) const; - bool GetDictionary(const std::string& path, DictionaryValue** out_value); + bool GetDictionary(StringPiece path, DictionaryValue** out_value); bool GetList(const std::string& path, const ListValue** out_value) const; bool GetList(const std::string& path, ListValue** out_value); |