OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
7 #include "chrome/browser/autocomplete/autocomplete_match.h" | 7 #include "chrome/browser/autocomplete/autocomplete_match.h" |
8 #include "grit/theme_resources.h" | 8 #include "grit/theme_resources.h" |
9 | 9 |
10 // AutocompleteMatch ---------------------------------------------------------- | 10 // AutocompleteMatch ---------------------------------------------------------- |
11 | 11 |
| 12 // static |
| 13 const char16 AutocompleteMatch::kInvalidChars[] = { |
| 14 '\n', '\r', '\t', |
| 15 0x2028, // Line separator |
| 16 0x2029, // Paragraph separator |
| 17 0 |
| 18 }; |
| 19 |
12 AutocompleteMatch::AutocompleteMatch() | 20 AutocompleteMatch::AutocompleteMatch() |
13 : provider(NULL), | 21 : provider(NULL), |
14 relevance(0), | 22 relevance(0), |
15 deletable(false), | 23 deletable(false), |
16 inline_autocomplete_offset(string16::npos), | 24 inline_autocomplete_offset(string16::npos), |
17 transition(content::PAGE_TRANSITION_GENERATED), | 25 transition(content::PAGE_TRANSITION_GENERATED), |
18 is_history_what_you_typed_match(false), | 26 is_history_what_you_typed_match(false), |
19 type(SEARCH_WHAT_YOU_TYPED), | 27 type(SEARCH_WHAT_YOU_TYPED), |
20 template_url(NULL), | 28 template_url(NULL), |
21 starred(false), | 29 starred(false), |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 const size_t after_match(match_location + match_length); | 162 const size_t after_match(match_location + match_length); |
155 if (after_match < overall_length) { | 163 if (after_match < overall_length) { |
156 classification->push_back(ACMatchClassification(after_match, style)); | 164 classification->push_back(ACMatchClassification(after_match, style)); |
157 } | 165 } |
158 } | 166 } |
159 | 167 |
160 // static | 168 // static |
161 string16 AutocompleteMatch::SanitizeString(const string16& text) { | 169 string16 AutocompleteMatch::SanitizeString(const string16& text) { |
162 // NOTE: This logic is mirrored by |sanitizeString()| in | 170 // NOTE: This logic is mirrored by |sanitizeString()| in |
163 // extension_process_bindings.js. | 171 // extension_process_bindings.js. |
164 // 0x2028 = line separator; 0x2029 = paragraph separator. | |
165 const char16 kRemoveChars[] = { '\n', '\r', '\t', | |
166 0x2028, // Line separator | |
167 0x2029, // Paragraph separator | |
168 0 }; | |
169 string16 result; | 172 string16 result; |
170 TrimWhitespace(text, TRIM_LEADING, &result); | 173 TrimWhitespace(text, TRIM_LEADING, &result); |
171 RemoveChars(result, kRemoveChars, &result); | 174 RemoveChars(result, kInvalidChars, &result); |
172 return result; | 175 return result; |
173 } | 176 } |
174 | 177 |
175 #ifndef NDEBUG | 178 #ifndef NDEBUG |
176 void AutocompleteMatch::Validate() const { | 179 void AutocompleteMatch::Validate() const { |
177 ValidateClassifications(contents, contents_class); | 180 ValidateClassifications(contents, contents_class); |
178 ValidateClassifications(description, description_class); | 181 ValidateClassifications(description, description_class); |
179 } | 182 } |
180 | 183 |
181 void AutocompleteMatch::ValidateClassifications( | 184 void AutocompleteMatch::ValidateClassifications( |
(...skipping 13 matching lines...) Expand all Loading... |
195 // The classifications should always be sorted. | 198 // The classifications should always be sorted. |
196 size_t last_offset = classifications[0].offset; | 199 size_t last_offset = classifications[0].offset; |
197 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); | 200 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); |
198 i != classifications.end(); ++i) { | 201 i != classifications.end(); ++i) { |
199 DCHECK(i->offset > last_offset) << "Classification unsorted"; | 202 DCHECK(i->offset > last_offset) << "Classification unsorted"; |
200 DCHECK(i->offset < text.length()) << "Classification out of bounds"; | 203 DCHECK(i->offset < text.length()) << "Classification out of bounds"; |
201 last_offset = i->offset; | 204 last_offset = i->offset; |
202 } | 205 } |
203 } | 206 } |
204 #endif | 207 #endif |
OLD | NEW |