Chromium Code Reviews| Index: chrome/browser/autocomplete/autocomplete_match.cc |
| diff --git a/chrome/browser/autocomplete/autocomplete_match.cc b/chrome/browser/autocomplete/autocomplete_match.cc |
| index d00ac976fcfb01120c87c6f359721bc80a857831..4a40af2bf0cc4654cac678ea5cce3d84b86b6a34 100644 |
| --- a/chrome/browser/autocomplete/autocomplete_match.cc |
| +++ b/chrome/browser/autocomplete/autocomplete_match.cc |
| @@ -19,6 +19,16 @@ |
| #include "content/public/common/url_constants.h" |
| #include "grit/theme_resources.h" |
| +namespace { |
| + |
| +bool IsTrivialClassification(const ACMatchClassifications& classifications) { |
| + return classifications.empty() || |
| + ((classifications.size() == 1) && |
| + (classifications.back().style == ACMatchClassification::NONE)); |
| +} |
| + |
| +} // namespace |
| + |
| // AutocompleteMatch ---------------------------------------------------------- |
| // static |
| @@ -233,6 +243,37 @@ void AutocompleteMatch::ClassifyLocationInString( |
| } |
| // static |
| +AutocompleteMatch::ACMatchClassifications |
| + AutocompleteMatch::MergeClassifications( |
| + const ACMatchClassifications& classifications1, |
|
Peter Kasting
2012/09/10 23:34:35
Nit: I would only indent these 4 and not 8? I ser
Daniel Erat
2012/09/10 23:46:05
Done.
|
| + const ACMatchClassifications& classifications2) { |
| + // We must return the empty vector only if both inputs are truly empty. |
|
Peter Kasting
2012/09/10 23:34:35
Nit: Comment should only be indented 2.
Daniel Erat
2012/09/10 23:46:05
Whoops. :-/ Sorry, done.
|
| + // The result of merging an empty vector with a single (0, NONE) |
| + // classification is the latter one-entry vector. |
| + if (IsTrivialClassification(classifications1)) |
| + return classifications2.empty() ? classifications1 : classifications2; |
| + if (IsTrivialClassification(classifications2)) |
| + return classifications1; |
| + |
| + ACMatchClassifications output; |
| + for (ACMatchClassifications::const_iterator i = classifications1.begin(), |
| + j = classifications2.begin(); i != classifications1.end();) { |
| + AutocompleteMatch::AddLastClassificationIfNecessary(&output, |
| + std::max(i->offset, j->offset), i->style | j->style); |
| + const size_t next_i_offset = (i + 1) == classifications1.end() ? |
| + static_cast<size_t>(-1) : (i + 1)->offset; |
| + const size_t next_j_offset = (j + 1) == classifications2.end() ? |
| + static_cast<size_t>(-1) : (j + 1)->offset; |
| + if (next_i_offset >= next_j_offset) |
| + ++j; |
| + if (next_j_offset >= next_i_offset) |
| + ++i; |
| + } |
| + |
| + return output; |
| +} |
| + |
| +// static |
| std::string AutocompleteMatch::ClassificationsToString( |
| const ACMatchClassifications& classifications) { |
| std::string serialized_classifications; |