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

Side by Side Diff: runtime/lib/regexp_patch.dart

Issue 15709018: Proof-of-concept matchPrefix on Pattern. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 patch class RegExp { 5 patch class RegExp {
6 /* patch */ factory RegExp(String pattern, 6 /* patch */ factory RegExp(String pattern,
7 {bool multiLine: false, 7 {bool multiLine: false,
8 bool caseSensitive: true}) { 8 bool caseSensitive: true}) {
9 return new _JSSyntaxRegExp(pattern, 9 return new _JSSyntaxRegExp(pattern,
10 multiLine: multiLine, 10 multiLine: multiLine,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return null; 74 return null;
75 } 75 }
76 return new _JSRegExpMatch(this, str, match); 76 return new _JSRegExpMatch(this, str, match);
77 } 77 }
78 78
79 Iterable<Match> allMatches(String str) { 79 Iterable<Match> allMatches(String str) {
80 if (str is! String) throw new ArgumentError(str); 80 if (str is! String) throw new ArgumentError(str);
81 return new _AllMatchesIterable(this, str); 81 return new _AllMatchesIterable(this, str);
82 } 82 }
83 83
84 Match matchPrefix(String string, [int start = 0]) {
85 if (start < 0 || start > string.length) {
86 throw new RangeError.range(start, 0, string.length);
87 }
88 // Inefficient check that searches for a later match too.
89 List<int> list = _ExecuteMatch(string, start);
90 if (list == null) return null;
91 if (list[0] != start) return null;
92 return new _JSRegExpMatch(this, string, list);
93 }
94
84 bool hasMatch(String str) { 95 bool hasMatch(String str) {
85 List match = _ExecuteMatch(str, 0); 96 List match = _ExecuteMatch(str, 0);
86 return (match == null) ? false : true; 97 return (match == null) ? false : true;
87 } 98 }
88 99
89 String stringMatch(String str) { 100 String stringMatch(String str) {
90 List match = _ExecuteMatch(str, 0); 101 List match = _ExecuteMatch(str, 0);
91 if (match == null) { 102 if (match == null) {
92 return null; 103 return null;
93 } 104 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 var match = _re._ExecuteMatch(_str, nextIndex); 153 var match = _re._ExecuteMatch(_str, nextIndex);
143 if (match == null) { 154 if (match == null) {
144 _current = null; 155 _current = null;
145 _re = null; 156 _re = null;
146 return false; 157 return false;
147 } 158 }
148 _current = new _JSRegExpMatch(_re, _str, match); 159 _current = new _JSRegExpMatch(_re, _str, match);
149 return true; 160 return true;
150 } 161 }
151 } 162 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698