Index: base/values.cc |
diff --git a/base/values.cc b/base/values.cc |
index dd8062b8388f8fac31e580fa1bbd42e2f78532fe..75b8e4f7d955b4e7ae5f4220438eef2b448e6572 100644 |
--- a/base/values.cc |
+++ b/base/values.cc |
@@ -3,6 +3,7 @@ |
// found in the LICENSE file. |
#include "base/logging.h" |
+#include "base/string_util.h" |
#include "base/values.h" |
///////////////////// Value //////////////////// |
@@ -31,6 +32,11 @@ Value* Value::CreateRealValue(double in_value) { |
} |
// static |
+Value* Value::CreateStringValue(const std::string& in_value) { |
+ return new StringValue(in_value); |
+} |
+ |
+// static |
Value* Value::CreateStringValue(const std::wstring& in_value) { |
return new StringValue(in_value); |
} |
@@ -52,6 +58,10 @@ bool Value::GetAsReal(double* in_value) const { |
return false; |
} |
+bool Value::GetAsString(std::string* in_value) const { |
+ return false; |
+} |
+ |
bool Value::GetAsString(std::wstring* in_value) const { |
return false; |
} |
@@ -135,15 +145,32 @@ bool FundamentalValue::Equals(const Value* other) const { |
///////////////////// StringValue //////////////////// |
+StringValue::StringValue(const std::string& in_value) |
+ : Value(TYPE_STRING), |
+ value_(in_value) { |
+ DCHECK(IsStringUTF8(in_value)); |
+} |
+ |
+StringValue::StringValue(const std::wstring& in_value) |
+ : Value(TYPE_STRING), |
+ value_(WideToUTF8(in_value)) { |
+} |
+ |
StringValue::~StringValue() { |
} |
-bool StringValue::GetAsString(std::wstring* out_value) const { |
+bool StringValue::GetAsString(std::string* out_value) const { |
if (out_value) |
*out_value = value_; |
return true; |
} |
+bool StringValue::GetAsString(std::wstring* out_value) const { |
+ if (out_value) |
+ *out_value = UTF8ToWide(value_); |
+ return true; |
+} |
+ |
Value* StringValue::DeepCopy() const { |
return CreateStringValue(value_); |
} |
@@ -151,7 +178,7 @@ Value* StringValue::DeepCopy() const { |
bool StringValue::Equals(const Value* other) const { |
if (other->GetType() != GetType()) |
return false; |
- std::wstring lhs, rhs; |
+ std::string lhs, rhs; |
return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; |
} |
@@ -276,6 +303,11 @@ bool DictionaryValue::SetReal(const std::wstring& path, double in_value) { |
} |
bool DictionaryValue::SetString(const std::wstring& path, |
+ const std::string& in_value) { |
+ return Set(path, CreateStringValue(in_value)); |
+} |
+ |
+bool DictionaryValue::SetString(const std::wstring& path, |
const std::wstring& in_value) { |
return Set(path, CreateStringValue(in_value)); |
} |
@@ -335,6 +367,15 @@ bool DictionaryValue::GetReal(const std::wstring& path, |
} |
bool DictionaryValue::GetString(const std::wstring& path, |
+ std::string* out_value) const { |
+ Value* value; |
+ if (!Get(path, &value)) |
+ return false; |
+ |
+ return value->GetAsString(out_value); |
+} |
+ |
+bool DictionaryValue::GetString(const std::wstring& path, |
std::wstring* out_value) const { |
Value* value; |
if (!Get(path, &value)) |