diff options
Diffstat (limited to 'base/values.cc')
-rw-r--r-- | base/values.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/base/values.cc b/base/values.cc index 7d0be65..7e55739 100644 --- a/base/values.cc +++ b/base/values.cc @@ -95,6 +95,11 @@ Value* Value::CreateStringValue(const std::wstring& in_value) { } // static +Value* Value::CreateStringValueFromUTF16(const string16& in_value) { + return new StringValue(in_value); +} + +// static BinaryValue* Value::CreateBinaryValue(char* buffer, size_t size) { return BinaryValue::Create(buffer, size); } @@ -119,6 +124,10 @@ bool Value::GetAsString(std::wstring* in_value) const { return false; } +bool Value::GetAsUTF16(string16* out_value) const { + return false; +} + Value* Value::DeepCopy() const { // This method should only be getting called for null Values--all subclasses // need to provide their own implementation;. @@ -209,6 +218,13 @@ StringValue::StringValue(const std::wstring& in_value) value_(WideToUTF8(in_value)) { } +#if !defined(WCHAR_T_IS_UTF16) +StringValue::StringValue(const string16& in_value) + : Value(TYPE_STRING), + value_(UTF16ToUTF8(in_value)) { +} +#endif + StringValue::~StringValue() { } @@ -224,6 +240,12 @@ bool StringValue::GetAsString(std::wstring* out_value) const { return true; } +bool StringValue::GetAsUTF16(string16* out_value) const { + if (out_value) + *out_value = UTF8ToUTF16(value_); + return true; +} + Value* StringValue::DeepCopy() const { return CreateStringValue(value_); } @@ -387,6 +409,11 @@ void DictionaryValue::SetString(const std::wstring& path, Set(path, CreateStringValue(in_value)); } +void DictionaryValue::SetStringFromUTF16(const std::wstring& path, + const string16& in_value) { + Set(path, CreateStringValueFromUTF16(in_value)); +} + void DictionaryValue::SetWithoutPathExpansion(const std::wstring& key, Value* in_value) { // If there's an existing value here, we need to delete it, because @@ -462,6 +489,15 @@ bool DictionaryValue::GetString(const std::wstring& path, return value->GetAsString(out_value); } +bool DictionaryValue::GetStringAsUTF16(const std::wstring& path, + string16* out_value) const { + Value* value; + if (!Get(path, &value)) + return false; + + return value->GetAsUTF16(out_value); +} + bool DictionaryValue::GetBinary(const std::wstring& path, BinaryValue** out_value) const { Value* value; @@ -542,6 +578,16 @@ bool DictionaryValue::GetStringWithoutPathExpansion( return value->GetAsString(out_value); } +bool DictionaryValue::GetStringAsUTF16WithoutPathExpansion( + const std::wstring& path, + string16* out_value) const { + Value* value; + if (!GetWithoutPathExpansion(path, &value)) + return false; + + return value->GetAsUTF16(out_value); +} + bool DictionaryValue::GetDictionaryWithoutPathExpansion( const std::wstring& path, DictionaryValue** out_value) const { @@ -683,6 +729,14 @@ bool ListValue::GetString(size_t index, std::wstring* out_value) const { return value->GetAsString(out_value); } +bool ListValue::GetStringAsUTF16(size_t index, string16* out_value) const { + Value* value; + if (!Get(index, &value)) + return false; + + return value->GetAsUTF16(out_value); +} + bool ListValue::GetBinary(size_t index, BinaryValue** out_value) const { Value* value; bool result = Get(index, &value); |