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 StringMatch implements Match { | 5 class StringMatch implements Match { |
6 const StringMatch(int this._start, | 6 const StringMatch(int this.start, |
7 String this.str, | 7 String this.str, |
8 String this.pattern); | 8 String this.pattern); |
9 | 9 |
10 int start() => _start; | 10 int get end => start + pattern.length; |
11 int end() => _start + pattern.length; | |
12 String operator[](int g) => group(g); | 11 String operator[](int g) => group(g); |
13 int groupCount() => 0; | 12 int get groupCount => 0; |
14 | 13 |
15 String group(int group_) { | 14 String group(int group_) { |
16 if (group_ != 0) { | 15 if (group_ != 0) { |
17 throw new IndexOutOfRangeException(group_); | 16 throw new IndexOutOfRangeException(group_); |
18 } | 17 } |
19 return pattern; | 18 return pattern; |
20 } | 19 } |
21 | 20 |
22 List<String> groups(List<int> groups_) { | 21 List<String> groups(List<int> groups_) { |
23 List<String> result = new List<String>(); | 22 List<String> result = new List<String>(); |
24 for (int g in groups_) { | 23 for (int g in groups_) { |
25 result.add(group(g)); | 24 result.add(group(g)); |
26 } | 25 } |
27 return result; | 26 return result; |
28 } | 27 } |
29 | 28 |
30 final int _start; | 29 final int start; |
31 final String str; | 30 final String str; |
32 final String pattern; | 31 final String pattern; |
33 } | 32 } |
34 | 33 |
35 List<Match> allMatchesInStringUnchecked(String needle, String haystack) { | 34 List<Match> allMatchesInStringUnchecked(String needle, String haystack) { |
36 // Copied from StringBase.allMatches in | 35 // Copied from StringBase.allMatches in |
37 // ../../../runtime/lib/string.dart | 36 // ../../../runtime/lib/string.dart |
38 List<Match> result = new List<Match>(); | 37 List<Match> result = new List<Match>(); |
39 int length = haystack.length; | 38 int length = haystack.length; |
40 int patternLength = needle.length; | 39 int patternLength = needle.length; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 var re = regExpGetNative(pattern); | 129 var re = regExpGetNative(pattern); |
131 return JS('List', r'#.split(#)', receiver, re); | 130 return JS('List', r'#.split(#)', receiver, re); |
132 } else { | 131 } else { |
133 throw "StringImplementation.split(Pattern) UNIMPLEMENTED"; | 132 throw "StringImplementation.split(Pattern) UNIMPLEMENTED"; |
134 } | 133 } |
135 } | 134 } |
136 | 135 |
137 stringJoinUnchecked(array, separator) { | 136 stringJoinUnchecked(array, separator) { |
138 return JS('String', r'#.join(#)', array, separator); | 137 return JS('String', r'#.join(#)', array, separator); |
139 } | 138 } |
OLD | NEW |