2 * Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
26 package java.util.regex;
30 * Utility class that implements the standard C ctype functionality.
37 static final int UPPER = 0x00000100;
39 static final int LOWER = 0x00000200;
41 static final int DIGIT = 0x00000400;
43 static final int SPACE = 0x00000800;
45 static final int PUNCT = 0x00001000;
47 static final int CNTRL = 0x00002000;
49 static final int BLANK = 0x00004000;
51 static final int HEX = 0x00008000;
53 static final int UNDER = 0x00010000;
55 static final int ASCII = 0x0000FF00;
57 static final int ALPHA = (UPPER|LOWER);
59 static final int ALNUM = (UPPER|LOWER|DIGIT);
61 static final int GRAPH = (PUNCT|UPPER|LOWER|DIGIT);
63 static final int WORD = (UPPER|LOWER|UNDER|DIGIT);
65 static final int XDIGIT = (HEX);
67 private static final int[] ctype = new int[] {
77 SPACE+CNTRL+BLANK, /* 09 (HT) */
78 SPACE+CNTRL, /* 0A (LF) */
79 SPACE+CNTRL, /* 0B (VT) */
80 SPACE+CNTRL, /* 0C (FF) */
81 SPACE+CNTRL, /* 0D (CR) */
100 SPACE+BLANK, /* 20 SPACE */
116 DIGIT+HEX+0, /* 30 0 */
117 DIGIT+HEX+1, /* 31 1 */
118 DIGIT+HEX+2, /* 32 2 */
119 DIGIT+HEX+3, /* 33 3 */
120 DIGIT+HEX+4, /* 34 4 */
121 DIGIT+HEX+5, /* 35 5 */
122 DIGIT+HEX+6, /* 36 6 */
123 DIGIT+HEX+7, /* 37 7 */
124 DIGIT+HEX+8, /* 38 8 */
125 DIGIT+HEX+9, /* 39 9 */
133 UPPER+HEX+10, /* 41 A */
134 UPPER+HEX+11, /* 42 B */
135 UPPER+HEX+12, /* 43 C */
136 UPPER+HEX+13, /* 44 D */
137 UPPER+HEX+14, /* 45 E */
138 UPPER+HEX+15, /* 46 F */
163 PUNCT|UNDER, /* 5F _ */
165 LOWER+HEX+10, /* 61 a */
166 LOWER+HEX+11, /* 62 b */
167 LOWER+HEX+12, /* 63 c */
168 LOWER+HEX+13, /* 64 d */
169 LOWER+HEX+14, /* 65 e */
170 LOWER+HEX+15, /* 66 f */
195 CNTRL, /* 7F (DEL) */
198 static int getType(int ch) {
199 return ((ch & 0xFFFFFF80) == 0 ? ctype[ch] : 0);
202 static boolean isType(int ch, int type) {
203 return (getType(ch) & type) != 0;
206 static boolean isAscii(int ch) {
207 return ((ch & 0xFFFFFF80) == 0);
210 static boolean isAlpha(int ch) {
211 return isType(ch, ALPHA);
214 static boolean isDigit(int ch) {
215 return ((ch-'0')|('9'-ch)) >= 0;
218 static boolean isAlnum(int ch) {
219 return isType(ch, ALNUM);
222 static boolean isGraph(int ch) {
223 return isType(ch, GRAPH);
226 static boolean isPrint(int ch) {
227 return ((ch-0x20)|(0x7E-ch)) >= 0;
230 static boolean isPunct(int ch) {
231 return isType(ch, PUNCT);
234 static boolean isSpace(int ch) {
235 return isType(ch, SPACE);
238 static boolean isHexDigit(int ch) {
239 return isType(ch, HEX);
242 static boolean isOctDigit(int ch) {
243 return ((ch-'0')|('7'-ch)) >= 0;
246 static boolean isCntrl(int ch) {
247 return isType(ch, CNTRL);
250 static boolean isLower(int ch) {
251 return ((ch-'a')|('z'-ch)) >= 0;
254 static boolean isUpper(int ch) {
255 return ((ch-'A')|('Z'-ch)) >= 0;
258 static boolean isWord(int ch) {
259 return isType(ch, WORD);
262 static int toDigit(int ch) {
263 return (ctype[ch & 0x7F] & 0x3F);
266 static int toLower(int ch) {
267 return isUpper(ch) ? (ch + 0x20) : ch;
270 static int toUpper(int ch) {
271 return isLower(ch) ? (ch - 0x20) : ch;