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

Unified Diff: sdk/lib/_internal/compiler/js_lib/string_helper.dart

Issue 949753005: Add String.replaceRange and use it in replaceFirst{,Mapped}. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. 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
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/js_string.dart ('k') | sdk/lib/core/string.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 77b8ab9c34a95b95cb4c4c44604578362ffed8ee..567e4042b0e009de2e2714dde640c3185be06945 100644
--- a/sdk/lib/_internal/compiler/js_lib/string_helper.dart
+++ b/sdk/lib/_internal/compiler/js_lib/string_helper.dart
@@ -82,7 +82,7 @@ stringReplaceFirstRE(receiver, regexp, to, startIndex) {
if (match == null) return receiver;
var start = match.start;
var end = match.end;
- return "${receiver.substring(0,start)}$to${receiver.substring(end)}";
+ return stringReplaceRangeUnchecked(receiver, start, end, to);
}
const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]';
@@ -197,8 +197,8 @@ stringReplaceFirstUnchecked(receiver, from, to, int startIndex) {
if (from is String) {
int index = receiver.indexOf(from, startIndex);
if (index < 0) return receiver;
- return '${receiver.substring(0, index)}$to'
- '${receiver.substring(index + from.length)}';
+ int end = index + from.length;
+ return stringReplaceRangeUnchecked(receiver, index, end, to);
}
if (from is JSSyntaxRegExp) {
return startIndex == 0 ?
@@ -226,3 +226,10 @@ stringReplaceFirstMappedUnchecked(receiver, from, replace,
stringJoinUnchecked(array, separator) {
return JS('String', r'#.join(#)', array, separator);
}
+
+String stringReplaceRangeUnchecked(String receiver,
+ int start, int end, String replacement) {
+ var prefix = JS('String', '#.substring(0, #)', receiver, start);
+ var suffix = JS('String', '#.substring(#)', receiver, end);
+ return "$prefix$replacement$suffix";
+}
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/js_string.dart ('k') | sdk/lib/core/string.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698