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

Side by Side Diff: components/omnibox/browser/keyword_provider.cc

Issue 1233453011: Revert of Remove some legacy versions of StartsWith and EndsWith. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/omnibox/browser/keyword_provider.h" 5 #include "components/omnibox/browser/keyword_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 DCHECK(model); 132 DCHECK(model);
133 const TemplateURL* template_url = model->GetTemplateURLForKeyword(keyword); 133 const TemplateURL* template_url = model->GetTemplateURLForKeyword(keyword);
134 if (template_url && 134 if (template_url &&
135 template_url->SupportsReplacement(model->search_terms_data())) { 135 template_url->SupportsReplacement(model->search_terms_data())) {
136 // Adjust cursor position iff it was set before, otherwise leave it as is. 136 // Adjust cursor position iff it was set before, otherwise leave it as is.
137 size_t cursor_position = base::string16::npos; 137 size_t cursor_position = base::string16::npos;
138 // The adjustment assumes that the keyword was stripped from the beginning 138 // The adjustment assumes that the keyword was stripped from the beginning
139 // of the original input. 139 // of the original input.
140 if (input->cursor_position() != base::string16::npos && 140 if (input->cursor_position() != base::string16::npos &&
141 !remaining_input.empty() && 141 !remaining_input.empty() &&
142 base::EndsWith(input->text(), remaining_input, 142 base::EndsWith(input->text(), remaining_input, true)) {
143 base::CompareCase::SENSITIVE)) {
144 int offset = input->text().length() - input->cursor_position(); 143 int offset = input->text().length() - input->cursor_position();
145 // The cursor should never be past the last character or before the 144 // The cursor should never be past the last character or before the
146 // first character. 145 // first character.
147 DCHECK_GE(offset, 0); 146 DCHECK_GE(offset, 0);
148 DCHECK_LE(offset, static_cast<int>(input->text().length())); 147 DCHECK_LE(offset, static_cast<int>(input->text().length()));
149 if (offset <= 0) { 148 if (offset <= 0) {
150 // Normalize the cursor to be exactly after the last character. 149 // Normalize the cursor to be exactly after the last character.
151 cursor_position = remaining_input.length(); 150 cursor_position = remaining_input.length();
152 } else { 151 } else {
153 // If somehow the cursor was before the remaining text, set it to 0, 152 // If somehow the cursor was before the remaining text, set it to 0,
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 ACMatchClassification::NONE, &match->contents_class); 470 ACMatchClassification::NONE, &match->contents_class);
472 } 471 }
473 } 472 }
474 473
475 TemplateURLService* KeywordProvider::GetTemplateURLService() const { 474 TemplateURLService* KeywordProvider::GetTemplateURLService() const {
476 // Make sure the model is loaded. This is cheap and quickly bails out if 475 // Make sure the model is loaded. This is cheap and quickly bails out if
477 // the model is already loaded. 476 // the model is already loaded.
478 model_->Load(); 477 model_->Load();
479 return model_; 478 return model_;
480 } 479 }
OLDNEW
« no previous file with comments | « components/google/core/browser/google_util.cc ('k') | components/omnibox/browser/search_suggestion_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698