| Index: sdk/lib/_internal/compiler/implementation/lib/string_helper.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/lib/string_helper.dart b/sdk/lib/_internal/compiler/implementation/lib/string_helper.dart
|
| index 3a35778c677a431b508c26c8ed97d583c9c8b487..7b1b07e7ca4facc11f9b6dacb71665cd52192a95 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/lib/string_helper.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/lib/string_helper.dart
|
| @@ -33,7 +33,7 @@ class StringMatch implements Match {
|
|
|
| List<Match> allMatchesInStringUnchecked(String needle, String haystack) {
|
| // Copied from StringBase.allMatches in
|
| - // ../../../runtime/lib/string.dart
|
| + // /runtime/lib/string_base.dart
|
| List<Match> result = new List<Match>();
|
| int length = haystack.length;
|
| int patternLength = needle.length;
|
| @@ -76,6 +76,10 @@ stringReplaceJS(receiver, replacer, to) {
|
| }
|
|
|
| stringReplaceAllUnchecked(receiver, from, to) {
|
| + if (to is Function) {
|
| + return stringReplaceAllFuncUnchecked(receiver, from, to);
|
| + }
|
| + checkString(to);
|
| if (from is String) {
|
| if (from == "") {
|
| if (receiver == "") {
|
| @@ -109,6 +113,57 @@ stringReplaceAllUnchecked(receiver, from, to) {
|
| }
|
| }
|
|
|
| +stringReplaceAllFuncUnchecked(receiver, pattern, replace) {
|
| + if (pattern is! Pattern) {
|
| + throw new ArgumentError("${pattern} is not a Pattern");
|
| + }
|
| + if (pattern is String) {
|
| + // Inline the allMatches code.
|
| + return stringReplaceAllStringFuncUnchecked(receiver, pattern, replace);
|
| + }
|
| + StringBuffer buffer = new StringBuffer();
|
| + int startIndex = 0;
|
| + for (Match match in pattern.allMatches(receiver)) {
|
| + if (startIndex < match.start) {
|
| + buffer.add(receiver.substring(startIndex, match.start));
|
| + }
|
| + buffer.add(replace(match).toString());
|
| + startIndex = match.end;
|
| + }
|
| + if (startIndex < receiver.length) {
|
| + buffer.add(receiver.substring(startIndex));
|
| + }
|
| + return buffer.toString();
|
| +}
|
| +
|
| +stringReplaceAllStringFuncUnchecked(receiver, pattern, replace) {
|
| + int length = receiver.length;
|
| + int patternLength = pattern.length;
|
| + int startIndex = 0;
|
| + StringBuffer buffer = new StringBuffer();
|
| + while (true) {
|
| + int position = receiver.indexOf(pattern, startIndex);
|
| + if (position == -1) {
|
| + if (startIndex < length) buffer.add(receiver.substring(startIndex));
|
| + return buffer.toString();
|
| + }
|
| + if (startIndex < position) {
|
| + buffer.add(receiver.substring(startIndex, position));
|
| + }
|
| + buffer.add(
|
| + replace(new StringMatch(position, receiver, pattern)).toString());
|
| + int endIndex = position + patternLength;
|
| + if (endIndex == length) {
|
| + return buffer.toString();
|
| + } else if (position == endIndex) {
|
| + ++startIndex; // empty match, advance and restart
|
| + } else {
|
| + startIndex = endIndex;
|
| + }
|
| + }
|
| +}
|
| +
|
| +
|
| stringReplaceFirstUnchecked(receiver, from, to) {
|
| if (from is String) {
|
| return stringReplaceJS(receiver, from, to);
|
|
|