Chromium Code Reviews| Index: chrome/browser/autocomplete/autocomplete_match.cc |
| =================================================================== |
| --- chrome/browser/autocomplete/autocomplete_match.cc (revision 79782) |
| +++ chrome/browser/autocomplete/autocomplete_match.cc (working copy) |
| @@ -106,6 +106,29 @@ |
| } |
| // static |
| +bool AutocompleteMatch::NormalizedSortFunc(const AutocompleteMatch& elem1, |
| + const AutocompleteMatch& elem2) { |
| + // Sort identical normalized_urls together. Place the most relevant matches |
| + // first, so that when we call std::unique(), these are the ones that get |
| + // preserved. |
| + return (elem1.normalized_url != elem2.normalized_url) ? |
| + (elem1.normalized_url < elem2.normalized_url) : |
| + MoreRelevant(elem1, elem2); |
| +} |
| + |
| +// static |
| +bool AutocompleteMatch::NormalizedEqual(const AutocompleteMatch& elem1, |
| + const AutocompleteMatch& elem2) { |
| + return elem1.normalized_url == elem2.normalized_url; |
| +} |
| + |
| +// static |
| +bool AutocompleteMatch::KeywordsEqual(const AutocompleteMatch& elem1, |
| + const AutocompleteMatch& elem2) { |
| + return elem1.keyword == elem2.keyword; |
| +} |
| + |
| +// static |
| void AutocompleteMatch::ClassifyMatchInString( |
| const string16& find_text, |
| const string16& text, |
| @@ -151,6 +174,26 @@ |
| } |
| } |
| + |
| +void AutocompleteMatch::NormalizeDestination() { |
| + static const char prefix[] = "www."; |
| + static const int prefix_len = strlen(prefix); |
| + |
| + if (destination_url.is_valid() && normalized_url.is_empty()) { |
|
Peter Kasting
2011/04/01 00:09:09
Nit: I would combine this check with the compare()
|
| + std::string host = destination_url.host(); |
| + |
| + if (host.compare(0, prefix_len, prefix) == 0) { |
| + host.erase(0, prefix_len); |
|
Peter Kasting
2011/04/01 00:09:09
Nit: You can eliminate this and use host.substr(..
|
| + |
| + GURL::Replacements replace_host; |
| + replace_host.SetHostStr(host); |
| + normalized_url = destination_url.ReplaceComponents(replace_host); |
| + } else { |
| + normalized_url = destination_url; |
| + } |
| + } |
| +} |
| + |
| #ifndef NDEBUG |
| void AutocompleteMatch::Validate() const { |
| ValidateClassifications(contents, contents_class); |