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