summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/bookmarks/bookmark_html_writer.cc2
-rw-r--r--chrome/browser/search_engines/template_url.cc19
-rw-r--r--net/base/escape.cc31
-rw-r--r--net/base/escape.h19
-rw-r--r--net/base/escape_unittest.cc12
-rw-r--r--net/base/net_util.cc10
6 files changed, 50 insertions, 43 deletions
diff --git a/chrome/browser/bookmarks/bookmark_html_writer.cc b/chrome/browser/bookmarks/bookmark_html_writer.cc
index 2dccfef..eb330ac 100644
--- a/chrome/browser/bookmarks/bookmark_html_writer.cc
+++ b/chrome/browser/bookmarks/bookmark_html_writer.cc
@@ -179,7 +179,7 @@ class Writer : public Task {
break;
case CONTENT:
- utf8_string = WideToUTF8(EscapeForHTML(text));
+ utf8_string = UTF16ToUTF8(EscapeForHTML(WideToUTF16Hack(text)));
break;
default:
diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc
index 3febf96..82bec3b 100644
--- a/chrome/browser/search_engines/template_url.cc
+++ b/chrome/browser/search_engines/template_url.cc
@@ -248,13 +248,14 @@ std::wstring TemplateURLRef::ReplaceSearchTerms(
// Encode the search terms so that we know the encoding.
const std::vector<std::string>& encodings = host.input_encodings();
- std::wstring encoded_terms;
- std::wstring encoded_original_query;
+ string16 encoded_terms;
+ string16 encoded_original_query;
std::wstring input_encoding;
for (size_t i = 0; i < encodings.size(); ++i) {
- if (EscapeQueryParamValue(terms, encodings[i].c_str(), &encoded_terms)) {
+ if (EscapeQueryParamValue(WideToUTF16Hack(terms),
+ encodings[i].c_str(), &encoded_terms)) {
if (!original_query_for_suggestion.empty()) {
- EscapeQueryParamValue(original_query_for_suggestion,
+ EscapeQueryParamValue(WideToUTF16Hack(original_query_for_suggestion),
encodings[i].c_str(), &encoded_original_query);
}
input_encoding = ASCIIToWide(encodings[i]);
@@ -262,10 +263,11 @@ std::wstring TemplateURLRef::ReplaceSearchTerms(
}
}
if (input_encoding.empty()) {
- encoded_terms = EscapeQueryParamValueUTF8(terms);
+ encoded_terms = WideToUTF16Hack(EscapeQueryParamValueUTF8(terms));
if (!original_query_for_suggestion.empty()) {
encoded_original_query =
- EscapeQueryParamValueUTF8(original_query_for_suggestion);
+ WideToUTF16Hack(
+ EscapeQueryParamValueUTF8(original_query_for_suggestion));
}
input_encoding = L"UTF-8";
}
@@ -298,7 +300,8 @@ std::wstring TemplateURLRef::ReplaceSearchTerms(
case GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION:
if (accepted_suggestion >= 0)
- url.insert(i->index, L"oq=" + encoded_original_query + L"&");
+ url.insert(i->index, L"oq=" +
+ UTF16ToWideHack(encoded_original_query) + L"&");
break;
case GOOGLE_RLZ: {
@@ -333,7 +336,7 @@ std::wstring TemplateURLRef::ReplaceSearchTerms(
break;
case SEARCH_TERMS:
- url.insert(i->index, encoded_terms);
+ url.insert(i->index, UTF16ToWideHack(encoded_terms));
break;
default:
diff --git a/net/base/escape.cc b/net/base/escape.cc
index 6963967..db03fa8 100644
--- a/net/base/escape.cc
+++ b/net/base/escape.cc
@@ -111,11 +111,11 @@ const char kUrlUnescape[128] = {
std::string UnescapeURLImpl(const std::string& escaped_text,
UnescapeRule::Type rules,
size_t* offset_for_adjustment) {
- size_t offset_temp = std::wstring::npos;
+ size_t offset_temp = string16::npos;
if (!offset_for_adjustment)
offset_for_adjustment = &offset_temp;
else if (*offset_for_adjustment >= escaped_text.length())
- *offset_for_adjustment = std::wstring::npos;
+ *offset_for_adjustment = string16::npos;
// Do not unescape anything, return the |escaped_text| text.
if (rules == UnescapeRule::NONE)
@@ -234,37 +234,36 @@ std::string EscapeExternalHandlerValue(const std::string& text) {
return Escape(text, kExternalHandlerCharmap, false);
}
-bool EscapeQueryParamValue(const std::wstring& text, const char* codepage,
- std::wstring* escaped) {
+bool EscapeQueryParamValue(const string16& text, const char* codepage,
+ string16* escaped) {
// TODO(brettw) bug 1201094: this function should be removed, this "SKIP"
// behavior is wrong when the character can't be encoded properly.
std::string encoded;
- if (!base::WideToCodepage(text, codepage,
- base::OnStringConversionError::SKIP, &encoded))
+ if (!base::UTF16ToCodepage(text, codepage,
+ base::OnStringConversionError::SKIP, &encoded))
return false;
- // It's safe to use UTF8ToWide here because Escape should only return
- // alphanumerics and !'()*-._~
- escaped->assign(UTF8ToWide(Escape(encoded, kQueryCharmap, true)));
+ escaped->assign(UTF8ToUTF16(Escape(encoded, kQueryCharmap, true)));
return true;
}
-std::wstring UnescapeAndDecodeUTF8URLComponent(const std::string& text,
- UnescapeRule::Type rules,
- size_t* offset_for_adjustment) {
+string16 UnescapeAndDecodeUTF8URLComponent(const std::string& text,
+ UnescapeRule::Type rules,
+ size_t* offset_for_adjustment) {
std::wstring result;
size_t original_offset = offset_for_adjustment ? *offset_for_adjustment : 0;
std::string unescaped_url(
UnescapeURLImpl(text, rules, offset_for_adjustment));
if (UTF8ToWideAndAdjustOffset(unescaped_url.data(), unescaped_url.length(),
&result, offset_for_adjustment))
- return result; // Character set looks like it's valid.
+ return WideToUTF16Hack(result); // Character set looks like it's valid.
// Not valid. Return the escaped version. Undo our changes to
// |offset_for_adjustment| since we haven't changed the string after all.
if (offset_for_adjustment)
*offset_for_adjustment = original_offset;
- return UTF8ToWideAndAdjustOffset(text, offset_for_adjustment);
+ return WideToUTF16Hack(UTF8ToWideAndAdjustOffset(text,
+ offset_for_adjustment));
}
std::string UnescapeURLComponent(const std::string& escaped_text,
@@ -301,7 +300,7 @@ void AppendEscapedCharForHTML(char c, std::string* output) {
AppendEscapedCharForHTMLImpl(c, output);
}
-void AppendEscapedCharForHTML(wchar_t c, std::wstring* output) {
+void AppendEscapedCharForHTML(wchar_t c, string16* output) {
AppendEscapedCharForHTMLImpl(c, output);
}
@@ -320,6 +319,6 @@ std::string EscapeForHTML(const std::string& input) {
return EscapeForHTMLImpl(input);
}
-std::wstring EscapeForHTML(const std::wstring& input) {
+string16 EscapeForHTML(const string16& input) {
return EscapeForHTMLImpl(input);
}
diff --git a/net/base/escape.h b/net/base/escape.h
index 9ff17b6..5476d9c 100644
--- a/net/base/escape.h
+++ b/net/base/escape.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/string16.h"
// Escaping --------------------------------------------------------------------
@@ -35,7 +36,7 @@ void AppendEscapedCharForHTML(char c, std::string* output);
// Escape chars that might cause this text to be interpretted as HTML tags.
std::string EscapeForHTML(const std::string& text);
-std::wstring EscapeForHTML(const std::wstring& text);
+string16 EscapeForHTML(const string16& text);
// Unescaping ------------------------------------------------------------------
@@ -95,29 +96,29 @@ std::string UnescapeURLComponent(const std::string& escaped_text,
// Unescapes the given substring as a URL, and then tries to interpret the
// result as being encoded as UTF-8. If the result is convertable into UTF-8, it
// will be returned as converted. If it is not, the original escaped string will
-// be converted into a wide string and returned.
+// be converted into a string16 and returned.
//
// |offset_for_adjustment| may be NULL; if not, it is an offset into |text| that
// will be adjusted to point at the same logical place in the result string. If
// this isn't possible because it points into the middle of an escape sequence
-// or past the end of the string, it will be set to std::wstring::npos.
-std::wstring UnescapeAndDecodeUTF8URLComponent(const std::string& text,
- UnescapeRule::Type rules,
- size_t* offset_for_adjustment);
+// or past the end of the string, it will be set to string16::npos.
+string16 UnescapeAndDecodeUTF8URLComponent(const std::string& text,
+ UnescapeRule::Type rules,
+ size_t* offset_for_adjustment);
// Deprecated ------------------------------------------------------------------
// Escapes characters in text suitable for use as a query parameter value.
// We %XX everything except alphanumerics and -_.!~*'()
// This is basically the same as encodeURIComponent in javascript.
-// For the wstring version, we do a conversion to charset before encoding the
+// For the string16 version, we do a conversion to charset before encoding the
// string. If the charset doesn't exist, we return false.
//
// TODO(brettw) bug 1201094: This function should be removed. See the bug for
// why and what callers should do instead.
std::string EscapeQueryParamValue(const std::string& text);
-bool EscapeQueryParamValue(const std::wstring& text, const char* codepage,
- std::wstring* escaped);
+bool EscapeQueryParamValue(const string16& text, const char* codepage,
+ string16* escaped);
// A specialized version of EscapeQueryParamValue for wide strings that
// assumes the codepage is UTF8. This is provided as a convenience.
diff --git a/net/base/escape_unittest.cc b/net/base/escape_unittest.cc
index 8e5e7dc..f350117f 100644
--- a/net/base/escape_unittest.cc
+++ b/net/base/escape_unittest.cc
@@ -88,14 +88,15 @@ TEST(EscapeTest, EscapeTextForFormSubmission) {
// Check to see if EscapeQueryParamValueUTF8 is the same as
// EscapeQueryParamValue(..., kCodepageUTF8,)
- std::wstring test_str;
+ string16 test_str;
test_str.reserve(5000);
for (int i = 1; i < 5000; ++i) {
test_str.push_back(i);
}
- std::wstring wide;
+ string16 wide;
EXPECT_TRUE(EscapeQueryParamValue(test_str, base::kCodepageUTF8, &wide));
- EXPECT_EQ(wide, EscapeQueryParamValueUTF8(test_str));
+ EXPECT_EQ(UTF16ToWideHack(wide),
+ EscapeQueryParamValueUTF8(UTF16ToWideHack(test_str)));
}
TEST(EscapeTest, EscapePath) {
@@ -243,9 +244,10 @@ TEST(EscapeTest, UnescapeAndDecodeUTF8URLComponent) {
EXPECT_EQ(std::string(unescape_cases[i].query_unescaped), unescaped);
// TODO: Need to test unescape_spaces and unescape_percent.
- std::wstring decoded = UnescapeAndDecodeUTF8URLComponent(
+ string16 decoded = UnescapeAndDecodeUTF8URLComponent(
unescape_cases[i].input, UnescapeRule::NORMAL, NULL);
- EXPECT_EQ(std::wstring(unescape_cases[i].decoded), decoded);
+ EXPECT_EQ(WideToUTF16Hack(std::wstring(unescape_cases[i].decoded)),
+ decoded);
}
}
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 2677abd..43fa906 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1257,8 +1257,10 @@ void GetIdentityFromURL(const GURL& url,
std::wstring* username,
std::wstring* password) {
UnescapeRule::Type flags = UnescapeRule::SPACES;
- *username = UnescapeAndDecodeUTF8URLComponent(url.username(), flags, NULL);
- *password = UnescapeAndDecodeUTF8URLComponent(url.password(), flags, NULL);
+ *username = UTF16ToWideHack(UnescapeAndDecodeUTF8URLComponent(url.username(),
+ flags, NULL));
+ *password = UTF16ToWideHack(UnescapeAndDecodeUTF8URLComponent(url.password(),
+ flags, NULL));
}
void AppendFormattedHost(const GURL& url,
@@ -1328,9 +1330,9 @@ void AppendFormattedComponent(const std::string& spec,
spec.substr(in_component.begin, in_component.len),
offset_into_component));
} else {
- output->append(UnescapeAndDecodeUTF8URLComponent(
+ output->append(UTF16ToWideHack(UnescapeAndDecodeUTF8URLComponent(
spec.substr(in_component.begin, in_component.len), unescape_rules,
- offset_into_component));
+ offset_into_component)));
}
out_component->len =
static_cast<int>(output->length()) - out_component->begin;