| 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 /** 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. */ |
| 11 class FormatException implements Exception { | 11 class FormatException implements Exception { |
| 12 final String message; | 12 final String message; |
| 13 | 13 |
| 14 FormatException(this.message); | 14 FormatException(this.message); |
| 15 | 15 |
| 16 String toString() => message; | 16 String toString() => message; |
| 17 } | 17 } |
| 18 | 18 |
| 19 /** A pair of values. */ | 19 /** A pair of values. */ |
| 20 class Pair<E, F> { | 20 class Pair<E, F> { |
| 21 E first; | 21 E first; |
| 22 F last; | 22 F last; |
| 23 | 23 |
| 24 Pair(this.first, this.last); | 24 Pair(this.first, this.last); |
| 25 | 25 |
| 26 String toString() => '($first, $last)'; | 26 String toString() => '($first, $last)'; |
| 27 |
| 28 bool operator==(other) { |
| 29 if (other is! Pair) return false; |
| 30 return other.first == first && other.last == last; |
| 31 } |
| 27 } | 32 } |
| 28 | 33 |
| 29 // TODO(rnystrom): Move into String? | 34 // TODO(rnystrom): Move into String? |
| 30 /** Pads [source] to [length] by adding spaces at the end. */ | 35 /** Pads [source] to [length] by adding spaces at the end. */ |
| 31 String padRight(String source, int length) { | 36 String padRight(String source, int length) { |
| 32 final result = new StringBuffer(); | 37 final result = new StringBuffer(); |
| 33 result.add(source); | 38 result.add(source); |
| 34 | 39 |
| 35 while (result.length < length) { | 40 while (result.length < length) { |
| 36 result.add(' '); | 41 result.add(' '); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 var buffer = new StringBuffer(); | 93 var buffer = new StringBuffer(); |
| 89 var start = 0; | 94 var start = 0; |
| 90 for (var match in matcher.allMatches(source)) { | 95 for (var match in matcher.allMatches(source)) { |
| 91 buffer.add(source.substring(start, match.start())); | 96 buffer.add(source.substring(start, match.start())); |
| 92 start = match.end(); | 97 start = match.end(); |
| 93 buffer.add(fn(match)); | 98 buffer.add(fn(match)); |
| 94 } | 99 } |
| 95 buffer.add(source.substring(start)); | 100 buffer.add(source.substring(start)); |
| 96 return buffer.toString(); | 101 return buffer.toString(); |
| 97 } | 102 } |
| OLD | NEW |