| 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 // Mocks of classes and interfaces that Leg cannot read directly. | 5 // Mocks of classes and interfaces that Leg cannot read directly. |
| 6 | 6 |
| 7 // TODO(ahe): Remove this file. | 7 // TODO(ahe): Remove this file. |
| 8 | 8 |
| 9 class JSSyntaxRegExp implements RegExp { | 9 class JSSyntaxRegExp implements RegExp { |
| 10 JSSyntaxRegExp(String pattern, | 10 final String pattern; |
| 11 [bool multiLine = false, | 11 final bool multiLine; |
| 12 bool ignoreCase = false]) { | 12 final bool ignoreCase; |
| 13 throw 'JSSyntaxRegExp is not implemented'; | 13 final RegExpWrapper _re; |
| 14 |
| 15 const JSSyntaxRegExp(String pattern, [bool multiLine, bool ignoreCase]) |
| 16 // TODO(ahe): Redirect to _internal when that is supported. |
| 17 : this.pattern = pattern, |
| 18 this.multiLine = multiLine, |
| 19 this.ignoreCase = ignoreCase, |
| 20 this._re = const RegExpWrapper(pattern, multiLine, ignoreCase, false); |
| 21 |
| 22 const JSSyntaxRegExp._internal(String pattern, bool multiLine, |
| 23 bool ignoreCase, bool global) |
| 24 : this.pattern = pattern, |
| 25 this.multiLine = multiLine, |
| 26 this.ignoreCase = ignoreCase, |
| 27 this._re = const RegExpWrapper(pattern, multiLine, ignoreCase, global); |
| 28 |
| 29 Match firstMatch(String str) { |
| 30 List<String> m = _re.exec(str); |
| 31 if (m === null) return null; |
| 32 var matchStart = RegExpWrapper.matchStart(m); |
| 33 return new MatchImplementation(pattern, str, matchStart, |
| 34 _re.lastIndex(), m); |
| 35 } |
| 36 |
| 37 bool hasMatch(String str) => _re.test(str); |
| 38 |
| 39 String stringMatch(String str) { |
| 40 var match = firstMatch(str); |
| 41 return match === null ? null : match.group(0); |
| 42 } |
| 43 |
| 44 Iterable<Match> allMatches(String str) => new _AllMatchesIterable(this, str); |
| 45 |
| 46 /** |
| 47 * Returns a new RegExp with the same pattern as this one and with the |
| 48 * "global" flag set. This allows us to match this RegExp against a string |
| 49 * multiple times, to support things like [allMatches] and |
| 50 * [String.replaceAll]. |
| 51 * |
| 52 * Note that the returned RegExp disobeys the normal API in that it maintains |
| 53 * state about the location of the last match. |
| 54 */ |
| 55 JSSyntaxRegExp get _global() { |
| 56 return new JSSyntaxRegExp._internal(pattern, multiLine, ignoreCase, true); |
| 14 } | 57 } |
| 15 } | 58 } |
| 16 | 59 |
| 60 class MatchImplementation implements Match { |
| 61 const MatchImplementation( |
| 62 String this.pattern, |
| 63 String this.str, |
| 64 int this._start, |
| 65 int this._end, |
| 66 List<String> this._groups); |
| 67 |
| 68 final String pattern; |
| 69 final String str; |
| 70 final int _start; |
| 71 final int _end; |
| 72 final List<String> _groups; |
| 73 |
| 74 int start() => _start; |
| 75 int end() => _end; |
| 76 String group(int group) => _groups[group]; |
| 77 String operator [](int group) => _groups[group]; |
| 78 int groupCount() => _groups.length; |
| 79 |
| 80 List<String> groups(List<int> groups) { |
| 81 List<String> out = []; |
| 82 for (int group in groups) { |
| 83 out.add(_groups[group]); |
| 84 } |
| 85 return out; |
| 86 } |
| 87 } |
| 88 |
| 89 class _AllMatchesIterable implements Iterable<Match> { |
| 90 final JSSyntaxRegExp _re; |
| 91 final String _str; |
| 92 |
| 93 const _AllMatchesIterable(this._re, this._str); |
| 94 |
| 95 Iterator<Match> iterator() => new _AllMatchesIterator(_re, _str); |
| 96 } |
| 97 |
| 98 class _AllMatchesIterator implements Iterator<Match> { |
| 99 final RegExp _re; |
| 100 final String _str; |
| 101 Match _next; |
| 102 bool _done; |
| 103 |
| 104 _AllMatchesIterator(JSSyntaxRegExp re, String this._str) |
| 105 : _done = false, _re = re._global; |
| 106 |
| 107 Match next() { |
| 108 if (!hasNext()) { |
| 109 throw const NoMoreElementsException(); |
| 110 } |
| 111 |
| 112 // _next is set by #hasNext |
| 113 var next = _next; |
| 114 _next = null; |
| 115 return next; |
| 116 } |
| 117 |
| 118 bool hasNext() { |
| 119 if (_done) { |
| 120 return false; |
| 121 } else if (_next != null) { |
| 122 return true; |
| 123 } |
| 124 |
| 125 _next = _re.firstMatch(_str); |
| 126 if (_next == null) { |
| 127 _done = true; |
| 128 return false; |
| 129 } else { |
| 130 return true; |
| 131 } |
| 132 } |
| 133 } |
| 134 |
| 17 class ReceivePortFactory { | 135 class ReceivePortFactory { |
| 18 factory ReceivePort() { | 136 factory ReceivePort() { |
| 19 throw 'factory ReceivePort is not implemented'; | 137 throw 'factory ReceivePort is not implemented'; |
| 20 } | 138 } |
| 21 | 139 |
| 22 factory ReceivePort.singleShot() { | 140 factory ReceivePort.singleShot() { |
| 23 throw 'factory ReceivePort.singleShot is not implemented'; | 141 throw 'factory ReceivePort.singleShot is not implemented'; |
| 24 } | 142 } |
| 25 } | 143 } |
| 26 | 144 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 384 } |
| 267 String twoDigitMinutes = | 385 String twoDigitMinutes = |
| 268 twoDigits(inMinutes.remainder(Duration.MINUTES_PER_HOUR)); | 386 twoDigits(inMinutes.remainder(Duration.MINUTES_PER_HOUR)); |
| 269 String twoDigitSeconds = | 387 String twoDigitSeconds = |
| 270 twoDigits(inSeconds.remainder(Duration.SECONDS_PER_MINUTE)); | 388 twoDigits(inSeconds.remainder(Duration.SECONDS_PER_MINUTE)); |
| 271 String threeDigitMs = | 389 String threeDigitMs = |
| 272 threeDigits(inMilliseconds.remainder(Duration.MILLISECONDS_PER_SECOND)); | 390 threeDigits(inMilliseconds.remainder(Duration.MILLISECONDS_PER_SECOND)); |
| 273 return "${inHours}:${twoDigitMinutes}:${twoDigitSeconds}.${threeDigitMs}"; | 391 return "${inHours}:${twoDigitMinutes}:${twoDigitSeconds}.${threeDigitMs}"; |
| 274 } | 392 } |
| 275 } | 393 } |
| OLD | NEW |