OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 part of dart.core; | 5 part of dart.core; |
6 | 6 |
7 /** | 7 /** |
8 * An interface for basic searches within strings. | 8 * An interface for basic searches within strings. |
9 */ | 9 */ |
10 abstract class Pattern { | 10 abstract class Pattern { |
11 // NOTE: When using "start" index from the language library, call | 11 // NOTE: When using "start" index from the language library, call |
12 // without an argument if start is zero. This allows backwards compatiblity | 12 // without an argument if start is zero. This allows backwards compatiblity |
13 // with implementations of the older interface that didn't have the start | 13 // with implementations of the older interface that didn't have the start |
14 // index argument. | 14 // index argument. |
15 /** | 15 /** |
16 * Match this pattern against the string repeatedly. | 16 * Match this pattern against the string repeatedly. |
17 * | 17 * |
18 * If [start] is provided, matching will start at that index. | 18 * If [start] is provided, matching will start at that index. |
19 * | 19 * |
20 * The iterable will contain all the non-overlapping matches of the | 20 * The returned iterable lazily computes all the non-overlapping matches |
21 * pattern on the string, ordered by start index. | 21 * of the pattern on the string, ordered by start index. |
| 22 * If a user only requests the first |
| 23 * match, this function should not compute all possible matches. |
22 * | 24 * |
23 * The matches are found by repeatedly finding the first match | 25 * The matches are found by repeatedly finding the first match |
24 * of the pattern on the string, starting from the end of the previous | 26 * of the pattern on the string, starting from the end of the previous |
25 * match, and initially starting from index zero. | 27 * match, and initially starting from index zero. |
26 * | 28 * |
27 * If the pattern matches the empty string at some point, the next | 29 * If the pattern matches the empty string at some point, the next |
28 * match is found by starting at the previous match's end plus one. | 30 * match is found by starting at the previous match's end plus one. |
29 */ | 31 */ |
30 Iterable<Match> allMatches(String string, [int start = 0]); | 32 Iterable<Match> allMatches(String string, [int start = 0]); |
31 | 33 |
32 /** | 34 /** |
33 * Match this pattern against the start of `string`. | 35 * Match this pattern against the start of `string`. |
34 * | 36 * |
35 * If [start] is provided, it must be an integer in the range `0` .. | 37 * If [start] is provided, it must be an integer in the range `0` .. |
36 * `string.length`. In that case, this patten is tested against the | 38 * `string.length`. In that case, this patten is tested against the |
37 * string at the [start] position. That is, a [Match] is returned if the | 39 * string at the [start] position. That is, a [Match] is returned if the |
38 * pattern can match a part of the string starting from position [start]. | 40 * pattern can match a part of the string starting from position [start]. |
39 * Returns `null` if the pattern doesn't match. | 41 * Returns `null` if the pattern doesn't match. |
40 */ | 42 */ |
41 Match matchAsPrefix(String string, [int start = 0]); | 43 Match matchAsPrefix(String string, [int start = 0]); |
42 } | 44 } |
OLD | NEW |