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