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
15 #include <java/lang/Character.h>
17 #include <java-chartables.h>
21 #define asize(x) ((sizeof (x)) / sizeof (x[0]))
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];
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];
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
)
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
)
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
82 table_search (const jchar table
[][2], int table_len
, jchar ch
)
84 int low
, high
, i
, old
;
94 else if (ch
> table
[i
][1])
100 i
= (high
+ low
) / 2;
109 java::lang::Character::digit_value (jchar ch
)
111 int index
= table_search (digit_table
, asize (digit_table
), ch
);
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;
123 java::lang::Character::getNumericValue (jchar ch
)
125 jint d
= digit (ch
, 36);
129 for (unsigned int i
= 0; i
< asize (numeric_table
); ++i
)
131 if (numeric_table
[i
] == ch
)
132 return numeric_value
[i
];
139 java::lang::Character::getType (jchar ch
)
141 int index
= table_search (all_table
, asize (all_table
), ch
);
143 return category_table
[index
];
148 java::lang::Character::isLowerCase (jchar ch
)
150 if (ch
>= 0x2000 && ch
<= 0x2fff)
152 if (table_search (lower_case_table
, asize (lower_case_table
), ch
) != -1)
155 int low
, high
, i
, old
;
158 high
= asize (lower_anomalous_table
);
163 if (ch
< lower_anomalous_table
[i
])
165 else if (ch
> lower_anomalous_table
[i
])
171 i
= (high
+ low
) / 2;
180 java::lang::Character::isSpaceChar (jchar ch
)
182 return table_search (space_table
, asize (space_table
), ch
) != -1;
186 java::lang::Character::isUpperCase (jchar ch
)
188 if (ch
>= 0x2000 && ch
<= 0x2fff)
190 return table_search (upper_case_table
, asize (upper_case_table
), ch
) != -1;
194 java::lang::Character::toLowerCase (jchar ch
)
196 int index
= table_search (upper_case_table
, asize (upper_case_table
), ch
);
198 return to_lower_title (ch
);
199 return (jchar
) (ch
- upper_case_table
[index
][0]
200 + upper_case_map_table
[index
]);
204 java::lang::Character::toUpperCase (jchar ch
)
206 int index
= table_search (lower_case_table
, asize (lower_case_table
), ch
);
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 */
216 java::lang::Character::digit_value (jchar ch
)
218 if (type_table
[ch
] == DECIMAL_DIGIT_NUMBER
)
219 return attribute_table
[ch
];
224 java::lang::Character::getNumericValue (jchar ch
)
226 jint d
= digit (ch
, 36);
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
];
239 java::lang::Character::getType (jchar ch
)
241 return type_table
[ch
];
245 java::lang::Character::isLowerCase (jchar ch
)
247 if (ch
>= 0x2000 && ch
<= 0x2fff)
249 return type_table
[ch
] == LOWERCASE_LETTER
;
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
);
261 java::lang::Character::isUpperCase (jchar ch
)
263 if (ch
>= 0x2000 && ch
<= 0x2fff)
265 return type_table
[ch
] == UPPERCASE_LETTER
;
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
);
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 */