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 return new _JSSyntaxRegExp(source, | 9 _JSSyntaxRegExpHash hash = new _JSSyntaxRegExpHash( |
| 10 » source, multiLine, caseSensitive); |
| 11 if (!_regExpCache.containsKey(hash)) { |
| 12 _regExpCache[hash] = new _JSSyntaxRegExp(source, |
10 multiLine: multiLine, | 13 multiLine: multiLine, |
11 caseSensitive: caseSensitive); | 14 caseSensitive: caseSensitive); |
| 15 } |
| 16 |
| 17 return _regExpCache[hash]; |
| 18 } |
| 19 |
| 20 static final Map<_JSSyntaxRegExpHash, _JSSyntaxRegExp> _regExpCache = |
| 21 <_JSSyntaxRegExpHash, _JSSyntaxRegExp>{ }; |
| 22 } |
| 23 |
| 24 // Represents a key in the regular expression cache. |
| 25 class _JSSyntaxRegExpHash { |
| 26 final String pattern; |
| 27 final bool multiLine; |
| 28 final bool caseSensitive; |
| 29 |
| 30 _JSSyntaxRegExpHash(this.pattern, this.multiLine, this.caseSensitive); |
| 31 |
| 32 int get hashCode => pattern.hashCode; |
| 33 bool operator==(_JSSyntaxRegExpHash that) { |
| 34 return (pattern == that.pattern) && |
| 35 (this.multiLine == that.multiLine) && |
| 36 (this.caseSensitive == that.caseSensitive); |
12 } | 37 } |
13 } | 38 } |
14 | 39 |
15 class _JSRegExpMatch implements Match { | 40 class _JSRegExpMatch implements Match { |
16 _JSRegExpMatch(this._regexp, this.input, this._match); | 41 _JSRegExpMatch(this._regexp, this.input, this._match); |
17 | 42 |
18 int get start => _start(0); | 43 int get start => _start(0); |
19 int get end => _end(0); | 44 int get end => _end(0); |
20 | 45 |
21 int _start(int groupIdx) { | 46 int _start(int groupIdx) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 136 } |
112 | 137 |
113 String get pattern native "JSSyntaxRegExp_getPattern"; | 138 String get pattern native "JSSyntaxRegExp_getPattern"; |
114 | 139 |
115 bool get isMultiLine native "JSSyntaxRegExp_getIsMultiLine"; | 140 bool get isMultiLine native "JSSyntaxRegExp_getIsMultiLine"; |
116 | 141 |
117 bool get isCaseSensitive native "JSSyntaxRegExp_getIsCaseSensitive"; | 142 bool get isCaseSensitive native "JSSyntaxRegExp_getIsCaseSensitive"; |
118 | 143 |
119 int get _groupCount native "JSSyntaxRegExp_getGroupCount"; | 144 int get _groupCount native "JSSyntaxRegExp_getGroupCount"; |
120 | 145 |
| 146 // Byte map of one byte characters with a 0xff if the character is a word |
| 147 // character (digit, letter or underscore) and 0x00 otherwise. |
| 148 // Used by generated RegExp code. |
| 149 static const List<int> _wordCharacterMap = const <int>[ |
| 150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 154 |
| 155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 157 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // '0' - '7' |
| 158 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // '8' - '9' |
| 159 |
| 160 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'A' - 'G' |
| 161 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'H' - 'O' |
| 162 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'P' - 'W' |
| 163 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, // 'X' - 'Z', '_' |
| 164 |
| 165 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'a' - 'g' |
| 166 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'h' - 'o' |
| 167 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'p' - 'w' |
| 168 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, // 'x' - 'z' |
| 169 // Latin-1 range |
| 170 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 174 |
| 175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 179 |
| 180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 181 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 184 |
| 185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 186 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 189 ]; |
| 190 |
121 List _ExecuteMatch(String str, int start_index) | 191 List _ExecuteMatch(String str, int start_index) |
122 native "JSSyntaxRegExp_ExecuteMatch"; | 192 native "JSSyntaxRegExp_ExecuteMatch"; |
123 } | 193 } |
124 | 194 |
125 class _AllMatchesIterable extends IterableBase<Match> { | 195 class _AllMatchesIterable extends IterableBase<Match> { |
126 final _JSSyntaxRegExp _re; | 196 final _JSSyntaxRegExp _re; |
127 final String _str; | 197 final String _str; |
128 final int _start; | 198 final int _start; |
129 | 199 |
130 _AllMatchesIterable(this._re, this._str, this._start); | 200 _AllMatchesIterable(this._re, this._str, this._start); |
(...skipping 23 matching lines...) Expand all Loading... |
154 _nextIndex++; | 224 _nextIndex++; |
155 } | 225 } |
156 return true; | 226 return true; |
157 } | 227 } |
158 } | 228 } |
159 _current = null; | 229 _current = null; |
160 _re = null; | 230 _re = null; |
161 return false; | 231 return false; |
162 } | 232 } |
163 } | 233 } |
OLD | NEW |