| 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'); | |
| 11 | |
| 12 /** Thrown by methods that parse text when the text isn't a valid. */ | 10 /** Thrown by methods that parse text when the text isn't a valid. */ |
| 13 class FormatException implements Exception { | 11 class FormatException implements Exception { |
| 14 final String message; | 12 final String message; |
| 15 | 13 |
| 16 FormatException(this.message); | 14 FormatException(this.message); |
| 17 | 15 |
| 18 String toString() => message; | 16 String toString() => message; |
| 19 } | 17 } |
| 20 | 18 |
| 21 /** A pair of values. */ | 19 /** A pair of values. */ |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 103 |
| 106 /** | 104 /** |
| 107 * Returns whether or not [str] ends with [matcher]. | 105 * Returns whether or not [str] ends with [matcher]. |
| 108 */ | 106 */ |
| 109 bool endsWithPattern(String str, Pattern matcher) { | 107 bool endsWithPattern(String str, Pattern matcher) { |
| 110 for (var match in matcher.allMatches(str)) { | 108 for (var match in matcher.allMatches(str)) { |
| 111 if (match.end() == str.length) return true; | 109 if (match.end() == str.length) return true; |
| 112 } | 110 } |
| 113 return false; | 111 return false; |
| 114 } | 112 } |
| 115 | |
| 116 /** | |
| 117 * Returns the hex-encoded sha1 hash of [source]. | |
| 118 */ | |
| 119 String sha1(String source) => | |
| 120 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes()).digest()); | |
| OLD | NEW |