| 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 = const RegExp(r"^[\x00-\x7F]+$"); | 117 final RegExp _ASCII_ONLY = new 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 /// The return values of all [Future]s are discarded. Any errors will cause the | 176 /// The return values of all [Future]s are discarded. Any errors will cause the |
| 177 /// iteration to stop and will be piped through the return value. | 177 /// iteration to stop and will be piped through the return value. |
| 178 Future forEachFuture(Iterable input, Future fn(element)) { | 178 Future forEachFuture(Iterable input, Future fn(element)) { |
| 179 var iterator = input.iterator(); | 179 var iterator = input.iterator(); |
| 180 Future nextElement(_) { | 180 Future nextElement(_) { |
| 181 if (!iterator.hasNext) return new Future.immediate(null); | 181 if (!iterator.hasNext) return new Future.immediate(null); |
| 182 return fn(iterator.next()).chain(nextElement); | 182 return fn(iterator.next()).chain(nextElement); |
| 183 } | 183 } |
| 184 return nextElement(null); | 184 return nextElement(null); |
| 185 } | 185 } |
| OLD | NEW |