allow all arm targets to use -mstructure-size-boundary=XX
[official-gcc.git] / libjava / java / lang / natCharacter.cc
blob4eca4a4f185f6ff617c6173e00026eef54c69a21
1 // natCharacter.cc - Native part of Character class.
3 /* Copyright (C) 1998, 1999 Cygnus Solutions
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 #include <config.h>
13 #include <gcj/cni.h>
14 #include <jvm.h>
15 #include <java/lang/Character.h>
17 #include <java-chartables.h>
21 #define asize(x) ((sizeof (x)) / sizeof (x[0]))
23 static jchar
24 to_lower_title (jchar ch)
26 for (unsigned int i = 0; i < asize (title_to_upper_table); ++i)
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];
34 return ch;
37 static jchar
38 to_upper_title (jchar ch)
40 for (unsigned int i = 0; i < asize (title_to_lower_table); ++i)
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];
48 return ch;
51 jboolean
52 java::lang::Character::isTitleCase (jchar ch)
54 for (unsigned int i = 0; i < asize (title_to_lower_table); ++i)
56 if (title_to_lower_table[i][0] == ch)
57 return true;
59 return false;
62 jchar
63 java::lang::Character::toTitleCase (jchar ch)
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)
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];
76 return toUpperCase (ch);
79 #ifdef COMPACT_CHARACTER
81 static int
82 table_search (const jchar table[][2], int table_len, jchar ch)
84 int low, high, i, old;
86 low = 0;
87 high = table_len;
88 i = high / 2;
90 while (true)
92 if (ch < table[i][0])
93 high = i;
94 else if (ch > table[i][1])
95 low = i;
96 else
97 return i;
99 old = i;
100 i = (high + low) / 2;
101 if (i == old)
102 break;
105 return -1;
108 jint
109 java::lang::Character::digit_value (jchar ch)
111 int index = table_search (digit_table, asize (digit_table), ch);
112 if (index == -1)
113 return -1;
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;
122 jint
123 java::lang::Character::getNumericValue (jchar ch)
125 jint d = digit (ch, 36);
126 if (d != -1)
127 return d;
129 for (unsigned int i = 0; i < asize (numeric_table); ++i)
131 if (numeric_table[i] == ch)
132 return numeric_value[i];
135 return -1;
138 jint
139 java::lang::Character::getType (jchar ch)
141 int index = table_search (all_table, asize (all_table), ch);
142 if (index != -1)
143 return category_table[index];
144 return UNASSIGNED;
147 jboolean
148 java::lang::Character::isLowerCase (jchar ch)
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;
155 int low, high, i, old;
157 low = 0;
158 high = asize (lower_anomalous_table);
159 i = high / 2;
161 while (true)
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;
170 old = i;
171 i = (high + low) / 2;
172 if (i == old)
173 break;
176 return false;
179 jboolean
180 java::lang::Character::isSpaceChar (jchar ch)
182 return table_search (space_table, asize (space_table), ch) != -1;
185 jboolean
186 java::lang::Character::isUpperCase (jchar ch)
188 if (ch >= 0x2000 && ch <= 0x2fff)
189 return false;
190 return table_search (upper_case_table, asize (upper_case_table), ch) != -1;
193 jchar
194 java::lang::Character::toLowerCase (jchar ch)
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]);
203 jchar
204 java::lang::Character::toUpperCase (jchar ch)
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]);
213 #else /* COMPACT_CHARACTER */
215 jint
216 java::lang::Character::digit_value (jchar ch)
218 if (type_table[ch] == DECIMAL_DIGIT_NUMBER)
219 return attribute_table[ch];
220 return -1;
223 jint
224 java::lang::Character::getNumericValue (jchar ch)
226 jint d = digit (ch, 36);
227 if (d != -1)
228 return d;
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;
238 jint
239 java::lang::Character::getType (jchar ch)
241 return type_table[ch];
244 jboolean
245 java::lang::Character::isLowerCase (jchar ch)
247 if (ch >= 0x2000 && ch <= 0x2fff)
248 return false;
249 return type_table[ch] == LOWERCASE_LETTER;
252 jboolean
253 java::lang::Character::isSpaceChar (jchar ch)
255 return (type_table[ch] == SPACE_SEPARATOR
256 || type_table[ch] == LINE_SEPARATOR
257 || type_table[ch] == PARAGRAPH_SEPARATOR);
260 jboolean
261 java::lang::Character::isUpperCase (jchar ch)
263 if (ch >= 0x2000 && ch <= 0x2fff)
264 return false;
265 return type_table[ch] == UPPERCASE_LETTER;
268 jchar
269 java::lang::Character::toLowerCase (jchar ch)
271 if (type_table[ch] == UPPERCASE_LETTER)
272 return attribute_table[ch];
273 return to_lower_title (ch);
276 jchar
277 java::lang::Character::toUpperCase (jchar ch)
279 if (type_table[ch] == LOWERCASE_LETTER)
280 return attribute_table[ch];
281 return to_upper_title (ch);
284 #endif /* COMPACT_CHARACTER */