feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
274
jdkSrc/jdk8/java/util/regex/ASCII.java
Normal file
274
jdkSrc/jdk8/java/util/regex/ASCII.java
Normal file
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package java.util.regex;
|
||||
|
||||
|
||||
/**
|
||||
* Utility class that implements the standard C ctype functionality.
|
||||
*
|
||||
* @author Hong Zhang
|
||||
*/
|
||||
|
||||
final class ASCII {
|
||||
|
||||
static final int UPPER = 0x00000100;
|
||||
|
||||
static final int LOWER = 0x00000200;
|
||||
|
||||
static final int DIGIT = 0x00000400;
|
||||
|
||||
static final int SPACE = 0x00000800;
|
||||
|
||||
static final int PUNCT = 0x00001000;
|
||||
|
||||
static final int CNTRL = 0x00002000;
|
||||
|
||||
static final int BLANK = 0x00004000;
|
||||
|
||||
static final int HEX = 0x00008000;
|
||||
|
||||
static final int UNDER = 0x00010000;
|
||||
|
||||
static final int ASCII = 0x0000FF00;
|
||||
|
||||
static final int ALPHA = (UPPER|LOWER);
|
||||
|
||||
static final int ALNUM = (UPPER|LOWER|DIGIT);
|
||||
|
||||
static final int GRAPH = (PUNCT|UPPER|LOWER|DIGIT);
|
||||
|
||||
static final int WORD = (UPPER|LOWER|UNDER|DIGIT);
|
||||
|
||||
static final int XDIGIT = (HEX);
|
||||
|
||||
private static final int[] ctype = new int[] {
|
||||
CNTRL, /* 00 (NUL) */
|
||||
CNTRL, /* 01 (SOH) */
|
||||
CNTRL, /* 02 (STX) */
|
||||
CNTRL, /* 03 (ETX) */
|
||||
CNTRL, /* 04 (EOT) */
|
||||
CNTRL, /* 05 (ENQ) */
|
||||
CNTRL, /* 06 (ACK) */
|
||||
CNTRL, /* 07 (BEL) */
|
||||
CNTRL, /* 08 (BS) */
|
||||
SPACE+CNTRL+BLANK, /* 09 (HT) */
|
||||
SPACE+CNTRL, /* 0A (LF) */
|
||||
SPACE+CNTRL, /* 0B (VT) */
|
||||
SPACE+CNTRL, /* 0C (FF) */
|
||||
SPACE+CNTRL, /* 0D (CR) */
|
||||
CNTRL, /* 0E (SI) */
|
||||
CNTRL, /* 0F (SO) */
|
||||
CNTRL, /* 10 (DLE) */
|
||||
CNTRL, /* 11 (DC1) */
|
||||
CNTRL, /* 12 (DC2) */
|
||||
CNTRL, /* 13 (DC3) */
|
||||
CNTRL, /* 14 (DC4) */
|
||||
CNTRL, /* 15 (NAK) */
|
||||
CNTRL, /* 16 (SYN) */
|
||||
CNTRL, /* 17 (ETB) */
|
||||
CNTRL, /* 18 (CAN) */
|
||||
CNTRL, /* 19 (EM) */
|
||||
CNTRL, /* 1A (SUB) */
|
||||
CNTRL, /* 1B (ESC) */
|
||||
CNTRL, /* 1C (FS) */
|
||||
CNTRL, /* 1D (GS) */
|
||||
CNTRL, /* 1E (RS) */
|
||||
CNTRL, /* 1F (US) */
|
||||
SPACE+BLANK, /* 20 SPACE */
|
||||
PUNCT, /* 21 ! */
|
||||
PUNCT, /* 22 " */
|
||||
PUNCT, /* 23 # */
|
||||
PUNCT, /* 24 $ */
|
||||
PUNCT, /* 25 % */
|
||||
PUNCT, /* 26 & */
|
||||
PUNCT, /* 27 ' */
|
||||
PUNCT, /* 28 ( */
|
||||
PUNCT, /* 29 ) */
|
||||
PUNCT, /* 2A * */
|
||||
PUNCT, /* 2B + */
|
||||
PUNCT, /* 2C , */
|
||||
PUNCT, /* 2D - */
|
||||
PUNCT, /* 2E . */
|
||||
PUNCT, /* 2F / */
|
||||
DIGIT+HEX+0, /* 30 0 */
|
||||
DIGIT+HEX+1, /* 31 1 */
|
||||
DIGIT+HEX+2, /* 32 2 */
|
||||
DIGIT+HEX+3, /* 33 3 */
|
||||
DIGIT+HEX+4, /* 34 4 */
|
||||
DIGIT+HEX+5, /* 35 5 */
|
||||
DIGIT+HEX+6, /* 36 6 */
|
||||
DIGIT+HEX+7, /* 37 7 */
|
||||
DIGIT+HEX+8, /* 38 8 */
|
||||
DIGIT+HEX+9, /* 39 9 */
|
||||
PUNCT, /* 3A : */
|
||||
PUNCT, /* 3B ; */
|
||||
PUNCT, /* 3C < */
|
||||
PUNCT, /* 3D = */
|
||||
PUNCT, /* 3E > */
|
||||
PUNCT, /* 3F ? */
|
||||
PUNCT, /* 40 @ */
|
||||
UPPER+HEX+10, /* 41 A */
|
||||
UPPER+HEX+11, /* 42 B */
|
||||
UPPER+HEX+12, /* 43 C */
|
||||
UPPER+HEX+13, /* 44 D */
|
||||
UPPER+HEX+14, /* 45 E */
|
||||
UPPER+HEX+15, /* 46 F */
|
||||
UPPER+16, /* 47 G */
|
||||
UPPER+17, /* 48 H */
|
||||
UPPER+18, /* 49 I */
|
||||
UPPER+19, /* 4A J */
|
||||
UPPER+20, /* 4B K */
|
||||
UPPER+21, /* 4C L */
|
||||
UPPER+22, /* 4D M */
|
||||
UPPER+23, /* 4E N */
|
||||
UPPER+24, /* 4F O */
|
||||
UPPER+25, /* 50 P */
|
||||
UPPER+26, /* 51 Q */
|
||||
UPPER+27, /* 52 R */
|
||||
UPPER+28, /* 53 S */
|
||||
UPPER+29, /* 54 T */
|
||||
UPPER+30, /* 55 U */
|
||||
UPPER+31, /* 56 V */
|
||||
UPPER+32, /* 57 W */
|
||||
UPPER+33, /* 58 X */
|
||||
UPPER+34, /* 59 Y */
|
||||
UPPER+35, /* 5A Z */
|
||||
PUNCT, /* 5B [ */
|
||||
PUNCT, /* 5C \ */
|
||||
PUNCT, /* 5D ] */
|
||||
PUNCT, /* 5E ^ */
|
||||
PUNCT|UNDER, /* 5F _ */
|
||||
PUNCT, /* 60 ` */
|
||||
LOWER+HEX+10, /* 61 a */
|
||||
LOWER+HEX+11, /* 62 b */
|
||||
LOWER+HEX+12, /* 63 c */
|
||||
LOWER+HEX+13, /* 64 d */
|
||||
LOWER+HEX+14, /* 65 e */
|
||||
LOWER+HEX+15, /* 66 f */
|
||||
LOWER+16, /* 67 g */
|
||||
LOWER+17, /* 68 h */
|
||||
LOWER+18, /* 69 i */
|
||||
LOWER+19, /* 6A j */
|
||||
LOWER+20, /* 6B k */
|
||||
LOWER+21, /* 6C l */
|
||||
LOWER+22, /* 6D m */
|
||||
LOWER+23, /* 6E n */
|
||||
LOWER+24, /* 6F o */
|
||||
LOWER+25, /* 70 p */
|
||||
LOWER+26, /* 71 q */
|
||||
LOWER+27, /* 72 r */
|
||||
LOWER+28, /* 73 s */
|
||||
LOWER+29, /* 74 t */
|
||||
LOWER+30, /* 75 u */
|
||||
LOWER+31, /* 76 v */
|
||||
LOWER+32, /* 77 w */
|
||||
LOWER+33, /* 78 x */
|
||||
LOWER+34, /* 79 y */
|
||||
LOWER+35, /* 7A z */
|
||||
PUNCT, /* 7B { */
|
||||
PUNCT, /* 7C | */
|
||||
PUNCT, /* 7D } */
|
||||
PUNCT, /* 7E ~ */
|
||||
CNTRL, /* 7F (DEL) */
|
||||
};
|
||||
|
||||
static int getType(int ch) {
|
||||
return ((ch & 0xFFFFFF80) == 0 ? ctype[ch] : 0);
|
||||
}
|
||||
|
||||
static boolean isType(int ch, int type) {
|
||||
return (getType(ch) & type) != 0;
|
||||
}
|
||||
|
||||
static boolean isAscii(int ch) {
|
||||
return ((ch & 0xFFFFFF80) == 0);
|
||||
}
|
||||
|
||||
static boolean isAlpha(int ch) {
|
||||
return isType(ch, ALPHA);
|
||||
}
|
||||
|
||||
static boolean isDigit(int ch) {
|
||||
return ((ch-'0')|('9'-ch)) >= 0;
|
||||
}
|
||||
|
||||
static boolean isAlnum(int ch) {
|
||||
return isType(ch, ALNUM);
|
||||
}
|
||||
|
||||
static boolean isGraph(int ch) {
|
||||
return isType(ch, GRAPH);
|
||||
}
|
||||
|
||||
static boolean isPrint(int ch) {
|
||||
return ((ch-0x20)|(0x7E-ch)) >= 0;
|
||||
}
|
||||
|
||||
static boolean isPunct(int ch) {
|
||||
return isType(ch, PUNCT);
|
||||
}
|
||||
|
||||
static boolean isSpace(int ch) {
|
||||
return isType(ch, SPACE);
|
||||
}
|
||||
|
||||
static boolean isHexDigit(int ch) {
|
||||
return isType(ch, HEX);
|
||||
}
|
||||
|
||||
static boolean isOctDigit(int ch) {
|
||||
return ((ch-'0')|('7'-ch)) >= 0;
|
||||
}
|
||||
|
||||
static boolean isCntrl(int ch) {
|
||||
return isType(ch, CNTRL);
|
||||
}
|
||||
|
||||
static boolean isLower(int ch) {
|
||||
return ((ch-'a')|('z'-ch)) >= 0;
|
||||
}
|
||||
|
||||
static boolean isUpper(int ch) {
|
||||
return ((ch-'A')|('Z'-ch)) >= 0;
|
||||
}
|
||||
|
||||
static boolean isWord(int ch) {
|
||||
return isType(ch, WORD);
|
||||
}
|
||||
|
||||
static int toDigit(int ch) {
|
||||
return (ctype[ch & 0x7F] & 0x3F);
|
||||
}
|
||||
|
||||
static int toLower(int ch) {
|
||||
return isUpper(ch) ? (ch + 0x20) : ch;
|
||||
}
|
||||
|
||||
static int toUpper(int ch) {
|
||||
return isLower(ch) ? (ch - 0x20) : ch;
|
||||
}
|
||||
|
||||
}
|
||||
188
jdkSrc/jdk8/java/util/regex/MatchResult.java
Normal file
188
jdkSrc/jdk8/java/util/regex/MatchResult.java
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package java.util.regex;
|
||||
|
||||
/**
|
||||
* The result of a match operation.
|
||||
*
|
||||
* <p>This interface contains query methods used to determine the
|
||||
* results of a match against a regular expression. The match boundaries,
|
||||
* groups and group boundaries can be seen but not modified through
|
||||
* a <code>MatchResult</code>.
|
||||
*
|
||||
* @author Michael McCloskey
|
||||
* @see Matcher
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface MatchResult {
|
||||
|
||||
/**
|
||||
* Returns the start index of the match.
|
||||
*
|
||||
* @return The index of the first character matched
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If no match has yet been attempted,
|
||||
* or if the previous match operation failed
|
||||
*/
|
||||
public int start();
|
||||
|
||||
/**
|
||||
* Returns the start index of the subsequence captured by the given group
|
||||
* during this match.
|
||||
*
|
||||
* <p> <a href="Pattern.html#cg">Capturing groups</a> are indexed from left
|
||||
* to right, starting at one. Group zero denotes the entire pattern, so
|
||||
* the expression <i>m.</i><tt>start(0)</tt> is equivalent to
|
||||
* <i>m.</i><tt>start()</tt>. </p>
|
||||
*
|
||||
* @param group
|
||||
* The index of a capturing group in this matcher's pattern
|
||||
*
|
||||
* @return The index of the first character captured by the group,
|
||||
* or <tt>-1</tt> if the match was successful but the group
|
||||
* itself did not match anything
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If no match has yet been attempted,
|
||||
* or if the previous match operation failed
|
||||
*
|
||||
* @throws IndexOutOfBoundsException
|
||||
* If there is no capturing group in the pattern
|
||||
* with the given index
|
||||
*/
|
||||
public int start(int group);
|
||||
|
||||
/**
|
||||
* Returns the offset after the last character matched.
|
||||
*
|
||||
* @return The offset after the last character matched
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If no match has yet been attempted,
|
||||
* or if the previous match operation failed
|
||||
*/
|
||||
public int end();
|
||||
|
||||
/**
|
||||
* Returns the offset after the last character of the subsequence
|
||||
* captured by the given group during this match.
|
||||
*
|
||||
* <p> <a href="Pattern.html#cg">Capturing groups</a> are indexed from left
|
||||
* to right, starting at one. Group zero denotes the entire pattern, so
|
||||
* the expression <i>m.</i><tt>end(0)</tt> is equivalent to
|
||||
* <i>m.</i><tt>end()</tt>. </p>
|
||||
*
|
||||
* @param group
|
||||
* The index of a capturing group in this matcher's pattern
|
||||
*
|
||||
* @return The offset after the last character captured by the group,
|
||||
* or <tt>-1</tt> if the match was successful
|
||||
* but the group itself did not match anything
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If no match has yet been attempted,
|
||||
* or if the previous match operation failed
|
||||
*
|
||||
* @throws IndexOutOfBoundsException
|
||||
* If there is no capturing group in the pattern
|
||||
* with the given index
|
||||
*/
|
||||
public int end(int group);
|
||||
|
||||
/**
|
||||
* Returns the input subsequence matched by the previous match.
|
||||
*
|
||||
* <p> For a matcher <i>m</i> with input sequence <i>s</i>,
|
||||
* the expressions <i>m.</i><tt>group()</tt> and
|
||||
* <i>s.</i><tt>substring(</tt><i>m.</i><tt>start(),</tt> <i>m.</i><tt>end())</tt>
|
||||
* are equivalent. </p>
|
||||
*
|
||||
* <p> Note that some patterns, for example <tt>a*</tt>, match the empty
|
||||
* string. This method will return the empty string when the pattern
|
||||
* successfully matches the empty string in the input. </p>
|
||||
*
|
||||
* @return The (possibly empty) subsequence matched by the previous match,
|
||||
* in string form
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If no match has yet been attempted,
|
||||
* or if the previous match operation failed
|
||||
*/
|
||||
public String group();
|
||||
|
||||
/**
|
||||
* Returns the input subsequence captured by the given group during the
|
||||
* previous match operation.
|
||||
*
|
||||
* <p> For a matcher <i>m</i>, input sequence <i>s</i>, and group index
|
||||
* <i>g</i>, the expressions <i>m.</i><tt>group(</tt><i>g</i><tt>)</tt> and
|
||||
* <i>s.</i><tt>substring(</tt><i>m.</i><tt>start(</tt><i>g</i><tt>),</tt> <i>m.</i><tt>end(</tt><i>g</i><tt>))</tt>
|
||||
* are equivalent. </p>
|
||||
*
|
||||
* <p> <a href="Pattern.html#cg">Capturing groups</a> are indexed from left
|
||||
* to right, starting at one. Group zero denotes the entire pattern, so
|
||||
* the expression <tt>m.group(0)</tt> is equivalent to <tt>m.group()</tt>.
|
||||
* </p>
|
||||
*
|
||||
* <p> If the match was successful but the group specified failed to match
|
||||
* any part of the input sequence, then <tt>null</tt> is returned. Note
|
||||
* that some groups, for example <tt>(a*)</tt>, match the empty string.
|
||||
* This method will return the empty string when such a group successfully
|
||||
* matches the empty string in the input. </p>
|
||||
*
|
||||
* @param group
|
||||
* The index of a capturing group in this matcher's pattern
|
||||
*
|
||||
* @return The (possibly empty) subsequence captured by the group
|
||||
* during the previous match, or <tt>null</tt> if the group
|
||||
* failed to match part of the input
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If no match has yet been attempted,
|
||||
* or if the previous match operation failed
|
||||
*
|
||||
* @throws IndexOutOfBoundsException
|
||||
* If there is no capturing group in the pattern
|
||||
* with the given index
|
||||
*/
|
||||
public String group(int group);
|
||||
|
||||
/**
|
||||
* Returns the number of capturing groups in this match result's pattern.
|
||||
*
|
||||
* <p> Group zero denotes the entire pattern by convention. It is not
|
||||
* included in this count.
|
||||
*
|
||||
* <p> Any non-negative integer smaller than or equal to the value
|
||||
* returned by this method is guaranteed to be a valid group index for
|
||||
* this matcher. </p>
|
||||
*
|
||||
* @return The number of capturing groups in this matcher's pattern
|
||||
*/
|
||||
public int groupCount();
|
||||
|
||||
}
|
||||
1319
jdkSrc/jdk8/java/util/regex/Matcher.java
Normal file
1319
jdkSrc/jdk8/java/util/regex/Matcher.java
Normal file
File diff suppressed because it is too large
Load Diff
5870
jdkSrc/jdk8/java/util/regex/Pattern.java
Normal file
5870
jdkSrc/jdk8/java/util/regex/Pattern.java
Normal file
File diff suppressed because it is too large
Load Diff
124
jdkSrc/jdk8/java/util/regex/PatternSyntaxException.java
Normal file
124
jdkSrc/jdk8/java/util/regex/PatternSyntaxException.java
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package java.util.regex;
|
||||
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
|
||||
/**
|
||||
* Unchecked exception thrown to indicate a syntax error in a
|
||||
* regular-expression pattern.
|
||||
*
|
||||
* @author unascribed
|
||||
* @since 1.4
|
||||
* @spec JSR-51
|
||||
*/
|
||||
|
||||
public class PatternSyntaxException
|
||||
extends IllegalArgumentException
|
||||
{
|
||||
private static final long serialVersionUID = -3864639126226059218L;
|
||||
|
||||
private final String desc;
|
||||
private final String pattern;
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of this class.
|
||||
*
|
||||
* @param desc
|
||||
* A description of the error
|
||||
*
|
||||
* @param regex
|
||||
* The erroneous pattern
|
||||
*
|
||||
* @param index
|
||||
* The approximate index in the pattern of the error,
|
||||
* or <tt>-1</tt> if the index is not known
|
||||
*/
|
||||
public PatternSyntaxException(String desc, String regex, int index) {
|
||||
this.desc = desc;
|
||||
this.pattern = regex;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the error index.
|
||||
*
|
||||
* @return The approximate index in the pattern of the error,
|
||||
* or <tt>-1</tt> if the index is not known
|
||||
*/
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the description of the error.
|
||||
*
|
||||
* @return The description of the error
|
||||
*/
|
||||
public String getDescription() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the erroneous regular-expression pattern.
|
||||
*
|
||||
* @return The erroneous pattern
|
||||
*/
|
||||
public String getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
private static final String nl =
|
||||
java.security.AccessController
|
||||
.doPrivileged(new GetPropertyAction("line.separator"));
|
||||
|
||||
/**
|
||||
* Returns a multi-line string containing the description of the syntax
|
||||
* error and its index, the erroneous regular-expression pattern, and a
|
||||
* visual indication of the error index within the pattern.
|
||||
*
|
||||
* @return The full detail message
|
||||
*/
|
||||
public String getMessage() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(desc);
|
||||
if (index >= 0) {
|
||||
sb.append(" near index ");
|
||||
sb.append(index);
|
||||
}
|
||||
sb.append(nl);
|
||||
sb.append(pattern);
|
||||
if (index >= 0 && pattern != null && index < pattern.length()) {
|
||||
sb.append(nl);
|
||||
for (int i = 0; i < index; i++) sb.append(' ');
|
||||
sb.append('^');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
246
jdkSrc/jdk8/java/util/regex/UnicodeProp.java
Normal file
246
jdkSrc/jdk8/java/util/regex/UnicodeProp.java
Normal file
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package java.util.regex;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
enum UnicodeProp {
|
||||
|
||||
ALPHABETIC {
|
||||
public boolean is(int ch) {
|
||||
return Character.isAlphabetic(ch);
|
||||
}
|
||||
},
|
||||
|
||||
LETTER {
|
||||
public boolean is(int ch) {
|
||||
return Character.isLetter(ch);
|
||||
}
|
||||
},
|
||||
|
||||
IDEOGRAPHIC {
|
||||
public boolean is(int ch) {
|
||||
return Character.isIdeographic(ch);
|
||||
}
|
||||
},
|
||||
|
||||
LOWERCASE {
|
||||
public boolean is(int ch) {
|
||||
return Character.isLowerCase(ch);
|
||||
}
|
||||
},
|
||||
|
||||
UPPERCASE {
|
||||
public boolean is(int ch) {
|
||||
return Character.isUpperCase(ch);
|
||||
}
|
||||
},
|
||||
|
||||
TITLECASE {
|
||||
public boolean is(int ch) {
|
||||
return Character.isTitleCase(ch);
|
||||
}
|
||||
},
|
||||
|
||||
WHITE_SPACE {
|
||||
// \p{Whitespace}
|
||||
public boolean is(int ch) {
|
||||
return ((((1 << Character.SPACE_SEPARATOR) |
|
||||
(1 << Character.LINE_SEPARATOR) |
|
||||
(1 << Character.PARAGRAPH_SEPARATOR)) >> Character.getType(ch)) & 1)
|
||||
!= 0 || (ch >= 0x9 && ch <= 0xd) || (ch == 0x85);
|
||||
}
|
||||
},
|
||||
|
||||
CONTROL {
|
||||
// \p{gc=Control}
|
||||
public boolean is(int ch) {
|
||||
return Character.getType(ch) == Character.CONTROL;
|
||||
}
|
||||
},
|
||||
|
||||
PUNCTUATION {
|
||||
// \p{gc=Punctuation}
|
||||
public boolean is(int ch) {
|
||||
return ((((1 << Character.CONNECTOR_PUNCTUATION) |
|
||||
(1 << Character.DASH_PUNCTUATION) |
|
||||
(1 << Character.START_PUNCTUATION) |
|
||||
(1 << Character.END_PUNCTUATION) |
|
||||
(1 << Character.OTHER_PUNCTUATION) |
|
||||
(1 << Character.INITIAL_QUOTE_PUNCTUATION) |
|
||||
(1 << Character.FINAL_QUOTE_PUNCTUATION)) >> Character.getType(ch)) & 1)
|
||||
!= 0;
|
||||
}
|
||||
},
|
||||
|
||||
HEX_DIGIT {
|
||||
// \p{gc=Decimal_Number}
|
||||
// \p{Hex_Digit} -> PropList.txt: Hex_Digit
|
||||
public boolean is(int ch) {
|
||||
return DIGIT.is(ch) ||
|
||||
(ch >= 0x0030 && ch <= 0x0039) ||
|
||||
(ch >= 0x0041 && ch <= 0x0046) ||
|
||||
(ch >= 0x0061 && ch <= 0x0066) ||
|
||||
(ch >= 0xFF10 && ch <= 0xFF19) ||
|
||||
(ch >= 0xFF21 && ch <= 0xFF26) ||
|
||||
(ch >= 0xFF41 && ch <= 0xFF46);
|
||||
}
|
||||
},
|
||||
|
||||
ASSIGNED {
|
||||
public boolean is(int ch) {
|
||||
return Character.getType(ch) != Character.UNASSIGNED;
|
||||
}
|
||||
},
|
||||
|
||||
NONCHARACTER_CODE_POINT {
|
||||
// PropList.txt:Noncharacter_Code_Point
|
||||
public boolean is(int ch) {
|
||||
return (ch & 0xfffe) == 0xfffe || (ch >= 0xfdd0 && ch <= 0xfdef);
|
||||
}
|
||||
},
|
||||
|
||||
DIGIT {
|
||||
// \p{gc=Decimal_Number}
|
||||
public boolean is(int ch) {
|
||||
return Character.isDigit(ch);
|
||||
}
|
||||
},
|
||||
|
||||
ALNUM {
|
||||
// \p{alpha}
|
||||
// \p{digit}
|
||||
public boolean is(int ch) {
|
||||
return ALPHABETIC.is(ch) || DIGIT.is(ch);
|
||||
}
|
||||
},
|
||||
|
||||
BLANK {
|
||||
// \p{Whitespace} --
|
||||
// [\N{LF} \N{VT} \N{FF} \N{CR} \N{NEL} -> 0xa, 0xb, 0xc, 0xd, 0x85
|
||||
// \p{gc=Line_Separator}
|
||||
// \p{gc=Paragraph_Separator}]
|
||||
public boolean is(int ch) {
|
||||
return Character.getType(ch) == Character.SPACE_SEPARATOR ||
|
||||
ch == 0x9; // \N{HT}
|
||||
}
|
||||
},
|
||||
|
||||
GRAPH {
|
||||
// [^
|
||||
// \p{space}
|
||||
// \p{gc=Control}
|
||||
// \p{gc=Surrogate}
|
||||
// \p{gc=Unassigned}]
|
||||
public boolean is(int ch) {
|
||||
return ((((1 << Character.SPACE_SEPARATOR) |
|
||||
(1 << Character.LINE_SEPARATOR) |
|
||||
(1 << Character.PARAGRAPH_SEPARATOR) |
|
||||
(1 << Character.CONTROL) |
|
||||
(1 << Character.SURROGATE) |
|
||||
(1 << Character.UNASSIGNED)) >> Character.getType(ch)) & 1)
|
||||
== 0;
|
||||
}
|
||||
},
|
||||
|
||||
PRINT {
|
||||
// \p{graph}
|
||||
// \p{blank}
|
||||
// -- \p{cntrl}
|
||||
public boolean is(int ch) {
|
||||
return (GRAPH.is(ch) || BLANK.is(ch)) && !CONTROL.is(ch);
|
||||
}
|
||||
},
|
||||
|
||||
WORD {
|
||||
// \p{alpha}
|
||||
// \p{gc=Mark}
|
||||
// \p{digit}
|
||||
// \p{gc=Connector_Punctuation}
|
||||
// \p{Join_Control} 200C..200D
|
||||
|
||||
public boolean is(int ch) {
|
||||
return ALPHABETIC.is(ch) ||
|
||||
((((1 << Character.NON_SPACING_MARK) |
|
||||
(1 << Character.ENCLOSING_MARK) |
|
||||
(1 << Character.COMBINING_SPACING_MARK) |
|
||||
(1 << Character.DECIMAL_DIGIT_NUMBER) |
|
||||
(1 << Character.CONNECTOR_PUNCTUATION)) >> Character.getType(ch)) & 1)
|
||||
!= 0 ||
|
||||
JOIN_CONTROL.is(ch);
|
||||
}
|
||||
},
|
||||
|
||||
JOIN_CONTROL {
|
||||
// 200C..200D PropList.txt:Join_Control
|
||||
public boolean is(int ch) {
|
||||
return (ch == 0x200C || ch == 0x200D);
|
||||
}
|
||||
};
|
||||
|
||||
private final static HashMap<String, String> posix = new HashMap<>();
|
||||
private final static HashMap<String, String> aliases = new HashMap<>();
|
||||
static {
|
||||
posix.put("ALPHA", "ALPHABETIC");
|
||||
posix.put("LOWER", "LOWERCASE");
|
||||
posix.put("UPPER", "UPPERCASE");
|
||||
posix.put("SPACE", "WHITE_SPACE");
|
||||
posix.put("PUNCT", "PUNCTUATION");
|
||||
posix.put("XDIGIT","HEX_DIGIT");
|
||||
posix.put("ALNUM", "ALNUM");
|
||||
posix.put("CNTRL", "CONTROL");
|
||||
posix.put("DIGIT", "DIGIT");
|
||||
posix.put("BLANK", "BLANK");
|
||||
posix.put("GRAPH", "GRAPH");
|
||||
posix.put("PRINT", "PRINT");
|
||||
|
||||
aliases.put("WHITESPACE", "WHITE_SPACE");
|
||||
aliases.put("HEXDIGIT","HEX_DIGIT");
|
||||
aliases.put("NONCHARACTERCODEPOINT", "NONCHARACTER_CODE_POINT");
|
||||
aliases.put("JOINCONTROL", "JOIN_CONTROL");
|
||||
}
|
||||
|
||||
public static UnicodeProp forName(String propName) {
|
||||
propName = propName.toUpperCase(Locale.ENGLISH);
|
||||
String alias = aliases.get(propName);
|
||||
if (alias != null)
|
||||
propName = alias;
|
||||
try {
|
||||
return valueOf (propName);
|
||||
} catch (IllegalArgumentException x) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static UnicodeProp forPOSIXName(String propName) {
|
||||
propName = posix.get(propName.toUpperCase(Locale.ENGLISH));
|
||||
if (propName == null)
|
||||
return null;
|
||||
return valueOf (propName);
|
||||
}
|
||||
|
||||
public abstract boolean is(int ch);
|
||||
}
|
||||
Reference in New Issue
Block a user