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

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

Issue 23566008: Rename Match.str to input. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months 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
« no previous file with comments | « sdk/lib/_internal/lib/core_patch.dart ('k') | no next file » | 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) 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 part of dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * [Match] contains methods to manipulate a regular expression match. 8 * [Match] contains methods to manipulate a pattern match.
9 * 9 *
10 * Iterables of [Match] objects are returned from [RegExp] matching methods. 10 * A [Match] or and iterable of [Match] objects are returned from [Pattern]
11 * matching methods.
11 * 12 *
12 * The following example finds all matches of a [RegExp] in a [String] 13 * The following example finds all matches of a [RegExp] in a [String]
13 * and iterates through the returned iterable of [Match] objects. 14 * and iterates through the returned iterable of [Match] objects.
14 * 15 *
15 * RegExp exp = new RegExp(r"(\w+)"); 16 * RegExp exp = new RegExp(r"(\w+)");
16 * String str = "Parse my string"; 17 * String str = "Parse my string";
17 * Iterable<Match> matches = exp.allMatches(str); 18 * Iterable<Match> matches = exp.allMatches(str);
18 * for (Match m in matches) { 19 * for (Match m in matches) {
19 * String match = m.group(0); 20 * String match = m.group(0);
20 * print(match); 21 * print(match);
21 * } 22 * }
22 * 23 *
23 * The output of the example is: 24 * The output of the example is:
24 * 25 *
25 * Parse 26 * Parse
26 * my 27 * my
27 * string 28 * string
29 *
30 * Some patterns, regular expressions in particular, may record subtrings
31 * that were part of the matching. These are called "groups" in the `Match`
32 * object. Some patterns may never have any groups, and their matches always
33 * have zero [groupCount].
28 */ 34 */
29 abstract class Match { 35 abstract class Match {
30 /** 36 /**
31 * Returns the index in the string where the match starts. 37 * Returns the index in the string where the match starts.
32 */ 38 */
33 int get start; 39 int get start;
34 40
35 /** 41 /**
36 * Returns the index in the string after the last character of the 42 * Returns the index in the string after the last character of the
37 * match. 43 * match.
38 */ 44 */
39 int get end; 45 int get end;
40 46
41 /** 47 /**
42 * Returns the string matched by the given [group]. If [group] is 0, 48 * Returns the string matched by the given [group].
43 * returns the match of the regular expression. 49 *
50 * If [group] is 0, returns the match of the pattern.
51 *
52 * The result may be `null` if the pattern didn't assign a value to it
53 * as part of this match.
44 */ 54 */
45 String group(int group); 55 String group(int group);
56
57 /**
58 * Returns the string matched by the given [group].
59 *
60 * If [group] is 0, returns the match of the pattern.
61 *
62 * Short alias for [Match.group].
63 */
46 String operator [](int group); 64 String operator [](int group);
47 65
48 /** 66 /**
49 * Returns the strings matched by [groups]. The order in the 67 * Returns a list of the full match and all the captured groups.
50 * returned string follows the order in [groups]. 68 *
69 * The list contains the strings returned by [group] for arguments from
70 * `0` to [groupCount] (inclusive), in that order.
floitsch 2013/08/28 09:34:50 That sounds wrong. This returns the groups request
Lasse Reichstein Nielsen 2013/08/28 10:43:24 Ack, I missed that there was an argument. Why is t
51 */ 71 */
52 List<String> groups(List<int> groups); 72 List<String> groups(List<int> groups);
53 73
54 /** 74 /**
55 * Returns the number of groups in the regular expression. 75 * Returns the number of captured groups in the match.
76 *
77 * Some patterns may capture parts of the input that was used to
78 * compute the full match. This is the number of captured groups,
79 * which is also the maximal allowed argument to the [group] method.
56 */ 80 */
57 int get groupCount; 81 int get groupCount;
58 82
59 /** 83 /**
60 * The string on which this matcher was computed. 84 * The string on which this match was computed.
61 */ 85 */
62 String get str; 86 String get input;
63 87
64 /** 88 /**
65 * The pattern used to search in [str]. 89 * Deprecated alias for [input].
90 *
91 * Will be removed soon.
floitsch 2013/08/28 09:34:50 If possible mark this an @deprecated so that users
Lasse Reichstein Nielsen 2013/08/28 10:43:24 Do we STILL have that silly declaration in _collec
92 */
93 String get src;
94
95 /**
96 * The pattern used to search in [input].
66 */ 97 */
67 Pattern get pattern; 98 Pattern get pattern;
68 } 99 }
69 100
70 101
71 /** 102 /**
72 * A class for working with regular expressions. 103 * A regular expression pattern.
104 *
105 * Regular expressions are [Pattern]s, and can as such be used to match strings
106 * or parts of strings.
73 * 107 *
74 * Dart regular expressions have the same syntax and semantics as 108 * Dart regular expressions have the same syntax and semantics as
75 * JavaScript regular expressions. See 109 * JavaScript regular expressions. See
76 * <http://ecma-international.org/ecma-262/5.1/#sec-15.10> 110 * <http://ecma-international.org/ecma-262/5.1/#sec-15.10>
77 * for the specification of JavaScript regular expressions. 111 * for the specification of JavaScript regular expressions.
78 * 112 *
79 * [firstMatch] is the main implementation method that applies a regular 113 * [firstMatch] is the main implementation method that applies a regular
80 * expression to a string and returns the first [Match]. All 114 * expression to a string and returns the first [Match]. All
81 * other methods in [RegExp] can build on it. 115 * other methods in [RegExp] can build on it.
82 * 116 *
83 * Use [allMatches] to look for all matches of a regular expression in 117 * Use [allMatches] to look for all matches of a regular expression in
84 * a string. 118 * a string.
85 * 119 *
86 * The following example finds all matches of a regular expression in 120 * The following example finds all matches of a regular expression in
87 * a string. 121 * a string.
88 * 122 *
89 * RegExp exp = new RegExp(r"(\w+)"); 123 * RegExp exp = new RegExp(r"(\w+)");
90 * String str = "Parse my string"; 124 * String str = "Parse my string";
91 * Iterable<Match> matches = exp.allMatches(str); 125 * Iterable<Match> matches = exp.allMatches(str);
92 */ 126 */
93 abstract class RegExp implements Pattern { 127 abstract class RegExp implements Pattern {
94 /** 128 /**
95 * Constructs a regular expression. The default implementation of a 129 * Constructs a regular expression.
96 * [RegExp] sets [multiLine] to false and [caseSensitive] to true. 130 *
97 * Throws a [FormatException] if [pattern] is not a valid regular 131 * Throws a [FormatException] if [source] is not valid regular
98 * exression pattern. 132 * expression syntax.
99 */ 133 */
100 external factory RegExp(String pattern, {bool multiLine: false, 134 external factory RegExp(String source, {bool multiLine: false,
101 bool caseSensitive: true}); 135 bool caseSensitive: true});
102 136
103 /** 137 /**
104 * Searches for the first match of the regular expression 138 * Searches for the first match of the regular expression
105 * in the string [str]. Returns `null` if there is no match. 139 * in the string [input]. Returns `null` if there is no match.
106 */ 140 */
107 Match firstMatch(String str); 141 Match firstMatch(String input);
108 142
109 /** 143 /**
110 * Returns an iterable on the matches of the regular 144 * Returns an iterable of the matches of the regular expression on [input].
111 * expression in [str].
112 */ 145 */
113 Iterable<Match> allMatches(String str); 146 Iterable<Match> allMatches(String input);
114 147
115 /** 148 /**
116 * Returns whether the regular expression has a match in the string [str]. 149 * Returns whether the regular expression has a match in the string [input].
117 */ 150 */
118 bool hasMatch(String str); 151 bool hasMatch(String input);
119 152
120 /** 153 /**
121 * Searches for the first match of the regular expression 154 * Returns the first substring match of this regular expression in [input].
122 * in the string [str] and returns the matched string.
123 */ 155 */
124 String stringMatch(String str); 156 String stringMatch(String input);
125 157
126 /** 158 /**
127 * The pattern of this regular expression. 159 * The pattern of this regular expression.
128 */ 160 */
129 String get pattern; 161 String get pattern;
130 162
131 /** 163 /**
132 * Whether this regular expression matches multiple lines. 164 * Whether this regular expression matches multiple lines.
165 *
166 * If the regexp does match multiple lines, the "^" and "$" characters
167 * match the beginning and end of lines. If not, the character match the
168 * beginning and end of the input.
133 */ 169 */
134 bool get isMultiLine; 170 bool get isMultiLine;
135 171
136 /** 172 /**
137 * Whether this regular expression is case insensitive. 173 * Whether this regular expression is case sensitive.
174 *
175 * If the regular expression is not case sensitive, it will match an input
176 * letter with a pattern letter even if the two letters are different case
177 * versions of the same letter.
138 */ 178 */
139 bool get isCaseSensitive; 179 bool get isCaseSensitive;
140 } 180 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/lib/core_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698