OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * [SearchText] represent the search field text. The text is viewed in three | 6 * [SearchText] represent the search field text. The text is viewed in three |
7 * ways: [text] holds the original search text, used for performing | 7 * ways: [text] holds the original search text, used for performing |
8 * case-sensitive matches, [lowerCase] holds the lower-case search text, used | 8 * case-sensitive matches, [lowerCase] holds the lower-case search text, used |
9 * for performing case-insenstive matches, [camelCase] holds a camel-case | 9 * for performing case-insenstive matches, [camelCase] holds a camel-case |
10 * interpretation of the search text, used to order matches in camel-case. | 10 * interpretation of the search text, used to order matches in camel-case. |
11 */ | 11 */ |
12 class SearchText { | 12 class SearchText { |
13 final String text; | 13 final String text; |
14 final String lowerCase; | 14 final String lowerCase; |
15 final String camelCase; | 15 final String camelCase; |
16 | 16 |
17 SearchText(String searchText) | 17 SearchText(String searchText) |
18 : text = searchText, | 18 : text = searchText, |
19 lowerCase = searchText.toLowerCase(), | 19 lowerCase = searchText.toLowerCase(), |
20 camelCase = searchText.isEmpty() ? '' | 20 camelCase = searchText.isEmpty ? '' |
21 : '${searchText.substring(0, 1).toUpperCase()}' | 21 : '${searchText.substring(0, 1).toUpperCase()}' |
22 '${searchText.substring(1)}'; | 22 '${searchText.substring(1)}'; |
23 | 23 |
24 int get length => text.length; | 24 int get length => text.length; |
25 | 25 |
26 bool isEmpty() => length == 0; | 26 bool get isEmpty => length == 0; |
27 } | 27 } |
28 | 28 |
29 /** | 29 /** |
30 * [StringMatch] represents the case-insensitive matching of [searchText] as a | 30 * [StringMatch] represents the case-insensitive matching of [searchText] as a |
31 * substring within a [text]. | 31 * substring within a [text]. |
32 */ | 32 */ |
33 class StringMatch { | 33 class StringMatch { |
34 final SearchText searchText; | 34 final SearchText searchText; |
35 final String text; | 35 final String text; |
36 final int matchOffset; | 36 final int matchOffset; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 sb.add('</td></tr></table></td>'); | 142 sb.add('</td></tr></table></td>'); |
143 row.innerHTML = sb.toString(); | 143 row.innerHTML = sb.toString(); |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 /** | 147 /** |
148 * Creates a [StringMatch] object for [text] if a substring matches | 148 * Creates a [StringMatch] object for [text] if a substring matches |
149 * [searchText], or returns [: null :] if no match is found. | 149 * [searchText], or returns [: null :] if no match is found. |
150 */ | 150 */ |
151 StringMatch obtainMatch(SearchText searchText, String text) { | 151 StringMatch obtainMatch(SearchText searchText, String text) { |
152 if (searchText.isEmpty()) { | 152 if (searchText.isEmpty) { |
153 return new StringMatch(searchText, text, 0, 0); | 153 return new StringMatch(searchText, text, 0, 0); |
154 } | 154 } |
155 int offset = text.toLowerCase().indexOf(searchText.lowerCase); | 155 int offset = text.toLowerCase().indexOf(searchText.lowerCase); |
156 if (offset != -1) { | 156 if (offset != -1) { |
157 return new StringMatch(searchText, text, | 157 return new StringMatch(searchText, text, |
158 offset, offset + searchText.length); | 158 offset, offset + searchText.length); |
159 } | 159 } |
160 return null; | 160 return null; |
161 } | 161 } |
162 | 162 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // Sort type alphabetically. | 215 // Sort type alphabetically. |
216 // TODO(4805): Use [:type.compareToIgnoreCase] when supported. | 216 // TODO(4805): Use [:type.compareToIgnoreCase] when supported. |
217 result = a.type.toLowerCase().compareTo(b.type.toLowerCase()); | 217 result = a.type.toLowerCase().compareTo(b.type.toLowerCase()); |
218 if (result != 0) return result; | 218 if (result != 0) return result; |
219 } | 219 } |
220 | 220 |
221 // Sort match alphabetically. | 221 // Sort match alphabetically. |
222 // TODO(4805): Use [:text.compareToIgnoreCase] when supported. | 222 // TODO(4805): Use [:text.compareToIgnoreCase] when supported. |
223 return a.match.text.toLowerCase().compareTo(b.match.text.toLowerCase()); | 223 return a.match.text.toLowerCase().compareTo(b.match.text.toLowerCase()); |
224 } | 224 } |
OLD | NEW |