4139N/A/*
4139N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4139N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4139N/A *
4139N/A * This code is free software; you can redistribute it and/or modify it
4139N/A * under the terms of the GNU General Public License version 2 only, as
4139N/A * published by the Free Software Foundation.
4139N/A *
4139N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4139N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4139N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4139N/A * version 2 for more details (a copy is included in the LICENSE file that
4139N/A * accompanied this code).
4139N/A *
4139N/A * You should have received a copy of the GNU General Public License version
4139N/A * 2 along with this work; if not, write to the Free Software Foundation,
4139N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4139N/A *
4139N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4139N/A * or visit www.oracle.com if you need additional information or have any
4139N/A * questions.
4139N/A */
4139N/A
4139N/Aimport java.util.HashMap;
4139N/Aimport java.util.Locale;
4139N/A
4139N/Afinal public class POSIX_Unicode {
4139N/A
4139N/A public static boolean isAlpha(int ch) {
4139N/A return Character.isAlphabetic(ch);
4139N/A }
4139N/A
4139N/A public static boolean isLower(int ch) {
4139N/A return Character.isLowerCase(ch);
4139N/A }
4139N/A
4139N/A public static boolean isUpper(int ch) {
4139N/A return Character.isUpperCase(ch);
4139N/A }
4139N/A
4139N/A // \p{Whitespace}
4139N/A public static boolean isSpace(int ch) {
4139N/A return ((((1 << Character.SPACE_SEPARATOR) |
4139N/A (1 << Character.LINE_SEPARATOR) |
4139N/A (1 << Character.PARAGRAPH_SEPARATOR)) >> Character.getType(ch)) & 1)
4139N/A != 0 ||
4139N/A (ch >= 0x9 && ch <= 0xd) ||
4139N/A (ch == 0x85);
4139N/A }
4139N/A
4139N/A // \p{gc=Control}
4139N/A public static boolean isCntrl(int ch) {
4139N/A return Character.getType(ch) == Character.CONTROL;
4139N/A }
4139N/A
4139N/A // \p{gc=Punctuation}
4139N/A public static boolean isPunct(int ch) {
4139N/A return ((((1 << Character.CONNECTOR_PUNCTUATION) |
4139N/A (1 << Character.DASH_PUNCTUATION) |
4139N/A (1 << Character.START_PUNCTUATION) |
4139N/A (1 << Character.END_PUNCTUATION) |
4139N/A (1 << Character.OTHER_PUNCTUATION) |
4139N/A (1 << Character.INITIAL_QUOTE_PUNCTUATION) |
4139N/A (1 << Character.FINAL_QUOTE_PUNCTUATION)) >> Character.getType(ch)) & 1)
4139N/A != 0;
4139N/A }
4139N/A
4139N/A // \p{gc=Decimal_Number}
4139N/A // \p{Hex_Digit} -> PropList.txt: Hex_Digit
4139N/A public static boolean isHexDigit(int ch) {
4139N/A return Character.isDigit(ch) ||
4139N/A (ch >= 0x0030 && ch <= 0x0039) ||
4139N/A (ch >= 0x0041 && ch <= 0x0046) ||
4139N/A (ch >= 0x0061 && ch <= 0x0066) ||
4139N/A (ch >= 0xFF10 && ch <= 0xFF19) ||
4139N/A (ch >= 0xFF21 && ch <= 0xFF26) ||
4139N/A (ch >= 0xFF41 && ch <= 0xFF46);
4139N/A }
4139N/A
4139N/A // \p{gc=Decimal_Number}
4139N/A public static boolean isDigit(int ch) {
4139N/A return Character.isDigit(ch);
4139N/A };
4139N/A
4139N/A // \p{alpha}
4139N/A // \p{digit}
4139N/A public static boolean isAlnum(int ch) {
4139N/A return Character.isAlphabetic(ch) || Character.isDigit(ch);
4139N/A }
4139N/A
4139N/A // \p{Whitespace} --
4139N/A // [\N{LF} \N{VT} \N{FF} \N{CR} \N{NEL} -> 0xa, 0xb, 0xc, 0xd, 0x85
4139N/A // \p{gc=Line_Separator}
4139N/A // \p{gc=Paragraph_Separator}]
4139N/A public static boolean isBlank(int ch) {
4139N/A int type = Character.getType(ch);
4139N/A return isSpace(ch) &&
4139N/A ch != 0xa & ch != 0xb && ch !=0xc && ch != 0xd && ch != 0x85 &&
4139N/A type != Character.LINE_SEPARATOR &&
4139N/A type != Character.PARAGRAPH_SEPARATOR;
4139N/A }
4139N/A
4139N/A // [^
4139N/A // \p{space}
4139N/A // \p{gc=Control}
4139N/A // \p{gc=Surrogate}
4139N/A // \p{gc=Unassigned}]
4139N/A public static boolean isGraph(int ch) {
4139N/A int type = Character.getType(ch);
4139N/A return !(isSpace(ch) ||
4139N/A Character.CONTROL == type ||
4139N/A Character.SURROGATE == type ||
4139N/A Character.UNASSIGNED == type);
4139N/A }
4139N/A
4139N/A // \p{graph}
4139N/A // \p{blank}
4139N/A // -- \p{cntrl}
4139N/A public static boolean isPrint(int ch) {
4139N/A return (isGraph(ch) || isBlank(ch)) && !isCntrl(ch);
4139N/A }
4139N/A
4139N/A // PropList.txt:Noncharacter_Code_Point
4139N/A public static boolean isNoncharacterCodePoint(int ch) {
4139N/A return (ch & 0xfffe) == 0xfffe || (ch >= 0xfdd0 && ch <= 0xfdef);
4139N/A }
4139N/A
4139N/A // \p{alpha}
4139N/A // \p{gc=Mark}
4139N/A // \p{digit}
4139N/A // \p{gc=Connector_Punctuation}
4139N/A public static boolean isWord(int ch) {
4139N/A return isAlpha(ch) ||
4139N/A ((((1 << Character.NON_SPACING_MARK) |
4139N/A (1 << Character.ENCLOSING_MARK) |
4139N/A (1 << Character.COMBINING_SPACING_MARK) |
4139N/A (1 << Character.CONNECTOR_PUNCTUATION)) >> Character.getType(ch)) & 1)
4139N/A != 0 ||
4139N/A isDigit(ch);
4139N/A }
4139N/A}