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:crypto'; | 7 import 'dart:crypto'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
10 import 'dart:scalarlist'; | 10 import 'dart:scalarlist'; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 | 108 |
109 /// Converts [string] into a byte array according to [encoding]. | 109 /// Converts [string] into a byte array according to [encoding]. |
110 List<int> encodeString(String string, Encoding encoding) { | 110 List<int> encodeString(String string, Encoding encoding) { |
111 // TODO(nweiz): implement this once issue 6284 is fixed. | 111 // TODO(nweiz): implement this once issue 6284 is fixed. |
112 return string.charCodes; | 112 return string.charCodes; |
113 } | 113 } |
114 | 114 |
115 /// A regular expression that matches strings that are composed entirely of | 115 /// A regular expression that matches strings that are composed entirely of |
116 /// ASCII-compatible characters. | 116 /// ASCII-compatible characters. |
117 final RegExp _ASCII_ONLY = new RegExp(r"^[\x00-\x7F]+$"); | 117 final RegExp _ASCII_ONLY = const RegExp(r"^[\x00-\x7F]+$"); |
118 | 118 |
119 /// Returns whether [string] is composed entirely of ASCII-compatible | 119 /// Returns whether [string] is composed entirely of ASCII-compatible |
120 /// characters. | 120 /// characters. |
121 bool isPlainAscii(String string) => _ASCII_ONLY.hasMatch(string); | 121 bool isPlainAscii(String string) => _ASCII_ONLY.hasMatch(string); |
122 | 122 |
123 /// Converts [input] into a [Uint8List]. If [input] is a [ByteArray] or | 123 /// Converts [input] into a [Uint8List]. If [input] is a [ByteArray] or |
124 /// [ByteArrayViewable], this just returns a view on [input]. | 124 /// [ByteArrayViewable], this just returns a view on [input]. |
125 Uint8List toUint8List(List<int> input) { | 125 Uint8List toUint8List(List<int> input) { |
126 if (input is Uint8List) return input; | 126 if (input is Uint8List) return input; |
127 if (input is ByteArrayViewable) input = input.asByteArray(); | 127 if (input is ByteArrayViewable) input = input.asByteArray(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 199 |
200 /// Configures [future] so that its result (success or exception) is passed on | 200 /// Configures [future] so that its result (success or exception) is passed on |
201 /// to [completer]. | 201 /// to [completer]. |
202 void chainToCompleter(Future future, Completer completer) { | 202 void chainToCompleter(Future future, Completer completer) { |
203 future.handleException((e) { | 203 future.handleException((e) { |
204 completer.completeException(e); | 204 completer.completeException(e); |
205 return true; | 205 return true; |
206 }); | 206 }); |
207 future.then(completer.complete); | 207 future.then(completer.complete); |
208 } | 208 } |
OLD | NEW |