1 7 8 package java.util.regex; 9 10 11 16 17 final class ASCII { 18 19 static final int UPPER = 0x00000100; 20 21 static final int LOWER = 0x00000200; 22 23 static final int DIGIT = 0x00000400; 24 25 static final int SPACE = 0x00000800; 26 27 static final int PUNCT = 0x00001000; 28 29 static final int CNTRL = 0x00002000; 30 31 static final int BLANK = 0x00004000; 32 33 static final int HEX = 0x00008000; 34 35 static final int UNDER = 0x00010000; 36 37 static final int ASCII = 0x0000FF00; 38 39 static final int ALPHA = (UPPER|LOWER); 40 41 static final int ALNUM = (UPPER|LOWER|DIGIT); 42 43 static final int GRAPH = (PUNCT|UPPER|LOWER|DIGIT); 44 45 static final int WORD = (UPPER|LOWER|UNDER|DIGIT); 46 47 static final int XDIGIT = (HEX); 48 49 private static final int[] ctype = new int[] { 50 CNTRL, 51 CNTRL, 52 CNTRL, 53 CNTRL, 54 CNTRL, 55 CNTRL, 56 CNTRL, 57 CNTRL, 58 CNTRL, 59 SPACE+CNTRL+BLANK, 60 SPACE+CNTRL, 61 SPACE+CNTRL, 62 SPACE+CNTRL, 63 SPACE+CNTRL, 64 CNTRL, 65 CNTRL, 66 CNTRL, 67 CNTRL, 68 CNTRL, 69 CNTRL, 70 CNTRL, 71 CNTRL, 72 CNTRL, 73 CNTRL, 74 CNTRL, 75 CNTRL, 76 CNTRL, 77 CNTRL, 78 CNTRL, 79 CNTRL, 80 CNTRL, 81 CNTRL, 82 SPACE+BLANK, 83 PUNCT, 84 PUNCT, 85 PUNCT, 86 PUNCT, 87 PUNCT, 88 PUNCT, 89 PUNCT, 90 PUNCT, 91 PUNCT, 92 PUNCT, 93 PUNCT, 94 PUNCT, 95 PUNCT, 96 PUNCT, 97 PUNCT, 98 DIGIT+HEX+0, 99 DIGIT+HEX+1, 100 DIGIT+HEX+2, 101 DIGIT+HEX+3, 102 DIGIT+HEX+4, 103 DIGIT+HEX+5, 104 DIGIT+HEX+6, 105 DIGIT+HEX+7, 106 DIGIT+HEX+8, 107 DIGIT+HEX+9, 108 PUNCT, 109 PUNCT, 110 PUNCT, 111 PUNCT, 112 PUNCT, 113 PUNCT, 114 PUNCT, 115 UPPER+HEX+10, 116 UPPER+HEX+11, 117 UPPER+HEX+12, 118 UPPER+HEX+13, 119 UPPER+HEX+14, 120 UPPER+HEX+15, 121 UPPER+16, 122 UPPER+17, 123 UPPER+18, 124 UPPER+19, 125 UPPER+20, 126 UPPER+21, 127 UPPER+22, 128 UPPER+23, 129 UPPER+24, 130 UPPER+25, 131 UPPER+26, 132 UPPER+27, 133 UPPER+28, 134 UPPER+29, 135 UPPER+30, 136 UPPER+31, 137 UPPER+32, 138 UPPER+33, 139 UPPER+34, 140 UPPER+35, 141 PUNCT, 142 PUNCT, 143 PUNCT, 144 PUNCT, 145 PUNCT|UNDER, 146 PUNCT, 147 LOWER+HEX+10, 148 LOWER+HEX+11, 149 LOWER+HEX+12, 150 LOWER+HEX+13, 151 LOWER+HEX+14, 152 LOWER+HEX+15, 153 LOWER+16, 154 LOWER+17, 155 LOWER+18, 156 LOWER+19, 157 LOWER+20, 158 LOWER+21, 159 LOWER+22, 160 LOWER+23, 161 LOWER+24, 162 LOWER+25, 163 LOWER+26, 164 LOWER+27, 165 LOWER+28, 166 LOWER+29, 167 LOWER+30, 168 LOWER+31, 169 LOWER+32, 170 LOWER+33, 171 LOWER+34, 172 LOWER+35, 173 PUNCT, 174 PUNCT, 175 PUNCT, 176 PUNCT, 177 CNTRL, 178 }; 179 180 static int getType(int ch) { 181 return ((ch & 0xFFFFFF80) == 0 ? ctype[ch] : 0); 182 } 183 184 static boolean isType(int ch, int type) { 185 return (getType(ch) & type) != 0; 186 } 187 188 static boolean isAscii(int ch) { 189 return ((ch & 0xFFFFFF80) == 0); 190 } 191 192 static boolean isAlpha(int ch) { 193 return isType(ch, ALPHA); 194 } 195 196 static boolean isDigit(int ch) { 197 return ((ch-'0')|('9'-ch)) >= 0; 198 } 199 200 static boolean isAlnum(int ch) { 201 return isType(ch, ALNUM); 202 } 203 204 static boolean isGraph(int ch) { 205 return isType(ch, GRAPH); 206 } 207 208 static boolean isPrint(int ch) { 209 return ((ch-0x20)|(0x7E-ch)) >= 0; 210 } 211 212 static boolean isPunct(int ch) { 213 return isType(ch, PUNCT); 214 } 215 216 static boolean isSpace(int ch) { 217 return isType(ch, SPACE); 218 } 219 220 static boolean isHexDigit(int ch) { 221 return isType(ch, HEX); 222 } 223 224 static boolean isOctDigit(int ch) { 225 return ((ch-'0')|('7'-ch)) >= 0; 226 } 227 228 static boolean isCntrl(int ch) { 229 return isType(ch, CNTRL); 230 } 231 232 static boolean isLower(int ch) { 233 return ((ch-'a')|('z'-ch)) >= 0; 234 } 235 236 static boolean isUpper(int ch) { 237 return ((ch-'A')|('Z'-ch)) >= 0; 238 } 239 240 static boolean isWord(int ch) { 241 return isType(ch, WORD); 242 } 243 244 static int toDigit(int ch) { 245 return (ctype[ch & 0x7F] & 0x3F); 246 } 247 248 static int toLower(int ch) { 249 return isUpper(ch) ? (ch + 0x20) : ch; 250 } 251 252 static int toUpper(int ch) { 253 return isLower(ch) ? (ch - 0x20) : ch; 254 } 255 256 } 257 | Popular Tags |