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

Side by Side Diff: sdk/lib/core/pattern.dart

Issue 1498963004: Move the `Match` class from core/regex.dart to core/pattern.dart (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | sdk/lib/core/regexp.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
(...skipping 24 matching lines...) Expand all
35 * Match this pattern against the start of `string`. 35 * Match this pattern against the start of `string`.
36 * 36 *
37 * 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` ..
38 * `string.length`. In that case, this patten is tested against the 38 * `string.length`. In that case, this patten is tested against the
39 * 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
40 * 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].
41 * Returns `null` if the pattern doesn't match. 41 * Returns `null` if the pattern doesn't match.
42 */ 42 */
43 Match matchAsPrefix(String string, [int start = 0]); 43 Match matchAsPrefix(String string, [int start = 0]);
44 } 44 }
45
46 /**
47 * A result from searching within a string.
48 *
49 * A Match or an [Iterable] of Match objects is returned from [Pattern]
50 * matching methods.
51 *
52 * The following example finds all matches of a [RegExp] in a [String]
53 * and iterates through the returned iterable of Match objects.
54 *
55 * RegExp exp = new RegExp(r"(\w+)");
56 * String str = "Parse my string";
57 * Iterable<Match> matches = exp.allMatches(str);
58 * for (Match m in matches) {
59 * String match = m.group(0);
60 * print(match);
61 * }
62 *
63 * The output of the example is:
64 *
65 * Parse
66 * my
67 * string
68 *
69 * Some patterns, regular expressions in particular, may record subtrings
70 * that were part of the matching. These are called _groups_ in the Match
71 * object. Some patterns may never have any groups, and their matches always
72 * have zero [groupCount].
73 */
74 abstract class Match {
75 /**
76 * Returns the index in the string where the match starts.
77 */
78 int get start;
79
80 /**
81 * Returns the index in the string after the last character of the
82 * match.
83 */
84 int get end;
85
86 /**
87 * Returns the string matched by the given [group].
88 *
89 * If [group] is 0, returns the match of the pattern.
90 *
91 * The result may be `null` if the pattern didn't assign a value to it
92 * as part of this match.
93 */
94 String group(int group);
95
96 /**
97 * Returns the string matched by the given [group].
98 *
99 * If [group] is 0, returns the match of the pattern.
100 *
101 * Short alias for [Match.group].
102 */
103 String operator [](int group);
104
105 /**
106 * Returns a list of the groups with the given indices.
107 *
108 * The list contains the strings returned by [group] for each index in
109 * [groupIndices].
110 */
111 List<String> groups(List<int> groupIndices);
112
113 /**
114 * Returns the number of captured groups in the match.
115 *
116 * Some patterns may capture parts of the input that was used to
117 * compute the full match. This is the number of captured groups,
118 * which is also the maximal allowed argument to the [group] method.
119 */
120 int get groupCount;
121
122 /**
123 * The string on which this match was computed.
124 */
125 String get input;
126
127 /**
128 * The pattern used to search in [input].
129 */
130 Pattern get pattern;
131 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/core/regexp.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698