summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/string_util.cc16
-rw-r--r--base/string_util.h16
-rw-r--r--base/string_util_unittest.cc80
-rw-r--r--chrome/browser/bookmarks/bookmark_html_writer.cc8
-rw-r--r--chrome/browser/importer/firefox2_importer.cc17
-rw-r--r--chrome/browser/importer/importer.cc5
-rw-r--r--chrome/browser/search_engines/template_url.cc72
7 files changed, 116 insertions, 98 deletions
diff --git a/base/string_util.cc b/base/string_util.cc
index 64c0cdc..e7f6c33 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -843,10 +843,10 @@ void DoReplaceSubstringsAfterOffset(StringType* str,
}
}
-void ReplaceFirstSubstringAfterOffset(std::wstring* str,
- std::wstring::size_type start_offset,
- const std::wstring& find_this,
- const std::wstring& replace_with) {
+void ReplaceFirstSubstringAfterOffset(string16* str,
+ string16::size_type start_offset,
+ const string16& find_this,
+ const string16& replace_with) {
DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with,
false); // replace first instance
}
@@ -859,10 +859,10 @@ void ReplaceFirstSubstringAfterOffset(std::string* str,
false); // replace first instance
}
-void ReplaceSubstringsAfterOffset(std::wstring* str,
- std::wstring::size_type start_offset,
- const std::wstring& find_this,
- const std::wstring& replace_with) {
+void ReplaceSubstringsAfterOffset(string16* str,
+ string16::size_type start_offset,
+ const string16& find_this,
+ const string16& replace_with) {
DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with,
true); // replace all instances
}
diff --git a/base/string_util.h b/base/string_util.h
index 4e04cd8..26c42e5 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -359,10 +359,10 @@ std::wstring FormatNumber(int64 number);
// Starting at |start_offset| (usually 0), replace the first instance of
// |find_this| with |replace_with|.
-void ReplaceFirstSubstringAfterOffset(std::wstring* str,
- std::wstring::size_type start_offset,
- const std::wstring& find_this,
- const std::wstring& replace_with);
+void ReplaceFirstSubstringAfterOffset(string16* str,
+ string16::size_type start_offset,
+ const string16& find_this,
+ const string16& replace_with);
void ReplaceFirstSubstringAfterOffset(std::string* str,
std::string::size_type start_offset,
const std::string& find_this,
@@ -374,10 +374,10 @@ void ReplaceFirstSubstringAfterOffset(std::string* str,
// This does entire substrings; use std::replace in <algorithm> for single
// characters, for example:
// std::replace(str.begin(), str.end(), 'a', 'b');
-void ReplaceSubstringsAfterOffset(std::wstring* str,
- std::wstring::size_type start_offset,
- const std::wstring& find_this,
- const std::wstring& replace_with);
+void ReplaceSubstringsAfterOffset(string16* str,
+ string16::size_type start_offset,
+ const string16& find_this,
+ const string16& replace_with);
void ReplaceSubstringsAfterOffset(std::string* str,
std::string::size_type start_offset,
const std::string& find_this,
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc
index 6fc6f7f..0ceb18f 100644
--- a/base/string_util_unittest.cc
+++ b/base/string_util_unittest.cc
@@ -673,60 +673,62 @@ TEST(StringUtilTest, FormatBytes) {
TEST(StringUtilTest, ReplaceSubstringsAfterOffset) {
static const struct {
- const wchar_t* str;
- std::wstring::size_type start_offset;
- const wchar_t* find_this;
- const wchar_t* replace_with;
- const wchar_t* expected;
+ const char* str;
+ string16::size_type start_offset;
+ const char* find_this;
+ const char* replace_with;
+ const char* expected;
} cases[] = {
- {L"aaa", 0, L"a", L"b", L"bbb"},
- {L"abb", 0, L"ab", L"a", L"ab"},
- {L"Removing some substrings inging", 0, L"ing", L"", L"Remov some substrs "},
- {L"Not found", 0, L"x", L"0", L"Not found"},
- {L"Not found again", 5, L"x", L"0", L"Not found again"},
- {L" Making it much longer ", 0, L" ", L"Four score and seven years ago",
- L"Four score and seven years agoMakingFour score and seven years agoit"
- L"Four score and seven years agomuchFour score and seven years agolonger"
- L"Four score and seven years ago"},
- {L"Invalid offset", 9999, L"t", L"foobar", L"Invalid offset"},
- {L"Replace me only me once", 9, L"me ", L"", L"Replace me only once"},
- {L"abababab", 2, L"ab", L"c", L"abccc"},
+ {"aaa", 0, "a", "b", "bbb"},
+ {"abb", 0, "ab", "a", "ab"},
+ {"Removing some substrings inging", 0, "ing", "", "Remov some substrs "},
+ {"Not found", 0, "x", "0", "Not found"},
+ {"Not found again", 5, "x", "0", "Not found again"},
+ {" Making it much longer ", 0, " ", "Four score and seven years ago",
+ "Four score and seven years agoMakingFour score and seven years agoit"
+ "Four score and seven years agomuchFour score and seven years agolonger"
+ "Four score and seven years ago"},
+ {"Invalid offset", 9999, "t", "foobar", "Invalid offset"},
+ {"Replace me only me once", 9, "me ", "", "Replace me only once"},
+ {"abababab", 2, "ab", "c", "abccc"},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
- std::wstring str(cases[i].str);
+ string16 str = ASCIIToUTF16(cases[i].str);
ReplaceSubstringsAfterOffset(&str, cases[i].start_offset,
- cases[i].find_this, cases[i].replace_with);
- EXPECT_EQ(cases[i].expected, str);
+ ASCIIToUTF16(cases[i].find_this),
+ ASCIIToUTF16(cases[i].replace_with));
+ EXPECT_EQ(ASCIIToUTF16(cases[i].expected), str);
}
}
TEST(StringUtilTest, ReplaceFirstSubstringAfterOffset) {
static const struct {
- const wchar_t* str;
- std::wstring::size_type start_offset;
- const wchar_t* find_this;
- const wchar_t* replace_with;
- const wchar_t* expected;
+ const char* str;
+ string16::size_type start_offset;
+ const char* find_this;
+ const char* replace_with;
+ const char* expected;
} cases[] = {
- {L"aaa", 0, L"a", L"b", L"baa"},
- {L"abb", 0, L"ab", L"a", L"ab"},
- {L"Removing some substrings inging", 0, L"ing", L"",
- L"Remov some substrings inging"},
- {L"Not found", 0, L"x", L"0", L"Not found"},
- {L"Not found again", 5, L"x", L"0", L"Not found again"},
- {L" Making it much longer ", 0, L" ", L"Four score and seven years ago",
- L"Four score and seven years agoMaking it much longer "},
- {L"Invalid offset", 9999, L"t", L"foobar", L"Invalid offset"},
- {L"Replace me only me once", 4, L"me ", L"", L"Replace only me once"},
- {L"abababab", 2, L"ab", L"c", L"abcabab"},
+ {"aaa", 0, "a", "b", "baa"},
+ {"abb", 0, "ab", "a", "ab"},
+ {"Removing some substrings inging", 0, "ing", "",
+ "Remov some substrings inging"},
+ {"Not found", 0, "x", "0", "Not found"},
+ {"Not found again", 5, "x", "0", "Not found again"},
+ {" Making it much longer ", 0, " ", "Four score and seven years ago",
+ "Four score and seven years agoMaking it much longer "},
+ {"Invalid offset", 9999, "t", "foobar", "Invalid offset"},
+ {"Replace me only me once", 4, "me ", "", "Replace only me once"},
+ {"abababab", 2, "ab", "c", "abcabab"},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
- std::wstring str(cases[i].str);
+ string16 str = ASCIIToUTF16(cases[i].str);
ReplaceFirstSubstringAfterOffset(&str, cases[i].start_offset,
- cases[i].find_this, cases[i].replace_with);
- EXPECT_EQ(cases[i].expected, str);
+ ASCIIToUTF16(cases[i].find_this),
+ ASCIIToUTF16(cases[i].replace_with));
+ EXPECT_EQ(ASCIIToUTF16(cases[i].expected), str);
}
}
diff --git a/chrome/browser/bookmarks/bookmark_html_writer.cc b/chrome/browser/bookmarks/bookmark_html_writer.cc
index 6b6c556..5ec7ca0 100644
--- a/chrome/browser/bookmarks/bookmark_html_writer.cc
+++ b/chrome/browser/bookmarks/bookmark_html_writer.cc
@@ -166,9 +166,11 @@ class Writer : public Task {
case ATTRIBUTE_VALUE:
// Convert " to \"
if (text.find(L"\"") != std::wstring::npos) {
- std::wstring replaced_string = text;
- ReplaceSubstringsAfterOffset(&replaced_string, 0, L"\"", L"\\\"");
- utf8_string = WideToUTF8(replaced_string);
+ string16 replaced_string = WideToUTF16Hack(text);
+ ReplaceSubstringsAfterOffset(&replaced_string, 0,
+ ASCIIToUTF16("\""),
+ ASCIIToUTF16("\\\""));
+ utf8_string = UTF16ToUTF8(replaced_string);
} else {
utf8_string = WideToUTF8(text);
}
diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc
index 77fd49f..8dfddd2 100644
--- a/chrome/browser/importer/firefox2_importer.cc
+++ b/chrome/browser/importer/firefox2_importer.cc
@@ -501,11 +501,18 @@ bool Firefox2Importer::GetAttribute(const std::string& attribute_list,
// static
void Firefox2Importer::HTMLUnescape(std::wstring *text) {
- ReplaceSubstringsAfterOffset(text, 0, L"&lt;", L"<");
- ReplaceSubstringsAfterOffset(text, 0, L"&gt;", L">");
- ReplaceSubstringsAfterOffset(text, 0, L"&amp;", L"&");
- ReplaceSubstringsAfterOffset(text, 0, L"&quot;", L"\"");
- ReplaceSubstringsAfterOffset(text, 0, L"&#39;", L"\'");
+ string16 text16 = WideToUTF16Hack(*text);
+ ReplaceSubstringsAfterOffset(
+ &text16, 0, ASCIIToUTF16("&lt;"), ASCIIToUTF16("<"));
+ ReplaceSubstringsAfterOffset(
+ &text16, 0, ASCIIToUTF16("&gt;"), ASCIIToUTF16(">"));
+ ReplaceSubstringsAfterOffset(
+ &text16, 0, ASCIIToUTF16("&amp;"), ASCIIToUTF16("&"));
+ ReplaceSubstringsAfterOffset(
+ &text16, 0, ASCIIToUTF16("&quot;"), ASCIIToUTF16("\""));
+ ReplaceSubstringsAfterOffset(
+ &text16, 0, ASCIIToUTF16("&#39;"), ASCIIToUTF16("\'"));
+ text->assign(UTF16ToWideHack(text16));
}
// static
diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc
index 9c98362..2d3f924 100644
--- a/chrome/browser/importer/importer.cc
+++ b/chrome/browser/importer/importer.cc
@@ -667,7 +667,10 @@ void ImporterHost::DetectFirefoxProfiles() {
std::wstring is_relative, path, profile_path;
if (root.GetString(current_profile + L".IsRelative", &is_relative) &&
root.GetString(current_profile + L".Path", &path)) {
- ReplaceSubstringsAfterOffset(&path, 0, L"/", L"\\");
+ string16 path16 = WideToUTF16Hack(path);
+ ReplaceSubstringsAfterOffset(
+ &path16, 0, ASCIIToUTF16("/"), ASCIIToUTF16("\\"));
+ path.assign(UTF16ToWideHack(path16));
#if defined(OS_WIN)
// IsRelative=1 means the folder path would be relative to the
diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc
index 27bfe1d..bd6c115 100644
--- a/chrome/browser/search_engines/template_url.cc
+++ b/chrome/browser/search_engines/template_url.cc
@@ -24,7 +24,7 @@ static const wchar_t kOptional = '?';
// Known parameters found in the URL.
static const wchar_t kSearchTermsParameter[] = L"searchTerms";
-static const wchar_t kSearchTermsParameterFull[] = L"{searchTerms}";
+static const char kSearchTermsParameterFull[] = "{searchTerms}";
static const wchar_t kCountParameter[] = L"count";
static const wchar_t kStartIndexParameter[] = L"startIndex";
static const wchar_t kStartPageParameter[] = L"startPage";
@@ -36,26 +36,26 @@ static const wchar_t kGoogleAcceptedSuggestionParameter[] =
L"google:acceptedSuggestion";
// Host/Domain Google searches are relative to.
static const wchar_t kGoogleBaseURLParameter[] = L"google:baseURL";
-static const wchar_t kGoogleBaseURLParameterFull[] = L"{google:baseURL}";
+static const char kGoogleBaseURLParameterFull[] = "{google:baseURL}";
// Like google:baseURL, but for the Search Suggest capability.
-static const wchar_t kGoogleBaseSuggestURLParameter[] =
- L"google:baseSuggestURL";
-static const wchar_t kGoogleBaseSuggestURLParameterFull[] =
- L"{google:baseSuggestURL}";
+static const char kGoogleBaseSuggestURLParameter[] =
+ "google:baseSuggestURL";
+static const char kGoogleBaseSuggestURLParameterFull[] =
+ "{google:baseSuggestURL}";
static const wchar_t kGoogleOriginalQueryForSuggestionParameter[] =
L"google:originalQueryForSuggestion";
static const wchar_t kGoogleRLZParameter[] = L"google:RLZ";
// Same as kSearchTermsParameter, with no escaping.
static const wchar_t kGoogleUnescapedSearchTermsParameter[] =
L"google:unescapedSearchTerms";
-static const wchar_t kGoogleUnescapedSearchTermsParameterFull[] =
- L"{google:unescapedSearchTerms}";
+static const char kGoogleUnescapedSearchTermsParameterFull[] =
+ "{google:unescapedSearchTerms}";
// Display value for kSearchTermsParameter.
-static const wchar_t kDisplaySearchTerms[] = L"%s";
+static const char kDisplaySearchTerms[] = "%s";
// Display value for kGoogleUnescapedSearchTermsParameter.
-static const wchar_t kDisplayUnescapedSearchTerms[] = L"%S";
+static const char kDisplayUnescapedSearchTerms[] = "%S";
// Used if the count parameter is not optional. Indicates we want 10 search
// results.
@@ -121,7 +121,8 @@ bool TemplateURLRef::ParseParameter(size_t start,
} else if (parameter == kGoogleBaseURLParameter) {
replacements->push_back(Replacement(GOOGLE_BASE_URL,
static_cast<int>(start)));
- } else if (parameter == kGoogleBaseSuggestURLParameter) {
+ } else if (WideToUTF16Hack(parameter) ==
+ ASCIIToUTF16(kGoogleBaseSuggestURLParameter)) {
replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL,
static_cast<int>(start)));
} else if (parameter == kGoogleOriginalQueryForSuggestionParameter) {
@@ -194,14 +195,15 @@ void TemplateURLRef::ParseIfNecessary() const {
}
void TemplateURLRef::ParseHostAndSearchTermKey() const {
- std::wstring url_string = url_;
- ReplaceSubstringsAfterOffset(&url_string, 0, kGoogleBaseURLParameterFull,
- GoogleBaseURLValue());
+ string16 url_string = WideToUTF16Hack(url_);
ReplaceSubstringsAfterOffset(&url_string, 0,
- kGoogleBaseSuggestURLParameterFull,
- GoogleBaseSuggestURLValue());
+ ASCIIToUTF16(kGoogleBaseURLParameterFull),
+ WideToUTF16Hack(GoogleBaseURLValue()));
+ ReplaceSubstringsAfterOffset(&url_string, 0,
+ ASCIIToUTF16(kGoogleBaseSuggestURLParameterFull),
+ WideToUTF16Hack(GoogleBaseSuggestURLValue()));
- GURL url(WideToUTF8(url_string));
+ GURL url(UTF16ToUTF8(url_string));
if (!url.is_valid())
return;
@@ -215,10 +217,9 @@ void TemplateURLRef::ParseHostAndSearchTermKey() const {
&value)) {
if (key.is_nonempty() && value.is_nonempty()) {
std::string value_string = query_string.substr(value.begin, value.len);
- if (value_string.find(WideToASCII(kSearchTermsParameterFull), 0) !=
+ if (value_string.find(kSearchTermsParameterFull, 0) !=
std::string::npos ||
- value_string.find(
- WideToASCII(kGoogleUnescapedSearchTermsParameterFull), 0) !=
+ value_string.find(kGoogleUnescapedSearchTermsParameterFull, 0) !=
std::string::npos) {
search_term_key_ = query_string.substr(key.begin, key.len);
host_ = url.host();
@@ -350,26 +351,30 @@ std::wstring TemplateURLRef::DisplayURL() const {
if (replacements_.empty())
return url_; // Nothing to replace, return the url.
- std::wstring result = url_;
- ReplaceSubstringsAfterOffset(&result, 0, kSearchTermsParameterFull,
- kDisplaySearchTerms);
-
+ string16 result = WideToUTF16Hack(url_);
ReplaceSubstringsAfterOffset(&result, 0,
- kGoogleUnescapedSearchTermsParameterFull,
- kDisplayUnescapedSearchTerms);
+ ASCIIToUTF16(kSearchTermsParameterFull),
+ ASCIIToUTF16(kDisplaySearchTerms));
- return result;
+ ReplaceSubstringsAfterOffset(
+ &result, 0,
+ ASCIIToUTF16(kGoogleUnescapedSearchTermsParameterFull),
+ ASCIIToUTF16(kDisplayUnescapedSearchTerms));
+
+ return UTF16ToWideHack(result);
}
// static
std::wstring TemplateURLRef::DisplayURLToURLRef(
const std::wstring& display_url) {
- std::wstring result = display_url;
- ReplaceSubstringsAfterOffset(&result, 0, kDisplaySearchTerms,
- kSearchTermsParameterFull);
- ReplaceSubstringsAfterOffset(&result, 0, kDisplayUnescapedSearchTerms,
- kGoogleUnescapedSearchTermsParameterFull);
- return result;
+ string16 result = WideToUTF16Hack(display_url);
+ ReplaceSubstringsAfterOffset(&result, 0, ASCIIToUTF16(kDisplaySearchTerms),
+ ASCIIToUTF16(kSearchTermsParameterFull));
+ ReplaceSubstringsAfterOffset(
+ &result, 0,
+ ASCIIToUTF16(kDisplayUnescapedSearchTerms),
+ ASCIIToUTF16(kGoogleUnescapedSearchTermsParameterFull));
+ return UTF16ToWideHack(result);
}
const std::string& TemplateURLRef::GetHost() const {
@@ -555,4 +560,3 @@ void TemplateURL::InvalidateCachedValues() const {
if (autogenerate_keyword_)
keyword_.clear();
}
-