1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
/*
* 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.
*
* 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.
*/
import java.util.HashMap;
import java.util.Locale;
public final class POSIX_Unicode {
public static boolean isAlpha(int ch) {
return Character.isAlphabetic(ch);
}
public static boolean isLower(int ch) {
return Character.isLowerCase(ch);
}
public static boolean isUpper(int ch) {
return Character.isUpperCase(ch);
}
// \p{Whitespace}
public static boolean isSpace(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);
}
// \p{gc=Control}
public static boolean isCntrl(int ch) {
return Character.getType(ch) == Character.CONTROL;
}
// \p{gc=Punctuation}
public static boolean isPunct(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;
}
// \p{gc=Decimal_Number}
// \p{Hex_Digit} -> PropList.txt: Hex_Digit
public static boolean isHexDigit(int ch) {
return Character.isDigit(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);
}
// \p{gc=Decimal_Number}
public static boolean isDigit(int ch) {
return Character.isDigit(ch);
};
// \p{alpha}
// \p{digit}
public static boolean isAlnum(int ch) {
return Character.isAlphabetic(ch) || Character.isDigit(ch);
}
// \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 static boolean isBlank(int ch) {
int type = Character.getType(ch);
return isSpace(ch) &&
ch != 0xa & ch != 0xb && ch !=0xc && ch != 0xd && ch != 0x85 &&
type != Character.LINE_SEPARATOR &&
type != Character.PARAGRAPH_SEPARATOR;
}
// [^
// \p{space}
// \p{gc=Control}
// \p{gc=Surrogate}
// \p{gc=Unassigned}]
public static boolean isGraph(int ch) {
int type = Character.getType(ch);
return !(isSpace(ch) ||
Character.CONTROL == type ||
Character.SURROGATE == type ||
Character.UNASSIGNED == type);
}
// \p{graph}
// \p{blank}
// -- \p{cntrl}
public static boolean isPrint(int ch) {
return (isGraph(ch) || isBlank(ch)) && !isCntrl(ch);
}
// PropList.txt:Noncharacter_Code_Point
public static boolean isNoncharacterCodePoint(int ch) {
return (ch & 0xfffe) == 0xfffe || (ch >= 0xfdd0 && ch <= 0xfdef);
}
public static boolean isJoinControl(int ch) {
return (ch == 0x200C || ch == 0x200D);
}
// \p{alpha}
// \p{gc=Mark}
// \p{digit}
// \p{gc=Connector_Punctuation}
public static boolean isWord(int ch) {
return isAlpha(ch) ||
((((1 << Character.NON_SPACING_MARK) |
(1 << Character.ENCLOSING_MARK) |
(1 << Character.COMBINING_SPACING_MARK) |
(1 << Character.CONNECTOR_PUNCTUATION)) >> Character.getType(ch)) & 1)
!= 0 ||
isDigit(ch) ||
isJoinControl(ch);
}
}
|