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

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

Issue 11365196: Move JSSyntaxRegExp to core as a private member. This removes the last refrences to dart:coreimpl. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Change arrow-syntax factory into brace-syntax, due to multiline content. Created 8 years, 1 month 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
OLDNEW
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 {
6 /* patch */ factory RegExp(String pattern,
7 {bool multiLine: false,
8 bool ignoreCase: false}) {
9 return new _JSSyntaxRegExp(pattern,
10 multiLine: multiLine,
11 ignoreCase: ignoreCase);
12 }
13 }
14
5 class _JSRegExpMatch implements Match { 15 class _JSRegExpMatch implements Match {
6 _JSRegExpMatch(this.regexp, this.str, this._match); 16 _JSRegExpMatch(this.regexp, this.str, this._match);
7 17
8 int get start => _start(0); 18 int get start => _start(0);
9 int get end => _end(0); 19 int get end => _end(0);
10 20
11 int _start(int groupIdx) { 21 int _start(int groupIdx) {
12 return _match[(groupIdx * MATCH_PAIR)]; 22 return _match[(groupIdx * MATCH_PAIR)];
13 } 23 }
14 24
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 56
47 String get pattern => regexp.pattern; 57 String get pattern => regexp.pattern;
48 58
49 final RegExp regexp; 59 final RegExp regexp;
50 final String str; 60 final String str;
51 final List<int> _match; 61 final List<int> _match;
52 static const int MATCH_PAIR = 2; 62 static const int MATCH_PAIR = 2;
53 } 63 }
54 64
55 65
56 patch class JSSyntaxRegExp { 66 class _JSSyntaxRegExp extends RegExp {
floitsch 2012/11/12 16:31:56 why not just "implements"?
Anders Johnsen 2012/11/12 16:58:38 Done.
57 /* patch */ const factory JSSyntaxRegExp( 67 factory _JSSyntaxRegExp(
58 String pattern, 68 String pattern,
59 {bool multiLine: false, 69 {bool multiLine: false,
60 bool ignoreCase: false}) native "JSSyntaxRegExp_factory"; 70 bool ignoreCase: false}) native "JSSyntaxRegExp_factory";
61 71
62 /* patch */ Match firstMatch(String str) { 72 Match firstMatch(String str) {
63 List match = _ExecuteMatch(str, 0); 73 List match = _ExecuteMatch(str, 0);
64 if (match === null) { 74 if (match === null) {
65 return null; 75 return null;
66 } 76 }
67 return new _JSRegExpMatch(this, str, match); 77 return new _JSRegExpMatch(this, str, match);
68 } 78 }
69 79
70 /* patch */ Iterable<Match> allMatches(String str) { 80 Iterable<Match> allMatches(String str) {
71 List<Match> result = new List<Match>(); 81 List<Match> result = new List<Match>();
72 int length = str.length; 82 int length = str.length;
73 int startIndex = 0; 83 int startIndex = 0;
74 while (true) { 84 while (true) {
75 List match = _ExecuteMatch(str, startIndex); 85 List match = _ExecuteMatch(str, startIndex);
76 if (match == null) { 86 if (match == null) {
77 break; 87 break;
78 } 88 }
79 result.add(new _JSRegExpMatch(this, str, match)); 89 result.add(new _JSRegExpMatch(this, str, match));
80 int endIndex = match[1]; 90 int endIndex = match[1];
81 if (endIndex == length) { 91 if (endIndex == length) {
82 break; 92 break;
83 } else if (match[0] == endIndex) { 93 } else if (match[0] == endIndex) {
84 ++startIndex; // empty match, advance and restart 94 ++startIndex; // empty match, advance and restart
85 } else { 95 } else {
86 startIndex = endIndex; 96 startIndex = endIndex;
87 } 97 }
88 } 98 }
89 return result; 99 return result;
90 } 100 }
91 101
92 /* patch */ bool hasMatch(String str) { 102 bool hasMatch(String str) {
93 List match = _ExecuteMatch(str, 0); 103 List match = _ExecuteMatch(str, 0);
94 return (match === null) ? false : true; 104 return (match === null) ? false : true;
95 } 105 }
96 106
97 /* patch */ String stringMatch(String str) { 107 String stringMatch(String str) {
98 List match = _ExecuteMatch(str, 0); 108 List match = _ExecuteMatch(str, 0);
99 if (match === null) { 109 if (match === null) {
100 return null; 110 return null;
101 } 111 }
102 // TODO(ajohnsen): Use _substringUnchecked when regexp is in core. 112 // TODO(ajohnsen): Use _substringUnchecked when regexp is in core.
103 return str.substring(match[0], match[1]); 113 return str.substring(match[0], match[1]);
104 } 114 }
105 115
106 /* patch */ String get pattern native "JSSyntaxRegExp_getPattern"; 116 String get pattern native "JSSyntaxRegExp_getPattern";
107 117
108 /* patch */ bool get multiLine native "JSSyntaxRegExp_multiLine"; 118 bool get multiLine native "JSSyntaxRegExp_multiLine";
109 119
110 /* patch */ bool get ignoreCase native "JSSyntaxRegExp_ignoreCase"; 120 bool get ignoreCase native "JSSyntaxRegExp_ignoreCase";
111 121
112 int get _groupCount native "JSSyntaxRegExp_getGroupCount"; 122 int get _groupCount native "JSSyntaxRegExp_getGroupCount";
113 123
114 List _ExecuteMatch(String str, int start_index) 124 List _ExecuteMatch(String str, int start_index)
115 native "JSSyntaxRegExp_ExecuteMatch"; 125 native "JSSyntaxRegExp_ExecuteMatch";
116 } 126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698