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 class _JSRegExpMatch implements Match { | 5 class _JSRegExpMatch implements Match { |
6 _JSRegExpMatch(this.regexp, this.str, this._match); | 6 _JSRegExpMatch(this.regexp, this.str, this._match); |
7 | 7 |
8 int get start => _start(0); | 8 int get start => _start(0); |
9 int get end => _end(0); | 9 int get end => _end(0); |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 | 55 |
56 patch class JSSyntaxRegExp { | 56 patch class JSSyntaxRegExp { |
57 /* patch */ const factory JSSyntaxRegExp( | 57 /* patch */ const factory JSSyntaxRegExp( |
58 String pattern, | 58 String pattern, |
59 {bool multiLine: false, | 59 {bool multiLine: false, |
60 bool ignoreCase: false}) native "JSSyntaxRegExp_factory"; | 60 bool ignoreCase: false}) native "JSSyntaxRegExp_factory"; |
61 | 61 |
62 /* patch */ Match firstMatch(String str) { | 62 /* patch */ Match firstMatch(String str) { |
63 List match = _ExecuteMatch(str, 0); | 63 List match = _ExecuteMatch(str, 0); |
64 if (match === null) { | 64 if (match == null) { |
65 return null; | 65 return null; |
66 } | 66 } |
67 return new _JSRegExpMatch(this, str, match); | 67 return new _JSRegExpMatch(this, str, match); |
68 } | 68 } |
69 | 69 |
70 /* patch */ Iterable<Match> allMatches(String str) { | 70 /* patch */ Iterable<Match> allMatches(String str) { |
71 List<Match> result = new List<Match>(); | 71 List<Match> result = new List<Match>(); |
72 int length = str.length; | 72 int length = str.length; |
73 int startIndex = 0; | 73 int startIndex = 0; |
74 while (true) { | 74 while (true) { |
75 List match = _ExecuteMatch(str, startIndex); | 75 List match = _ExecuteMatch(str, startIndex); |
76 if (match == null) { | 76 if (match == null) { |
77 break; | 77 break; |
78 } | 78 } |
79 result.add(new _JSRegExpMatch(this, str, match)); | 79 result.add(new _JSRegExpMatch(this, str, match)); |
80 int endIndex = match[1]; | 80 int endIndex = match[1]; |
81 if (endIndex == length) { | 81 if (endIndex == length) { |
82 break; | 82 break; |
83 } else if (match[0] == endIndex) { | 83 } else if (match[0] == endIndex) { |
84 ++startIndex; // empty match, advance and restart | 84 ++startIndex; // empty match, advance and restart |
85 } else { | 85 } else { |
86 startIndex = endIndex; | 86 startIndex = endIndex; |
87 } | 87 } |
88 } | 88 } |
89 return result; | 89 return result; |
90 } | 90 } |
91 | 91 |
92 /* patch */ bool hasMatch(String str) { | 92 /* patch */ bool hasMatch(String str) { |
93 List match = _ExecuteMatch(str, 0); | 93 List match = _ExecuteMatch(str, 0); |
94 return (match === null) ? false : true; | 94 return (match == null) ? false : true; |
95 } | 95 } |
96 | 96 |
97 /* patch */ String stringMatch(String str) { | 97 /* patch */ String stringMatch(String str) { |
98 List match = _ExecuteMatch(str, 0); | 98 List match = _ExecuteMatch(str, 0); |
99 if (match === null) { | 99 if (match == null) { |
100 return null; | 100 return null; |
101 } | 101 } |
102 // TODO(ajohnsen): Use _substringUnchecked when regexp is in core. | 102 // TODO(ajohnsen): Use _substringUnchecked when regexp is in core. |
103 return str.substring(match[0], match[1]); | 103 return str.substring(match[0], match[1]); |
104 } | 104 } |
105 | 105 |
106 /* patch */ String get pattern native "JSSyntaxRegExp_getPattern"; | 106 /* patch */ String get pattern native "JSSyntaxRegExp_getPattern"; |
107 | 107 |
108 /* patch */ bool get multiLine native "JSSyntaxRegExp_multiLine"; | 108 /* patch */ bool get multiLine native "JSSyntaxRegExp_multiLine"; |
109 | 109 |
110 /* patch */ bool get ignoreCase native "JSSyntaxRegExp_ignoreCase"; | 110 /* patch */ bool get ignoreCase native "JSSyntaxRegExp_ignoreCase"; |
111 | 111 |
112 int get _groupCount native "JSSyntaxRegExp_getGroupCount"; | 112 int get _groupCount native "JSSyntaxRegExp_getGroupCount"; |
113 | 113 |
114 List _ExecuteMatch(String str, int start_index) | 114 List _ExecuteMatch(String str, int start_index) |
115 native "JSSyntaxRegExp_ExecuteMatch"; | 115 native "JSSyntaxRegExp_ExecuteMatch"; |
116 } | 116 } |
OLD | NEW |