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

Unified Diff: frog/lib/corelib_impl.dart

Issue 8907042: Support replaceAll for regexps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years 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 | frog/lib/string_implementation.dart » ('j') | frog/lib/string_implementation.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/lib/corelib_impl.dart
diff --git a/frog/lib/corelib_impl.dart b/frog/lib/corelib_impl.dart
index 0ed43dcc0218047815e2c9a2235c692b6ccca3dd..2c7bc003da2714b8774bf67c13517cc3d7e81486 100644
--- a/frog/lib/corelib_impl.dart
+++ b/frog/lib/corelib_impl.dart
@@ -279,6 +279,18 @@ class JSSyntaxRegExp implements RegExp {
}
Iterable<Match> allMatches(String str) => new _AllMatchesIterable(this, str);
+
+ /**
+ * Returns a new RegExp with the same pattern as this one and with the
+ * "global" flag set. This allows us to match this RegExp against a string
+ * multiple times, to support things like [allMatches] and
+ * [String.replaceAll].
+ *
+ * Note that the returned RegExp disobeys the normal API in that it maintains
Jennifer Messerly 2011/12/14 20:36:56 nice refactoring :) out of curiosity--what does i
nweiz 2011/12/14 21:39:21 It's an implementation note. When a JS regexp has
+ * state about the location of the last match.
+ */
+ JSSyntaxRegExp get _global() => new JSSyntaxRegExp._create(pattern,
+ 'g' + (multiLine ? 'm' : '') + (ignoreCase ? 'i' : ''));
}
class MatchImplementation implements Match {
@@ -323,13 +335,8 @@ class _AllMatchesIterator implements Iterator<Match> {
Match _next;
bool _done;
- _AllMatchesIterator(RegExp re, String this._str)
- : _done = false,
- _re = new JSSyntaxRegExp._create(re.pattern,
- // Create a new RegExp with the "global" flag set so we can use it to
- // iterate over multiple matches. Note that this will make the RegExp
- // disobey the normal API.
- 'g' + (re.multiLine ? 'm' : '') + (re.ignoreCase ? 'i' : ''));
+ _AllMatchesIterator(JSSyntaxRegExp re, String this._str)
+ : _done = false, _re = re._global;
Match next() {
if (!hasNext()) {
« no previous file with comments | « no previous file | frog/lib/string_implementation.dart » ('j') | frog/lib/string_implementation.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698