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/browser/search_suggestion_parser.h" | 5 #include "components/omnibox/browser/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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 144 } |
145 | 145 |
146 base::string16 lookup_text = input_text; | 146 base::string16 lookup_text = input_text; |
147 if (type_ == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { | 147 if (type_ == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { |
148 const size_t contents_index = | 148 const size_t contents_index = |
149 suggestion_.length() - match_contents_.length(); | 149 suggestion_.length() - match_contents_.length(); |
150 // Ensure the query starts with the input text, and ends with the match | 150 // Ensure the query starts with the input text, and ends with the match |
151 // contents, and the input text has an overlap with contents. | 151 // contents, and the input text has an overlap with contents. |
152 if (base::StartsWith(suggestion_, input_text, | 152 if (base::StartsWith(suggestion_, input_text, |
153 base::CompareCase::SENSITIVE) && | 153 base::CompareCase::SENSITIVE) && |
154 base::EndsWith(suggestion_, match_contents_, true) && | 154 base::EndsWith(suggestion_, match_contents_, |
| 155 base::CompareCase::SENSITIVE) && |
155 (input_text.length() > contents_index)) { | 156 (input_text.length() > contents_index)) { |
156 lookup_text = input_text.substr(contents_index); | 157 lookup_text = input_text.substr(contents_index); |
157 } | 158 } |
158 } | 159 } |
159 // Do a case-insensitive search for |lookup_text|. | 160 // Do a case-insensitive search for |lookup_text|. |
160 base::string16::const_iterator lookup_position = std::search( | 161 base::string16::const_iterator lookup_position = std::search( |
161 match_contents_.begin(), match_contents_.end(), lookup_text.begin(), | 162 match_contents_.begin(), match_contents_.end(), lookup_text.begin(), |
162 lookup_text.end(), SimpleCaseInsensitiveCompareUCS2()); | 163 lookup_text.end(), SimpleCaseInsensitiveCompareUCS2()); |
163 if (!allow_bolding_all && (lookup_position == match_contents_.end())) { | 164 if (!allow_bolding_all && (lookup_position == match_contents_.end())) { |
164 // Bail if the code below to update the bolding would bold the whole | 165 // 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... |
536 base::CollapseWhitespace(suggestion, false), match_type, | 537 base::CollapseWhitespace(suggestion, false), match_type, |
537 base::CollapseWhitespace(match_contents, false), | 538 base::CollapseWhitespace(match_contents, false), |
538 match_contents_prefix, annotation, answer_contents, answer_type_str, | 539 match_contents_prefix, annotation, answer_contents, answer_type_str, |
539 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result, | 540 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result, |
540 relevance, relevances != NULL, should_prefetch, trimmed_input)); | 541 relevance, relevances != NULL, should_prefetch, trimmed_input)); |
541 } | 542 } |
542 } | 543 } |
543 results->relevances_from_server = relevances != NULL; | 544 results->relevances_from_server = relevances != NULL; |
544 return true; | 545 return true; |
545 } | 546 } |
OLD | NEW |