summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authordsh@google.com <dsh@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-03 01:21:09 +0000
committerdsh@google.com <dsh@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-03 01:21:09 +0000
commitdbf476de0ef1cdcc11c5f2d689b8755809a857fb (patch)
tree5a68c5a8fb056c10441752dcd230e96180d1e775 /chrome/browser
parente1b01fc18365da2c58cc17981bf28fe71fd06b7e (diff)
downloadchromium_src-dbf476de0ef1cdcc11c5f2d689b8755809a857fb.zip
chromium_src-dbf476de0ef1cdcc11c5f2d689b8755809a857fb.tar.gz
chromium_src-dbf476de0ef1cdcc11c5f2d689b8755809a857fb.tar.bz2
Port Replace(First)SubstringsAfterOffset to string16.
Review URL: http://codereview.chromium.org/28324 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10767 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-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
4 files changed, 59 insertions, 43 deletions
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();
}
-