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

Unified Diff: sdk/lib/_internal/js_runtime/lib/string_helper.dart

Issue 1559953002: Revert "js_runtime: streamline stringReplaceAllUnchecked" (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 12 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 | « no previous file | tests/corelib/string_replace_all_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/js_runtime/lib/string_helper.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/string_helper.dart b/sdk/lib/_internal/js_runtime/lib/string_helper.dart
index 904c5e913deed71e3d7749a82c452aa25c3b41ee..9ce91f8a179d7505935707a47ea45e8fef2c2f6d 100644
--- a/sdk/lib/_internal/js_runtime/lib/string_helper.dart
+++ b/sdk/lib/_internal/js_runtime/lib/string_helper.dart
@@ -130,6 +130,8 @@ stringReplaceFirstRE(receiver, regexp, replacement, startIndex) {
return stringReplaceRangeUnchecked(receiver, start, end, replacement);
}
+const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]';
+
stringReplaceAllUnchecked(receiver, pattern, replacement) {
checkString(replacement);
if (pattern is String) {
@@ -147,10 +149,8 @@ stringReplaceAllUnchecked(receiver, pattern, replacement) {
return result.toString();
}
} else {
- // Convert string [pattern] into a RegExp [replacer], escaping all
- // metacharacters.
- var quoted = JS('String',
- r'#.replace(/[[\]{}()*+?.\\^$|]/g, "\\$&")', pattern);
+ var quoter = JS('', "new RegExp(#, 'g')", ESCAPE_REGEXP);
+ var quoted = JS('String', r'#.replace(#, "\\$&")', pattern, quoter);
var replacer = JS('', "new RegExp(#, 'g')", quoted);
return stringReplaceJS(receiver, replacer, replacement);
}
« no previous file with comments | « no previous file | tests/corelib/string_replace_all_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698