Chromium Code Reviews| Index: sdk/lib/_internal/compiler/js_lib/string_helper.dart |
| diff --git a/sdk/lib/_internal/compiler/js_lib/string_helper.dart b/sdk/lib/_internal/compiler/js_lib/string_helper.dart |
| index ff2505729a1b3cce8352be876681941925776479..6032d9f1f95f367e600030a25403131670d273ba 100644 |
| --- a/sdk/lib/_internal/compiler/js_lib/string_helper.dart |
| +++ b/sdk/lib/_internal/compiler/js_lib/string_helper.dart |
| @@ -193,21 +193,34 @@ stringReplaceAllStringFuncUnchecked(receiver, pattern, onMatch, onNonMatch) { |
| } |
| -stringReplaceFirstUnchecked(receiver, from, to, [int startIndex = 0]) { |
| +stringReplaceFirstUnchecked(receiver, from, to, int startIndex) { |
| if (from is String) { |
| var index = receiver.indexOf(from, startIndex); |
|
floitsch
2015/02/11 11:49:14
we are missing types here... (and in your code).
Lasse Reichstein Nielsen
2015/02/12 09:17:16
Added.
You are also missing types on all the funct
|
| if (index < 0) return receiver; |
| return '${receiver.substring(0, index)}$to' |
| '${receiver.substring(index + from.length)}'; |
| - } else if (from is JSSyntaxRegExp) { |
| + } |
| + if (from is JSSyntaxRegExp) { |
| return startIndex == 0 ? |
| stringReplaceJS(receiver, regExpGetNative(from), to) : |
| stringReplaceFirstRE(receiver, from, to, startIndex); |
| - } else { |
| - checkNull(from); |
| - // TODO(floitsch): implement generic String.replace (with patterns). |
| - throw "String.replace(Pattern) UNIMPLEMENTED"; |
| } |
| + checkNull(from); |
| + var matches = from.allMatches(receiver, startIndex).iterator; |
| + if (!matches.moveNext()) return receiver; |
| + var match = matches.current; |
| + return '${receiver.substring(0, match.start)}$to' |
| + '${receiver.substring(match.end)}'; |
| +} |
| + |
| +stringReplaceFirstMappedUnchecked(receiver, from, replace, |
| + int startIndex) { |
| + var matches = from.allMatches(receiver, startIndex).iterator; |
| + if (!matches.moveNext()) return receiver; |
| + var match = matches.current; |
| + var replacement = "${replace(match)}"; |
| + return '${receiver.substring(0, match.start)}$replacement' |
| + '${receiver.substring(match.end)}'; |
| } |
| stringJoinUnchecked(array, separator) { |