From 9430e4bae7a8faa17b353f66ed572b72cf393c05 Mon Sep 17 00:00:00 2001 From: "evan@chromium.org" Date: Fri, 19 Feb 2010 13:32:16 +0000 Subject: importer: use FilePath instead of wstring in some places Added API to DictionaryValue to use ASCII where appropriate. BUG=24672 TEST=profile import still got my bookmarks Review URL: http://codereview.chromium.org/647016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39441 0039d316-1c4b-4281-b951-d872f2087c98 --- base/values.cc | 24 ++++++++++++++++++++++++ base/values.h | 7 +++++++ 2 files changed, 31 insertions(+) (limited to 'base') diff --git a/base/values.cc b/base/values.cc index 7e55739..f78f474 100644 --- a/base/values.cc +++ b/base/values.cc @@ -354,6 +354,10 @@ bool DictionaryValue::HasKey(const std::wstring& key) const { return current_entry != dictionary_.end(); } +bool DictionaryValue::HasKeyASCII(const std::string& key) const { + return HasKey(ASCIIToWide(key)); +} + void DictionaryValue::Clear() { ValueMap::iterator dict_iterator = dictionary_.begin(); while (dict_iterator != dictionary_.end()) { @@ -471,6 +475,26 @@ bool DictionaryValue::GetReal(const std::wstring& path, return value->GetAsReal(out_value); } +bool DictionaryValue::GetString(const std::string& path, + string16* out_value) const { + return GetStringAsUTF16(ASCIIToWide(path), out_value); +} + +bool DictionaryValue::GetStringASCII(const std::string& path, + std::string* out_value) const { + std::string out; + if (!GetString(ASCIIToWide(path), &out)) + return false; + + if (!IsStringASCII(out)) { + NOTREACHED(); + return false; + } + + out_value->assign(out); + return true; +} + bool DictionaryValue::GetString(const std::wstring& path, std::string* out_value) const { Value* value; diff --git a/base/values.h b/base/values.h index e000508..ac6307a 100644 --- a/base/values.h +++ b/base/values.h @@ -214,6 +214,9 @@ class DictionaryValue : public Value { virtual bool Equals(const Value* other) const; // Returns true if the current dictionary has a value for the given key. + bool HasKeyASCII(const std::string& key) const; + // Deprecated version of the above. TODO: add a string16 version for Unicode. + // http://code.google.com/p/chromium/issues/detail?id=23581 bool HasKey(const std::wstring& key) const; // Returns the number of Values in this dictionary. @@ -264,6 +267,10 @@ class DictionaryValue : public Value { bool GetBoolean(const std::wstring& path, bool* out_value) const; bool GetInteger(const std::wstring& path, int* out_value) const; bool GetReal(const std::wstring& path, double* out_value) const; + bool GetString(const std::string& path, string16* out_value) const; + bool GetStringASCII(const std::string& path, std::string* out_value) const; + // TODO: deprecate wstring accessors. + // http://code.google.com/p/chromium/issues/detail?id=23581 bool GetString(const std::wstring& path, std::string* out_value) const; bool GetString(const std::wstring& path, std::wstring* out_value) const; bool GetStringAsUTF16(const std::wstring& path, string16* out_value) const; -- cgit v1.1