Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #library("dart:coreimpl"); | 5 #library("dart:coreimpl"); |
| 6 | 6 |
| 7 #source("../../corelib/src/implementation/dual_pivot_quicksort.dart"); | 7 #source("../../corelib/src/implementation/dual_pivot_quicksort.dart"); |
| 8 #source("../../corelib/src/implementation/duration_implementation.dart"); | 8 #source("../../corelib/src/implementation/duration_implementation.dart"); |
| 9 #source("../../corelib/src/implementation/exceptions.dart"); | 9 #source("../../corelib/src/implementation/exceptions.dart"); |
| 10 #source("../../corelib/src/implementation/future_implementation.dart"); | 10 #source("../../corelib/src/implementation/future_implementation.dart"); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 int get _lastIndex() native "return this.re.lastIndex;"; | 272 int get _lastIndex() native "return this.re.lastIndex;"; |
| 273 | 273 |
| 274 bool hasMatch(String str) native "return this.re.test(str);"; | 274 bool hasMatch(String str) native "return this.re.test(str);"; |
| 275 | 275 |
| 276 String stringMatch(String str) { | 276 String stringMatch(String str) { |
| 277 var match = firstMatch(str); | 277 var match = firstMatch(str); |
| 278 return match === null ? null : match.group(0); | 278 return match === null ? null : match.group(0); |
| 279 } | 279 } |
| 280 | 280 |
| 281 Iterable<Match> allMatches(String str) => new _AllMatchesIterable(this, str); | 281 Iterable<Match> allMatches(String str) => new _AllMatchesIterable(this, str); |
| 282 | |
| 283 /** | |
| 284 * Returns a new RegExp with the same pattern as this one and with the | |
| 285 * "global" flag set. This allows us to match this RegExp against a string | |
| 286 * multiple times, to support things like [allMatches] and | |
| 287 * [String.replaceAll]. | |
| 288 * | |
| 289 * 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
| |
| 290 * state about the location of the last match. | |
| 291 */ | |
| 292 JSSyntaxRegExp get _global() => new JSSyntaxRegExp._create(pattern, | |
| 293 'g' + (multiLine ? 'm' : '') + (ignoreCase ? 'i' : '')); | |
| 282 } | 294 } |
| 283 | 295 |
| 284 class MatchImplementation implements Match { | 296 class MatchImplementation implements Match { |
| 285 const MatchImplementation( | 297 const MatchImplementation( |
| 286 String this.pattern, | 298 String this.pattern, |
| 287 String this.str, | 299 String this.str, |
| 288 int this._start, | 300 int this._start, |
| 289 int this._end, | 301 int this._end, |
| 290 List<String> this._groups); | 302 List<String> this._groups); |
| 291 | 303 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 316 | 328 |
| 317 Iterator<Match> iterator() => new _AllMatchesIterator(_re, _str); | 329 Iterator<Match> iterator() => new _AllMatchesIterator(_re, _str); |
| 318 } | 330 } |
| 319 | 331 |
| 320 class _AllMatchesIterator implements Iterator<Match> { | 332 class _AllMatchesIterator implements Iterator<Match> { |
| 321 final RegExp _re; | 333 final RegExp _re; |
| 322 final String _str; | 334 final String _str; |
| 323 Match _next; | 335 Match _next; |
| 324 bool _done; | 336 bool _done; |
| 325 | 337 |
| 326 _AllMatchesIterator(RegExp re, String this._str) | 338 _AllMatchesIterator(JSSyntaxRegExp re, String this._str) |
| 327 : _done = false, | 339 : _done = false, _re = re._global; |
| 328 _re = new JSSyntaxRegExp._create(re.pattern, | |
| 329 // Create a new RegExp with the "global" flag set so we can use it to | |
| 330 // iterate over multiple matches. Note that this will make the RegExp | |
| 331 // disobey the normal API. | |
| 332 'g' + (re.multiLine ? 'm' : '') + (re.ignoreCase ? 'i' : '')); | |
| 333 | 340 |
| 334 Match next() { | 341 Match next() { |
| 335 if (!hasNext()) { | 342 if (!hasNext()) { |
| 336 throw const NoMoreElementsException(); | 343 throw const NoMoreElementsException(); |
| 337 } | 344 } |
| 338 | 345 |
| 339 // _next is set by #hasNext | 346 // _next is set by #hasNext |
| 340 var next = _next; | 347 var next = _next; |
| 341 _next = null; | 348 _next = null; |
| 342 return next; | 349 return next; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 } else if (isNaN()) { | 434 } else if (isNaN()) { |
| 428 if (other.isNaN()) { | 435 if (other.isNaN()) { |
| 429 return 0; | 436 return 0; |
| 430 } | 437 } |
| 431 return 1; | 438 return 1; |
| 432 } else { | 439 } else { |
| 433 return -1; | 440 return -1; |
| 434 } | 441 } |
| 435 } | 442 } |
| 436 } | 443 } |
| OLD | NEW |