From e8749c99e678b18cf1b0b4051fab7d518e9ef0f9 Mon Sep 17 00:00:00 2001 From: "scherkus@chromium.org" Date: Wed, 10 Dec 2008 22:30:57 +0000 Subject: [PATCH] Revert "Added std::string to Value via Set/GetString overloading." Review URL: http://codereview.chromium.org/13358 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6747 0039d316-1c4b-4281-b951-d872f2087c98 --- base/values.cc | 42 +++--------------------------------------- base/values.h | 11 +++-------- base/values_unittest.cc | 48 ++++-------------------------------------------- 3 files changed, 10 insertions(+), 91 deletions(-) diff --git a/base/values.cc b/base/values.cc index b0160e176210..dd8062b8388f 100644 --- a/base/values.cc +++ b/base/values.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "base/logging.h" -#include "base/string_util.h" #include "base/values.h" ///////////////////// Value //////////////////// @@ -32,13 +31,8 @@ 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(WideToUTF8(in_value)); + return new StringValue(in_value); } // static @@ -58,10 +52,6 @@ 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; } @@ -145,24 +135,12 @@ 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() { } -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_); + *out_value = value_; return true; } @@ -173,7 +151,7 @@ Value* StringValue::DeepCopy() const { bool StringValue::Equals(const Value* other) const { if (other->GetType() != GetType()) return false; - std::string lhs, rhs; + std::wstring lhs, rhs; return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; } @@ -298,11 +276,6 @@ 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)); } @@ -362,15 +335,6 @@ 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)) diff --git a/base/values.h b/base/values.h index 846eb6770478..4786ff64fd86 100644 --- a/base/values.h +++ b/base/values.h @@ -52,7 +52,6 @@ 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 @@ -87,7 +86,6 @@ 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 @@ -139,12 +137,11 @@ class FundamentalValue : public Value { class StringValue : public Value { public: - // Initializes a StringValue with a UTF-8 narrow character string. - StringValue(const std::string& in_value); + StringValue(const std::wstring& in_value) + : Value(TYPE_STRING), value_(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; @@ -152,7 +149,7 @@ class StringValue : public Value { private: DISALLOW_EVIL_CONSTRUCTORS(StringValue); - std::string value_; + std::wstring value_; }; class BinaryValue: public Value { @@ -219,7 +216,6 @@ 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. @@ -237,7 +233,6 @@ 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, diff --git a/base/values_unittest.cc b/base/values_unittest.cc index 1a7808945c87..67515ece3be8 100644 --- a/base/values_unittest.cc +++ b/base/values_unittest.cc @@ -93,30 +93,6 @@ TEST(ValuesTest, BinaryValue) { delete binary; } -TEST(ValuesTest, StringValue) { - // Test overloaded CreateStringValue. - Value* narrow_value = Value::CreateStringValue("narrow"); - ASSERT_TRUE(narrow_value); - ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING)); - Value* wide_value = Value::CreateStringValue(L"wide"); - ASSERT_TRUE(wide_value); - ASSERT_TRUE(wide_value->IsType(Value::TYPE_STRING)); - - // Test overloaded GetString. - std::string narrow = "http://google.com"; - std::wstring wide = L"http://google.com"; - ASSERT_TRUE(narrow_value->GetAsString(&narrow)); - ASSERT_TRUE(narrow_value->GetAsString(&wide)); - ASSERT_EQ(std::string("narrow"), narrow); - ASSERT_EQ(std::wstring(L"narrow"), wide); - ASSERT_TRUE(wide_value->GetAsString(&narrow)); - ASSERT_TRUE(wide_value->GetAsString(&wide)); - ASSERT_EQ(std::string("wide"), narrow); - ASSERT_EQ(std::wstring(L"wide"), wide); - delete narrow_value; - delete wide_value; -} - // This is a Value object that allows us to tell if it's been // properly deleted by modifying the value of external flag on destruction. class DeletionTestValue : public Value { @@ -266,10 +242,8 @@ TEST(ValuesTest, DeepCopy) { original_dict.Set(L"int", original_int); Value* original_real = Value::CreateRealValue(3.14); original_dict.Set(L"real", original_real); - Value* original_string = Value::CreateStringValue("hello"); + Value* original_string = Value::CreateStringValue(L"peek-a-boo"); original_dict.Set(L"string", original_string); - Value* original_wstring = Value::CreateStringValue(L"peek-a-boo"); - original_dict.Set(L"wstring", original_wstring); char* original_buffer = new char[42]; memset(original_buffer, '!', 42); @@ -326,22 +300,9 @@ TEST(ValuesTest, DeepCopy) { ASSERT_TRUE(copy_string); ASSERT_NE(copy_string, original_string); ASSERT_TRUE(copy_string->IsType(Value::TYPE_STRING)); - std::string copy_string_value; - std::wstring copy_wstring_value; + std::wstring copy_string_value; ASSERT_TRUE(copy_string->GetAsString(©_string_value)); - ASSERT_TRUE(copy_string->GetAsString(©_wstring_value)); - ASSERT_EQ(std::string("hello"), copy_string_value); - ASSERT_EQ(std::wstring(L"hello"), copy_wstring_value); - - Value* copy_wstring = NULL; - ASSERT_TRUE(copy_dict->Get(L"wstring", ©_wstring)); - ASSERT_TRUE(copy_wstring); - ASSERT_NE(copy_wstring, original_wstring); - ASSERT_TRUE(copy_wstring->IsType(Value::TYPE_STRING)); - ASSERT_TRUE(copy_wstring->GetAsString(©_string_value)); - ASSERT_TRUE(copy_wstring->GetAsString(©_wstring_value)); - ASSERT_EQ(std::string("peek-a-boo"), copy_string_value); - ASSERT_EQ(std::wstring(L"peek-a-boo"), copy_wstring_value); + ASSERT_EQ(std::wstring(L"peek-a-boo"), copy_string_value); Value* copy_binary = NULL; ASSERT_TRUE(copy_dict->Get(L"binary", ©_binary)); @@ -399,8 +360,7 @@ TEST(ValuesTest, Equals) { dv.SetBoolean(L"a", false); dv.SetInteger(L"b", 2); dv.SetReal(L"c", 2.5); - dv.SetString(L"d1", "string"); - dv.SetString(L"d2", L"string"); + dv.SetString(L"d", L"string"); dv.Set(L"e", Value::CreateNullValue()); DictionaryValue* copy = static_cast(dv.DeepCopy()); -- 2.11.4.GIT