KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > CharacterData0E


1 // This file was generated AUTOMATICALLY from a template file Sat Feb 09 01:22:08 PST 2008
2
/* @(#)CharacterData0E.java.template 1.3 03/07/26
3  *
4  * Copyright 1994-2002 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * This software is the proprietary information of Sun Microsystems, Inc.
7  * Use is subject to license terms.
8  *
9  */

10
11 package java.lang;
12
13 /** The CharacterData class encapsulates the large tables found in
14     Java.lang.Character. */

15
16 class CharacterData0E {
17     /* The character properties are currently encoded into 32 bits in the following manner:
18         1 bit mirrored property
19         4 bits directionality property
20         9 bits signed offset used for converting case
21         1 bit if 1, adding the signed offset converts the character to lowercase
22         1 bit if 1, subtracting the signed offset converts the character to uppercase
23         1 bit if 1, this character has a titlecase equivalent (possibly itself)
24         3 bits 0 may not be part of an identifier
25                 1 ignorable control; may continue a Unicode identifier or Java identifier
26                 2 may continue a Java identifier but not a Unicode identifier (unused)
27                 3 may continue a Unicode identifier or Java identifier
28                 4 is a Java whitespace character
29                 5 may start or continue a Java identifier;
30                    may continue but not start a Unicode identifier (underscores)
31                 6 may start or continue a Java identifier but not a Unicode identifier ($)
32                 7 may start or continue a Unicode identifier or Java identifier
33                 Thus:
34                    5, 6, 7 may start a Java identifier
35                    1, 2, 3, 5, 6, 7 may continue a Java identifier
36                    7 may start a Unicode identifier
37                    1, 3, 5, 7 may continue a Unicode identifier
38                    1 is ignorable within an identifier
39                    4 is Java whitespace
40         2 bits 0 this character has no numeric property
41                 1 adding the digit offset to the character code and then
42                    masking with 0x1F will produce the desired numeric value
43                 2 this character has a "strange" numeric value
44                 3 a Java supradecimal digit: adding the digit offset to the
45                    character code, then masking with 0x1F, then adding 10
46                    will produce the desired numeric value
47         5 bits digit offset
48         5 bits character type
49
50         The encoding of character properties is subject to change at any time.
51      */

52
53     static int getProperties(int ch) {
54         char offset = (char)ch;
55         int props = A[Y[X[offset>>5]|((offset>>1)&0xF)]|(offset&0x1)];
56         return props;
57     }
58
59     static int getType(int ch) {
60         int props = getProperties(ch);
61         return (props & 0x1F);
62     }
63
64     static boolean isLowerCase(int ch) {
65         int type = getType(ch);
66         return (type == Character.LOWERCASE_LETTER);
67     }
68
69     static boolean isUpperCase(int ch) {
70         int type = getType(ch);
71         return (type == Character.UPPERCASE_LETTER);
72     }
73
74     static boolean isTitleCase(int ch) {
75         int type = getType(ch);
76         return (type == Character.TITLECASE_LETTER);
77     }
78
79     static boolean isDigit(int ch) {
80         int type = getType(ch);
81         return (type == Character.DECIMAL_DIGIT_NUMBER);
82     }
83
84     static boolean isDefined(int ch) {
85         int type = getType(ch);
86         return (type != Character.UNASSIGNED);
87     }
88
89     static boolean isLetter(int ch) {
90         int type = getType(ch);
91         return (((((1 << Character.UPPERCASE_LETTER) |
92             (1 << Character.LOWERCASE_LETTER) |
93             (1 << Character.TITLECASE_LETTER) |
94             (1 << Character.MODIFIER_LETTER) |
95             (1 << Character.OTHER_LETTER)) >> type) & 1) != 0);
96     }
97
98     static boolean isLetterOrDigit(int ch) {
99         int type = getType(ch);
100         return (((((1 << Character.UPPERCASE_LETTER) |
101             (1 << Character.LOWERCASE_LETTER) |
102             (1 << Character.TITLECASE_LETTER) |
103             (1 << Character.MODIFIER_LETTER) |
104             (1 << Character.OTHER_LETTER) |
105             (1 << Character.DECIMAL_DIGIT_NUMBER)) >> type) & 1) != 0);
106     }
107
108     static boolean isSpaceChar(int ch) {
109         int type = getType(ch);
110         return (((((1 << Character.SPACE_SEPARATOR) |
111                    (1 << Character.LINE_SEPARATOR) |
112                    (1 << Character.PARAGRAPH_SEPARATOR))
113                 >> type) & 1) != 0);
114     }
115
116
117     static boolean isJavaIdentifierStart(int ch) {
118         int props = getProperties(ch);
119         return ((props & 0x00007000) >= 0x00005000);
120     }
121
122     static boolean isJavaIdentifierPart(int ch) {
123         int props = getProperties(ch);
124         return ((props & 0x00003000) != 0);
125     }
126
127     static boolean isUnicodeIdentifierStart(int ch) {
128         int props = getProperties(ch);
129         return ((props & 0x00007000) == 0x00007000);
130     }
131
132     static boolean isUnicodeIdentifierPart(int ch) {
133         int props = getProperties(ch);
134         return ((props & 0x00001000) != 0);
135     }
136
137     static boolean isIdentifierIgnorable(int ch) {
138         int props = getProperties(ch);
139         return ((props & 0x00007000) == 0x00001000);
140     }
141
142     static int toLowerCase(int ch) {
143         int mapChar = ch;
144         int val = getProperties(ch);
145
146         if ((val & 0x00020000) != 0) {
147             int offset = val << 5 >> (5+18);
148             mapChar = ch + offset;
149         }
150         return mapChar;
151     }
152
153     static int toUpperCase(int ch) {
154         int mapChar = ch;
155         int val = getProperties(ch);
156
157         if ((val & 0x00010000) != 0) {
158             int offset = val << 5 >> (5+18);
159             mapChar = ch - offset;
160         }
161         return mapChar;
162     }
163
164     static int toTitleCase(int ch) {
165         int mapChar = ch;
166         int val = getProperties(ch);
167
168         if ((val & 0x00008000) != 0) {
169             // There is a titlecase equivalent. Perform further checks:
170
if ((val & 0x00010000) == 0) {
171                 // The character does not have an uppercase equivalent, so it must
172
// already be uppercase; so add 1 to get the titlecase form.
173
mapChar = ch + 1;
174             }
175             else if ((val & 0x00020000) == 0) {
176                 // The character does not have a lowercase equivalent, so it must
177
// already be lowercase; so subtract 1 to get the titlecase form.
178
mapChar = ch - 1;
179             }
180             // else {
181
// The character has both an uppercase equivalent and a lowercase
182
// equivalent, so it must itself be a titlecase form; return it.
183
// return ch;
184
//}
185
}
186         else if ((val & 0x00010000) != 0) {
187             // This character has no titlecase equivalent but it does have an
188
// uppercase equivalent, so use that (subtract the signed case offset).
189
mapChar = toUpperCase(ch);
190         }
191         return mapChar;
192     }
193
194     static int digit(int ch, int radix) {
195         int value = -1;
196         if (radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX) {
197             int val = getProperties(ch);
198             int kind = val & 0x1F;
199             if (kind == Character.DECIMAL_DIGIT_NUMBER) {
200                 value = ch + ((val & 0x3E0) >> 5) & 0x1F;
201             }
202             else if ((val & 0xC00) == 0x00000C00) {
203                 // Java supradecimal digit
204
value = (ch + ((val & 0x3E0) >> 5) & 0x1F) + 10;
205             }
206         }
207         return (value < radix) ? value : -1;
208     }
209
210     static int getNumericValue(int ch) {
211         int val = getProperties(ch);
212         int retval = -1;
213
214         switch (val & 0xC00) {
215         default: // cannot occur
216
case (0x00000000): // not numeric
217
retval = -1;
218             break;
219         case (0x00000400): // simple numeric
220
retval = ch + ((val & 0x3E0) >> 5) & 0x1F;
221             break;
222         case (0x00000800) : // "strange" numeric
223
retval = -2;
224             break;
225         case (0x00000C00): // Java supradecimal
226
retval = (ch + ((val & 0x3E0) >> 5) & 0x1F) + 10;
227             break;
228         }
229         return retval;
230     }
231
232     static boolean isWhitespace(int ch) {
233         int props = getProperties(ch);
234         return ((props & 0x00007000) == 0x00004000);
235     }
236
237     static byte getDirectionality(int ch) {
238         int val = getProperties(ch);
239         byte directionality = (byte)((val & 0x78000000) >> 27);
240         if (directionality == 0xF ) {
241             directionality = Character.DIRECTIONALITY_UNDEFINED;
242         }
243         return directionality;
244     }
245
246     static boolean isMirrored(int ch) {
247         int props = getProperties(ch);
248         return ((props & 0x80000000) != 0);
249     }
250
251     // may need to implement for JSR 204
252
// static int toUpperCaseEx(int ch);
253
// static char[] toUpperCaseCharArray(int ch);
254

255     // The following tables and code generated using:
256
// java GenerateCharacter -plane 14 -template ../../tools/GenerateCharacter/CharacterData0E.java.template -spec ../../tools/GenerateCharacter/UnicodeData.txt -specialcasing ../../tools/GenerateCharacter/SpecialCasing.txt -o C:/BUILD_AREA/jdk1.5.0_15/control/build/windows-i586/gensrc/java/lang/CharacterData0E.java -string -usecharforbyte 11 4 1
257
// The X table has 2048 entries for a total of 4096 bytes.
258

259   static final char X[] = (
260     "\000\020\020\020\040\040\040\040\060\060\060\060\060\060\060\100\040\040\040"+
261     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
262     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
263     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
264     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
265     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
266     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
267     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
268     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
269     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
270     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
271     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
272     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
273     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
274     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
275     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
276     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
277     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
278     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
279     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
280     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
281     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
282     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
283     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
284     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
285     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
286     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
287     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
288     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
289     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
290     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
291     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
292     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
293     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
294     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
295     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
296     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
297     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
298     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
299     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
300     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
301     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
302     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
303     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
304     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
305     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
306     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
307     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
308     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
309     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
310     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
311     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
312     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
313     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
314     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
315     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
316     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
317     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
318     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
319     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
320     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
321     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
322     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
323     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
324     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
325     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
326     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
327     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
328     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
329     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
330     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
331     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
332     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
333     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
334     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
335     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
336     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
337     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
338     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
339     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
340     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
341     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
342     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
343     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
344     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
345     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
346     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
347     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
348     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
349     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
350     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
351     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
352     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
353     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
354     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
355     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
356     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
357     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
358     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
359     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
360     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
361     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
362     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
363     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
364     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
365     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
366     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
367     "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040").toCharArray();
368
369   // The Y table has 80 entries for a total of 160 bytes.
370

371   static final char Y[] = (
372     "\000\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\004\004\004"+
373     "\004\004\004\004\004\004\004\004\004\004\004\004\004\002\002\002\002\002\002"+
374     "\002\002\002\002\002\002\002\002\002\002\006\006\006\006\006\006\006\006\006"+
375     "\006\006\006\006\006\006\006\006\006\006\006\006\006\006\006\002\002\002\002"+
376     "\002\002\002\002").toCharArray();
377
378   // The A table has 8 entries for a total of 32 bytes.
379

380   static final int A[] = new int[8];
381   static final String JavaDoc A_DATA =
382     "\u7800\000\u4800\u1010\u7800\000\u7800\000\u4800\u1010\u4800\u1010\u4000\u3006"+
383     "\u4000\u3006";
384
385   // In all, the character property tables require 4288 bytes.
386

387     static {
388                 { // THIS CODE WAS AUTOMATICALLY CREATED BY GenerateCharacter:
389
char[] data = A_DATA.toCharArray();
390             assert (data.length == (8 * 2));
391             int i = 0, j = 0;
392             while (i < (8 * 2)) {
393                 int entry = data[i++] << 16;
394                 A[j++] = entry | data[i++];
395             }
396         }
397
398     }
399 }
400
Popular Tags