]> gcc.gnu.org Git - gcc.git/blob - libjava/java/lang/natCharacter.cc
configure: Rebuilt.
[gcc.git] / libjava / java / lang / natCharacter.cc
1 // natCharacter.cc - Native part of Character class.
2
3 /* Copyright (C) 1998, 1999 Cygnus Solutions
4
5 This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
10
11 #include <config.h>
12
13 #include <gcj/cni.h>
14 #include <jvm.h>
15 #include <java/lang/Character.h>
16
17 #include <java-chartables.h>
18
19 \f
20
21 #define asize(x) ((sizeof (x)) / sizeof (x[0]))
22
23 static jchar
24 to_lower_title (jchar ch)
25 {
26 for (unsigned int i = 0; i < asize (title_to_upper_table); ++i)
27 {
28 // We can assume that the entries in the two tables are
29 // parallel. This is checked in the script.
30 if (title_to_upper_table[i][1] == ch
31 || title_to_upper_table[i][0] == ch)
32 return title_to_lower_table[i][1];
33 }
34 return ch;
35 }
36
37 static jchar
38 to_upper_title (jchar ch)
39 {
40 for (unsigned int i = 0; i < asize (title_to_lower_table); ++i)
41 {
42 // We can assume that the entries in the two tables are
43 // parallel. This is checked in the script.
44 if (title_to_lower_table[i][1] == ch
45 || title_to_lower_table[i][0] == ch)
46 return title_to_upper_table[i][1];
47 }
48 return ch;
49 }
50
51 jboolean
52 java::lang::Character::isTitleCase (jchar ch)
53 {
54 for (unsigned int i = 0; i < asize (title_to_lower_table); ++i)
55 {
56 if (title_to_lower_table[i][0] == ch)
57 return true;
58 }
59 return false;
60 }
61
62 jchar
63 java::lang::Character::toTitleCase (jchar ch)
64 {
65 // Both titlecase mapping tables have the same length. This is
66 // checked in the chartables script.
67 for (unsigned int i = 0; i < asize (title_to_lower_table); ++i)
68 {
69 if (title_to_lower_table[i][0] == ch)
70 return ch;
71 if (title_to_lower_table[i][1] == ch)
72 return title_to_lower_table[i][0];
73 if (title_to_upper_table[i][1] == ch)
74 return title_to_upper_table[i][0];
75 }
76 return toUpperCase (ch);
77 }
78
79 #ifdef COMPACT_CHARACTER
80
81 static int
82 table_search (const jchar table[][2], int table_len, jchar ch)
83 {
84 int low, high, i, old;
85
86 low = 0;
87 high = table_len;
88 i = high / 2;
89
90 while (true)
91 {
92 if (ch < table[i][0])
93 high = i;
94 else if (ch > table[i][1])
95 low = i;
96 else
97 return i;
98
99 old = i;
100 i = (high + low) / 2;
101 if (i == old)
102 break;
103 }
104
105 return -1;
106 }
107
108 jint
109 java::lang::Character::digit_value (jchar ch)
110 {
111 int index = table_search (digit_table, asize (digit_table), ch);
112 if (index == -1)
113 return -1;
114
115 jchar base = digit_table[index][0];
116 // Tamil doesn't have a digit `0'. So we special-case it here.
117 if (base == TAMIL_DIGIT_ONE)
118 return ch - base + 1;
119 return ch - base;
120 }
121
122 jint
123 java::lang::Character::getNumericValue (jchar ch)
124 {
125 jint d = digit (ch, 36);
126 if (d != -1)
127 return d;
128
129 for (unsigned int i = 0; i < asize (numeric_table); ++i)
130 {
131 if (numeric_table[i] == ch)
132 return numeric_value[i];
133 }
134
135 return -1;
136 }
137
138 jint
139 java::lang::Character::getType (jchar ch)
140 {
141 int index = table_search (all_table, asize (all_table), ch);
142 if (index != -1)
143 return category_table[index];
144 return UNASSIGNED;
145 }
146
147 jboolean
148 java::lang::Character::isLowerCase (jchar ch)
149 {
150 if (ch >= 0x2000 && ch <= 0x2fff)
151 return false;
152 if (table_search (lower_case_table, asize (lower_case_table), ch) != -1)
153 return true;
154
155 int low, high, i, old;
156
157 low = 0;
158 high = asize (lower_anomalous_table);
159 i = high / 2;
160
161 while (true)
162 {
163 if (ch < lower_anomalous_table[i])
164 high = i;
165 else if (ch > lower_anomalous_table[i])
166 low = i;
167 else
168 return true;
169
170 old = i;
171 i = (high + low) / 2;
172 if (i == old)
173 break;
174 }
175
176 return false;
177 }
178
179 jboolean
180 java::lang::Character::isSpaceChar (jchar ch)
181 {
182 return table_search (space_table, asize (space_table), ch) != -1;
183 }
184
185 jboolean
186 java::lang::Character::isUpperCase (jchar ch)
187 {
188 if (ch >= 0x2000 && ch <= 0x2fff)
189 return false;
190 return table_search (upper_case_table, asize (upper_case_table), ch) != -1;
191 }
192
193 jchar
194 java::lang::Character::toLowerCase (jchar ch)
195 {
196 int index = table_search (upper_case_table, asize (upper_case_table), ch);
197 if (index == -1)
198 return to_lower_title (ch);
199 return (jchar) (ch - upper_case_table[index][0]
200 + upper_case_map_table[index]);
201 }
202
203 jchar
204 java::lang::Character::toUpperCase (jchar ch)
205 {
206 int index = table_search (lower_case_table, asize (lower_case_table), ch);
207 if (index == -1)
208 return to_upper_title (ch);
209 return (jchar) (ch - lower_case_table[index][0]
210 + lower_case_map_table[index]);
211 }
212
213 #else /* COMPACT_CHARACTER */
214
215 jint
216 java::lang::Character::digit_value (jchar ch)
217 {
218 if (type_table[ch] == DECIMAL_DIGIT_NUMBER)
219 return attribute_table[ch];
220 return -1;
221 }
222
223 jint
224 java::lang::Character::getNumericValue (jchar ch)
225 {
226 jint d = digit (ch, 36);
227 if (d != -1)
228 return d;
229
230 // Some characters require two attributes. We special-case them here.
231 if (ch >= ROMAN_START && ch <= ROMAN_END)
232 return secondary_attribute_table[ch - ROMAN_START];
233 if (type_table[ch] == LETTER_NUMBER || type_table[ch] == OTHER_NUMBER)
234 return attribute_table[ch];
235 return -1;
236 }
237
238 jint
239 java::lang::Character::getType (jchar ch)
240 {
241 return type_table[ch];
242 }
243
244 jboolean
245 java::lang::Character::isLowerCase (jchar ch)
246 {
247 if (ch >= 0x2000 && ch <= 0x2fff)
248 return false;
249 return type_table[ch] == LOWERCASE_LETTER;
250 }
251
252 jboolean
253 java::lang::Character::isSpaceChar (jchar ch)
254 {
255 return (type_table[ch] == SPACE_SEPARATOR
256 || type_table[ch] == LINE_SEPARATOR
257 || type_table[ch] == PARAGRAPH_SEPARATOR);
258 }
259
260 jboolean
261 java::lang::Character::isUpperCase (jchar ch)
262 {
263 if (ch >= 0x2000 && ch <= 0x2fff)
264 return false;
265 return type_table[ch] == UPPERCASE_LETTER;
266 }
267
268 jchar
269 java::lang::Character::toLowerCase (jchar ch)
270 {
271 if (type_table[ch] == UPPERCASE_LETTER)
272 return attribute_table[ch];
273 return to_lower_title (ch);
274 }
275
276 jchar
277 java::lang::Character::toUpperCase (jchar ch)
278 {
279 if (type_table[ch] == LOWERCASE_LETTER)
280 return attribute_table[ch];
281 return to_upper_title (ch);
282 }
283
284 #endif /* COMPACT_CHARACTER */
This page took 0.06624 seconds and 6 git commands to generate.