Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: utils/pub/utils.dart

Issue 10636045: Add a Pub source for pub.dartlang.org. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
+}

Powered by Google App Engine
This is Rietveld 408576698