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

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

Issue 9689085: Clean up ShortcutsProvider and related classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_number_conversions.h"
6 #include "base/string_util.h" 7 #include "base/string_util.h"
7 #include "chrome/browser/autocomplete/autocomplete_match.h" 8 #include "chrome/browser/autocomplete/autocomplete_match.h"
8 #include "chrome/browser/search_engines/template_url.h" 9 #include "chrome/browser/search_engines/template_url.h"
9 #include "grit/theme_resources.h" 10 #include "grit/theme_resources.h"
10 11
11 // AutocompleteMatch ---------------------------------------------------------- 12 // AutocompleteMatch ----------------------------------------------------------
12 13
13 // static 14 // static
14 const char16 AutocompleteMatch::kInvalidChars[] = { 15 const char16 AutocompleteMatch::kInvalidChars[] = {
15 '\n', '\r', '\t', 16 '\n', '\r', '\t',
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM)); 210 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM));
210 211
211 // Mark post-match portion of string (if any). 212 // Mark post-match portion of string (if any).
212 const size_t after_match(match_location + match_length); 213 const size_t after_match(match_location + match_length);
213 if (after_match < overall_length) { 214 if (after_match < overall_length) {
214 classification->push_back(ACMatchClassification(after_match, style)); 215 classification->push_back(ACMatchClassification(after_match, style));
215 } 216 }
216 } 217 }
217 218
218 // static 219 // static
220 std::string AutocompleteMatch::ClassificationsToString(
221 const ACMatchClassifications& classifications) {
222 std::string serialized_classifications;
223 for (size_t i = 0; i < classifications.size(); ++i) {
224 if (i)
225 serialized_classifications += ',';
226 serialized_classifications += base::IntToString(classifications[i].offset) +
227 ',' + base::IntToString(classifications[i].style);
228 }
229 return serialized_classifications;
230 }
231
232 // static
233 ACMatchClassifications AutocompleteMatch::ClassificationsFromString(
234 const std::string& serialized_classifications) {
235 ACMatchClassifications classifications;
236 std::vector<std::string> tokens;
237 Tokenize(serialized_classifications, ",", &tokens);
238 DCHECK(!(tokens.size() & 1)); // The number of tokens should be even.
239 for (size_t i = 0; i < tokens.size(); i += 2) {
240 int classification_offset = 0;
241 int classification_style = ACMatchClassification::NONE;
242 if (!base::StringToInt(tokens[i], &classification_offset) ||
243 !base::StringToInt(tokens[i + 1], &classification_style)) {
244 NOTREACHED();
245 return classifications;
246 }
247 classifications.push_back(ACMatchClassification(classification_offset,
248 classification_style));
249 }
250 return classifications;
251 }
252
253 // static
254 void AutocompleteMatch::AddLastClassificationIfNecessary(
255 ACMatchClassifications* classifications,
256 size_t offset,
257 int style) {
258 DCHECK(classifications);
259 if (classifications->empty() || classifications->back().style != style) {
260 DCHECK(classifications->empty() ||
261 (offset > classifications->back().offset));
262 classifications->push_back(ACMatchClassification(offset, style));
263 }
264 }
265
266 // static
219 string16 AutocompleteMatch::SanitizeString(const string16& text) { 267 string16 AutocompleteMatch::SanitizeString(const string16& text) {
220 // NOTE: This logic is mirrored by |sanitizeString()| in 268 // NOTE: This logic is mirrored by |sanitizeString()| in
221 // schema_generated_bindings.js. 269 // schema_generated_bindings.js.
222 string16 result; 270 string16 result;
223 TrimWhitespace(text, TRIM_LEADING, &result); 271 TrimWhitespace(text, TRIM_LEADING, &result);
224 RemoveChars(result, kInvalidChars, &result); 272 RemoveChars(result, kInvalidChars, &result);
225 return result; 273 return result;
226 } 274 }
227 275
228 void AutocompleteMatch::ComputeStrippedDestinationURL() { 276 void AutocompleteMatch::ComputeStrippedDestinationURL() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); 331 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1);
284 i != classifications.end(); ++i) { 332 i != classifications.end(); ++i) {
285 DCHECK_GT(i->offset, last_offset) 333 DCHECK_GT(i->offset, last_offset)
286 << "Classification unsorted for \"" << text << '"'; 334 << "Classification unsorted for \"" << text << '"';
287 DCHECK_LT(i->offset, text.length()) 335 DCHECK_LT(i->offset, text.length())
288 << "Classification out of bounds for \"" << text << '"'; 336 << "Classification out of bounds for \"" << text << '"';
289 last_offset = i->offset; 337 last_offset = i->offset;
290 } 338 }
291 } 339 }
292 #endif 340 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698