author | redestad |
Sat, 01 Jun 2019 03:18:23 +0200 | |
changeset 55141 | db105c4c5776 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
18787 | 2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.util.regex; |
|
27 |
||
28 |
/** |
|
29 |
* The result of a match operation. |
|
30 |
* |
|
31 |
* <p>This interface contains query methods used to determine the |
|
32 |
* results of a match against a regular expression. The match boundaries, |
|
33 |
* groups and group boundaries can be seen but not modified through |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
34 |
* a {@code MatchResult}. |
2 | 35 |
* |
36 |
* @author Michael McCloskey |
|
37 |
* @see Matcher |
|
38 |
* @since 1.5 |
|
39 |
*/ |
|
40 |
public interface MatchResult { |
|
41 |
||
42 |
/** |
|
43 |
* Returns the start index of the match. |
|
44 |
* |
|
45 |
* @return The index of the first character matched |
|
46 |
* |
|
47 |
* @throws IllegalStateException |
|
48 |
* If no match has yet been attempted, |
|
49 |
* or if the previous match operation failed |
|
50 |
*/ |
|
51 |
public int start(); |
|
52 |
||
53 |
/** |
|
54 |
* Returns the start index of the subsequence captured by the given group |
|
55 |
* during this match. |
|
56 |
* |
|
57 |
* <p> <a href="Pattern.html#cg">Capturing groups</a> are indexed from left |
|
58 |
* to right, starting at one. Group zero denotes the entire pattern, so |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
59 |
* the expression <i>m.</i>{@code start(0)} is equivalent to |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
60 |
* <i>m.</i>{@code start()}. </p> |
2 | 61 |
* |
62 |
* @param group |
|
63 |
* The index of a capturing group in this matcher's pattern |
|
64 |
* |
|
65 |
* @return The index of the first character captured by the group, |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
66 |
* or {@code -1} if the match was successful but the group |
2 | 67 |
* itself did not match anything |
68 |
* |
|
69 |
* @throws IllegalStateException |
|
70 |
* If no match has yet been attempted, |
|
71 |
* or if the previous match operation failed |
|
72 |
* |
|
73 |
* @throws IndexOutOfBoundsException |
|
74 |
* If there is no capturing group in the pattern |
|
75 |
* with the given index |
|
76 |
*/ |
|
77 |
public int start(int group); |
|
78 |
||
79 |
/** |
|
18787 | 80 |
* Returns the offset after the last character matched. |
2 | 81 |
* |
18156 | 82 |
* @return The offset after the last character matched |
2 | 83 |
* |
84 |
* @throws IllegalStateException |
|
85 |
* If no match has yet been attempted, |
|
86 |
* or if the previous match operation failed |
|
87 |
*/ |
|
88 |
public int end(); |
|
89 |
||
90 |
/** |
|
91 |
* Returns the offset after the last character of the subsequence |
|
92 |
* captured by the given group during this match. |
|
93 |
* |
|
94 |
* <p> <a href="Pattern.html#cg">Capturing groups</a> are indexed from left |
|
95 |
* to right, starting at one. Group zero denotes the entire pattern, so |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
96 |
* the expression <i>m.</i>{@code end(0)} is equivalent to |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
97 |
* <i>m.</i>{@code end()}. </p> |
2 | 98 |
* |
99 |
* @param group |
|
100 |
* The index of a capturing group in this matcher's pattern |
|
101 |
* |
|
102 |
* @return The offset after the last character captured by the group, |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
103 |
* or {@code -1} if the match was successful |
2 | 104 |
* but the group itself did not match anything |
105 |
* |
|
106 |
* @throws IllegalStateException |
|
107 |
* If no match has yet been attempted, |
|
108 |
* or if the previous match operation failed |
|
109 |
* |
|
110 |
* @throws IndexOutOfBoundsException |
|
111 |
* If there is no capturing group in the pattern |
|
112 |
* with the given index |
|
113 |
*/ |
|
114 |
public int end(int group); |
|
115 |
||
116 |
/** |
|
117 |
* Returns the input subsequence matched by the previous match. |
|
118 |
* |
|
119 |
* <p> For a matcher <i>m</i> with input sequence <i>s</i>, |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
120 |
* the expressions <i>m.</i>{@code group()} and |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
121 |
* <i>s.</i>{@code substring(}<i>m.</i>{@code start(),} <i>m.</i>{@code end())} |
2 | 122 |
* are equivalent. </p> |
123 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
124 |
* <p> Note that some patterns, for example {@code a*}, match the empty |
2 | 125 |
* string. This method will return the empty string when the pattern |
126 |
* successfully matches the empty string in the input. </p> |
|
127 |
* |
|
128 |
* @return The (possibly empty) subsequence matched by the previous match, |
|
129 |
* in string form |
|
130 |
* |
|
131 |
* @throws IllegalStateException |
|
132 |
* If no match has yet been attempted, |
|
133 |
* or if the previous match operation failed |
|
134 |
*/ |
|
135 |
public String group(); |
|
136 |
||
137 |
/** |
|
138 |
* Returns the input subsequence captured by the given group during the |
|
139 |
* previous match operation. |
|
140 |
* |
|
141 |
* <p> For a matcher <i>m</i>, input sequence <i>s</i>, and group index |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
142 |
* <i>g</i>, the expressions <i>m.</i>{@code group(}<i>g</i>{@code )} and |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
143 |
* <i>s.</i>{@code substring(}<i>m.</i>{@code start(}<i>g</i>{@code |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
144 |
* ),} <i>m.</i>{@code end(}<i>g</i>{@code ))} |
2 | 145 |
* are equivalent. </p> |
146 |
* |
|
147 |
* <p> <a href="Pattern.html#cg">Capturing groups</a> are indexed from left |
|
148 |
* to right, starting at one. Group zero denotes the entire pattern, so |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
149 |
* the expression {@code m.group(0)} is equivalent to {@code m.group()}. |
2 | 150 |
* </p> |
151 |
* |
|
152 |
* <p> If the match was successful but the group specified failed to match |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
153 |
* any part of the input sequence, then {@code null} is returned. Note |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
154 |
* that some groups, for example {@code (a*)}, match the empty string. |
2 | 155 |
* This method will return the empty string when such a group successfully |
156 |
* matches the empty string in the input. </p> |
|
157 |
* |
|
158 |
* @param group |
|
159 |
* The index of a capturing group in this matcher's pattern |
|
160 |
* |
|
161 |
* @return The (possibly empty) subsequence captured by the group |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
162 |
* during the previous match, or {@code null} if the group |
2 | 163 |
* failed to match part of the input |
164 |
* |
|
165 |
* @throws IllegalStateException |
|
166 |
* If no match has yet been attempted, |
|
167 |
* or if the previous match operation failed |
|
168 |
* |
|
169 |
* @throws IndexOutOfBoundsException |
|
170 |
* If there is no capturing group in the pattern |
|
171 |
* with the given index |
|
172 |
*/ |
|
173 |
public String group(int group); |
|
174 |
||
175 |
/** |
|
176 |
* Returns the number of capturing groups in this match result's pattern. |
|
177 |
* |
|
178 |
* <p> Group zero denotes the entire pattern by convention. It is not |
|
179 |
* included in this count. |
|
180 |
* |
|
181 |
* <p> Any non-negative integer smaller than or equal to the value |
|
182 |
* returned by this method is guaranteed to be a valid group index for |
|
183 |
* this matcher. </p> |
|
184 |
* |
|
185 |
* @return The number of capturing groups in this matcher's pattern |
|
186 |
*/ |
|
187 |
public int groupCount(); |
|
188 |
||
189 |
} |