OLD | NEW |
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 source, | 6 @patch factory RegExp(String source, |
7 {bool multiLine: false, | 7 {bool multiLine: false, |
8 bool caseSensitive: true}) { | 8 bool caseSensitive: true}) { |
9 _RegExpHashKey key = new _RegExpHashKey( | 9 _RegExpHashKey key = new _RegExpHashKey( |
10 source, multiLine, caseSensitive); | 10 source, multiLine, caseSensitive); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 return new _AllMatchesIterable(this, string, start); | 154 return new _AllMatchesIterable(this, string, start); |
155 } | 155 } |
156 | 156 |
157 Match matchAsPrefix(String string, [int start = 0]) { | 157 Match matchAsPrefix(String string, [int start = 0]) { |
158 if (string is! String) throw new ArgumentError(string); | 158 if (string is! String) throw new ArgumentError(string); |
159 if (start is! int) throw new ArgumentError(start); | 159 if (start is! int) throw new ArgumentError(start); |
160 if (start < 0 || start > string.length) { | 160 if (start < 0 || start > string.length) { |
161 throw new RangeError.range(start, 0, string.length); | 161 throw new RangeError.range(start, 0, string.length); |
162 } | 162 } |
163 // Inefficient check that searches for a later match too. | 163 List<int> list = _ExecuteMatchSticky(string, start); |
164 // Change this when possible. | |
165 List<int> list = _ExecuteMatch(string, start); | |
166 if (list == null) return null; | 164 if (list == null) return null; |
167 if (list[0] != start) return null; | |
168 return new _RegExpMatch(this, string, list); | 165 return new _RegExpMatch(this, string, list); |
169 } | 166 } |
170 | 167 |
171 bool hasMatch(String str) { | 168 bool hasMatch(String str) { |
172 if (str is! String) throw new ArgumentError(str); | 169 if (str is! String) throw new ArgumentError(str); |
173 List match = _ExecuteMatch(str, 0); | 170 List match = _ExecuteMatch(str, 0); |
174 return (match == null) ? false : true; | 171 return (match == null) ? false : true; |
175 } | 172 } |
176 | 173 |
177 String stringMatch(String str) { | 174 String stringMatch(String str) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
232 | 229 |
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
237 ]; | 234 ]; |
238 | 235 |
239 List _ExecuteMatch(String str, int start_index) | 236 List _ExecuteMatch(String str, int start_index) |
240 native "RegExp_ExecuteMatch"; | 237 native "RegExp_ExecuteMatch"; |
| 238 |
| 239 List _ExecuteMatchSticky(String str, int start_index) |
| 240 native "RegExp_ExecuteMatchSticky"; |
241 } | 241 } |
242 | 242 |
243 class _AllMatchesIterable extends IterableBase<Match> { | 243 class _AllMatchesIterable extends IterableBase<Match> { |
244 final _RegExp _re; | 244 final _RegExp _re; |
245 final String _str; | 245 final String _str; |
246 final int _start; | 246 final int _start; |
247 | 247 |
248 _AllMatchesIterable(this._re, this._str, this._start); | 248 _AllMatchesIterable(this._re, this._str, this._start); |
249 | 249 |
250 Iterator<Match> get iterator => new _AllMatchesIterator(_re, _str, _start); | 250 Iterator<Match> get iterator => new _AllMatchesIterator(_re, _str, _start); |
(...skipping 21 matching lines...) Expand all Loading... |
272 _nextIndex++; | 272 _nextIndex++; |
273 } | 273 } |
274 return true; | 274 return true; |
275 } | 275 } |
276 } | 276 } |
277 _current = null; | 277 _current = null; |
278 _re = null; | 278 _re = null; |
279 return false; | 279 return false; |
280 } | 280 } |
281 } | 281 } |
OLD | NEW |