/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A compiled representation of a regular expression.
*
* <p> A regular expression, specified as a string, must first be compiled into
* an instance of this class. The resulting pattern can then be used to create
* a {@link Matcher} object that can match arbitrary {@link
* java.lang.CharSequence </code>character sequences<code>} against the regular
* expression. All of the state involved in performing a match resides in the
* matcher, so many matchers can share the same pattern.
*
* <p> A typical invocation sequence is thus
*
* <blockquote><pre>
* Pattern p = Pattern.{@link #compile compile}("a*b");
* Matcher m = p.{@link #matcher matcher}("aaaaab");
* boolean b = m.{@link Matcher#matches matches}();</pre></blockquote>
*
* <p> A {@link #matches matches} method is defined by this class as a
* convenience for when a regular expression is used just once. This method
* compiles an expression and matches an input sequence against it in a single
* invocation. The statement
*
* <blockquote><pre>
* boolean b = Pattern.matches("a*b", "aaaaab");</pre></blockquote>
*
* is equivalent to the three statements above, though for repeated matches it
* is less efficient since it does not allow the compiled pattern to be reused.
*
* <p> Instances of this class are immutable and are safe for use by multiple
* concurrent threads. Instances of the {@link Matcher} class are not safe for
* such use.
*
*
* <a name="sum">
* <h4> Summary of regular-expression constructs </h4>
*
* <table border="0" cellpadding="1" cellspacing="0"
* summary="Regular expression constructs, and what they match">
*
* <tr align="left">
* <th bgcolor="#CCCCFF" align="left" id="construct">Construct</th>
* <th bgcolor="#CCCCFF" align="left" id="matches">Matches</th>
* </tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="characters">Characters</th></tr>
*
* <tr><td valign="top" headers="construct characters"><i>x</i></td>
* <td headers="matches">The character <i>x</i></td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\\</tt></td>
* <td headers="matches">The backslash character</td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\0</tt><i>n</i></td>
* <td headers="matches">The character with octal value <tt>0</tt><i>n</i>
* (0 <tt><=</tt> <i>n</i> <tt><=</tt> 7)</td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\0</tt><i>nn</i></td>
* <td headers="matches">The character with octal value <tt>0</tt><i>nn</i>
* (0 <tt><=</tt> <i>n</i> <tt><=</tt> 7)</td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\0</tt><i>mnn</i></td>
* <td headers="matches">The character with octal value <tt>0</tt><i>mnn</i>
* (0 <tt><=</tt> <i>m</i> <tt><=</tt> 3,
* 0 <tt><=</tt> <i>n</i> <tt><=</tt> 7)</td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\x</tt><i>hh</i></td>
* <td headers="matches">The character with hexadecimal value <tt>0x</tt><i>hh</i></td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\u</tt><i>hhhh</i></td>
* <td headers="matches">The character with hexadecimal value <tt>0x</tt><i>hhhh</i></td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\x</tt><i>{h...h}</i></td>
* <td headers="matches">The character with hexadecimal value <tt>0x</tt><i>h...h</i>
* ({@link java.lang.Character#MIN_CODE_POINT Character.MIN_CODE_POINT}
* <= <tt>0x</tt><i>h...h</i> <= 
* {@link java.lang.Character#MAX_CODE_POINT Character.MAX_CODE_POINT})</td></tr>
* <tr><td valign="top" headers="matches"><tt>\t</tt></td>
* <td headers="matches">The tab character (<tt>'\u0009'</tt>)</td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\n</tt></td>
* <td headers="matches">The newline (line feed) character (<tt>'\u000A'</tt>)</td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\r</tt></td>
* <td headers="matches">The carriage-return character (<tt>'\u000D'</tt>)</td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\f</tt></td>
* <td headers="matches">The form-feed character (<tt>'\u000C'</tt>)</td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\a</tt></td>
* <td headers="matches">The alert (bell) character (<tt>'\u0007'</tt>)</td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\e</tt></td>
* <td headers="matches">The escape character (<tt>'\u001B'</tt>)</td></tr>
* <tr><td valign="top" headers="construct characters"><tt>\c</tt><i>x</i></td>
* <td headers="matches">The control character corresponding to <i>x</i></td></tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="classes">Character classes</th></tr>
*
* <tr><td valign="top" headers="construct classes"><tt>[abc]</tt></td>
* <td headers="matches"><tt>a</tt>, <tt>b</tt>, or <tt>c</tt> (simple class)</td></tr>
* <tr><td valign="top" headers="construct classes"><tt>[^abc]</tt></td>
* <td headers="matches">Any character except <tt>a</tt>, <tt>b</tt>, or <tt>c</tt> (negation)</td></tr>
* <tr><td valign="top" headers="construct classes"><tt>[a-zA-Z]</tt></td>
* <td headers="matches"><tt>a</tt> through <tt>z</tt>
* or <tt>A</tt> through <tt>Z</tt>, inclusive (range)</td></tr>
* <tr><td valign="top" headers="construct classes"><tt>[a-d[m-p]]</tt></td>
* <td headers="matches"><tt>a</tt> through <tt>d</tt>,
* or <tt>m</tt> through <tt>p</tt>: <tt>[a-dm-p]</tt> (union)</td></tr>
* <tr><td valign="top" headers="construct classes"><tt>[a-z&&[def]]</tt></td>
* <td headers="matches"><tt>d</tt>, <tt>e</tt>, or <tt>f</tt> (intersection)</tr>
* <tr><td valign="top" headers="construct classes"><tt>[a-z&&[^bc]]</tt></td>
* <td headers="matches"><tt>a</tt> through <tt>z</tt>,
* except for <tt>b</tt> and <tt>c</tt>: <tt>[ad-z]</tt> (subtraction)</td></tr>
* <tr><td valign="top" headers="construct classes"><tt>[a-z&&[^m-p]]</tt></td>
* <td headers="matches"><tt>a</tt> through <tt>z</tt>,
* and not <tt>m</tt> through <tt>p</tt>: <tt>[a-lq-z]</tt>(subtraction)</td></tr>
* <tr><th> </th></tr>
*
* <tr align="left"><th colspan="2" id="predef">Predefined character classes</th></tr>
*
* <tr><td valign="top" headers="construct predef"><tt>.</tt></td>
* <td headers="matches">Any character (may or may not match <a href="#lt">line terminators</a>)</td></tr>
* <tr><td valign="top" headers="construct predef"><tt>\d</tt></td>
* <td headers="matches">A digit: <tt>[0-9]</tt></td></tr>
* <tr><td valign="top" headers="construct predef"><tt>\D</tt></td>
* <td headers="matches">A non-digit: <tt>[^0-9]</tt></td></tr>
* <tr><td valign="top" headers="construct predef"><tt>\s</tt></td>
* <td headers="matches">A whitespace character: <tt>[ \t\n\x0B\f\r]</tt></td></tr>
* <tr><td valign="top" headers="construct predef"><tt>\S</tt></td>
* <td headers="matches">A non-whitespace character: <tt>[^\s]</tt></td></tr>
* <tr><td valign="top" headers="construct predef"><tt>\w</tt></td>
* <td headers="matches">A word character: <tt>[a-zA-Z_0-9]</tt></td></tr>
* <tr><td valign="top" headers="construct predef"><tt>\W</tt></td>
* <td headers="matches">A non-word character: <tt>[^\w]</tt></td></tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="posix">POSIX character classes</b> (US-ASCII only)<b></th></tr>
*
* <tr><td valign="top" headers="construct posix"><tt>\p{Lower}</tt></td>
* <td headers="matches">A lower-case alphabetic character: <tt>[a-z]</tt></td></tr>
* <tr><td valign="top" headers="construct posix"><tt>\p{Upper}</tt></td>
* <td headers="matches">An upper-case alphabetic character:<tt>[A-Z]</tt></td></tr>
* <tr><td valign="top" headers="construct posix"><tt>\p{ASCII}</tt></td>
* <td headers="matches">All ASCII:<tt>[\x00-\x7F]</tt></td></tr>
* <tr><td valign="top" headers="construct posix"><tt>\p{Alpha}</tt></td>
* <td headers="matches">An alphabetic character:<tt>[\p{Lower}\p{Upper}]</tt></td></tr>
* <tr><td valign="top" headers="construct posix"><tt>\p{Digit}</tt></td>
* <td headers="matches">A decimal digit: <tt>[0-9]</tt></td></tr>
* <tr><td valign="top" headers="construct posix"><tt>\p{Alnum}</tt></td>
* <td headers="matches">An alphanumeric character:<tt>[\p{Alpha}\p{Digit}]</tt></td></tr>
* <tr><td valign="top" headers="construct posix"><tt>\p{Punct}</tt></td>
* <td headers="matches">Punctuation: One of <tt>!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~</tt></td></tr>
* <!-- <tt>[\!"#\$%&'\(\)\*\+,\-\./:;\<=\>\?@\[\\\]\^_`\{\|\}~]</tt>
* <tt>[\X21-\X2F\X31-\X40\X5B-\X60\X7B-\X7E]</tt> -->
* <tr><td valign="top" headers="construct posix"><tt>\p{Graph}</tt></td>
* <td headers="matches">A visible character: <tt>[\p{Alnum}\p{Punct}]</tt></td></tr>
* <tr><td valign="top" headers="construct posix"><tt>\p{Print}</tt></td>
* <td headers="matches">A printable character: <tt>[\p{Graph}\x20]</tt></td></tr>
* <tr><td valign="top" headers="construct posix"><tt>\p{Blank}</tt></td>
* <td headers="matches">A space or a tab: <tt>[ \t]</tt></td></tr>
* <tr><td valign="top" headers="construct posix"><tt>\p{Cntrl}</tt></td>
* <td headers="matches">A control character: <tt>[\x00-\x1F\x7F]</tt></td></tr>
* <tr><td valign="top" headers="construct posix"><tt>\p{XDigit}</tt></td>
* <td headers="matches">A hexadecimal digit: <tt>[0-9a-fA-F]</tt></td></tr>
* <tr><td valign="top" headers="construct posix"><tt>\p{Space}</tt></td>
* <td headers="matches">A whitespace character: <tt>[ \t\n\x0B\f\r]</tt></td></tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2">java.lang.Character classes (simple <a href="#jcc">java character type</a>)</th></tr>
*
* <tr><td valign="top"><tt>\p{javaLowerCase}</tt></td>
* <td>Equivalent to java.lang.Character.isLowerCase()</td></tr>
* <tr><td valign="top"><tt>\p{javaUpperCase}</tt></td>
* <td>Equivalent to java.lang.Character.isUpperCase()</td></tr>
* <tr><td valign="top"><tt>\p{javaWhitespace}</tt></td>
* <td>Equivalent to java.lang.Character.isWhitespace()</td></tr>
* <tr><td valign="top"><tt>\p{javaMirrored}</tt></td>
* <td>Equivalent to java.lang.Character.isMirrored()</td></tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="unicode">Classes for Unicode scripts, blocks, categories and binary properties</th></tr>
* * <tr><td valign="top" headers="construct unicode"><tt>\p{IsLatin}</tt></td>
* <td headers="matches">A Latin script character (<a href="#usc">script</a>)</td></tr>
* <tr><td valign="top" headers="construct unicode"><tt>\p{InGreek}</tt></td>
* <td headers="matches">A character in the Greek block (<a href="#ubc">block</a>)</td></tr>
* <tr><td valign="top" headers="construct unicode"><tt>\p{Lu}</tt></td>
* <td headers="matches">An uppercase letter (<a href="#ucc">category</a>)</td></tr>
* <tr><td valign="top" headers="construct unicode"><tt>\p{IsAlphabetic}</tt></td>
* <td headers="matches">An alphabetic character (<a href="#ubpc">binary property</a>)</td></tr>
* <tr><td valign="top" headers="construct unicode"><tt>\p{Sc}</tt></td>
* <td headers="matches">A currency symbol</td></tr>
* <tr><td valign="top" headers="construct unicode"><tt>\P{InGreek}</tt></td>
* <td headers="matches">Any character except one in the Greek block (negation)</td></tr>
* <tr><td valign="top" headers="construct unicode"><tt>[\p{L}&&[^\p{Lu}]] </tt></td>
* <td headers="matches">Any letter except an uppercase letter (subtraction)</td></tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="bounds">Boundary matchers</th></tr>
*
* <tr><td valign="top" headers="construct bounds"><tt>^</tt></td>
* <td headers="matches">The beginning of a line</td></tr>
* <tr><td valign="top" headers="construct bounds"><tt>$</tt></td>
* <td headers="matches">The end of a line</td></tr>
* <tr><td valign="top" headers="construct bounds"><tt>\b</tt></td>
* <td headers="matches">A word boundary</td></tr>
* <tr><td valign="top" headers="construct bounds"><tt>\B</tt></td>
* <td headers="matches">A non-word boundary</td></tr>
* <tr><td valign="top" headers="construct bounds"><tt>\A</tt></td>
* <td headers="matches">The beginning of the input</td></tr>
* <tr><td valign="top" headers="construct bounds"><tt>\G</tt></td>
* <td headers="matches">The end of the previous match</td></tr>
* <tr><td valign="top" headers="construct bounds"><tt>\Z</tt></td>
* <td headers="matches">The end of the input but for the final
* <a href="#lt">terminator</a>, if any</td></tr>
* <tr><td valign="top" headers="construct bounds"><tt>\z</tt></td>
* <td headers="matches">The end of the input</td></tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="greedy">Greedy quantifiers</th></tr>
*
* <tr><td valign="top" headers="construct greedy"><i>X</i><tt>?</tt></td>
* <td headers="matches"><i>X</i>, once or not at all</td></tr>
* <tr><td valign="top" headers="construct greedy"><i>X</i><tt>*</tt></td>
* <td headers="matches"><i>X</i>, zero or more times</td></tr>
* <tr><td valign="top" headers="construct greedy"><i>X</i><tt>+</tt></td>
* <td headers="matches"><i>X</i>, one or more times</td></tr>
* <tr><td valign="top" headers="construct greedy"><i>X</i><tt>{</tt><i>n</i><tt>}</tt></td>
* <td headers="matches"><i>X</i>, exactly <i>n</i> times</td></tr>
* <tr><td valign="top" headers="construct greedy"><i>X</i><tt>{</tt><i>n</i><tt>,}</tt></td>
* <td headers="matches"><i>X</i>, at least <i>n</i> times</td></tr>
* <tr><td valign="top" headers="construct greedy"><i>X</i><tt>{</tt><i>n</i><tt>,</tt><i>m</i><tt>}</tt></td>
* <td headers="matches"><i>X</i>, at least <i>n</i> but not more than <i>m</i> times</td></tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="reluc">Reluctant quantifiers</th></tr>
*
* <tr><td valign="top" headers="construct reluc"><i>X</i><tt>??</tt></td>
* <td headers="matches"><i>X</i>, once or not at all</td></tr>
* <tr><td valign="top" headers="construct reluc"><i>X</i><tt>*?</tt></td>
* <td headers="matches"><i>X</i>, zero or more times</td></tr>
* <tr><td valign="top" headers="construct reluc"><i>X</i><tt>+?</tt></td>
* <td headers="matches"><i>X</i>, one or more times</td></tr>
* <tr><td valign="top" headers="construct reluc"><i>X</i><tt>{</tt><i>n</i><tt>}?</tt></td>
* <td headers="matches"><i>X</i>, exactly <i>n</i> times</td></tr>
* <tr><td valign="top" headers="construct reluc"><i>X</i><tt>{</tt><i>n</i><tt>,}?</tt></td>
* <td headers="matches"><i>X</i>, at least <i>n</i> times</td></tr>
* <tr><td valign="top" headers="construct reluc"><i>X</i><tt>{</tt><i>n</i><tt>,</tt><i>m</i><tt>}?</tt></td>
* <td headers="matches"><i>X</i>, at least <i>n</i> but not more than <i>m</i> times</td></tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="poss">Possessive quantifiers</th></tr>
*
* <tr><td valign="top" headers="construct poss"><i>X</i><tt>?+</tt></td>
* <td headers="matches"><i>X</i>, once or not at all</td></tr>
* <tr><td valign="top" headers="construct poss"><i>X</i><tt>*+</tt></td>
* <td headers="matches"><i>X</i>, zero or more times</td></tr>
* <tr><td valign="top" headers="construct poss"><i>X</i><tt>++</tt></td>
* <td headers="matches"><i>X</i>, one or more times</td></tr>
* <tr><td valign="top" headers="construct poss"><i>X</i><tt>{</tt><i>n</i><tt>}+</tt></td>
* <td headers="matches"><i>X</i>, exactly <i>n</i> times</td></tr>
* <tr><td valign="top" headers="construct poss"><i>X</i><tt>{</tt><i>n</i><tt>,}+</tt></td>
* <td headers="matches"><i>X</i>, at least <i>n</i> times</td></tr>
* <tr><td valign="top" headers="construct poss"><i>X</i><tt>{</tt><i>n</i><tt>,</tt><i>m</i><tt>}+</tt></td>
* <td headers="matches"><i>X</i>, at least <i>n</i> but not more than <i>m</i> times</td></tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="logical">Logical operators</th></tr>
*
* <tr><td valign="top" headers="construct logical"><i>XY</i></td>
* <td headers="matches"><i>X</i> followed by <i>Y</i></td></tr>
* <tr><td valign="top" headers="construct logical"><i>X</i><tt>|</tt><i>Y</i></td>
* <td headers="matches">Either <i>X</i> or <i>Y</i></td></tr>
* <tr><td valign="top" headers="construct logical"><tt>(</tt><i>X</i><tt>)</tt></td>
* <td headers="matches">X, as a <a href="#cg">capturing group</a></td></tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="backref">Back references</th></tr>
*
* <tr><td valign="bottom" headers="construct backref"><tt>\</tt><i>n</i></td>
* <td valign="bottom" headers="matches">Whatever the <i>n</i><sup>th</sup>
* <a href="#cg">capturing group</a> matched</td></tr>
*
* <tr><td valign="bottom" headers="construct backref"><tt>\</tt><i>k</i><<i>name</i>></td>
* <td valign="bottom" headers="matches">Whatever the
* <a href="#groupname">named-capturing group</a> "name" matched</td></tr>
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="quot">Quotation</th></tr>
*
* <tr><td valign="top" headers="construct quot"><tt>\</tt></td>
* <td headers="matches">Nothing, but quotes the following character</td></tr>
* <tr><td valign="top" headers="construct quot"><tt>\Q</tt></td>
* <td headers="matches">Nothing, but quotes all characters until <tt>\E</tt></td></tr>
* <tr><td valign="top" headers="construct quot"><tt>\E</tt></td>
* <td headers="matches">Nothing, but ends quoting started by <tt>\Q</tt></td></tr>
* <!-- Metachars: !$()*+.<>?[\]^{|} -->
*
* <tr><th> </th></tr>
* <tr align="left"><th colspan="2" id="special">Special constructs (named-capturing and non-capturing)</th></tr>
*
* <tr><td valign="top" headers="construct special"><tt>(?<<a href="#groupname">name</a>></tt><i>X</i><tt>)</tt></td>
* <td headers="matches"><i>X</i>, as a named-capturing group</td></tr>
* <tr><td valign="top" headers="construct special"><tt>(?:</tt><i>X</i><tt>)</tt></td>
* <td headers="matches"><i>X</i>, as a non-capturing group</td></tr>
* <tr><td valign="top" headers="construct special"><tt>(?idmsuxU-idmsuxU) </tt></td>
* <td headers="matches">Nothing, but turns match flags <a href="#CASE_INSENSITIVE">i</a>
* <a href="#UNIX_LINES">d</a> <a href="#MULTILINE">m</a> <a href="#DOTALL">s</a>
* <a href="#UNICODE_CASE">u</a> <a href="#COMMENTS">x</a> <a href="#UNICODE_CHARACTER_CLASS">U</a>
* on - off</td></tr>
* <tr><td valign="top" headers="construct special"><tt>(?idmsux-idmsux:</tt><i>X</i><tt>)</tt> </td>
* <td headers="matches"><i>X</i>, as a <a href="#cg">non-capturing group</a> with the
* given flags <a href="#CASE_INSENSITIVE">i</a> <a href="#UNIX_LINES">d</a>
* <a href="#MULTILINE">m</a> <a href="#DOTALL">s</a> <a href="#UNICODE_CASE">u</a >
* <a href="#COMMENTS">x</a> on - off</td></tr>
* <tr><td valign="top" headers="construct special"><tt>(?=</tt><i>X</i><tt>)</tt></td>
* <td headers="matches"><i>X</i>, via zero-width positive lookahead</td></tr>
* <tr><td valign="top" headers="construct special"><tt>(?!</tt><i>X</i><tt>)</tt></td>
* <td headers="matches"><i>X</i>, via zero-width negative lookahead</td></tr>
* <tr><td valign="top" headers="construct special"><tt>(?<=</tt><i>X</i><tt>)</tt></td>
* <td headers="matches"><i>X</i>, via zero-width positive lookbehind</td></tr>
* <tr><td valign="top" headers="construct special"><tt>(?<!</tt><i>X</i><tt>)</tt></td>
* <td headers="matches"><i>X</i>, via zero-width negative lookbehind</td></tr>
* <tr><td valign="top" headers="construct special"><tt>(?></tt><i>X</i><tt>)</tt></td>
* <td headers="matches"><i>X</i>, as an independent, non-capturing group</td></tr>
*
* </table>
*
* <hr>
*
*
* <a name="bs">
* <h4> Backslashes, escapes, and quoting </h4>
*
* <p> The backslash character (<tt>'\'</tt>) serves to introduce escaped
* constructs, as defined in the table above, as well as to quote characters
* that otherwise would be interpreted as unescaped constructs. Thus the
* expression <tt>\\</tt> matches a single backslash and <tt>\{</tt> matches a
* left brace.
*
* <p> It is an error to use a backslash prior to any alphabetic character that
* does not denote an escaped construct; these are reserved for future
* extensions to the regular-expression language. A backslash may be used
* prior to a non-alphabetic character regardless of whether that character is
* part of an unescaped construct.
*
* <p> Backslashes within string literals in Java source code are interpreted
* as required by
* <cite>The Java™ Language Specification</cite>
* as either Unicode escapes (section 3.3) or other character escapes (section 3.10.6)
* It is therefore necessary to double backslashes in string
* literals that represent regular expressions to protect them from
* interpretation by the Java bytecode compiler. The string literal
* <tt>"\b"</tt>, for example, matches a single backspace character when
* interpreted as a regular expression, while <tt>"\\b"</tt> matches a
* word boundary. The string literal <tt>"\(hello\)"</tt> is illegal
* and leads to a compile-time error; in order to match the string
* <tt>(hello)</tt> the string literal <tt>"\\(hello\\)"</tt>
* must be used.
*
* <a name="cc">
* <h4> Character Classes </h4>
*
* <p> Character classes may appear within other character classes, and
* may be composed by the union operator (implicit) and the intersection
* operator (<tt>&&</tt>).
* The union operator denotes a class that contains every character that is
* in at least one of its operand classes. The intersection operator
* denotes a class that contains every character that is in both of its
* operand classes.
*
* <p> The precedence of character-class operators is as follows, from
* highest to lowest:
*
* <blockquote><table border="0" cellpadding="1" cellspacing="0"
* summary="Precedence of character class operators.">
* <tr><th>1 </th>
* <td>Literal escape </td>
* <td><tt>\x</tt></td></tr>
* <tr><th>2 </th>
* <td>Grouping</td>
* <td><tt>[...]</tt></td></tr>
* <tr><th>3 </th>
* <td>Range</td>
* <td><tt>a-z</tt></td></tr>
* <tr><th>4 </th>
* <td>Union</td>
* <td><tt>[a-e][i-u]</tt></td></tr>
* <tr><th>5 </th>
* <td>Intersection</td>
* <td><tt>[a-z&&[aeiou]]</tt></td></tr>
* </table></blockquote>
*
* <p> Note that a different set of metacharacters are in effect inside
* a character class than outside a character class. For instance, the
* regular expression <tt>.</tt> loses its special meaning inside a
* character class, while the expression <tt>-</tt> becomes a range
* forming metacharacter.
*
* <a name="lt">
* <h4> Line terminators </h4>
*
* <p> A <i>line terminator</i> is a one- or two-character sequence that marks
* the end of a line of the input character sequence. The following are
* recognized as line terminators:
*
* <ul>
*
* <li> A newline (line feed) character (<tt>'\n'</tt>),
*
* <li> A carriage-return character followed immediately by a newline
* character (<tt>"\r\n"</tt>),
*
* <li> A standalone carriage-return character (<tt>'\r'</tt>),
*
* <li> A next-line character (<tt>'\u0085'</tt>),
*
* <li> A line-separator character (<tt>'\u2028'</tt>), or
*
* <li> A paragraph-separator character (<tt>'\u2029</tt>).
*
* </ul>
* <p>If {@link #UNIX_LINES} mode is activated, then the only line terminators
* recognized are newline characters.
*
* <p> The regular expression <tt>.</tt> matches any character except a line
* terminator unless the {@link #DOTALL} flag is specified.
*
* <p> By default, the regular expressions <tt>^</tt> and <tt>$</tt> ignore
* line terminators and only match at the beginning and the end, respectively,
* of the entire input sequence. If {@link #MULTILINE} mode is activated then
* <tt>^</tt> matches at the beginning of input and after any line terminator
* except at the end of input. When in {@link #MULTILINE} mode <tt>$</tt>
* matches just before a line terminator or the end of the input sequence.
*
* <a name="cg">
* <h4> Groups and capturing </h4>
*
* <a name="gnumber">
* <h5> Group number </h5>
* <p> Capturing groups are numbered by counting their opening parentheses from
* left to right. In the expression <tt>((A)(B(C)))</tt>, for example, there
* are four such groups: </p>
*
* <blockquote><table cellpadding=1 cellspacing=0 summary="Capturing group numberings">
* <tr><th>1 </th>
* <td><tt>((A)(B(C)))</tt></td></tr>
* <tr><th>2 </th>
* <td><tt>(A)</tt></td></tr>
* <tr><th>3 </th>
* <td><tt>(B(C))</tt></td></tr>
* <tr><th>4 </th>
* <td><tt>(C)</tt></td></tr>
* </table></blockquote>
*
* <p> Group zero always stands for the entire expression.
*
* <p> Capturing groups are so named because, during a match, each subsequence
* of the input sequence that matches such a group is saved. The captured
* subsequence may be used later in the expression, via a back reference, and
* may also be retrieved from the matcher once the match operation is complete.
*
* <a name="groupname">
* <h5> Group name </h5>
* <p>A capturing group can also be assigned a "name", a <tt>named-capturing group</tt>,
* and then be back-referenced later by the "name". Group names are composed of
* the following characters. The first character must be a <tt>letter</tt>.
*
* <ul>
* <li> The uppercase letters <tt>'A'</tt> through <tt>'Z'</tt>
* (<tt>'\u0041'</tt> through <tt>'\u005a'</tt>),
* <li> The lowercase letters <tt>'a'</tt> through <tt>'z'</tt>
* (<tt>'\u0061'</tt> through <tt>'\u007a'</tt>),
* <li> The digits <tt>'0'</tt> through <tt>'9'</tt>
* (<tt>'\u0030'</tt> through <tt>'\u0039'</tt>),
* </ul>
*
* <p> A <tt>named-capturing group</tt> is still numbered as described in
* <a href="#gnumber">Group number</a>.
*
* <p> The captured input associated with a group is always the subsequence
* that the group most recently matched. If a group is evaluated a second time
* because of quantification then its previously-captured value, if any, will
* be retained if the second evaluation fails. Matching the string
* <tt>"aba"</tt> against the expression <tt>(a(b)?)+</tt>, for example, leaves
* group two set to <tt>"b"</tt>. All captured input is discarded at the
* beginning of each match.
*
* <p> Groups beginning with <tt>(?</tt> are either pure, <i>non-capturing</i> groups
* that do not capture text and do not count towards the group total, or
* <i>named-capturing</i> group.
*
* <h4> Unicode support </h4>
*
* <p> This class is in conformance with Level 1 of <a
* href="http://www.unicode.org/reports/tr18/"><i>Unicode Technical
* Standard #18: Unicode Regular Expression</i></a>, plus RL2.1
* Canonical Equivalents.
* <p>
* <b>Unicode escape sequences</b> such as <tt>\u2014</tt> in Java source code
* are processed as described in section 3.3 of
* <cite>The Java™ Language Specification</cite>.
* Such escape sequences are also implemented directly by the regular-expression
* parser so that Unicode escapes can be used in expressions that are read from
* files or from the keyboard. Thus the strings <tt>"\u2014"</tt> and
* <tt>"\\u2014"</tt>, while not equal, compile into the same pattern, which
* matches the character with hexadecimal value <tt>0x2014</tt>.
* <p>
* A Unicode character can also be represented in a regular-expression by
* using its <b>Hex notation</b>(hexadecimal code point value) directly as described in construct
* <tt>\x{...}</tt>, for example a supplementary character U+2011F
* can be specified as <tt>\x{2011F}</tt>, instead of two consecutive
* Unicode escape sequences of the surrogate pair
* <tt>\uD840</tt><tt>\uDD1F</tt>.
* <p>
* Unicode scripts, blocks, categories and binary properties are written with
* the <tt>\p</tt> and <tt>\P</tt> constructs as in Perl.
* <tt>\p{</tt><i>prop</i><tt>}</tt> matches if
* the input has the property <i>prop</i>, while <tt>\P{</tt><i>prop</i><tt>}</tt>
* does not match if the input has that property.
* <p>
* Scripts, blocks, categories and binary properties can be used both inside
* and outside of a character class.
* <a name="usc">
* <p>
* <b>Scripts</b> are specified either with the prefix {@code Is}, as in
* {@code IsHiragana}, or by using the {@code script} keyword (or its short
* form {@code sc})as in {@code script=Hiragana} or {@code sc=Hiragana}.
* <p>
* The script names supported by <code>Pattern</code> are the valid script names
* accepted and defined by
* {@link java.lang.Character.UnicodeScript#forName(String) UnicodeScript.forName}.
* <a name="ubc">
* <p>
* <b>Blocks</b> are specified with the prefix {@code In}, as in
* {@code InMongolian}, or by using the keyword {@code block} (or its short
* form {@code blk}) as in {@code block=Mongolian} or {@code blk=Mongolian}.
* <p>
* The block names supported by <code>Pattern</code> are the valid block names
* accepted and defined by
* {@link java.lang.Character.UnicodeBlock#forName(String) UnicodeBlock.forName}.
* <p>
* <a name="ucc">
* <b>Categories</b> may be specified with the optional prefix {@code Is}:
* Both {@code \p{L}} and {@code \p{IsL}} denote the category of Unicode
* letters. Same as scripts and blocks, categories can also be specified
* by using the keyword {@code general_category} (or its short form
* {@code gc}) as in {@code general_category=Lu} or {@code gc=Lu}.
* <p>
* The supported categories are those of
* <i>The Unicode Standard</i></a> in the version specified by the
* {@link java.lang.Character Character} class. The category names are those
* defined in the Standard, both normative and informative.
* <p>
* <a name="ubpc">
* <b>Binary properties</b> are specified with the prefix {@code Is}, as in
* {@code IsAlphabetic}. The supported binary properties by <code>Pattern</code>
* are
* <ul>
* <li> Alphabetic
* <li> Ideographic
* <li> Letter
* <li> Lowercase
* <li> Uppercase
* <li> Titlecase
* <li> Punctuation
* <Li> Control
* <li> White_Space
* <li> Digit
* <li> Hex_Digit
* <li> Noncharacter_Code_Point
* <li> Assigned
* </ul>
* <p>
* <b>Predefined Character classes</b> and <b>POSIX character classes</b> are in
* conformance with the recommendation of <i>Annex C: Compatibility Properties</i>
* of <a href="http://www.unicode.org/reports/tr18/"><i>Unicode Regular Expression
* </i></a>, when {@link #UNICODE_CHARACTER_CLASS} flag is specified.
* <p>
* <table border="0" cellpadding="1" cellspacing="0"
* summary="predefined and posix character classes in Unicode mode">
* <tr align="left">
* <th bgcolor="#CCCCFF" align="left" id="classes">Classes</th>
* <th bgcolor="#CCCCFF" align="left" id="matches">Matches</th>
*</tr>
* <tr><td><tt>\p{Lower}</tt></td>
* <td>A lowercase character:<tt>\p{IsLowercase}</tt></td></tr>
* <tr><td><tt>\p{Upper}</tt></td>
* <td>An uppercase character:<tt>\p{IsUppercase}</tt></td></tr>
* <tr><td><tt>\p{ASCII}</tt></td>
* <td>All ASCII:<tt>[\x00-\x7F]</tt></td></tr>
* <tr><td><tt>\p{Alpha}</tt></td>
* <td>An alphabetic character:<tt>\p{IsAlphabetic}</tt></td></tr>
* <tr><td><tt>\p{Digit}</tt></td>
* <td>A decimal digit character:<tt>p{IsDigit}</tt></td></tr>
* <tr><td><tt>\p{Alnum}</tt></td>
* <td>An alphanumeric character:<tt>[\p{IsAlphabetic}\p{IsDigit}]</tt></td></tr>
* <tr><td><tt>\p{Punct}</tt></td>
* <td>A punctuation character:<tt>p{IsPunctuation}</tt></td></tr>
* <tr><td><tt>\p{Graph}</tt></td>
* <td>A visible character: <tt>[^\p{IsWhite_Space}\p{gc=Cc}\p{gc=Cs}\p{gc=Cn}]</tt></td></tr>
* <tr><td><tt>\p{Print}</tt></td>
* <td>A printable character: <tt>[\p{Graph}\p{Blank}&&[^\p{Cntrl}]]</tt></td></tr>
* <tr><td><tt>\p{Blank}</tt></td>
* <td>A space or a tab: <tt>[\p{IsWhite_Space}&&[^\p{gc=Zl}\p{gc=Zp}\x0a\x0b\x0c\x0d\x85]]</tt></td></tr>
* <tr><td><tt>\p{Cntrl}</tt></td>
* <td>A control character: <tt>\p{gc=Cc}</tt></td></tr>
* <tr><td><tt>\p{XDigit}</tt></td>
* <td>A hexadecimal digit: <tt>[\p{gc=Nd}\p{IsHex_Digit}]</tt></td></tr>
* <tr><td><tt>\p{Space}</tt></td>
* <td>A whitespace character:<tt>\p{IsWhite_Space}</tt></td></tr>
* <tr><td><tt>\d</tt></td>
* <td>A digit: <tt>\p{IsDigit}</tt></td></tr>
* <tr><td><tt>\D</tt></td>
* <td>A non-digit: <tt>[^\d]</tt></td></tr>
* <tr><td><tt>\s</tt></td>
* <td>A whitespace character: <tt>\p{IsWhite_Space}</tt></td></tr>
* <tr><td><tt>\S</tt></td>
* <td>A non-whitespace character: <tt>[^\s]</tt></td></tr>
* <tr><td><tt>\w</tt></td>
* <td>A word character: <tt>[\p{Alpha}\p{gc=Mn}\p{gc=Me}\p{gc=Mc}\p{Digit}\p{gc=Pc}]</tt></td></tr>
* <tr><td><tt>\W</tt></td>
* <td>A non-word character: <tt>[^\w]</tt></td></tr>
* </table>
* <p>
* <a name="jcc">
* Categories that behave like the java.lang.Character
* boolean is<i>methodname</i> methods (except for the deprecated ones) are
* available through the same <tt>\p{</tt><i>prop</i><tt>}</tt> syntax where
* the specified property has the name <tt>java<i>methodname</i></tt>.
*
* <h4> Comparison to Perl 5 </h4>
*
* <p>The <code>Pattern</code> engine performs traditional NFA-based matching
* with ordered alternation as occurs in Perl 5.
*
* <p> Perl constructs not supported by this class: </p>
*
* <ul>
* <li><p> Predefined character classes (Unicode character)
* <p><tt>\h </tt>A horizontal whitespace
* <p><tt>\H </tt>A non horizontal whitespace
* <p><tt>\v </tt>A vertical whitespace
* <p><tt>\V </tt>A non vertical whitespace
* <p><tt>\R </tt>Any Unicode linebreak sequence
* <tt>\u005cu000D\u005cu000A|[\u005cu000A\u005cu000B\u005cu000C\u005cu000D\u005cu0085\u005cu2028\u005cu2029]</tt>
* <p><tt>\X </tt>Match Unicode
* <a href="http://www.unicode.org/reports/tr18/#Default_Grapheme_Clusters">
* <i>extended grapheme cluster</i></a>
* </p></li>
*
* <li><p> The backreference constructs, <tt>\g{</tt><i>n</i><tt>}</tt> for
* the <i>n</i><sup>th</sup><a href="#cg">capturing group</a> and
* <tt>\g{</tt><i>name</i><tt>}</tt> for
* <a href="#groupname">named-capturing group</a>.
* </p></li>
*
* <li><p> The named character construct, <tt>\N{</tt><i>name</i><tt>}</tt>
* for a Unicode character by its name.
* </p></li>
*
* <li><p> The conditional constructs
* <tt>(?(</tt><i>condition</i><tt>)</tt><i>X</i><tt>)</tt> and
* <tt>(?(</tt><i>condition</i><tt>)</tt><i>X</i><tt>|</tt><i>Y</i><tt>)</tt>,
* </p></li>
*
* <li><p> The embedded code constructs <tt>(?{</tt><i>code</i><tt>})</tt>
* and <tt>(??{</tt><i>code</i><tt>})</tt>,</p></li>
*
* <li><p> The embedded comment syntax <tt>(?#comment)</tt>, and </p></li>
*
* <li><p> The preprocessing operations <tt>\l</tt> <tt>\u</tt>,
* <tt>\L</tt>, and <tt>\U</tt>. </p></li>
*
* </ul>
*
* <p> Constructs supported by this class but not by Perl: </p>
*
* <ul>
*
* <li><p> Character-class union and intersection as described
* <a href="#cc">above</a>.</p></li>
*
* </ul>
*
* <p> Notable differences from Perl: </p>
*
* <ul>
*
* <li><p> In Perl, <tt>\1</tt> through <tt>\9</tt> are always interpreted
* as back references; a backslash-escaped number greater than <tt>9</tt> is
* treated as a back reference if at least that many subexpressions exist,
* otherwise it is interpreted, if possible, as an octal escape. In this
* class octal escapes must always begin with a zero. In this class,
* <tt>\1</tt> through <tt>\9</tt> are always interpreted as back
* references, and a larger number is accepted as a back reference if at
* least that many subexpressions exist at that point in the regular
* expression, otherwise the parser will drop digits until the number is
* smaller or equal to the existing number of groups or it is one digit.
* </p></li>
*
* <li><p> Perl uses the <tt>g</tt> flag to request a match that resumes
* where the last match left off. This functionality is provided implicitly
* by the {@link Matcher} class: Repeated invocations of the {@link
* Matcher#find find} method will resume where the last match left off,
* unless the matcher is reset. </p></li>
*
* <li><p> In Perl, embedded flags at the top level of an expression affect
* the whole expression. In this class, embedded flags always take effect
* at the point at which they appear, whether they are at the top level or
* within a group; in the latter case, flags are restored at the end of the
* group just as in Perl. </p></li>
*
* </ul>
*
*
* <p> For a more precise description of the behavior of regular expression
* constructs, please see <a href="http://www.oreilly.com/catalog/regex3/">
* <i>Mastering Regular Expressions, 3nd Edition</i>, Jeffrey E. F. Friedl,
* O'Reilly and Associates, 2006.</a>
* </p>
*
* @see java.lang.String#split(String, int)
* @see java.lang.String#split(String)
*
* @author Mike McCloskey
* @author Mark Reinhold
* @author JSR-51 Expert Group
* @since 1.4
* @spec JSR-51
*/
public final class Pattern
{
/**
* Regular expression modifier values. Instead of being passed as
* arguments, they can also be passed as inline modifiers.
* For example, the following statements have the same effect.
* <pre>
* RegExp r1 = RegExp.compile("abc", Pattern.I|Pattern.M);
* RegExp r2 = RegExp.compile("(?im)abc", 0);
* </pre>
*
* The flags are duplicated so that the familiar Perl match flag
* names are available.
*/
/**
* Enables Unix lines mode.
*
* <p> In this mode, only the <tt>'\n'</tt> line terminator is recognized
* in the behavior of <tt>.</tt>, <tt>^</tt>, and <tt>$</tt>.
*
* <p> Unix lines mode can also be enabled via the embedded flag
* expression <tt>(?d)</tt>.
*/
/**
* Enables case-insensitive matching.
*
* <p> By default, case-insensitive matching assumes that only characters
* in the US-ASCII charset are being matched. Unicode-aware
* case-insensitive matching can be enabled by specifying the {@link
* #UNICODE_CASE} flag in conjunction with this flag.
*
* <p> Case-insensitive matching can also be enabled via the embedded flag
* expression <tt>(?i)</tt>.
*
* <p> Specifying this flag may impose a slight performance penalty. </p>
*/
/**
* Permits whitespace and comments in pattern.
*
* <p> In this mode, whitespace is ignored, and embedded comments starting
* with <tt>#</tt> are ignored until the end of a line.
*
* <p> Comments mode can also be enabled via the embedded flag
* expression <tt>(?x)</tt>.
*/
/**
* Enables multiline mode.
*
* <p> In multiline mode the expressions <tt>^</tt> and <tt>$</tt> match
* just after or just before, respectively, a line terminator or the end of
* the input sequence. By default these expressions only match at the
* beginning and the end of the entire input sequence.
*
* <p> Multiline mode can also be enabled via the embedded flag
* expression <tt>(?m)</tt>. </p>
*/
/**
* Enables literal parsing of the pattern.
*
* <p> When this flag is specified then the input string that specifies
* the pattern is treated as a sequence of literal characters.
* Metacharacters or escape sequences in the input sequence will be
* given no special meaning.
*
* <p>The flags CASE_INSENSITIVE and UNICODE_CASE retain their impact on
* matching when used in conjunction with this flag. The other flags
* become superfluous.
*
* <p> There is no embedded flag character for enabling literal parsing.
* @since 1.5
*/
/**
* Enables dotall mode.
*
* <p> In dotall mode, the expression <tt>.</tt> matches any character,
* including a line terminator. By default this expression does not match
* line terminators.
*
* <p> Dotall mode can also be enabled via the embedded flag
* expression <tt>(?s)</tt>. (The <tt>s</tt> is a mnemonic for
* "single-line" mode, which is what this is called in Perl.) </p>
*/
/**
* Enables Unicode-aware case folding.
*
* <p> When this flag is specified then case-insensitive matching, when
* enabled by the {@link #CASE_INSENSITIVE} flag, is done in a manner
* consistent with the Unicode Standard. By default, case-insensitive
* matching assumes that only characters in the US-ASCII charset are being
* matched.
*
* <p> Unicode-aware case folding can also be enabled via the embedded flag
* expression <tt>(?u)</tt>.
*
* <p> Specifying this flag may impose a performance penalty. </p>
*/
/**
* Enables canonical equivalence.
*
* <p> When this flag is specified then two characters will be considered
* to match if, and only if, their full canonical decompositions match.
* The expression <tt>"a\u030A"</tt>, for example, will match the
* string <tt>"\u00E5"</tt> when this flag is specified. By default,
* matching does not take canonical equivalence into account.
*
* <p> There is no embedded flag character for enabling canonical
* equivalence.
*
* <p> Specifying this flag may impose a performance penalty. </p>
*/
/**
* Enables the Unicode version of <i>Predefined character classes</i> and
* <i>POSIX character classes</i>.
*
* <p> When this flag is specified then the (US-ASCII only)
* <i>Predefined character classes</i> and <i>POSIX character classes</i>
* are in conformance with
* <a href="http://www.unicode.org/reports/tr18/"><i>Unicode Technical
* Standard #18: Unicode Regular Expression</i></a>
* <i>Annex C: Compatibility Properties</i>.
* <p>
* The UNICODE_CHARACTER_CLASS mode can also be enabled via the embedded
* flag expression <tt>(?U)</tt>.
* <p>
* The flag implies UNICODE_CASE, that is, it enables Unicode-aware case
* folding.
* <p>
* Specifying this flag may impose a performance penalty. </p>
* @since 1.7
*/
/* Pattern has only two serialized components: The pattern string
* and the flags, which are all that is needed to recompile the pattern
* when it is deserialized.
*/
/** use serialVersionUID from Merlin b59 for interoperability */
/**
* The original regular-expression pattern string.
*
* @serial
*/
/**
* The original pattern flags.
*
* @serial
*/
private int flags;
/**
* Boolean indicating this Pattern is compiled; this is necessary in order
* to lazily compile deserialized Patterns.
*/
private transient volatile boolean compiled = false;
/**
* The normalized pattern string.
*/
/**
* The starting point of state machine for the find operation. This allows
* a match to start anywhere in the input.
*/
/**
* The root of object tree for a match operation. The pattern is matched
* at the beginning. This may include a find that uses BnM or a First
* node.
*/
/**
* Temporary storage used by parsing pattern slice.
*/
transient int[] buffer;
/**
* Map the "name" of the "named capturing group" to its group id
* node.
*/
/**
* Temporary storage used while parsing group references.
*/
/**
* Temporary null terminated code point array used by pattern compiling.
*/
private transient int[] temp;
/**
* The number of capturing groups in this Pattern. Used by matchers to
* allocate storage needed to perform a match.
*/
transient int capturingGroupCount;
/**
* The local variable count used by parsing tree. Used by matchers to
* allocate storage needed to perform a match.
*/
transient int localCount;
/**
* Index into the pattern string that keeps track of how much has been
* parsed.
*/
private transient int cursor;
/**
* Holds the length of the pattern string.
*/
private transient int patternLength;
/**
* If the Start node might possibly match supplementary characters.
* It is set to true during compiling if
* (1) There is supplementary char in pattern, or
* (2) There is complement node of Category or Block
*/
private transient boolean hasSupplementary;
/**
* Compiles the given regular expression into a pattern. </p>
*
* @param regex
* The expression to be compiled
*
* @throws PatternSyntaxException
* If the expression's syntax is invalid
*/
}
/**
* Compiles the given regular expression into a pattern with the given
* flags. </p>
*
* @param regex
* The expression to be compiled
*
* @param flags
* Match flags, a bit mask that may include
* {@link #CASE_INSENSITIVE}, {@link #MULTILINE}, {@link #DOTALL},
* {@link #UNICODE_CASE}, {@link #CANON_EQ}, {@link #UNIX_LINES},
* {@link #LITERAL}, {@link #UNICODE_CHARACTER_CLASS}
* and {@link #COMMENTS}
*
* @throws IllegalArgumentException
* If bit values other than those corresponding to the defined
* match flags are set in <tt>flags</tt>
*
* @throws PatternSyntaxException
* If the expression's syntax is invalid
*/
}
/**
* Returns the regular expression from which this pattern was compiled.
* </p>
*
* @return The source of this pattern
*/
return pattern;
}
/**
* <p>Returns the string representation of this pattern. This
* is the regular expression from which this pattern was
* compiled.</p>
*
* @return The string representation of this pattern
* @since 1.5
*/
return pattern;
}
/**
* Creates a matcher that will match the given input against this pattern.
* </p>
*
* @param input
* The character sequence to be matched
*
* @return A new matcher for this pattern
*/
if (!compiled) {
synchronized(this) {
if (!compiled)
compile();
}
}
return m;
}
/**
* Returns this pattern's match flags. </p>
*
* @return The match flags specified when this pattern was compiled
*/
public int flags() {
return flags;
}
/**
* Compiles the given regular expression and attempts to match the given
* input against it.
*
* <p> An invocation of this convenience method of the form
*
* <blockquote><pre>
* Pattern.matches(regex, input);</pre></blockquote>
*
* behaves in exactly the same way as the expression
*
* <blockquote><pre>
* Pattern.compile(regex).matcher(input).matches()</pre></blockquote>
*
* <p> If a pattern is to be used multiple times, compiling it once and reusing
* it will be more efficient than invoking this method each time. </p>
*
* @param regex
* The expression to be compiled
*
* @param input
* The character sequence to be matched
*
* @throws PatternSyntaxException
* If the expression's syntax is invalid
*/
return m.matches();
}
/**
* Splits the given input sequence around matches of this pattern.
*
* <p> The array returned by this method contains each substring of the
* input sequence that is terminated by another subsequence that matches
* this pattern or is terminated by the end of the input sequence. The
* substrings in the array are in the order in which they occur in the
* input. If this pattern does not match any subsequence of the input then
* the resulting array has just one element, namely the input sequence in
* string form.
*
* <p> The <tt>limit</tt> parameter controls the number of times the
* pattern is applied and therefore affects the length of the resulting
* array. If the limit <i>n</i> is greater than zero then the pattern
* will be applied at most <i>n</i> - 1 times, the array's
* length will be no greater than <i>n</i>, and the array's last entry
* will contain all input beyond the last matched delimiter. If <i>n</i>
* is non-positive then the pattern will be applied as many times as
* possible and the array can have any length. If <i>n</i> is zero then
* the pattern will be applied as many times as possible, the array can
* have any length, and trailing empty strings will be discarded.
*
* <p> The input <tt>"boo:and:foo"</tt>, for example, yields the following
* results with these parameters:
*
* <blockquote><table cellpadding=1 cellspacing=0
* summary="Split examples showing regex, limit, and result">
* <tr><th><P align="left"><i>Regex </i></th>
* <th><P align="left"><i>Limit </i></th>
* <th><P align="left"><i>Result </i></th></tr>
* <tr><td align=center>:</td>
* <td align=center>2</td>
* <td><tt>{ "boo", "and:foo" }</tt></td></tr>
* <tr><td align=center>:</td>
* <td align=center>5</td>
* <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
* <tr><td align=center>:</td>
* <td align=center>-2</td>
* <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
* <tr><td align=center>o</td>
* <td align=center>5</td>
* <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
* <tr><td align=center>o</td>
* <td align=center>-2</td>
* <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
* <tr><td align=center>o</td>
* <td align=center>0</td>
* <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
* </table></blockquote>
*
*
* @param input
* The character sequence to be split
*
* @param limit
* The result threshold, as described above
*
* @return The array of strings computed by splitting the input
* around matches of this pattern
*/
int index = 0;
// Add segments before each match found
while(m.find()) {
}
}
// If no match was found, return this
if (index == 0)
// Add remaining segment
// Construct result
if (limit == 0)
resultSize--;
}
/**
* Splits the given input sequence around matches of this pattern.
*
* <p> This method works as if by invoking the two-argument {@link
* #split(java.lang.CharSequence, int) split} method with the given input
* sequence and a limit argument of zero. Trailing empty strings are
* therefore not included in the resulting array. </p>
*
* <p> The input <tt>"boo:and:foo"</tt>, for example, yields the following
* results with these expressions:
*
* <blockquote><table cellpadding=1 cellspacing=0
* summary="Split examples showing regex and result">
* <tr><th><P align="left"><i>Regex </i></th>
* <th><P align="left"><i>Result</i></th></tr>
* <tr><td align=center>:</td>
* <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
* <tr><td align=center>o</td>
* <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
* </table></blockquote>
*
*
* @param input
* The character sequence to be split
*
* @return The array of strings computed by splitting the input
* around matches of this pattern
*/
}
/**
* Returns a literal pattern <code>String</code> for the specified
* <code>String</code>.
*
* <p>This method produces a <code>String</code> that can be used to
* create a <code>Pattern</code> that would match the string
* <code>s</code> as if it were a literal pattern.</p> Metacharacters
* or escape sequences in the input sequence will be given no special
* meaning.
*
* @param s The string to be literalized
* @return A literal string replacement
* @since 1.5
*/
if (slashEIndex == -1)
return "\\Q" + s + "\\E";
slashEIndex = 0;
int current = 0;
}
}
/**
* Recompile the Pattern instance from a stream. The original pattern
* string is read in and the object tree is recompiled from it.
*/
// Read in all fields
s.defaultReadObject();
// Initialize counts
capturingGroupCount = 1;
localCount = 0;
// if length > 0, the Pattern is lazily compiled
compiled = false;
compiled = true;
}
}
/**
* This private constructor is used to create all Patterns. The pattern
* string and match flags are all that is needed to completely describe
* a Pattern. An empty pattern string results in an object tree with
* only a Start node and a LastNode node.
*/
pattern = p;
flags = f;
// to use UNICODE_CASE if UNICODE_CHARACTER_CLASS present
flags |= UNICODE_CASE;
// Reset group index count
capturingGroupCount = 1;
localCount = 0;
compile();
} else {
}
}
/**
* The pattern is converted to normalizedD form and then a pure group
* is constructed to match canonical equivalences of the characters.
*/
private void normalize() {
boolean inCharClass = false;
int lastCodePoint = -1;
// Convert pattern into normalizedD form
// Modify pattern to match canonical equivalences
for(int i=0; i<patternLength; ) {
int c = normalizedPattern.codePointAt(i);
&& (lastCodePoint != -1)) {
sequenceBuffer = new StringBuilder();
if (i >= patternLength)
break;
c = normalizedPattern.codePointAt(i);
}
i = normalizeCharClass(newPattern, i);
} else {
}
lastCodePoint = c;
}
}
/**
* Complete the character class being parsed and add a set
* of alternations to it that will match the canonical equivalences
* of the characters within the class.
*/
int lastCodePoint = -1;
i++;
while(true) {
int c = normalizedPattern.codePointAt(i);
break;
sequenceBuffer = new StringBuilder();
if (i >= normalizedPattern.length())
break;
c = normalizedPattern.codePointAt(i);
}
eq = new StringBuilder();
} else {
i++;
}
if (i == normalizedPattern.length())
throw error("Unclosed character class");
lastCodePoint = c;
}
} else {
}
return i;
}
/**
* Given a specific sequence composed of a regular character and
* combining marks that follow it, produce the alternation that will
* match all canonical equivalences of that sequence.
*/
// source has one character.
return source;
// Add combined permutations
if (x>0)
}
}
/**
* Returns an array of strings that have all the possible
* permutations of the characters in the input string.
* This is used to get a list of all possible orderings
* of a set of combining marks. Note that some of the permutations
* are invalid because of combining class collisions, and these
* possibilities must be removed because they are not canonically
* equivalent.
*/
}
return result;
}
int length = 1;
for(int x=1; x<nCodePoints; x++)
int combClass[] = new int[nCodePoints];
}
// For each char, take it out and add the permutations
// of the remaining chars
int index = 0;
int len;
// offset maintains the index in code units.
boolean skip = false;
for(int y=x-1; y>=0; y--) {
continue loop;
}
}
}
for (int x=0; x<index; x++)
return result;
}
private int getClass(int c) {
}
/**
* Attempts to compose input by combining the first character
* with the first combining mark following it. Returns a String
* that is the composition of the leading character with its first
* combining mark followed by the remaining combining marks. Returns
* null if the first two characters cannot be further composed.
*/
return null;
else {
}
}
/**
* Preprocess any \Q...\E sequences in `temp', meta-quoting them.
* See the description of `quotemeta' in perlfunc(1).
*/
private void RemoveQEQuoting() {
final int pLen = patternLength;
int i = 0;
while (i < pLen-1) {
if (temp[i] != '\\')
i += 1;
i += 2;
else
break;
}
return;
int j = i;
i += 2;
boolean inQuote = true;
while (i < pLen) {
int c = temp[i++];
newtemp[j++] = c;
} else if (c != '\\') {
newtemp[j++] = c;
} else if (inQuote) {
if (temp[i] == 'E') {
i++;
inQuote = false;
} else {
newtemp[j++] = '\\';
newtemp[j++] = '\\';
}
} else {
if (temp[i] == 'Q') {
i++;
inQuote = true;
} else {
newtemp[j++] = c;
if (i != pLen)
}
}
}
patternLength = j;
}
/**
* Copies regular expression to an int array and invokes the parsing
* of the expression which will create the object tree.
*/
private void compile() {
// Handle canonical equivalences
normalize();
} else {
}
// Copy pattern to int array for convenience
// Use double zero to terminate pattern
hasSupplementary = false;
int c, count = 0;
// Convert all chars into code points
c = normalizedPattern.codePointAt(x);
if (isSupplementary(c)) {
hasSupplementary = true;
}
}
// Allocate all temporary objects here.
buffer = new int[32];
namedGroups = null;
// Literal pattern handling
} else {
// Start recursive descent parsing
// Check extra pattern characters
if (patternLength != cursor) {
if (peek() == ')') {
throw error("Unmatched closing ')'");
} else {
throw error("Unexpected internal error");
}
}
}
// Peephole optimization
}
} else {
}
// Release temporary storage
groupNodes = null;
patternLength = 0;
compiled = true;
}
if (namedGroups == null)
return namedGroups;
}
/**
* Used to print out a subtree of the Pattern to help with debugging.
*/
} else if (node instanceof GroupCurly) {
return;
} else {
}
}
}
}
/**
* Used to accumulate information about a subtree of the object graph
* so that optimizations can be applied to the subtree.
*/
static final class TreeInfo {
int minLength;
int maxLength;
boolean maxValid;
boolean deterministic;
TreeInfo() {
reset();
}
void reset() {
minLength = 0;
maxLength = 0;
maxValid = true;
deterministic = true;
}
}
/*
* The following private methods are mainly used to improve the
* readability of the code. In order to let the Java compiler easily
* inline them, we should not put many assertions or error checks in them.
*/
/**
* Indicates whether a particular flag is set or not.
*/
private boolean has(int f) {
return (flags & f) != 0;
}
/**
* Match next character, signal error if failed.
*/
throw error(s);
}
}
/**
* Mark the end of pattern with a specific character.
*/
private void mark(int c) {
temp[patternLength] = c;
}
/**
* Peek the next character, and do not advance the cursor.
*/
private int peek() {
return ch;
}
/**
* Read the next character, and advance the cursor by one.
*/
private int read() {
return ch;
}
/**
* Read the next character, and advance the cursor by one,
* ignoring the COMMENTS setting
*/
private int readEscaped() {
return ch;
}
/**
* Advance the cursor by one, and peek the next character.
*/
private int next() {
return ch;
}
/**
* Advance the cursor by one, and peek the next character,
* ignoring the COMMENTS setting
*/
private int nextEscaped() {
return ch;
}
/**
* If in xmode peek past whitespace and comments.
*/
if (ch == '#') {
ch = peekPastLine();
}
}
return ch;
}
/**
* If in xmode parse past whitespace and comments.
*/
if (ch == '#')
ch = parsePastLine();
}
return ch;
}
/**
* xmode parse past comment to end of line.
*/
private int parsePastLine() {
return ch;
}
/**
* xmode peek past comment to end of line.
*/
private int peekPastLine() {
return ch;
}
/**
* Determines if character is a line separator in the current mode
*/
if (has(UNIX_LINES)) {
return ch == '\n';
} else {
return (ch == '\n' ||
ch == '\r' ||
ch == '\u0085');
}
}
/**
* Read the character after the next one, and advance the cursor by two.
*/
private int skip() {
int i = cursor;
cursor = i + 2;
return ch;
}
/**
* Unread one next character, and retreat cursor by one.
*/
private void unread() {
cursor--;
}
/**
* Internal method used for handling all syntax errors. The pattern is
* displayed with a pointer to aid in locating the syntax error.
*/
}
/**
* Determines if there is any supplementary character or unpaired
* surrogate in the specified range.
*/
if (isSupplementary(temp[i]))
return true;
}
return false;
}
/**
* Determines if the specified code point is a supplementary
* character or unpaired surrogate.
*/
}
/**
* The following methods handle the main parsing. They are sorted
* according to their precedence order, the lowest one first.
*/
/**
* The expression is parsed with branch nodes added for alternations.
* This may be called recursively to parse sub expressions that may
* contain alternations.
*/
for (;;) {
} else {
// Branch
if (branchConn == null) {
branchConn = new BranchConn();
}
// if the node returned from sequence() is "end"
// we have an empty expr, set a null atom into
// the branch to indicate to go "next" directly.
} else {
// the "tail.next" of each atom goes to branchConn
}
} else {
} else {
// replace the "end" with "branchConn" at its tail.next
// when put the "prev" into the branch as the first atom.
}
}
}
if (peek() != '|') {
return prev;
}
next();
}
}
/**
* Parsing of sequences between alternations.
*/
LOOP:
for (;;) {
switch (ch) {
case '(':
// Because group handles its own closure,
// we need to treat it differently
// Check for comment or flag group
continue;
else
// Double return: Tail was returned in root
continue;
case '[':
break;
case '\\':
ch = nextEscaped();
boolean oneLetter = true;
if (ch != '{') {
unread();
} else {
oneLetter = false;
}
} else {
unread();
}
break;
case '^':
next();
if (has(UNIX_LINES))
else
} else {
}
break;
case '$':
next();
if (has(UNIX_LINES))
else
break;
case '.':
next();
} else {
if (has(UNIX_LINES))
else {
}
}
break;
case '|':
case ')':
break LOOP;
case ']': // Now interpreting dangling ] and } as literals
case '}':
break;
case '?':
case '*':
case '+':
next();
case 0:
if (cursor >= patternLength) {
break LOOP;
}
// Fall through
default:
break;
}
} else {
}
}
return end;
}
return head;
}
/**
* Parse and add a new Single or Slice.
*/
int first = 0;
int prev = -1;
boolean hasSupplementary = false;
for (;;) {
switch (ch) {
case '*':
case '+':
case '?':
case '{':
if (first > 1) {
first--;
}
break;
case '$':
case '.':
case '^':
case '(':
case '[':
case '|':
case ')':
break;
case '\\':
ch = nextEscaped();
unread();
break;
} else { // No slice; just return the family node
boolean oneLetter = true;
if (ch != '{')
unread();
else
oneLetter = false;
}
}
unread();
if (ch >= 0) {
first++;
if (isSupplementary(ch)) {
hasSupplementary = true;
}
continue;
} else if (first == 0) {
return root;
}
// Unwind meta escape sequence
break;
case 0:
if (cursor >= patternLength) {
break;
}
// Fall through
default:
first++;
if (isSupplementary(ch)) {
hasSupplementary = true;
}
continue;
}
break;
}
if (first == 1) {
} else {
}
}
}
}
/**
* Parses a backref greedily, taking as many numbers as it
* can. The first digit is always treated as a backref, but
* multi digit numbers are only treated as a backref if at
* least that many backrefs exist at this point in the regex.
*/
boolean done = false;
while(!done) {
switch(ch) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
// Add another number if it doesn't make a group
// that doesn't exist
done = true;
break;
}
read();
break;
default:
done = true;
break;
}
}
if (has(CASE_INSENSITIVE))
else
}
/**
* Parses an escape sequence to determine the actual value that needs
* to be matched.
* If -1 is returned and create was true a new object was added to the tree
* to handle the escape sequence.
* If the returned value is greater than zero, it is the value that
* matches the escape sequence.
*/
switch (ch) {
case '0':
return o();
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (inclass) break;
if (create) {
}
return -1;
case 'A':
if (inclass) break;
return -1;
case 'B':
if (inclass) break;
return -1;
case 'C':
break;
case 'D':
return -1;
case 'E':
case 'F':
break;
case 'G':
if (inclass) break;
return -1;
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
break;
case 'S':
return -1;
case 'T':
case 'U':
case 'V':
break;
case 'W':
return -1;
case 'X':
case 'Y':
break;
case 'Z':
if (inclass) break;
if (create) {
if (has(UNIX_LINES))
root = new UnixDollar(false);
else
}
return -1;
case 'a':
return '\007';
case 'b':
if (inclass) break;
return -1;
case 'c':
return c();
case 'd':
return -1;
case 'e':
return '\033';
case 'f':
return '\f';
case 'g':
case 'h':
case 'i':
case 'j':
break;
case 'k':
if (inclass)
break;
if (read() != '<')
throw error("\\k is not followed by '<' for named capturing group");
if (create) {
if (has(CASE_INSENSITIVE))
else
}
return -1;
case 'l':
case 'm':
break;
case 'n':
return '\n';
case 'o':
case 'p':
case 'q':
break;
case 'r':
return '\r';
case 's':
return -1;
case 't':
return '\t';
case 'u':
return u();
case 'v':
return '\013';
case 'w':
return -1;
case 'x':
return x();
case 'y':
break;
case 'z':
if (inclass) break;
return -1;
default:
return ch;
}
throw error("Illegal/unsupported escape sequence");
}
/**
* Parse a character class, and return the node that matches it.
*
* Consumes a ] on the way out if consume is true. Usually consume
* is true except for the case of [abc&&def] where def is a separate
* right hand node with "understood" brackets.
*/
boolean include = true;
boolean firstInClass = true;
for (;;) {
switch (ch) {
case '^':
// Negates if first char in a class, otherwise literal
if (firstInClass) {
break;
continue;
} else {
// ^ not first in class, treat as literal
break;
}
case '[':
firstInClass = false;
else
continue;
case '&':
firstInClass = false;
if (ch == '&') {
if (ch == '[') {
else
} else { // abc&&def
unread();
}
}
throw error("Bad class syntax");
else
} else {
}
} else {
// treat as a literal &
unread();
break;
}
continue;
case 0:
firstInClass = false;
if (cursor >= patternLength)
throw error("Unclosed character class");
break;
case ']':
firstInClass = false;
if (consume)
next();
return prev;
}
break;
default:
firstInClass = false;
break;
}
if (include) {
} else {
}
} else {
} else {
}
}
}
}
/* Bits can only handle codepoints in [u+0000-u+00ff] range.
Use "single" node instead of bits when dealing with unicode
case folding for codepoints listed below.
(1)Uppercase out of range: u+00ff, u+00b5
toUpperCase(u+00ff) -> u+0178
toUpperCase(u+00b5) -> u+039c
(2)LatinSmallLetterLongS u+17f
toUpperCase(u+017f) -> u+0053
(3)LatinSmallLetterDotlessI u+131
toUpperCase(u+0131) -> u+0049
(4)LatinCapitalLetterIWithDotAbove u+0130
toLowerCase(u+0130) -> u+0069
(5)KelvinSign u+212a
toLowerCase(u+212a) ==> u+006B
(6)AngstromSign u+212b
toLowerCase(u+212b) ==> u+00e5
*/
int d;
if (ch < 256 &&
}
/**
* Parse a single character or a character range in a character class
* and return its representative node.
*/
if (ch == '\\') {
ch = nextEscaped();
boolean oneLetter = true;
// Consume { if present
if (ch != '{')
unread();
else
oneLetter = false;
} else { // ordinary escape
unread();
if (ch == -1)
return (CharProperty) root;
}
} else {
}
if (ch >= 0) {
if (peek() == '-') {
if (endRange == '[') {
}
if (endRange != ']') {
next();
int m = single();
if (m < ch)
throw error("Illegal character range");
if (has(CASE_INSENSITIVE))
return caseInsensitiveRangeFor(ch, m);
else
}
}
}
}
private int single() {
switch (ch) {
case '\\':
return escape(true, false);
default:
next();
return ch;
}
}
/**
* Parses a Unicode character family and returns its representative node.
*/
boolean maybeComplement)
{
next();
if (singleLetter) {
if (!Character.isSupplementaryCodePoint(c)) {
} else {
}
read();
} else {
int i = cursor;
mark('}');
while(read() != '}') {
}
mark('\000');
int j = cursor;
if (j > patternLength)
throw error("Unclosed character family");
if (i + 1 >= j)
throw error("Empty character family");
}
if (i != -1) {
// property construct \p{name=value}
} else {
}
} else {
// \p{inBlockName}
// \p{isGeneralCategory} and \p{isScriptName}
} else {
if (has(UNICODE_CHARACTER_CLASS)) {
}
}
}
if (maybeComplement) {
hasSupplementary = true;
}
return node;
}
/**
* Returns a CharProperty matching all characters belong to
* a UnicodeScript.
*/
try {
} catch (IllegalArgumentException iae) {
}
}
/**
* Returns a CharProperty matching all characters in a UnicodeBlock.
*/
try {
} catch (IllegalArgumentException iae) {
}
}
/**
* Returns a CharProperty matching all characters in a named property.
*/
if (p == null)
return p;
}
/**
* Parses and returns the name of a "named capturing group", the trailing
* ">" is consumed after parsing.
*/
}
throw error("named capturing group has 0 length name");
if (ch != '>')
throw error("named capturing group is missing trailing '>'");
}
/**
* Parses a group and returns the head node of a set of nodes that process
* the group. Sometimes a double return system is used where the tail is
* returned in root.
*/
boolean capturingGroup = false;
if (ch == '?') {
switch (ch) {
case ':': // (?:xxx) pure group
head = createGroup(true);
break;
case '=': // (?=xxx) and (?!xxx) lookahead
case '!':
head = createGroup(true);
if (ch == '=') {
} else {
}
break;
case '>': // (?>xxx) independent group
head = createGroup(true);
break;
case '<': // (?<xxx) look behind
// named captured group
+ "> is already defined");
capturingGroup = true;
head = createGroup(false);
break;
}
head = createGroup(true);
throw error("Look-behind group does not have "
+ "an obvious maximum length");
}
if (ch == '=') {
} else if (ch == '!') {
} else {
throw error("Unknown look-behind group");
}
break;
case '$':
case '@':
throw error("Unknown group type");
default: // (?xxx:) inlined match flags
unread();
addFlag();
if (ch == ')') {
return null; // Inline modifier only
}
if (ch != ':') {
throw error("Unknown inline modifier");
}
head = createGroup(true);
break;
}
} else { // (xxx) a regular group
capturingGroup = true;
head = createGroup(false);
}
// Check for quantifiers
return node; // Dual return
}
return node; // Dual return
}
return node;
}
} else { // Reluctant quantifier
}
return head;
return node;
}
// Discover if the group is deterministic
return head;
} else { // Non-deterministic
else // Reluctant Curly
this.localCount += 1;
return prolog; // Dual return
}
}
throw error("Internal logic error");
}
/**
* Create group head and tail nodes using double return. If the group is
* created with anonymous true then it is a pure group and should not
* affect group counting.
*/
int localIndex = localCount++;
int groupIndex = 0;
if (!anonymous)
return head;
}
/**
* Parses inlined match flags and set them appropriately.
*/
private void addFlag() {
for (;;) {
switch (ch) {
case 'i':
break;
case 'm':
break;
case 's':
break;
case 'd':
flags |= UNIX_LINES;
break;
case 'u':
flags |= UNICODE_CASE;
break;
case 'c':
break;
case 'x':
break;
case 'U':
break;
case '-': // subFlag then fall through
subFlag();
default:
return;
}
}
}
/**
* Parses the second part of inlined match flags and turns off
* flags appropriately.
*/
private void subFlag() {
for (;;) {
switch (ch) {
case 'i':
flags &= ~CASE_INSENSITIVE;
break;
case 'm':
break;
case 's':
break;
case 'd':
flags &= ~UNIX_LINES;
break;
case 'u':
flags &= ~UNICODE_CASE;
break;
case 'c':
break;
case 'x':
break;
case 'U':
default:
return;
}
}
}
/**
* Processes repetition. If the next character peeked is a quantifier
* then new nodes must be appended to handle the repetition.
* Prev could be a single or a group, so it could be a chain of nodes.
*/
switch (ch) {
case '?':
if (ch == '?') {
next();
} else if (ch == '+') {
next();
}
case '*':
if (ch == '?') {
next();
} else if (ch == '+') {
next();
}
case '+':
if (ch == '?') {
next();
} else if (ch == '+') {
next();
}
case '{':
skip();
int cmin = 0;
do {
if (ch == ',') {
if (ch != '}') {
cmax = 0;
}
}
}
if (ch != '}')
throw error("Unclosed counted closure");
throw error("Illegal repetition range");
if (ch == '?') {
next();
} else if (ch == '+') {
next();
} else {
}
return curly;
} else {
throw error("Illegal repetition");
}
default:
return prev;
}
}
/**
* Utility method for parsing control escape sequences.
*/
private int c() {
if (cursor < patternLength) {
return read() ^ 64;
}
throw error("Illegal control escape sequence");
}
/**
* Utility method for parsing octal escape sequences.
*/
private int o() {
int n = read();
if (((n-'0')|('7'-n)) >= 0) {
int m = read();
if (((m-'0')|('7'-m)) >= 0) {
int o = read();
if ((((o-'0')|('7'-o)) >= 0) && (((n-'0')|('3'-n)) >= 0)) {
return (n - '0') * 64 + (m - '0') * 8 + (o - '0');
}
unread();
return (n - '0') * 8 + (m - '0');
}
unread();
return (n - '0');
}
throw error("Illegal octal escape sequence");
}
/**
* Utility method for parsing hexadecimal escape sequences.
*/
private int x() {
int n = read();
if (ASCII.isHexDigit(n)) {
int m = read();
if (ASCII.isHexDigit(m)) {
}
int ch = 0;
throw error("Hexadecimal codepoint is too big");
}
if (n != '}')
throw error("Unclosed hexadecimal escape sequence");
return ch;
}
throw error("Illegal hexadecimal escape sequence");
}
/**
* Utility method for parsing unicode escape sequences.
*/
private int cursor() {
return cursor;
}
}
private int uxxxx() {
int n = 0;
for (int i = 0; i < 4; i++) {
throw error("Illegal Unicode escape sequence");
}
}
return n;
}
private int u() {
int n = uxxxx();
if (Character.isHighSurrogate((char)n)) {
}
}
return n;
}
//
// Utility methods for code point support
//
int lengthInCodePoints) {
// optimization
return 1;
}
int x = index;
if (lengthInCodePoints >= 0) {
x++;
}
}
}
return x - index;
}
if (index == 0) {
return 0;
}
int len = -lengthInCodePoints;
x--;
}
}
}
return index - x;
}
int n = 0;
for (int i = 0; i < length; ) {
n++;
i++;
}
}
}
return n;
}
/**
* Creates a bit vector for matching Latin-1 values. A normal BitClass
* never matches values above Latin-1, and a complemented BitClass always
* matches values above Latin-1.
*/
final boolean[] bits;
assert c >= 0 && c <= 255;
}
}
bits[c] = true;
return this;
}
}
}
/**
* Returns a suitably optimized, single character matcher.
*/
if (has(CASE_INSENSITIVE)) {
if (has(UNICODE_CASE)) {
}
}
if (isSupplementary(ch))
}
/**
* Utility method for creating a string slice matcher.
*/
if (has(CASE_INSENSITIVE)) {
if (has(UNICODE_CASE)) {
for (int i = 0; i < count; i++) {
}
}
for (int i = 0; i < count; i++) {
}
}
for (int i = 0; i < count; i++) {
}
}
/**
* The following classes are the building components of the object
* tree that represents a compiled regular expression. The object tree
* is made of individual elements that handle constructs in the Pattern.
* Each type of object knows how to match its equivalent construct with
* the match() method.
*/
/**
* Base class for all node classes. Subclasses should override the match()
* method as appropriate. This class is an accepting node, so its match()
* always returns true.
*/
Node() {
}
/**
* This method implements the classic accept node.
*/
return true;
}
/**
* This method is good for all zero length assertions.
*/
} else {
return info.deterministic;
}
}
}
/**
* This method implements the classic accept node with
* the addition of a check to see if the match occurred
* using all of the input.
*/
return false;
return true;
}
}
/**
* Used for REs that can start anywhere within the input string.
* This basically tries to match repeatedly at each spot in the
* input string, moving forward after each try. An anchored search
* or a BnM will bypass this node completely.
*/
int minLength;
}
return false;
}
for (; i <= guard; i++) {
return true;
}
}
return false;
}
info.deterministic = false;
return false;
}
}
/*
* StartS supports supplementary characters, including unpaired surrogates.
*/
super(node);
}
return false;
}
while (i <= guard) {
//if ((ret = next.match(matcher, i, seq)) || i == guard)
return true;
}
if (i == guard)
break;
// Optimization to move to the next character. This is
// faster than countChars(seq, i, 1).
i++;
}
}
}
return false;
}
}
/**
* Node to anchor at the beginning of input. This object implements the
* match for a \A sequence, and the caret anchor will use this if not in
* multiline mode.
*/
return true;
} else {
return false;
}
}
}
/**
* Node to anchor at the end of input. This is the absolute end, so this
* should not match at the last newline before the end as $ will.
*/
if (i == endIndex) {
}
return false;
}
}
/**
* Node to anchor at the beginning of a line. This is essentially the
* object to match for the multiline ^.
*/
if (!matcher.anchoringBounds) {
startIndex = 0;
}
// Perl does not match ^ at end of input even after newline
if (i == endIndex) {
return false;
}
if (i > startIndex) {
&& ch != '\u0085' ) {
return false;
}
// Should treat /r/n as one newline
return false;
}
}
}
/**
* Node to anchor at the beginning of a line when in unixdot mode.
*/
if (!matcher.anchoringBounds) {
startIndex = 0;
}
// Perl does not match ^ at end of input even after newline
if (i == endIndex) {
return false;
}
if (i > startIndex) {
if (ch != '\n') {
return false;
}
}
}
}
/**
* Node to match the location where the last match ended.
* This is used for the \G construct.
*/
return false;
}
}
/**
* Node to anchor at the end of a line or the end of input based on the
* multiline mode.
*
* When not in multiline mode, the $ can only match at the very end
* of the input, unless the input ends in a line terminator in which
* it matches right before the last line terminator.
*
* Note that \r\n is considered an atomic line terminator.
*
* Like ^ the $ operator matches at a position, it does not match the
* line terminators themselves.
*/
boolean multiline;
}
if (!multiline) {
if (i < endIndex - 2)
return false;
if (i == endIndex - 2) {
if (ch != '\r')
return false;
if (ch != '\n')
return false;
}
}
// Matches before any line terminator; also matches at the
// end of input
// Before line terminator:
// If multiline, we match here no matter what
// If not multiline, fall through so that the end
// is marked as hit; this must be a /r/n or a /n
// at the very end so the end was hit; more input
// could make this not match here
if (i < endIndex) {
if (ch == '\n') {
// No match between \r\n
return false;
if (multiline)
if (multiline)
} else { // No line terminator, no match
return false;
}
}
// Matched at current end so hit end
// If a $ matches because of end of input, then more input
// could cause it to fail!
matcher.requireEnd = true;
}
return info.deterministic;
}
}
/**
* Node to anchor at the end of a line or the end of input based on the
* multiline mode when in unix lines mode.
*/
boolean multiline;
}
if (i < endIndex) {
if (ch == '\n') {
// If not multiline, then only possible to
// match at very end or one before end
return false;
// If multiline return next.match without setting
// matcher.hitEnd
if (multiline)
} else {
return false;
}
}
// Matching because at the end or 1 before the end;
// more input could change this so set hitEnd
// If a $ matches because of end of input, then more input
// could cause it to fail!
matcher.requireEnd = true;
}
return info.deterministic;
}
}
/**
* Abstract node class to match one character satisfying some
* boolean property.
*/
return new CharProperty() {
boolean isSatisfiedBy(int ch) {
}
return isSatisfiedBy(ch)
} else {
return false;
}
}
}
}
/**
* Optimized version of CharProperty that works only for
* properties never satisfied by Supplementary characters.
*/
} else {
return false;
}
}
}
/**
* Node class that matches a Supplementary Unicode character
*/
final int c;
SingleS(int c) { this.c = c; }
return ch == c;
}
}
/**
* Optimization -- matches a given BMP character
*/
final int c;
Single(int c) { this.c = c; }
return ch == c;
}
}
/**
* Case insensitive matches a given BMP character
*/
final int lower;
final int upper;
}
}
}
/**
* Unicode case insensitive matches a given Unicode character
*/
final int lower;
}
}
}
/**
* Node class that matches a Unicode block.
*/
}
}
}
/**
* Node class that matches a Unicode script
*/
}
}
}
/**
* Node class that matches a Unicode category.
*/
final int typeMask;
}
}
/**
* Node class that matches a Unicode "type"
*/
}
}
/**
* Node class that matches a POSIX type.
*/
final int ctype;
}
}
/**
* Base class for all Slice nodes
*/
int[] buffer;
}
}
}
/**
* characters.
*/
super(buf);
}
for (int j=0; j<len; j++) {
return false;
}
return false;
}
}
}
/**
* Node class for a case_insensitive/BMP-only sequence of literal
* characters.
*/
super(buf);
}
for (int j=0; j<len; j++) {
return false;
}
if (buf[j] != c &&
return false;
}
}
}
/**
* Node class for a unicode_case_insensitive/BMP-only sequence of
* literal characters. Uses unicode case folding.
*/
super(buf);
}
for (int j=0; j<len; j++) {
return false;
}
if (buf[j] != c &&
return false;
}
}
}
/**
* Node class for a case sensitive sequence of literal characters
* including supplementary characters.
*/
super(buf);
}
int x = i;
return false;
}
if (buf[j] != c)
return false;
return false;
}
}
}
}
/**
* Node class for a case insensitive sequence of literal characters
* including supplementary characters.
*/
super(buf);
}
int toLower(int c) {
}
int x = i;
return false;
}
return false;
return false;
}
}
}
}
/**
* Node class for a case insensitive sequence of literal characters.
* Uses unicode case folding.
*/
super(buf);
}
int toLower(int c) {
}
}
}
/**
* Returns node for matching characters within an explicit value range.
*/
final int upper) {
return new CharProperty() {
boolean isSatisfiedBy(int ch) {
}
/**
* Returns node for matching characters within an explicit value
* range in a case insensitive manner.
*/
final int upper) {
if (has(UNICODE_CASE))
return new CharProperty() {
boolean isSatisfiedBy(int ch) {
return true;
return new CharProperty() {
boolean isSatisfiedBy(int ch) {
}};
}
/**
* Implements the Unicode category ALL and the dot metacharacter when
* in dotall mode.
*/
return true;
}
}
/**
* Node class for the dot metacharacter when dotall is not enabled.
*/
&& ch != '\u0085');
}
}
/**
* Node class for the dot metacharacter when dotall is not enabled
* but UNIX_LINES is enabled.
*/
return ch != '\n';
}
}
/**
* The 0 or 1 quantifier. This one class implements all three types.
*/
int type;
}
switch (type) {
case GREEDY:
case LAZY:
case POSSESSIVE:
default:
}
}
if (type != INDEPENDENT) {
info.deterministic = false;
} else {
}
}
}
/**
* Handles the curly-brace style repetition with a specified minimum and
* maximum occurrences. The * quantifier is handled as a special case.
* This class handles the three types.
*/
int type;
int cmin;
int cmax;
}
int j;
for (j = 0; j < cmin; j++) {
continue;
}
return false;
}
else
}
// Greedy match.
// i is the index to start matching at
// j is the number of atoms that have matched
if (j >= cmax) {
// We have matched the maximum... continue with the rest of
// the regular expression
}
int backLimit = j;
// k is the length of this match
if (k == 0) // Zero length match
break;
// Move up index and number matched
j++;
// We are greedy so match as many as we can
while (j < cmax) {
break;
return true;
break;
}
i += k;
j++;
}
// Handle backing off if match fails
while (j >= backLimit) {
return true;
i -= k;
j--;
}
return false;
}
}
// Reluctant match. At this point, the minimum has been satisfied.
// i is the index to start matching at
// j is the number of atoms that have matched
for (;;) {
// Try finishing match without consuming any more
return true;
// At the maximum, no match found
if (j >= cmax)
return false;
// Okay, must try one more atom
return false;
// If we haven't moved forward then must break out
return false;
// Move up index and number matched
j++;
}
}
for (; j < cmax; j++) {
break;
break;
}
}
// Save original info
}
}
} else {
}
else
info.deterministic = false;
}
}
/**
* Handles the curly-brace style repetition with a specified minimum and
* maximum occurrences in deterministic cases. This is an iterative
* optimization over the Prolog and Loop system which would handle this
* in a recursive way. The * quantifier is handled as a special case.
* If capture is true then this class saves group settings and ensures
* that groups are unset when backing off of a group match.
*/
int type;
int cmin;
int cmax;
int localIndex;
int groupIndex;
boolean capture;
this.localIndex = local;
this.groupIndex = group;
}
int save1 = 0;
int save2 = 0;
if (capture) {
}
// Notify GroupTail there is no need to setup group info
// because it will be set here
boolean ret = true;
for (int j = 0; j < cmin; j++) {
if (capture) {
groups[groupIndex] = i;
}
} else {
ret = false;
break;
}
}
if (ret) {
} else {
}
}
if (!ret) {
if (capture) {
}
}
return ret;
}
// Aggressive group match
int save0 = 0;
int save1 = 0;
if (capture) {
}
for (;;) {
if (j >= cmax)
break;
break;
if (k <= 0) {
if (capture) {
groups[groupIndex] = i;
}
i = i + k;
break;
}
for (;;) {
if (capture) {
groups[groupIndex] = i;
}
i = i + k;
if (++j >= cmax)
break;
break;
return true;
break;
}
}
while (j > cmin) {
if (capture) {
groups[groupIndex] = i - k;
}
i = i - k;
return true;
}
// backing off
if (capture) {
groups[groupIndex] = i - k;
}
i = i - k;
j--;
}
break;
}
if (capture) {
}
}
// Reluctant matching
for (;;) {
return true;
if (j >= cmax)
return false;
return false;
return false;
if (capture) {
}
j++;
}
}
// Possessive matching
for (; j < cmax; j++) {
break;
}
if (capture) {
}
break;
}
}
}
// Save original info
}
}
} else {
}
} else {
info.deterministic = false;
}
}
}
/**
* A Guard node at the end of each atom node in a Branch. It
* serves the purpose of chaining the "match" operation to
* "next" but not the "study", so we can collect the TreeInfo
* of each atom node without including the TreeInfo of the
* "next".
*/
BranchConn() {};
}
return info.deterministic;
}
}
/**
* Handles the branching of alternations. Note this is also used for
* the ? quantifier to branch between the case where it matches once
* and where it does not occur.
*/
conn = branchConn;
}
}
}
for (int n = 0; n < size; n++) {
return true;
return true;
}
}
return false;
}
int maxL2 = -1;
for (int n = 0; n < size; n++) {
}
info.deterministic = false;
return false;
}
}
/**
* The GroupHead saves the location where the group begins in the locals
* and restores them when the match is done.
*
* The matchRef is used when a reference to this group is accessed later
* in the expression. The locals will have a negative value in them to
* indicate that we do not want to unset the group if the reference
* doesn't match.
*/
int localIndex;
}
return ret;
}
return ret;
}
}
/**
* Recursive reference to a group in the regular expression. It calls
* matchRef because if the reference fails to match we would not unset
* the group.
*/
}
}
info.deterministic = false;
}
}
/**
* The GroupTail handles the setting of group beginning and ending
* locations when groups are successfully matched. It must also be able to
* unset groups that have to be backed off of.
*
* The GroupTail node is also used when a previous group is referenced,
* and in that case no group information needs to be set.
*/
int localIndex;
int groupIndex;
}
// Save the group so we can unset it if it
// backs off of a match.
return true;
}
return false;
} else {
// This is a group reference case. We don't need to save any
// group info because it isn't really a group.
return true;
}
}
}
/**
* This sets up a loop to handle a recursive quantifier structure.
*/
}
}
}
}
/**
* Handles the repetition count for a greedy Curly. The matchInit
* is called from the Prolog to save the index of where the group
* beginning is stored. A zero length group check occurs in the
* normal match but is skipped in the matchInit.
*/
this.countIndex = countIndex;
this.beginIndex = beginIndex;
}
// Avoid infinite loop in zero-length case.
// This block is for before we reach the minimum
// iterations required for the loop to match
// If match failed we must backtrack, so
// the loop count should NOT be incremented
if (!b)
// Return success or failure since we are under
// minimum
return b;
}
// This block is for after we have the minimum
// iterations required for the loop to match
// If match failed we must backtrack, so
// the loop count should NOT be incremented
if (!b)
else
return true;
}
}
}
boolean ret = false;
if (0 < cmin) {
} else if (0 < cmax) {
if (ret == false)
} else {
}
return ret;
}
info.deterministic = false;
return false;
}
}
/**
* Handles the repetition count for a reluctant Curly. The matchInit
* is called from the Prolog to save the index of where the group
* beginning is stored. A zero length group check occurs in the
* normal match but is skipped in the matchInit.
*/
super(countIndex, beginIndex);
}
// Check for zero length group
// If match failed we must backtrack, so
// the loop count should NOT be incremented
if (!result)
return result;
}
return true;
// If match failed we must backtrack, so
// the loop count should NOT be incremented
if (!result)
return result;
}
return false;
}
}
boolean ret = false;
if (0 < cmin) {
ret = true;
} else if (0 < cmax) {
}
return ret;
}
info.deterministic = false;
return false;
}
}
/**
* Refers to a group in the regular expression. Attempts to match
* whatever the group referred to last matched.
*/
int groupIndex;
super();
}
int groupSize = k - j;
// If the referenced group didn't match, neither can this
if (j < 0)
return false;
// If there isn't enough input left no match
return false;
}
// Check each new char to make sure it matches what the group
// referenced matched last time around
return false;
}
}
}
int groupIndex;
boolean doUnicodeCase;
super();
this.doUnicodeCase = doUnicodeCase;
}
int groupSize = k - j;
// If the referenced group didn't match, neither can this
if (j < 0)
return false;
// If there isn't enough input left no match
return false;
}
// Check each new char to make sure it matches what the group
// referenced matched last time around
int x = i;
if (doUnicodeCase) {
return false;
} else {
return false;
}
}
}
}
}
}
/**
* Searches until the next instance of its atom. This is useful for
* finding the atom efficiently without passing an instance of it
* (greedy problem) and without a lot of wasted search time (reluctant
* problem).
*/
}
}
for (;;) {
return false;
}
}
}
}
info.deterministic = false;
}
}
}
} else {
}
}
info.deterministic = false;
}
}
/**
* Zero width positive lookahead.
*/
}
boolean conditionMatched = false;
// Relax transparent region boundaries for lookahead
if (matcher.transparentBounds)
try {
} finally {
// Reinstate region boundaries
}
}
}
/**
* Zero width negative lookahead.
*/
}
boolean conditionMatched = false;
// Relax transparent region boundaries for lookahead
if (matcher.transparentBounds)
try {
} else {
// If a negative lookahead succeeds then more input
// could cause it to fail!
matcher.requireEnd = true;
}
} finally {
// Reinstate region boundaries
}
}
}
/**
* For use with lookbehinds; matches the position where the lookbehind
* was encountered.
*/
return i == matcher.lookbehindTo;
}
};
/**
* Zero width positive lookbehind.
*/
}
boolean conditionMatched = false;
// Set end boundary
matcher.lookbehindTo = i;
// Relax transparent region boundaries for lookbehind
if (matcher.transparentBounds)
}
}
}
/**
* Zero width positive lookbehind, including supplementary
* characters or unpaired surrogates.
*/
}
boolean conditionMatched = false;
// Set end boundary
matcher.lookbehindTo = i;
// Relax transparent region boundaries for lookbehind
if (matcher.transparentBounds)
for (int j = i - rminChars;
!conditionMatched && j >= from;
}
}
}
/**
* Zero width negative lookbehind.
*/
}
boolean conditionMatched = false;
matcher.lookbehindTo = i;
// Relax transparent region boundaries for lookbehind
if (matcher.transparentBounds)
}
// Reinstate region boundaries
}
}
/**
* Zero width negative lookbehind, including supplementary
* characters or unpaired surrogates.
*/
}
boolean conditionMatched = false;
matcher.lookbehindTo = i;
// Relax transparent region boundaries for lookbehind
if (matcher.transparentBounds)
for (int j = i - rminChars;
!conditionMatched && j >= from;
}
//Reinstate region boundaries
}
}
/**
* Returns the set union of two CharProperty nodes.
*/
final CharProperty rhs) {
return new CharProperty() {
boolean isSatisfiedBy(int ch) {
}
/**
* Returns the set intersection of two CharProperty nodes.
*/
final CharProperty rhs) {
return new CharProperty() {
boolean isSatisfiedBy(int ch) {
}
/**
* Returns the set difference of two CharProperty nodes.
*/
final CharProperty rhs) {
return new CharProperty() {
boolean isSatisfiedBy(int ch) {
}
/**
* Handles word boundaries. Includes a field to allow this one class to
* deal with the different types of word boundaries we can match. The word
* characters include underscores, letters, and digits. Non spacing marks
* can are also part of a word if they have a base character, otherwise
* they are ignored for purposes of finding word boundaries.
*/
int type;
boolean useUWORD;
type = n;
}
}
int ch;
boolean left = false;
if (matcher.transparentBounds) {
startIndex = 0;
}
if (i > startIndex) {
}
boolean right = false;
if (i < endIndex) {
} else {
// Tried to access char past the end
// The addition of another char could wreck a boundary
matcher.requireEnd = true;
}
}
}
}
/**
* Non spacing marks only count as word characters in bounds calculations
* if they have a base character.
*/
{
for (int x=i; x >= start; x--) {
return true;
continue;
return false;
}
return false;
}
/**
* Attempts to match a slice in the input using the Boyer-Moore string
* matching algorithm. The algorithm is based on the idea that the
* pattern can be shifted farther ahead in the search text if it is
* matched right to left.
* <p>
* The pattern is compared to the input one character at a time, from
* the rightmost character in the pattern to the left. If the characters
* all match the pattern has been found. If a character does not match,
* the pattern is shifted right a distance that is the maximum of two
* functions, the bad character shift and the good suffix shift. This
* shift moves the attempted match position through the input more
* quickly than a naive one position at a time check.
* <p>
* The bad character shift is based on the character from the text that
* did not match. If the character does not appear in the pattern, the
* pattern can be shifted completely beyond the bad character. If the
* character does occur in the pattern, the pattern can be shifted to
* line the pattern up with the next occurrence of that character.
* <p>
* The good suffix shift is based on the idea that some subset on the right
* side of the pattern has matched. When a bad character is found, the
* pattern can be shifted right by the pattern length if the subset does
* not occur again in pattern, or by the amount of distance to the
* next occurrence of the subset in the pattern.
*
* Boyer-Moore search methods adapted from code by Amy Yu.
*/
int[] buffer;
int[] lastOcc;
int[] optoSft;
/**
* Pre calculates arrays needed to generate the bad character
* shift and the good suffix shift. Only the last seven bits
* are used to see if chars match; This keeps the tables small
* and covers the heavily used ASCII range, but occasionally
* results in an aliased match for the bad character shift.
*/
return node;
}
// The BM algorithm requires a bit of overhead;
// If the pattern is short don't use it, since
// a shift larger than the pattern length cannot
// be used anyway.
if (patternLength < 4) {
return node;
}
int i, j, k;
int[] lastOcc = new int[128];
int[] optoSft = new int[patternLength];
// Precalculate part of the bad character shift
// It is a table for where in the pattern each
// lower 7-bit value occurs
for (i = 0; i < patternLength; i++) {
}
// Precalculate the good suffix shift
// i is the shift amount being considered
// j is the beginning index of suffix being considered
for (j = patternLength - 1; j >= i; j--) {
// Testing for good suffix
// src[j..len] is a good suffix
optoSft[j-1] = i;
} else {
// No match. The array has already been
// filled up with correct values before.
continue NEXT;
}
}
// This fills up the remaining of optoSft
// any suffix can not have larger shift amount
// then its sub-suffix. Why???
while (j > 0) {
optoSft[--j] = i;
}
}
// Set the guard value because of unicode compression
}
}
// Loop over all possible match positions in text
// Loop over pattern from right to left
// Shift search to the right by the maximum of the
// bad character shift and the good suffix shift
continue NEXT;
}
}
// Entire pattern matched starting at i
if (ret) {
return true;
}
i++;
}
// BnM is only used as the leading node in the unanchored case,
// and it replaced its Start() which always searches to the end
// if it doesn't find what it's looking for, so hitEnd is true.
return false;
}
}
}
/**
* Supplementary support version of BnM(). Unpaired surrogates are
* also handled by this class.
*/
int lengthInChars;
}
}
// Loop over all possible match positions in text
// Loop over pattern from right to left
int ch;
// Shift search to the right by the maximum of the
// bad character shift and the good suffix shift
i += countChars(seq, i, n);
continue NEXT;
}
}
// Entire pattern matched starting at i
if (ret) {
return true;
}
}
return false;
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/**
* This must be the very first initializer.
*/
private static class CharPropertyNames {
}
private static abstract class CharPropertyFactory {
}
final int typeMask) {
}
}
final int ctype) {
}
private static abstract class CloneableProperty
extends CharProperty implements Cloneable
{
try {
return (CloneableProperty) super.clone();
} catch (CloneNotSupportedException e) {
throw new AssertionError(e);
}
}
}
final CloneableProperty p) {
}
= new HashMap<>();
static {
// Unicode character property aliases, defined in
// Posix regular expression character classes, defined in
// Java character properties, defined by methods in Character.java
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
boolean isSatisfiedBy(int ch) {
}
}
}