1 /* 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package test.java.util.regex; 25 26 27 final class POSIX_ASCII { 28 29 static final int UPPER = 0x00000100; 30 31 static final int LOWER = 0x00000200; 32 33 static final int DIGIT = 0x00000400; 34 35 static final int SPACE = 0x00000800; 36 37 static final int PUNCT = 0x00001000; 38 39 static final int CNTRL = 0x00002000; 40 41 static final int BLANK = 0x00004000; 42 43 static final int HEX = 0x00008000; 44 45 static final int UNDER = 0x00010000; 46 47 static final int ASCII = 0x0000FF00; 48 49 static final int ALPHA = (UPPER|LOWER); 50 51 static final int ALNUM = (UPPER|LOWER|DIGIT); 52 53 static final int GRAPH = (PUNCT|UPPER|LOWER|DIGIT); 54 55 static final int WORD = (UPPER|LOWER|UNDER|DIGIT); 56 57 static final int XDIGIT = (HEX); 58 59 private static final int[] ctype = new int[] { 60 CNTRL, /* 00 (NUL) */ 61 CNTRL, /* 01 (SOH) */ 62 CNTRL, /* 02 (STX) */ 63 CNTRL, /* 03 (ETX) */ 64 CNTRL, /* 04 (EOT) */ 65 CNTRL, /* 05 (ENQ) */ 66 CNTRL, /* 06 (ACK) */ 67 CNTRL, /* 07 (BEL) */ 68 CNTRL, /* 08 (BS) */ 69 SPACE+CNTRL+BLANK, /* 09 (HT) */ 70 SPACE+CNTRL, /* 0A (LF) */ 71 SPACE+CNTRL, /* 0B (VT) */ 72 SPACE+CNTRL, /* 0C (FF) */ 73 SPACE+CNTRL, /* 0D (CR) */ 74 CNTRL, /* 0E (SI) */ 75 CNTRL, /* 0F (SO) */ 76 CNTRL, /* 10 (DLE) */ 77 CNTRL, /* 11 (DC1) */ 78 CNTRL, /* 12 (DC2) */ 79 CNTRL, /* 13 (DC3) */ 80 CNTRL, /* 14 (DC4) */ 81 CNTRL, /* 15 (NAK) */ 82 CNTRL, /* 16 (SYN) */ 83 CNTRL, /* 17 (ETB) */ 84 CNTRL, /* 18 (CAN) */ 85 CNTRL, /* 19 (EM) */ 86 CNTRL, /* 1A (SUB) */ 87 CNTRL, /* 1B (ESC) */ 88 CNTRL, /* 1C (FS) */ 89 CNTRL, /* 1D (GS) */ 90 CNTRL, /* 1E (RS) */ 91 CNTRL, /* 1F (US) */ 92 SPACE+BLANK, /* 20 SPACE */ 93 PUNCT, /* 21 ! */ 94 PUNCT, /* 22 " */ 95 PUNCT, /* 23 # */ 96 PUNCT, /* 24 $ */ 97 PUNCT, /* 25 % */ 98 PUNCT, /* 26 & */ 99 PUNCT, /* 27 ' */ 100 PUNCT, /* 28 ( */ 101 PUNCT, /* 29 ) */ 102 PUNCT, /* 2A * */ 103 PUNCT, /* 2B + */ 104 PUNCT, /* 2C , */ 105 PUNCT, /* 2D - */ 106 PUNCT, /* 2E . */ 107 PUNCT, /* 2F / */ 108 DIGIT+HEX+0, /* 30 0 */ 109 DIGIT+HEX+1, /* 31 1 */ 110 DIGIT+HEX+2, /* 32 2 */ 111 DIGIT+HEX+3, /* 33 3 */ 112 DIGIT+HEX+4, /* 34 4 */ 113 DIGIT+HEX+5, /* 35 5 */ 114 DIGIT+HEX+6, /* 36 6 */ 115 DIGIT+HEX+7, /* 37 7 */ 116 DIGIT+HEX+8, /* 38 8 */ 117 DIGIT+HEX+9, /* 39 9 */ 118 PUNCT, /* 3A : */ 119 PUNCT, /* 3B ; */ 120 PUNCT, /* 3C < */ 121 PUNCT, /* 3D = */ 122 PUNCT, /* 3E > */ 123 PUNCT, /* 3F ? */ 124 PUNCT, /* 40 @ */ 125 UPPER+HEX+10, /* 41 A */ 126 UPPER+HEX+11, /* 42 B */ 127 UPPER+HEX+12, /* 43 C */ 128 UPPER+HEX+13, /* 44 D */ 129 UPPER+HEX+14, /* 45 E */ 130 UPPER+HEX+15, /* 46 F */ 131 UPPER+16, /* 47 G */ 132 UPPER+17, /* 48 H */ 133 UPPER+18, /* 49 I */ 134 UPPER+19, /* 4A J */ 135 UPPER+20, /* 4B K */ 136 UPPER+21, /* 4C L */ 137 UPPER+22, /* 4D M */ 138 UPPER+23, /* 4E N */ 139 UPPER+24, /* 4F O */ 140 UPPER+25, /* 50 P */ 141 UPPER+26, /* 51 Q */ 142 UPPER+27, /* 52 R */ 143 UPPER+28, /* 53 S */ 144 UPPER+29, /* 54 T */ 145 UPPER+30, /* 55 U */ 146 UPPER+31, /* 56 V */ 147 UPPER+32, /* 57 W */ 148 UPPER+33, /* 58 X */ 149 UPPER+34, /* 59 Y */ 150 UPPER+35, /* 5A Z */ 151 PUNCT, /* 5B [ */ 152 PUNCT, /* 5C \ */ 153 PUNCT, /* 5D ] */ 154 PUNCT, /* 5E ^ */ 155 PUNCT|UNDER, /* 5F _ */ 156 PUNCT, /* 60 ` */ 157 LOWER+HEX+10, /* 61 a */ 158 LOWER+HEX+11, /* 62 b */ 159 LOWER+HEX+12, /* 63 c */ 160 LOWER+HEX+13, /* 64 d */ 161 LOWER+HEX+14, /* 65 e */ 162 LOWER+HEX+15, /* 66 f */ 163 LOWER+16, /* 67 g */ 164 LOWER+17, /* 68 h */ 165 LOWER+18, /* 69 i */ 166 LOWER+19, /* 6A j */ 167 LOWER+20, /* 6B k */ 168 LOWER+21, /* 6C l */ 169 LOWER+22, /* 6D m */ 170 LOWER+23, /* 6E n */ 171 LOWER+24, /* 6F o */ 172 LOWER+25, /* 70 p */ 173 LOWER+26, /* 71 q */ 174 LOWER+27, /* 72 r */ 175 LOWER+28, /* 73 s */ 176 LOWER+29, /* 74 t */ 177 LOWER+30, /* 75 u */ 178 LOWER+31, /* 76 v */ 179 LOWER+32, /* 77 w */ 180 LOWER+33, /* 78 x */ 181 LOWER+34, /* 79 y */ 182 LOWER+35, /* 7A z */ 183 PUNCT, /* 7B { */ 184 PUNCT, /* 7C | */ 185 PUNCT, /* 7D } */ 186 PUNCT, /* 7E ~ */ 187 CNTRL, /* 7F (DEL) */ 188 }; 189 getType(int ch)190 static int getType(int ch) { 191 return ((ch & 0xFFFFFF80) == 0 ? ctype[ch] : 0); 192 } 193 isType(int ch, int type)194 static boolean isType(int ch, int type) { 195 return (getType(ch) & type) != 0; 196 } 197 isAscii(int ch)198 static boolean isAscii(int ch) { 199 return ((ch & 0xFFFFFF80) == 0); 200 } 201 isAlpha(int ch)202 static boolean isAlpha(int ch) { 203 return isType(ch, ALPHA); 204 } 205 isDigit(int ch)206 static boolean isDigit(int ch) { 207 return ((ch-'0')|('9'-ch)) >= 0; 208 } 209 isAlnum(int ch)210 static boolean isAlnum(int ch) { 211 return isType(ch, ALNUM); 212 } 213 isGraph(int ch)214 static boolean isGraph(int ch) { 215 return isType(ch, GRAPH); 216 } 217 isPrint(int ch)218 static boolean isPrint(int ch) { 219 return ((ch-0x20)|(0x7E-ch)) >= 0; 220 } 221 isPunct(int ch)222 static boolean isPunct(int ch) { 223 return isType(ch, PUNCT); 224 } 225 isSpace(int ch)226 static boolean isSpace(int ch) { 227 return isType(ch, SPACE); 228 } 229 isHexDigit(int ch)230 static boolean isHexDigit(int ch) { 231 return isType(ch, HEX); 232 } 233 isCntrl(int ch)234 static boolean isCntrl(int ch) { 235 return isType(ch, CNTRL); 236 } 237 isLower(int ch)238 static boolean isLower(int ch) { 239 return ((ch-'a')|('z'-ch)) >= 0; 240 } 241 isUpper(int ch)242 static boolean isUpper(int ch) { 243 return ((ch-'A')|('Z'-ch)) >= 0; 244 } 245 isWord(int ch)246 static boolean isWord(int ch) { 247 return isType(ch, WORD); 248 } 249 } 250