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