KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > CharacterDataLatin1


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

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

54
55     static int getProperties(int ch) {
56         char offset = (char)ch;
57         int props = A[offset];
58         return props;
59     }
60
61     static int getType(int ch) {
62         int props = getProperties(ch);
63         return (props & 0x1F);
64     }
65
66     static boolean isLowerCase(int ch) {
67         int type = getType(ch);
68         return (type == Character.LOWERCASE_LETTER);
69     }
70
71     static boolean isUpperCase(int ch) {
72         int type = getType(ch);
73         return (type == Character.UPPERCASE_LETTER);
74     }
75
76     static boolean isTitleCase(int ch) {
77         return false;
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                 ((val & 0x07FC0000) != 0x07FC0000)) {
148             int offset = val << 5 >> (5+18);
149             mapChar = ch + offset;
150         }
151         return mapChar;
152     }
153
154     static int toUpperCase(int ch) {
155         int mapChar = ch;
156         int val = getProperties(ch);
157
158         if ((val & 0x00010000) != 0) {
159             if ((val & 0x07FC0000) != 0x07FC0000) {
160                 int offset = val << 5 >> (5+18);
161                 mapChar = ch - offset;
162             } else if (ch == 0x00B5) {
163                 mapChar = 0x039C;
164             }
165         }
166         return mapChar;
167     }
168
169     static int toTitleCase(int ch) {
170         return toUpperCase(ch);
171     }
172
173     static int digit(int ch, int radix) {
174         int value = -1;
175         if (radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX) {
176             int val = getProperties(ch);
177             int kind = val & 0x1F;
178             if (kind == Character.DECIMAL_DIGIT_NUMBER) {
179                 value = ch + ((val & 0x3E0) >> 5) & 0x1F;
180             }
181             else if ((val & 0xC00) == 0x00000C00) {
182                 // Java supradecimal digit
183
value = (ch + ((val & 0x3E0) >> 5) & 0x1F) + 10;
184             }
185         }
186         return (value < radix) ? value : -1;
187     }
188
189     static int getNumericValue(int ch) {
190         int val = getProperties(ch);
191         int retval = -1;
192
193         switch (val & 0xC00) {
194             default: // cannot occur
195
case (0x00000000): // not numeric
196
retval = -1;
197                 break;
198             case (0x00000400): // simple numeric
199
retval = ch + ((val & 0x3E0) >> 5) & 0x1F;
200                 break;
201             case (0x00000800) : // "strange" numeric
202
retval = -2;
203                  break;
204             case (0x00000C00): // Java supradecimal
205
retval = (ch + ((val & 0x3E0) >> 5) & 0x1F) + 10;
206                 break;
207         }
208         return retval;
209     }
210
211     static boolean isWhitespace(int ch) {
212         int props = getProperties(ch);
213         return ((props & 0x00007000) == 0x00004000);
214     }
215
216     static byte getDirectionality(int ch) {
217         int val = getProperties(ch);
218         byte directionality = (byte)((val & 0x78000000) >> 27);
219
220         if (directionality == 0xF ) {
221             directionality = -1;
222         }
223         return directionality;
224     }
225
226     static boolean isMirrored(int ch) {
227         int props = getProperties(ch);
228         return ((props & 0x80000000) != 0);
229     }
230
231     static int toUpperCaseEx(int ch) {
232         int mapChar = ch;
233         int val = getProperties(ch);
234
235         if ((val & 0x00010000) != 0) {
236             if ((val & 0x07FC0000) != 0x07FC0000) {
237                 int offset = val << 5 >> (5+18);
238                 mapChar = ch - offset;
239             }
240             else {
241                 switch(ch) {
242                     // map overflow characters
243
case 0x00B5 : mapChar = 0x039C; break;
244                     default : mapChar = Character.ERROR; break;
245                 }
246             }
247         }
248         return mapChar;
249     }
250
251     static char[] sharpsMap = new char[] {'S', 'S'};
252
253     static char[] toUpperCaseCharArray(int ch) {
254         char[] upperMap = {(char)ch};
255         if (ch == 0x00DF) {
256             upperMap = sharpsMap;
257         }
258         return upperMap;
259     }
260
261
262     // The following tables and code generated using:
263
// java GenerateCharacter -template ../../tools/GenerateCharacter/CharacterDataLatin1.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/CharacterDataLatin1.java -string -usecharforbyte -latin1 8
264
// The A table has 256 entries for a total of 1024 bytes.
265

266   static final int A[] = new int[256];
267   static final String JavaDoc A_DATA =
268     "\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800"+
269     "\u100F\u4800\u100F\u4800\u100F\u5800\u400F\u5000\u400F\u5800\u400F\u6000\u400F"+
270     "\u5000\u400F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800"+
271     "\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F"+
272     "\u4800\u100F\u4800\u100F\u5000\u400F\u5000\u400F\u5000\u400F\u5800\u400F\u6000"+
273     "\u400C\u6800\030\u6800\030\u2800\030\u2800\u601A\u2800\030\u6800\030\u6800"+
274     "\030\uE800\025\uE800\026\u6800\030\u2800\031\u3800\030\u2800\024\u3800\030"+
275     "\u2000\030\u1800\u3609\u1800\u3609\u1800\u3609\u1800\u3609\u1800\u3609\u1800"+
276     "\u3609\u1800\u3609\u1800\u3609\u1800\u3609\u1800\u3609\u3800\030\u6800\030"+
277     "\uE800\031\u6800\031\uE800\031\u6800\030\u6800\030\202\u7FE1\202\u7FE1\202"+
278     "\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1"+
279     "\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202"+
280     "\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1"+
281     "\202\u7FE1\uE800\025\u6800\030\uE800\026\u6800\033\u6800\u5017\u6800\033\201"+
282     "\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2"+
283     "\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201"+
284     "\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2"+
285     "\201\u7FE2\201\u7FE2\201\u7FE2\uE800\025\u6800\031\uE800\026\u6800\031\u4800"+
286     "\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u5000\u100F"+
287     "\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800"+
288     "\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F"+
289     "\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800"+
290     "\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F"+
291     "\u3800\014\u6800\030\u2800\u601A\u2800\u601A\u2800\u601A\u2800\u601A\u6800"+
292     "\034\u6800\034\u6800\033\u6800\034\000\u7002\uE800\035\u6800\031\u6800\u1010"+
293     "\u6800\034\u6800\033\u2800\034\u2800\031\u1800\u060B\u1800\u060B\u6800\033"+
294     "\u07FD\u7002\u6800\034\u6800\030\u6800\033\u1800\u050B\000\u7002\uE800\036"+
295     "\u6800\u080B\u6800\u080B\u6800\u080B\u6800\030\202\u7001\202\u7001\202\u7001"+
296     "\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202"+
297     "\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001"+
298     "\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\u6800\031\202\u7001\202"+
299     "\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\u07FD\u7002\201\u7002"+
300     "\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201"+
301     "\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002"+
302     "\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\u6800"+
303     "\031\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002"+
304     "\u061D\u7002";
305
306   // In all, the character property tables require 1024 bytes.
307

308     static {
309                 { // THIS CODE WAS AUTOMATICALLY CREATED BY GenerateCharacter:
310
char[] data = A_DATA.toCharArray();
311             assert (data.length == (256 * 2));
312             int i = 0, j = 0;
313             while (i < (256 * 2)) {
314                 int entry = data[i++] << 16;
315                 A[j++] = entry | data[i++];
316             }
317         }
318
319     }
320 }
321
322
Popular Tags