| Index: utils/pub/utils.dart
|
| diff --git a/utils/pub/utils.dart b/utils/pub/utils.dart
|
| index f0065faa72aa6a82ccc4964da65e318b65515c1b..4eb840a7a1777121c63ecbe8c475f6d0b2789279 100644
|
| --- a/utils/pub/utils.dart
|
| +++ b/utils/pub/utils.dart
|
| @@ -16,6 +16,16 @@ class FormatException implements Exception {
|
| String toString() => message;
|
| }
|
|
|
| +/** A pair of values. */
|
| +class Pair<E, F> {
|
| + E first;
|
| + F last;
|
| +
|
| + Pair(this.first, this.last);
|
| +
|
| + String toString() => '($first, $last)';
|
| +}
|
| +
|
| // TODO(rnystrom): Move into String?
|
| /** Pads [source] to [length] by adding spaces at the end. */
|
| String padRight(String source, int length) {
|
| @@ -70,3 +80,18 @@ only(Iterable iter) {
|
| assert(!iterator.hasNext());
|
| return obj;
|
| }
|
| +
|
| +/**
|
| + * Replace each instance of [matcher] in [source] with the return value of [fn].
|
| + */
|
| +String replace(String source, Pattern matcher, String fn(Match)) {
|
| + var buffer = new StringBuffer();
|
| + var start = 0;
|
| + for (var match in matcher.allMatches(source)) {
|
| + buffer.add(source.substring(start, match.start()));
|
| + start = match.end();
|
| + buffer.add(fn(match));
|
| + }
|
| + buffer.add(source.substring(start));
|
| + return buffer.toString();
|
| +}
|
|
|