diff options
author | dsh@google.com <dsh@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-25 19:17:45 +0000 |
---|---|---|
committer | dsh@google.com <dsh@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-25 19:17:45 +0000 |
commit | e2219171711f7acf49a52ba89eb6e05c27f11103 (patch) | |
tree | 464c5ec96e0a288bf0460d9d7109d12f9bd29207 | |
parent | 5e5bf59cbc75839aafef3ae29bcb53408adb715d (diff) | |
download | chromium_src-e2219171711f7acf49a52ba89eb6e05c27f11103.zip chromium_src-e2219171711f7acf49a52ba89eb6e05c27f11103.tar.gz chromium_src-e2219171711f7acf49a52ba89eb6e05c27f11103.tar.bz2 |
Change the string_escape functions to use string16 rather than wstring.
Review URL: http://codereview.chromium.org/27116
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10358 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/json_writer.cc | 4 | ||||
-rw-r--r-- | base/string_escape.cc | 7 | ||||
-rw-r--r-- | base/string_escape.h | 5 | ||||
-rw-r--r-- | base/string_escape_unittest.cc | 16 | ||||
-rw-r--r-- | base/string_util.h | 13 | ||||
-rw-r--r-- | net/base/net_util.cc | 7 |
6 files changed, 32 insertions, 20 deletions
diff --git a/base/json_writer.cc b/base/json_writer.cc index 0da2925..20c533b 100644 --- a/base/json_writer.cc +++ b/base/json_writer.cc @@ -156,7 +156,8 @@ void JSONWriter::BuildJSONString(const Value* const node, int depth) { } void JSONWriter::AppendQuotedString(const std::wstring& str) { - string_escape::JavascriptDoubleQuote(str, true, json_string_); + string_escape::JavascriptDoubleQuote(WideToUTF16Hack(str), true, + json_string_); } void JSONWriter::IndentLine(int depth) { @@ -164,4 +165,3 @@ void JSONWriter::IndentLine(int depth) { // reallocating. json_string_->append(std::string(depth * 3, ' ')); } - diff --git a/base/string_escape.cc b/base/string_escape.cc index c2fc542..aafee11 100644 --- a/base/string_escape.cc +++ b/base/string_escape.cc @@ -46,14 +46,14 @@ static bool JavascriptSingleEscapeChar(const CHAR c, std::string* dst) { return true; } -void JavascriptDoubleQuote(const std::wstring& str, +void JavascriptDoubleQuote(const string16& str, bool put_in_quotes, std::string* dst) { if (put_in_quotes) dst->push_back('"'); - for (std::wstring::const_iterator it = str.begin(); it != str.end(); ++it) { - wchar_t c = *it; + for (string16::const_iterator it = str.begin(); it != str.end(); ++it) { + char16 c = *it; if (!JavascriptSingleEscapeChar(c, dst)) { if (c > 255) { // Non-ascii values need to be unicode dst-> @@ -96,4 +96,3 @@ void JavascriptDoubleQuote(const std::string& str, } } // namespace string_escape - diff --git a/base/string_escape.h b/base/string_escape.h index f58651e..9c6233a 100644 --- a/base/string_escape.h +++ b/base/string_escape.h @@ -7,7 +7,7 @@ #ifndef BASE_STRING_ESCAPE_H__ #define BASE_STRING_ESCAPE_H__ -#include <string> +#include "base/string16.h" namespace string_escape { @@ -17,7 +17,7 @@ namespace string_escape { // If |put_in_quotes| is true, the result will be surrounded in double quotes. // The outputted literal, when interpreted by the browser, should result in a // javascript string that is identical and the same length as the input |str|. -void JavascriptDoubleQuote(const std::wstring& str, +void JavascriptDoubleQuote(const string16& str, bool put_in_quotes, std::string* dst); @@ -33,4 +33,3 @@ void JavascriptDoubleQuote(const std::string& str, } // namespace string_escape #endif // BASE_STRING_ESCAPE_H__ - diff --git a/base/string_escape_unittest.cc b/base/string_escape_unittest.cc index 28be9bd..e6a1806 100644 --- a/base/string_escape_unittest.cc +++ b/base/string_escape_unittest.cc @@ -4,6 +4,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "base/string_escape.h" +#include "base/string_util.h" TEST(StringEscapeTest, JavascriptDoubleQuote) { static const char* kToEscape = "\b\001aZ\"\\wee"; @@ -17,21 +18,21 @@ TEST(StringEscapeTest, JavascriptDoubleQuote) { // Test wide unicode escaping out = "testy: "; - string_escape::JavascriptDoubleQuote(std::wstring(kUToEscape), false, &out); + string_escape::JavascriptDoubleQuote(WideToUTF16(kUToEscape), false, &out); ASSERT_EQ(std::string("testy: ") + kUEscaped, out); out = "testy: "; - string_escape::JavascriptDoubleQuote(std::wstring(kUToEscape), true, &out); + string_escape::JavascriptDoubleQuote(WideToUTF16(kUToEscape), true, &out); ASSERT_EQ(std::string("testy: ") + kUEscapedQuoted, out); // Test null and high bit / negative unicode values - std::wstring wstr(L"TeSt"); - wstr.push_back(0); - wstr.push_back(0xffb1); - wstr.push_back(0x00ff); + string16 str16 = UTF8ToUTF16("TeSt"); + str16.push_back(0); + str16.push_back(0xffb1); + str16.push_back(0x00ff); out = "testy: "; - string_escape::JavascriptDoubleQuote(wstr, false, &out); + string_escape::JavascriptDoubleQuote(str16, false, &out); ASSERT_EQ("testy: TeSt\\x00\\uFFB1\\xFF", out); // Test escaping of 7bit ascii @@ -61,4 +62,3 @@ TEST(StringEscapeTest, JavascriptDoubleQuote) { string_escape::JavascriptDoubleQuote("a\b\f\n\r\t\v\1\\.\"z", false, &out); ASSERT_EQ("testy: a\\b\\f\\n\\r\\t\\v\\x01\\\\.\\\"z", out); } - diff --git a/base/string_util.h b/base/string_util.h index 6ee079a..500a114 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -181,6 +181,19 @@ string16 UTF8ToUTF16(const std::string& utf8); bool UTF16ToUTF8(const char16* src, size_t src_len, std::string* output); std::string UTF16ToUTF8(const string16& utf16); +// We are trying to get rid of wstring as much as possible, but it's too big +// a mess to do it all at once. These conversions should be used when we +// really should just be passing a string16 around, but we haven't finished +// porting whatever module uses wstring and the conversion is being used as a +// stopcock. This makes it easy to grep for the ones that should be removed. +#if defined(OS_WIN) +# define WideToUTF16Hack +# define UTF16ToWideHack +#else +# define WideToUTF16Hack WideToUTF16 +# define UTF16ToWideHack UTF16ToWide +#endif + // Defines the error handling modes of WideToCodepage and CodepageToWide. class OnStringUtilConversionError { public: diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 5c042d1..7cee8f1 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -848,14 +848,15 @@ std::string GetDirectoryListingEntry(const std::string& name, } string_escape::JavascriptDoubleQuote( - FormatBytes(size, GetByteDisplayUnits(size), true), true, &result); + WideToUTF16Hack(FormatBytes(size, GetByteDisplayUnits(size), true)), true, + &result); result.append(","); - std::wstring modified_str; + string16 modified_str; // |modified| can be NULL in FTP listings. if (!modified.is_null()) { - modified_str = base::TimeFormatShortDateAndTime(modified); + modified_str = WideToUTF16Hack(base::TimeFormatShortDateAndTime(modified)); } string_escape::JavascriptDoubleQuote(modified_str, true, &result); |