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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_match.cc

Issue 8364001: Strip special characters in extension omnibox suggestions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/string_util.h"
6 #include "chrome/browser/autocomplete/autocomplete_match.h" 7 #include "chrome/browser/autocomplete/autocomplete_match.h"
7 #include "grit/theme_resources.h" 8 #include "grit/theme_resources.h"
8 9
9 // AutocompleteMatch ---------------------------------------------------------- 10 // AutocompleteMatch ----------------------------------------------------------
10 11
11 AutocompleteMatch::AutocompleteMatch() 12 AutocompleteMatch::AutocompleteMatch()
12 : provider(NULL), 13 : provider(NULL),
13 relevance(0), 14 relevance(0),
14 deletable(false), 15 deletable(false),
15 inline_autocomplete_offset(string16::npos), 16 inline_autocomplete_offset(string16::npos),
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 classification->push_back(ACMatchClassification(match_location, 150 classification->push_back(ACMatchClassification(match_location,
150 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM)); 151 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM));
151 152
152 // Mark post-match portion of string (if any). 153 // Mark post-match portion of string (if any).
153 const size_t after_match(match_location + match_length); 154 const size_t after_match(match_location + match_length);
154 if (after_match < overall_length) { 155 if (after_match < overall_length) {
155 classification->push_back(ACMatchClassification(after_match, style)); 156 classification->push_back(ACMatchClassification(after_match, style));
156 } 157 }
157 } 158 }
158 159
160 // static
161 string16 AutocompleteMatch::SanitizeString(const string16& text) {
162 const char16 kRemoveChars[] = { '\n', '\r', '\t', 0x2028, 0x2029, 0 };
163 string16 result;
164 TrimWhitespace(text, TRIM_ALL, &result);
165 RemoveChars(result, kRemoveChars, &result);
166 return result;
167 }
168
159 #ifndef NDEBUG 169 #ifndef NDEBUG
160 void AutocompleteMatch::Validate() const { 170 void AutocompleteMatch::Validate() const {
161 ValidateClassifications(contents, contents_class); 171 ValidateClassifications(contents, contents_class);
162 ValidateClassifications(description, description_class); 172 ValidateClassifications(description, description_class);
163 } 173 }
164 174
165 void AutocompleteMatch::ValidateClassifications( 175 void AutocompleteMatch::ValidateClassifications(
166 const string16& text, 176 const string16& text,
167 const ACMatchClassifications& classifications) const { 177 const ACMatchClassifications& classifications) const {
168 if (text.empty()) { 178 if (text.empty()) {
(...skipping 10 matching lines...) Expand all
179 // The classifications should always be sorted. 189 // The classifications should always be sorted.
180 size_t last_offset = classifications[0].offset; 190 size_t last_offset = classifications[0].offset;
181 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); 191 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1);
182 i != classifications.end(); ++i) { 192 i != classifications.end(); ++i) {
183 DCHECK(i->offset > last_offset) << "Classification unsorted"; 193 DCHECK(i->offset > last_offset) << "Classification unsorted";
184 DCHECK(i->offset < text.length()) << "Classification out of bounds"; 194 DCHECK(i->offset < text.length()) << "Classification out of bounds";
185 last_offset = i->offset; 195 last_offset = i->offset;
186 } 196 }
187 } 197 }
188 #endif 198 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698