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

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

Issue 10880020: Use patching for regexp implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Real VM fix from Ivan. Created 8 years, 4 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
« no previous file with comments | « runtime/lib/lib_impl_sources.gypi ('k') | runtime/lib/regexp_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 class JSRegExpMatch implements Match {
6 JSRegExpMatch(this.regexp, this.str, this._match);
7
8 int start() {
9 return _start(0);
10 }
11
12 int end() {
13 return _end(0);
14 }
15
16 int _start(int groupIdx) {
17 return _match[(groupIdx * MATCH_PAIR)];
18 }
19
20 int _end(int groupIdx) {
21 return _match[(groupIdx * MATCH_PAIR) + 1];
22 }
23
24 String group(int groupIdx) {
25 if (groupIdx < 0 || groupIdx > regexp._groupCount) {
26 throw new IndexOutOfRangeException(groupIdx);
27 }
28 int startIndex = _start(groupIdx);
29 int endIndex = _end(groupIdx);
30 if (startIndex == -1) {
31 assert(endIndex == -1);
32 return null;
33 }
34 return str.substringUnchecked_(startIndex, endIndex);
35 }
36
37 String operator [](int groupIdx) {
38 return this.group(groupIdx);
39 }
40
41 List<String> groups(List<int> groupsSpec) {
42 var groupsList = new List<String>(groupsSpec.length);
43 for (int i = 0; i < groupsSpec.length; i++) {
44 groupsList[i] = group(groupsSpec[i]);
45 }
46 return groupsList;
47 }
48
49 int groupCount() {
50 return regexp._groupCount;
51 }
52
53 String get pattern() => regexp.pattern;
54
55 final RegExp regexp;
56 final String str;
57 final List<int> _match;
58 static final int MATCH_PAIR = 2;
59 }
60
61
62 class JSSyntaxRegExp implements RegExp {
63 const factory JSSyntaxRegExp(
64 String pattern,
65 [bool multiLine = false,
66 bool ignoreCase = false]) native "JSSyntaxRegExp_factory";
67
68 Match firstMatch(String str) {
69 List match = _ExecuteMatch(str, 0);
70 if (match === null) {
71 return null;
72 }
73 return new JSRegExpMatch(this, str, match);
74 }
75
76 Iterable<Match> allMatches(String str) {
77 List<Match> result = new List<Match>();
78 int length = str.length;
79 int startIndex = 0;
80 while (true) {
81 List match = _ExecuteMatch(str, startIndex);
82 if (match == null) {
83 break;
84 }
85 result.add(new JSRegExpMatch(this, str, match));
86 int endIndex = match[1];
87 if (endIndex == length) {
88 break;
89 } else if (match[0] == endIndex) {
90 ++startIndex; // empty match, advance and restart
91 } else {
92 startIndex = endIndex;
93 }
94 }
95 return result;
96 }
97
98 bool hasMatch(String str) {
99 List match = _ExecuteMatch(str, 0);
100 return (match === null) ? false : true;
101 }
102
103 String stringMatch(String str) {
104 List match = _ExecuteMatch(str, 0);
105 if (match === null) {
106 return null;
107 }
108 return str.substringUnchecked_(match[0], match[1]);
109 }
110
111 String get pattern() native "JSSyntaxRegExp_getPattern";
112
113 bool get multiLine() native "JSSyntaxRegExp_multiLine";
114
115 bool get ignoreCase() native "JSSyntaxRegExp_ignoreCase";
116
117 int get _groupCount() native "JSSyntaxRegExp_getGroupCount";
118
119 List _ExecuteMatch(String str, int start_index)
120 native "JSSyntaxRegExp_ExecuteMatch";
121 }
OLDNEW
« no previous file with comments | « runtime/lib/lib_impl_sources.gypi ('k') | runtime/lib/regexp_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698