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 part of html_common; | 5 part of html_common; |
6 | 6 |
7 abstract class CssClassSetImpl implements CssClassSet { | 7 abstract class CssClassSetImpl implements CssClassSet { |
8 | |
9 static final RegExp _validTokenRE = new RegExp(r'^\S+$'); | 8 static final RegExp _validTokenRE = new RegExp(r'^\S+$'); |
10 | 9 |
11 String _validateToken(String value) { | 10 String _validateToken(String value) { |
12 if (_validTokenRE.hasMatch(value)) return value; | 11 if (_validTokenRE.hasMatch(value)) return value; |
13 throw new ArgumentError.value(value, 'value', 'Not a valid class token'); | 12 throw new ArgumentError.value(value, 'value', 'Not a valid class token'); |
14 } | 13 } |
15 | 14 |
16 String toString() { | 15 String toString() { |
17 return readClasses().join(' '); | 16 return readClasses().join(' '); |
18 } | 17 } |
(...skipping 30 matching lines...) Expand all Loading... |
49 Iterator<String> get iterator => readClasses().iterator; | 48 Iterator<String> get iterator => readClasses().iterator; |
50 // interface Iterable - END | 49 // interface Iterable - END |
51 | 50 |
52 // interface Collection - BEGIN | 51 // interface Collection - BEGIN |
53 void forEach(void f(String element)) { | 52 void forEach(void f(String element)) { |
54 readClasses().forEach(f); | 53 readClasses().forEach(f); |
55 } | 54 } |
56 | 55 |
57 String join([String separator = ""]) => readClasses().join(separator); | 56 String join([String separator = ""]) => readClasses().join(separator); |
58 | 57 |
59 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(String e)) => | 58 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(String e)) => readClasses().map/*<T>*/(f); |
60 readClasses().map/*<T>*/(f); | |
61 | 59 |
62 Iterable<String> where(bool f(String element)) => readClasses().where(f); | 60 Iterable<String> where(bool f(String element)) => readClasses().where(f); |
63 | 61 |
64 Iterable/*<T>*/ expand/*<T>*/(Iterable/*<T>*/ f(String element)) => | 62 Iterable/*<T>*/ expand/*<T>*/(Iterable/*<T>*/ f(String element)) => |
65 readClasses().expand/*<T>*/(f); | 63 readClasses().expand/*<T>*/(f); |
66 | 64 |
67 bool every(bool f(String element)) => readClasses().every(f); | 65 bool every(bool f(String element)) => readClasses().every(f); |
68 | 66 |
69 bool any(bool f(String element)) => readClasses().any(f); | 67 bool any(bool f(String element)) => readClasses().any(f); |
70 | 68 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 169 |
172 void removeWhere(bool test(String name)) { | 170 void removeWhere(bool test(String name)) { |
173 modify((s) => s.removeWhere(test)); | 171 modify((s) => s.removeWhere(test)); |
174 } | 172 } |
175 | 173 |
176 void retainWhere(bool test(String name)) { | 174 void retainWhere(bool test(String name)) { |
177 modify((s) => s.retainWhere(test)); | 175 modify((s) => s.retainWhere(test)); |
178 } | 176 } |
179 | 177 |
180 bool containsAll(Iterable<Object> collection) => | 178 bool containsAll(Iterable<Object> collection) => |
181 readClasses().containsAll(collection); | 179 readClasses().containsAll(collection); |
182 | 180 |
183 Set<String> intersection(Set<Object> other) => | 181 Set<String> intersection(Set<Object> other) => |
184 readClasses().intersection(other); | 182 readClasses().intersection(other); |
185 | 183 |
186 Set<String> union(Set<String> other) => | 184 Set<String> union(Set<String> other) => readClasses().union(other); |
187 readClasses().union(other); | |
188 | 185 |
189 Set<String> difference(Set<Object> other) => | 186 Set<String> difference(Set<Object> other) => readClasses().difference(other); |
190 readClasses().difference(other); | |
191 | 187 |
192 String get first => readClasses().first; | 188 String get first => readClasses().first; |
193 String get last => readClasses().last; | 189 String get last => readClasses().last; |
194 String get single => readClasses().single; | 190 String get single => readClasses().single; |
195 List<String> toList({ bool growable: true }) => | 191 List<String> toList({bool growable: true}) => |
196 readClasses().toList(growable: growable); | 192 readClasses().toList(growable: growable); |
197 Set<String> toSet() => readClasses().toSet(); | 193 Set<String> toSet() => readClasses().toSet(); |
198 Iterable<String> take(int n) => readClasses().take(n); | 194 Iterable<String> take(int n) => readClasses().take(n); |
199 Iterable<String> takeWhile(bool test(String value)) => | 195 Iterable<String> takeWhile(bool test(String value)) => |
200 readClasses().takeWhile(test); | 196 readClasses().takeWhile(test); |
201 Iterable<String> skip(int n) => readClasses().skip(n); | 197 Iterable<String> skip(int n) => readClasses().skip(n); |
202 Iterable<String> skipWhile(bool test(String value)) => | 198 Iterable<String> skipWhile(bool test(String value)) => |
203 readClasses().skipWhile(test); | 199 readClasses().skipWhile(test); |
204 String firstWhere(bool test(String value), { String orElse() }) => | 200 String firstWhere(bool test(String value), {String orElse()}) => |
205 readClasses().firstWhere(test, orElse: orElse); | 201 readClasses().firstWhere(test, orElse: orElse); |
206 String lastWhere(bool test(String value), { String orElse()}) => | 202 String lastWhere(bool test(String value), {String orElse()}) => |
207 readClasses().lastWhere(test, orElse: orElse); | 203 readClasses().lastWhere(test, orElse: orElse); |
208 String singleWhere(bool test(String value)) => | 204 String singleWhere(bool test(String value)) => |
209 readClasses().singleWhere(test); | 205 readClasses().singleWhere(test); |
210 String elementAt(int index) => readClasses().elementAt(index); | 206 String elementAt(int index) => readClasses().elementAt(index); |
211 | 207 |
212 void clear() { | 208 void clear() { |
213 // TODO(sra): Do this without reading the classes. | 209 // TODO(sra): Do this without reading the classes. |
214 modify((s) => s.clear()); | 210 modify((s) => s.clear()); |
215 } | 211 } |
216 // interface Set - END | 212 // interface Set - END |
(...skipping 21 matching lines...) Expand all Loading... |
238 */ | 234 */ |
239 Set<String> readClasses(); | 235 Set<String> readClasses(); |
240 | 236 |
241 /** | 237 /** |
242 * Join all the elements of a set into one string and write | 238 * Join all the elements of a set into one string and write |
243 * back to the element. | 239 * back to the element. |
244 * This is intended to be overridden by specific implementations. | 240 * This is intended to be overridden by specific implementations. |
245 */ | 241 */ |
246 void writeClasses(Set<String> s); | 242 void writeClasses(Set<String> s); |
247 } | 243 } |
OLD | NEW |