diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-10 22:18:47 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-10 22:18:47 +0000 |
commit | 3e9fe53e8e10628ba4432e50ea114200757ffe40 (patch) | |
tree | 4d7f8df513db02c3a4557c52d2f55568344c50b6 /base/values.h | |
parent | fc6ff4229344bf1a799a13c8aa651c657c2e9bbd (diff) | |
download | chromium_src-3e9fe53e8e10628ba4432e50ea114200757ffe40.zip chromium_src-3e9fe53e8e10628ba4432e50ea114200757ffe40.tar.gz chromium_src-3e9fe53e8e10628ba4432e50ea114200757ffe40.tar.bz2 |
Added std::string to Value via Set/GetString overloading.
All input is converted to UTF-8. Output is converted back to wide during std::wstring version of GetString().
This is part one of some more patches to come where I switch clients over to UTF-8 strings.
Review URL: http://codereview.chromium.org/13230
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.h')
-rw-r--r-- | base/values.h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/base/values.h b/base/values.h index 4786ff6..846eb67 100644 --- a/base/values.h +++ b/base/values.h @@ -52,6 +52,7 @@ class Value { static Value* CreateBooleanValue(bool in_value); static Value* CreateIntegerValue(int in_value); static Value* CreateRealValue(double in_value); + static Value* CreateStringValue(const std::string& in_value); static Value* CreateStringValue(const std::wstring& in_value); // This one can return NULL if the input isn't valid. If the return value @@ -86,6 +87,7 @@ class Value { virtual bool GetAsBoolean(bool* out_value) const; virtual bool GetAsInteger(int* out_value) const; virtual bool GetAsReal(double* out_value) const; + virtual bool GetAsString(std::string* out_value) const; virtual bool GetAsString(std::wstring* out_value) const; // This creates a deep copy of the entire Value tree, and returns a pointer @@ -137,11 +139,12 @@ class FundamentalValue : public Value { class StringValue : public Value { public: - StringValue(const std::wstring& in_value) - : Value(TYPE_STRING), value_(in_value) {} + // Initializes a StringValue with a UTF-8 narrow character string. + StringValue(const std::string& in_value); ~StringValue(); // Subclassed methods + bool GetAsString(std::string* out_value) const; bool GetAsString(std::wstring* out_value) const; Value* DeepCopy() const; virtual bool Equals(const Value* other) const; @@ -149,7 +152,7 @@ class StringValue : public Value { private: DISALLOW_EVIL_CONSTRUCTORS(StringValue); - std::wstring value_; + std::string value_; }; class BinaryValue: public Value { @@ -216,6 +219,7 @@ class DictionaryValue : public Value { bool SetBoolean(const std::wstring& path, bool in_value); bool SetInteger(const std::wstring& path, int in_value); bool SetReal(const std::wstring& path, double in_value); + bool SetString(const std::wstring& path, const std::string& in_value); bool SetString(const std::wstring& path, const std::wstring& in_value); // Gets the Value associated with the given path starting from this object. @@ -233,6 +237,7 @@ 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::wstring& path, std::string* out_value) const; bool GetString(const std::wstring& path, std::wstring* out_value) const; bool GetBinary(const std::wstring& path, BinaryValue** out_value) const; bool GetDictionary(const std::wstring& path, |