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

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

Issue 1182183003: Move EndsWith to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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/keyword_provider.h" 5 #include "components/omnibox/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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 DCHECK(model); 131 DCHECK(model);
132 const TemplateURL* template_url = model->GetTemplateURLForKeyword(keyword); 132 const TemplateURL* template_url = model->GetTemplateURLForKeyword(keyword);
133 if (template_url && 133 if (template_url &&
134 template_url->SupportsReplacement(model->search_terms_data())) { 134 template_url->SupportsReplacement(model->search_terms_data())) {
135 // Adjust cursor position iff it was set before, otherwise leave it as is. 135 // Adjust cursor position iff it was set before, otherwise leave it as is.
136 size_t cursor_position = base::string16::npos; 136 size_t cursor_position = base::string16::npos;
137 // The adjustment assumes that the keyword was stripped from the beginning 137 // The adjustment assumes that the keyword was stripped from the beginning
138 // of the original input. 138 // of the original input.
139 if (input->cursor_position() != base::string16::npos && 139 if (input->cursor_position() != base::string16::npos &&
140 !remaining_input.empty() && 140 !remaining_input.empty() &&
141 EndsWith(input->text(), remaining_input, true)) { 141 base::EndsWith(input->text(), remaining_input, true)) {
142 int offset = input->text().length() - input->cursor_position(); 142 int offset = input->text().length() - input->cursor_position();
143 // The cursor should never be past the last character or before the 143 // The cursor should never be past the last character or before the
144 // first character. 144 // first character.
145 DCHECK_GE(offset, 0); 145 DCHECK_GE(offset, 0);
146 DCHECK_LE(offset, static_cast<int>(input->text().length())); 146 DCHECK_LE(offset, static_cast<int>(input->text().length()));
147 if (offset <= 0) { 147 if (offset <= 0) {
148 // Normalize the cursor to be exactly after the last character. 148 // Normalize the cursor to be exactly after the last character.
149 cursor_position = remaining_input.length(); 149 cursor_position = remaining_input.length();
150 } else { 150 } else {
151 // If somehow the cursor was before the remaining text, set it to 0, 151 // If somehow the cursor was before the remaining text, set it to 0,
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 ACMatchClassification::NONE, &match->contents_class); 470 ACMatchClassification::NONE, &match->contents_class);
471 } 471 }
472 } 472 }
473 473
474 TemplateURLService* KeywordProvider::GetTemplateURLService() const { 474 TemplateURLService* KeywordProvider::GetTemplateURLService() const {
475 // 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
476 // the model is already loaded. 476 // the model is already loaded.
477 model_->Load(); 477 model_->Load();
478 return model_; 478 return model_;
479 } 479 }
OLDNEW
« no previous file with comments | « components/google/core/browser/google_util.cc ('k') | components/omnibox/search_suggestion_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698