| Index: runtime/lib/string_patch.dart
|
| diff --git a/runtime/lib/string_patch.dart b/runtime/lib/string_patch.dart
|
| index f750fc31f153281a011307d53d6e7ee6481ed193..3ac78a8fd9404faa5724cd771666eb61053110d5 100644
|
| --- a/runtime/lib/string_patch.dart
|
| +++ b/runtime/lib/string_patch.dart
|
| @@ -414,23 +414,29 @@ class _StringBase {
|
| return pattern.allMatches(this.substring(startIndex)).isNotEmpty;
|
| }
|
|
|
| - String replaceFirst(Pattern pattern, String replacement) {
|
| + String replaceFirst(Pattern pattern,
|
| + String replacement,
|
| + [int startIndex = 0]) {
|
| if (pattern is! Pattern) {
|
| throw new ArgumentError("${pattern} is not a Pattern");
|
| }
|
| if (replacement is! String) {
|
| throw new ArgumentError("${replacement} is not a String");
|
| }
|
| - StringBuffer buffer = new StringBuffer();
|
| - int startIndex = 0;
|
| - Iterator iterator = pattern.allMatches(this).iterator;
|
| - if (iterator.moveNext()) {
|
| - Match match = iterator.current;
|
| - buffer..write(this.substring(startIndex, match.start))
|
| - ..write(replacement);
|
| - startIndex = match.end;
|
| + if (startIndex is! int) {
|
| + throw new ArgumentError("${startIndex} is not an int");
|
| }
|
| - return (buffer..write(this.substring(startIndex))).toString();
|
| + if ((startIndex < 0) || (startIndex > this.length)) {
|
| + throw new RangeError.range(startIndex, 0, this.length);
|
| + }
|
| + Iterator iterator =
|
| + startIndex == 0 ? pattern.allMatches(this).iterator
|
| + : pattern.allMatches(this, startIndex).iterator;
|
| + if (!iterator.moveNext()) return this;
|
| + Match match = iterator.current;
|
| + return "${this.substring(0, match.start)}"
|
| + "$replacement"
|
| + "${this.substring(match.end)}";
|
| }
|
|
|
| String replaceAll(Pattern pattern, String replacement) {
|
|
|