KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > CharacterData02


1 // This file was generated AUTOMATICALLY from a template file Sat Feb 09 01:22:07 PST 2008
2

3 /* @(#)CharacterData02.java.template 1.3 03/07/26
4  *
5  * Copyright 1994-2002 Sun Microsystems, Inc. All Rights Reserved.
6  *
7  * This software is the proprietary information of Sun Microsystems, Inc.
8  * Use is subject to license terms.
9  *
10  */

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

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

53
54     static int getProperties(int ch) {
55         char offset = (char)ch;
56         int props = A[Y[X[offset>>5]|((offset>>1)&0xF)]|(offset&0x1)];
57         return props;
58     }
59
60     static int getType(int ch) {
61         int props = getProperties(ch);
62         return (props & 0x1F);
63     }
64
65     static boolean isLowerCase(int ch) {
66         int type = getType(ch);
67         return (type == Character.LOWERCASE_LETTER);
68     }
69
70     static boolean isUpperCase(int ch) {
71         int type = getType(ch);
72         return (type == Character.UPPERCASE_LETTER);
73     }
74
75     static boolean isTitleCase(int ch) {
76         int type = getType(ch);
77         return (type == Character.TITLECASE_LETTER);
78     }
79
80     static boolean isDigit(int ch) {
81         int type = getType(ch);
82         return (type == Character.DECIMAL_DIGIT_NUMBER);
83     }
84
85     static boolean isDefined(int ch) {
86         int type = getType(ch);
87         return (type != Character.UNASSIGNED);
88     }
89
90     static boolean isLetter(int ch) {
91         int type = getType(ch);
92         return (((((1 << Character.UPPERCASE_LETTER) |
93             (1 << Character.LOWERCASE_LETTER) |
94             (1 << Character.TITLECASE_LETTER) |
95             (1 << Character.MODIFIER_LETTER) |
96             (1 << Character.OTHER_LETTER)) >> type) & 1) != 0);
97     }
98
99     static boolean isLetterOrDigit(int ch) {
100         int type = getType(ch);
101         return (((((1 << Character.UPPERCASE_LETTER) |
102             (1 << Character.LOWERCASE_LETTER) |
103             (1 << Character.TITLECASE_LETTER) |
104             (1 << Character.MODIFIER_LETTER) |
105             (1 << Character.OTHER_LETTER) |
106             (1 << Character.DECIMAL_DIGIT_NUMBER)) >> type) & 1) != 0);
107     }
108
109     static boolean isSpaceChar(int ch) {
110         int type = getType(ch);
111         return (((((1 << Character.SPACE_SEPARATOR) |
112             (1 << Character.LINE_SEPARATOR) |
113             (1 << Character.PARAGRAPH_SEPARATOR)) >> 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         return (getProperties(ch) & 0x00007000) == 0x00004000;
234     }
235
236     static byte getDirectionality(int ch) {
237         int val = getProperties(ch);
238         byte directionality = (byte)((val & 0x78000000) >> 27);
239         if (directionality == 0xF ) {
240             directionality = Character.DIRECTIONALITY_UNDEFINED;
241         }
242         return directionality;
243     }
244
245     static boolean isMirrored(int ch) {
246         return (getProperties(ch) & 0x80000000) != 0;
247     }
248
249     // may need to implement for JSR 204
250
// static int toUpperCaseEx(int ch);
251
// static char[] toUpperCaseCharArray(int ch);
252

253     // The following tables and code generated using:
254
// java GenerateCharacter -plane 2 -template ../../tools/GenerateCharacter/CharacterData02.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/CharacterData02.java -string -usecharforbyte 11 4 1
255
// The X table has 2048 entries for a total of 4096 bytes.
256

257   static final char X[] = (
258     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
259     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
260     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
261     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
262     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
263     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
264     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
265     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
266     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
267     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
268     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
269     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
270     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
271     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
272     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
273     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
274     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
275     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
276     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
277     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
278     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
279     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
280     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
281     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
282     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
283     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
284     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
285     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
286     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
287     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
288     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
289     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
290     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
291     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
292     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
293     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
294     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
295     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
296     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
297     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
298     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
299     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
300     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
301     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
302     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
303     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
304     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
305     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
306     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
307     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
308     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
309     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
310     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
311     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
312     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
313     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
314     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
315     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
316     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
317     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
318     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
319     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
320     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
321     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
322     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
323     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
324     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
325     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
326     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
327     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
328     "\000\000\000\000\020\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\000\000\000\000\000\000\000\000\000\000\000"+
363     "\000\000\000\000\000\060\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").toCharArray();
366
367   // The Y table has 64 entries for a total of 128 bytes.
368

369   static final char Y[] = (
370     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
371     "\000\000\000\000\000\000\000\000\002\004\004\004\004\004\004\004\004\004\004"+
372     "\004\004\004\004\004\004\004\004\004\004\000\000\000\000\000\000\000\000\000"+
373     "\000\000\000\000\000\000\004").toCharArray();
374
375   // The A table has 6 entries for a total of 24 bytes.
376

377   static final int A[] = new int[6];
378   static final String JavaDoc A_DATA =
379     "\000\u7005\000\u7005\000\u7005\u7800\000\u7800\000\u7800\000";
380
381   // In all, the character property tables require 4248 bytes.
382

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