OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/search_suggestion_parser.h" | 5 #include "components/omnibox/search_suggestion_parser.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/icu_string_conversions.h" | 9 #include "base/i18n/icu_string_conversions.h" |
10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 return; | 142 return; |
143 } | 143 } |
144 | 144 |
145 base::string16 lookup_text = input_text; | 145 base::string16 lookup_text = input_text; |
146 if (type_ == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { | 146 if (type_ == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { |
147 const size_t contents_index = | 147 const size_t contents_index = |
148 suggestion_.length() - match_contents_.length(); | 148 suggestion_.length() - match_contents_.length(); |
149 // Ensure the query starts with the input text, and ends with the match | 149 // Ensure the query starts with the input text, and ends with the match |
150 // contents, and the input text has an overlap with contents. | 150 // contents, and the input text has an overlap with contents. |
151 if (base::StartsWith(suggestion_, input_text, true) && | 151 if (base::StartsWith(suggestion_, input_text, true) && |
152 EndsWith(suggestion_, match_contents_, true) && | 152 base::EndsWith(suggestion_, match_contents_, true) && |
153 (input_text.length() > contents_index)) { | 153 (input_text.length() > contents_index)) { |
154 lookup_text = input_text.substr(contents_index); | 154 lookup_text = input_text.substr(contents_index); |
155 } | 155 } |
156 } | 156 } |
157 // Do a case-insensitive search for |lookup_text|. | 157 // Do a case-insensitive search for |lookup_text|. |
158 base::string16::const_iterator lookup_position = std::search( | 158 base::string16::const_iterator lookup_position = std::search( |
159 match_contents_.begin(), match_contents_.end(), lookup_text.begin(), | 159 match_contents_.begin(), match_contents_.end(), lookup_text.begin(), |
160 lookup_text.end(), base::CaseInsensitiveCompare<base::char16>()); | 160 lookup_text.end(), base::CaseInsensitiveCompare<base::char16>()); |
161 if (!allow_bolding_all && (lookup_position == match_contents_.end())) { | 161 if (!allow_bolding_all && (lookup_position == match_contents_.end())) { |
162 // Bail if the code below to update the bolding would bold the whole | 162 // Bail if the code below to update the bolding would bold the whole |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 base::CollapseWhitespace(suggestion, false), match_type, | 534 base::CollapseWhitespace(suggestion, false), match_type, |
535 base::CollapseWhitespace(match_contents, false), | 535 base::CollapseWhitespace(match_contents, false), |
536 match_contents_prefix, annotation, answer_contents, answer_type_str, | 536 match_contents_prefix, annotation, answer_contents, answer_type_str, |
537 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result, | 537 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result, |
538 relevance, relevances != NULL, should_prefetch, trimmed_input)); | 538 relevance, relevances != NULL, should_prefetch, trimmed_input)); |
539 } | 539 } |
540 } | 540 } |
541 results->relevances_from_server = relevances != NULL; | 541 results->relevances_from_server = relevances != NULL; |
542 return true; | 542 return true; |
543 } | 543 } |
OLD | NEW |