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

Unified Diff: sdk/lib/core/string.dart

Issue 920453002: Add String.replaceFirstMapped. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: With change to _interpolate methods. Created 5 years, 10 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: sdk/lib/core/string.dart
diff --git a/sdk/lib/core/string.dart b/sdk/lib/core/string.dart
index e4a1c1d5c9712f50e45c9578eaa7e1e063ddb3d1..625446fb8df99ec859c2052dbd6f32b0138ebb1b 100644
--- a/sdk/lib/core/string.dart
+++ b/sdk/lib/core/string.dart
@@ -414,7 +414,7 @@ abstract class String implements Comparable<String>, Pattern {
bool contains(Pattern other, [int startIndex = 0]);
/**
- * Returns a new string in which the first occurence of [from] in this string
+ * Returns a new string in which the first occurence of [from] in this string
* is replaced with [to], starting from [startIndex]:
*
* '0.0001'.replaceFirst(new RegExp(r'0'), ''); // '.0001'
@@ -423,6 +423,20 @@ abstract class String implements Comparable<String>, Pattern {
String replaceFirst(Pattern from, String to, [int startIndex = 0]);
/**
+ * Replace the first occurence of [from] in this string.
+ *
+ * Returns a new string, which is this string
+ * except that the first match of [pattern], starting from [startIndex],
+ * is replaced by the result of calling [replace] with the match object.
+ *
+ * If the value returned by calling `replace` is not a [String], it
+ * is converted to a `String` using its `toString` method, which must
+ * then return a string.
+ */
+ String replaceFirstMapped(Pattern from, String replace(Match match),
+ [int startIndex = 0]);
+
+ /**
* Replaces all substrings that match [from] with [replace].
*
* Returns a new string in which the non-overlapping substrings matching

Powered by Google App Engine
This is Rietveld 408576698