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 "chrome/browser/autocomplete/autocomplete_match.h" | 7 #include "chrome/browser/autocomplete/autocomplete_match.h" |
7 #include "grit/theme_resources.h" | 8 #include "grit/theme_resources.h" |
8 | 9 |
9 // AutocompleteMatch ---------------------------------------------------------- | 10 // AutocompleteMatch ---------------------------------------------------------- |
10 | 11 |
11 AutocompleteMatch::AutocompleteMatch() | 12 AutocompleteMatch::AutocompleteMatch() |
12 : provider(NULL), | 13 : provider(NULL), |
13 relevance(0), | 14 relevance(0), |
14 deletable(false), | 15 deletable(false), |
15 inline_autocomplete_offset(string16::npos), | 16 inline_autocomplete_offset(string16::npos), |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 classification->push_back(ACMatchClassification(match_location, | 150 classification->push_back(ACMatchClassification(match_location, |
150 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM)); | 151 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM)); |
151 | 152 |
152 // Mark post-match portion of string (if any). | 153 // Mark post-match portion of string (if any). |
153 const size_t after_match(match_location + match_length); | 154 const size_t after_match(match_location + match_length); |
154 if (after_match < overall_length) { | 155 if (after_match < overall_length) { |
155 classification->push_back(ACMatchClassification(after_match, style)); | 156 classification->push_back(ACMatchClassification(after_match, style)); |
156 } | 157 } |
157 } | 158 } |
158 | 159 |
160 // static | |
161 string16 AutocompleteMatch::SanitizeString(const string16& text) { | |
162 // NOTE: This logic is mirrored by |sanitizeString()| in | |
163 // extension_process_bindings.js. | |
164 // 0x2028 = line separator; 0x2029 = paragraph separator. | |
Peter Kasting
2011/10/27 18:37:10
Nit: How about:
const char16 kRemoveChars[] = {
| |
165 const char16 kRemoveChars[] = { '\n', '\r', '\t', 0x2028, 0x2029, 0 }; | |
166 string16 result; | |
167 TrimWhitespace(text, TRIM_LEADING, &result); | |
168 RemoveChars(result, kRemoveChars, &result); | |
169 return result; | |
170 } | |
171 | |
159 #ifndef NDEBUG | 172 #ifndef NDEBUG |
160 void AutocompleteMatch::Validate() const { | 173 void AutocompleteMatch::Validate() const { |
161 ValidateClassifications(contents, contents_class); | 174 ValidateClassifications(contents, contents_class); |
162 ValidateClassifications(description, description_class); | 175 ValidateClassifications(description, description_class); |
163 } | 176 } |
164 | 177 |
165 void AutocompleteMatch::ValidateClassifications( | 178 void AutocompleteMatch::ValidateClassifications( |
166 const string16& text, | 179 const string16& text, |
167 const ACMatchClassifications& classifications) const { | 180 const ACMatchClassifications& classifications) const { |
168 if (text.empty()) { | 181 if (text.empty()) { |
(...skipping 10 matching lines...) Expand all Loading... | |
179 // The classifications should always be sorted. | 192 // The classifications should always be sorted. |
180 size_t last_offset = classifications[0].offset; | 193 size_t last_offset = classifications[0].offset; |
181 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); | 194 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); |
182 i != classifications.end(); ++i) { | 195 i != classifications.end(); ++i) { |
183 DCHECK(i->offset > last_offset) << "Classification unsorted"; | 196 DCHECK(i->offset > last_offset) << "Classification unsorted"; |
184 DCHECK(i->offset < text.length()) << "Classification out of bounds"; | 197 DCHECK(i->offset < text.length()) << "Classification out of bounds"; |
185 last_offset = i->offset; | 198 last_offset = i->offset; |
186 } | 199 } |
187 } | 200 } |
188 #endif | 201 #endif |
OLD | NEW |