Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: chrome/browser/tab_contents/render_view_context_menu.cc

Issue 12294022: Simplify Ampersand escaping logic in RenderViewContextMenu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit fixed Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/tab_contents/render_view_context_menu.cc
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index fdc406fe5b69d11cb045c003061153e9474c9b6e..2a451976c036d27fefd95f3aaf2efcd61957a130 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -229,6 +229,13 @@ bool ShouldShowTranslateItem(const GURL& page_url) {
void DevToolsInspectElementAt(RenderViewHost* rvh, int x, int y) {
DevToolsWindow::InspectElement(rvh, x, y);
}
+
+// Helper function to escape "&" as "&&".
+void EscapeAmpersands(string16& text) {
+ const char16 ampersand[] = {'&', 0};
+ ReplaceChars(text, ampersand, ASCIIToUTF16("&&"), &text);
+}
+
} // namespace
// static
@@ -388,11 +395,7 @@ void RenderViewContextMenu::AppendAllExtensionItems() {
for (i = sorted_ids.begin();
i != sorted_ids.end(); ++i) {
string16 printable_selection_text = PrintableSelectionText();
- // Escape "&" as "&&".
- for (size_t position = printable_selection_text.find('&');
- position != string16::npos;
- position = printable_selection_text.find('&', position + 2))
- printable_selection_text.insert(position, 1, '&');
+ EscapeAmpersands(printable_selection_text);
extension_items_.AppendExtensionItems(i->second, printable_selection_text,
&index);
@@ -829,10 +832,7 @@ void RenderViewContextMenu::AppendSearchProvider() {
return;
string16 printable_selection_text = PrintableSelectionText();
- // Escape "&" as "&&".
- for (size_t i = printable_selection_text.find('&'); i != string16::npos;
- i = printable_selection_text.find('&', i + 2))
- printable_selection_text.insert(i, 1, '&');
+ EscapeAmpersands(printable_selection_text);
if (AutocompleteMatch::IsSearchType(match.type)) {
const TemplateURL* const default_provider =
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698