| 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 * Generic utility functions. Stuff that should possibly be in core. | 6 * Generic utility functions. Stuff that should possibly be in core. |
| 7 */ | 7 */ |
| 8 #library('utils'); | 8 #library('utils'); |
| 9 | 9 |
| 10 #import('dart:crypto'); | 10 #import('dart:crypto'); |
| 11 #import('dart:isolate'); |
| 11 | 12 |
| 12 /** Thrown by methods that parse text when the text isn't a valid. */ | 13 /** Thrown by methods that parse text when the text isn't a valid. */ |
| 13 class FormatException implements Exception { | 14 class FormatException implements Exception { |
| 14 final String message; | 15 final String message; |
| 15 | 16 |
| 16 FormatException(this.message); | 17 FormatException(this.message); |
| 17 | 18 |
| 18 String toString() => message; | 19 String toString() => message; |
| 19 } | 20 } |
| 20 | 21 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (match.end() == str.length) return true; | 112 if (match.end() == str.length) return true; |
| 112 } | 113 } |
| 113 return false; | 114 return false; |
| 114 } | 115 } |
| 115 | 116 |
| 116 /** | 117 /** |
| 117 * Returns the hex-encoded sha1 hash of [source]. | 118 * Returns the hex-encoded sha1 hash of [source]. |
| 118 */ | 119 */ |
| 119 String sha1(String source) => | 120 String sha1(String source) => |
| 120 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes()).digest()); | 121 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes()).digest()); |
| 122 |
| 123 /** |
| 124 * Returns a [Future] that completes in [milliSeconds]. |
| 125 */ |
| 126 Future sleep(int milliSeconds) { |
| 127 var completer = new Completer(); |
| 128 new Timer(milliSeconds, completer.complete); |
| 129 return completer.future; |
| 130 } |
| OLD | NEW |