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

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

Issue 10911188: autocomplete: Add AutocompleteMatch::MergeClassifications() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 "chrome/browser/autocomplete/autocomplete_match.h" 5 #include "chrome/browser/autocomplete/autocomplete_match.h"
6 6
7 #include "base/i18n/time_formatting.h" 7 #include "base/i18n/time_formatting.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM)); 226 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM));
227 227
228 // Mark post-match portion of string (if any). 228 // Mark post-match portion of string (if any).
229 const size_t after_match(match_location + match_length); 229 const size_t after_match(match_location + match_length);
230 if (after_match < overall_length) { 230 if (after_match < overall_length) {
231 classification->push_back(ACMatchClassification(after_match, style)); 231 classification->push_back(ACMatchClassification(after_match, style));
232 } 232 }
233 } 233 }
234 234
235 // static 235 // static
236 AutocompleteMatch::ACMatchClassifications
237 AutocompleteMatch::MergeClassifications(
Peter Kasting 2012/09/10 18:56:11 Nit: Style guide is vague here; I usually suggest
Daniel Erat 2012/09/10 19:36:17 Done.
238 const ACMatchClassifications& classifications1,
239 const ACMatchClassifications& classifications2) {
240 ACMatchClassifications output;
241 for (ACMatchClassifications::const_iterator i = classifications1.begin(),
Peter Kasting 2012/09/10 18:56:11 This is not quite safe. If someone passes in an e
Daniel Erat 2012/09/10 19:36:17 Done.
242 j = classifications2.begin(); i != classifications1.end();) {
243 AutocompleteMatch::AddLastClassificationIfNecessary(&output,
244 std::max(i->offset, j->offset), i->style | j->style);
245 const size_t next_i_offset = (i + 1) == classifications1.end() ?
246 static_cast<size_t>(-1) : (i + 1)->offset;
247 const size_t next_j_offset = (j + 1) == classifications2.end() ?
248 static_cast<size_t>(-1) : (j + 1)->offset;
249 if (next_i_offset >= next_j_offset)
250 ++j;
251 if (next_j_offset >= next_i_offset)
252 ++i;
253 }
254
255 return output;
256 }
257
258 // static
236 std::string AutocompleteMatch::ClassificationsToString( 259 std::string AutocompleteMatch::ClassificationsToString(
237 const ACMatchClassifications& classifications) { 260 const ACMatchClassifications& classifications) {
238 std::string serialized_classifications; 261 std::string serialized_classifications;
239 for (size_t i = 0; i < classifications.size(); ++i) { 262 for (size_t i = 0; i < classifications.size(); ++i) {
240 if (i) 263 if (i)
241 serialized_classifications += ','; 264 serialized_classifications += ',';
242 serialized_classifications += base::IntToString(classifications[i].offset) + 265 serialized_classifications += base::IntToString(classifications[i].offset) +
243 ',' + base::IntToString(classifications[i].style); 266 ',' + base::IntToString(classifications[i].style);
244 } 267 }
245 return serialized_classifications; 268 return serialized_classifications;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 << " is unsorted in relation to last offset of " << last_offset 425 << " is unsorted in relation to last offset of " << last_offset
403 << ". Provider: " << (provider ? provider->name() : "None") << "."; 426 << ". Provider: " << (provider ? provider->name() : "None") << ".";
404 DCHECK_LT(i->offset, text.length()) 427 DCHECK_LT(i->offset, text.length())
405 << " Classification of [" << i->offset << "," << text.length() 428 << " Classification of [" << i->offset << "," << text.length()
406 << "] is out of bounds for \"" << text << "\". Provider: " 429 << "] is out of bounds for \"" << text << "\". Provider: "
407 << (provider ? provider->name() : "None") << "."; 430 << (provider ? provider->name() : "None") << ".";
408 last_offset = i->offset; 431 last_offset = i->offset;
409 } 432 }
410 } 433 }
411 #endif 434 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698