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

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

Issue 1233043003: 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, true)) { 142 base::EndsWith(input->text(), remaining_input,
143 base::CompareCase::SENSITIVE)) {
143 int offset = input->text().length() - input->cursor_position(); 144 int offset = input->text().length() - input->cursor_position();
144 // The cursor should never be past the last character or before the 145 // The cursor should never be past the last character or before the
145 // first character. 146 // first character.
146 DCHECK_GE(offset, 0); 147 DCHECK_GE(offset, 0);
147 DCHECK_LE(offset, static_cast<int>(input->text().length())); 148 DCHECK_LE(offset, static_cast<int>(input->text().length()));
148 if (offset <= 0) { 149 if (offset <= 0) {
149 // Normalize the cursor to be exactly after the last character. 150 // Normalize the cursor to be exactly after the last character.
150 cursor_position = remaining_input.length(); 151 cursor_position = remaining_input.length();
151 } else { 152 } else {
152 // If somehow the cursor was before the remaining text, set it to 0, 153 // 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
470 ACMatchClassification::NONE, &match->contents_class); 471 ACMatchClassification::NONE, &match->contents_class);
471 } 472 }
472 } 473 }
473 474
474 TemplateURLService* KeywordProvider::GetTemplateURLService() const { 475 TemplateURLService* KeywordProvider::GetTemplateURLService() const {
475 // Make sure the model is loaded. This is cheap and quickly bails out if 476 // Make sure the model is loaded. This is cheap and quickly bails out if
476 // the model is already loaded. 477 // the model is already loaded.
477 model_->Load(); 478 model_->Load();
478 return model_; 479 return model_;
479 } 480 }
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