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 library utils; | 5 library utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 if (index == -1) return [toSplit]; | 55 if (index == -1) return [toSplit]; |
56 return [ | 56 return [ |
57 toSplit.substring(0, index), | 57 toSplit.substring(0, index), |
58 toSplit.substring(index + pattern.length) | 58 toSplit.substring(index + pattern.length) |
59 ]; | 59 ]; |
60 } | 60 } |
61 | 61 |
62 /// Returns the [Encoding] that corresponds to [charset]. Returns [fallback] if | 62 /// Returns the [Encoding] that corresponds to [charset]. Returns [fallback] if |
63 /// [charset] is null or if no [Encoding] was found that corresponds to | 63 /// [charset] is null or if no [Encoding] was found that corresponds to |
64 /// [charset]. | 64 /// [charset]. |
65 Encoding encodingForCharset( | 65 Encoding encodingForCharset(String charset, [Encoding fallback = LATIN1]) { |
66 String charset, [Encoding fallback = LATIN1]) { | |
67 if (charset == null) return fallback; | 66 if (charset == null) return fallback; |
68 var encoding = Encoding.getByName(charset); | 67 var encoding = Encoding.getByName(charset); |
69 return encoding == null ? fallback : encoding; | 68 return encoding == null ? fallback : encoding; |
70 } | 69 } |
71 | 70 |
72 | 71 |
73 /// Returns the [Encoding] that corresponds to [charset]. Throws a | 72 /// Returns the [Encoding] that corresponds to [charset]. Throws a |
74 /// [FormatException] if no [Encoding] was found that corresponds to [charset]. | 73 /// [FormatException] if no [Encoding] was found that corresponds to [charset]. |
75 /// [charset] may not be null. | 74 /// [charset] may not be null. |
76 Encoding requiredEncodingForCharset(String charset) { | 75 Encoding requiredEncodingForCharset(String charset) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 192 } |
194 | 193 |
195 /// Configures [future] so that its result (success or exception) is passed on | 194 /// Configures [future] so that its result (success or exception) is passed on |
196 /// to [completer]. | 195 /// to [completer]. |
197 void chainToCompleter(Future future, Completer completer) { | 196 void chainToCompleter(Future future, Completer completer) { |
198 future.then(completer.complete, onError: completer.completeError); | 197 future.then(completer.complete, onError: completer.completeError); |
199 } | 198 } |
200 | 199 |
201 /// Like [Future.sync], but wraps the Future in [Chain.track] as well. | 200 /// Like [Future.sync], but wraps the Future in [Chain.track] as well. |
202 Future syncFuture(callback()) => Chain.track(new Future.sync(callback)); | 201 Future syncFuture(callback()) => Chain.track(new Future.sync(callback)); |
OLD | NEW |