svn merge -r108665:108708 svn+ssh://gcc.gnu.org/svn/gcc/trunk
[official-gcc.git] / libjava / java / lang / Character.java
blobaa29e0bd523dbdd210c492eba1c9ebcf82114d55
1 /* java.lang.Character -- Wrapper class for char, and Unicode subsets
2 Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 * Note: This class must not be merged with Classpath. Gcj uses C-style
40 * arrays (see include/java-chartables.h) to store the Unicode character
41 * database, whereas Classpath uses Java objects (char[] extracted from
42 * String constants) in gnu.java.lang.CharData. Gcj's approach is more
43 * efficient, because there is no vtable or data relocation to worry about.
44 * However, despite the difference in the database interface, the two
45 * versions share identical algorithms.
48 package java.lang;
50 import java.io.Serializable;
52 /**
53 * Wrapper class for the primitive char data type. In addition, this class
54 * allows one to retrieve property information and perform transformations
55 * on the 57,707 defined characters in the Unicode Standard, Version 3.0.0.
56 * java.lang.Character is designed to be very dynamic, and as such, it
57 * retrieves information on the Unicode character set from a separate
58 * database, gnu.java.lang.CharData, which can be easily upgraded.
60 * <p>For predicates, boundaries are used to describe
61 * the set of characters for which the method will return true.
62 * This syntax uses fairly normal regular expression notation.
63 * See 5.13 of the Unicode Standard, Version 3.0, for the
64 * boundary specification.
66 * <p>See <a href="http://www.unicode.org">http://www.unicode.org</a>
67 * for more information on the Unicode Standard.
69 * @author Tom Tromey (tromey@cygnus.com)
70 * @author Paul N. Fisher
71 * @author Jochen Hoenicke
72 * @author Eric Blake (ebb9@email.byu.edu)
73 * @since 1.0
74 * @status updated to 1.4
76 public final class Character implements Serializable, Comparable
78 /**
79 * A subset of Unicode blocks.
81 * @author Paul N. Fisher
82 * @author Eric Blake (ebb9@email.byu.edu)
83 * @since 1.2
85 public static class Subset
87 /** The name of the subset. */
88 private final String name;
90 /**
91 * Construct a new subset of characters.
93 * @param name the name of the subset
94 * @throws NullPointerException if name is null
96 protected Subset(String name)
98 // Note that name.toString() is name, unless name was null.
99 this.name = name.toString();
103 * Compares two Subsets for equality. This is <code>final</code>, and
104 * restricts the comparison on the <code>==</code> operator, so it returns
105 * true only for the same object.
107 * @param o the object to compare
108 * @return true if o is this
110 public final boolean equals(Object o)
112 return o == this;
116 * Makes the original hashCode of Object final, to be consistent with
117 * equals.
119 * @return the hash code for this object
121 public final int hashCode()
123 return super.hashCode();
127 * Returns the name of the subset.
129 * @return the name
131 public final String toString()
133 return name;
135 } // class Subset
138 * A family of character subsets in the Unicode specification. A character
139 * is in at most one of these blocks.
141 * This inner class was generated automatically from
142 * <code>libjava/gnu/gcj/convert/Blocks-3.txt</code>, by some perl scripts.
143 * This Unicode definition file can be found on the
144 * <a href="http://www.unicode.org">http://www.unicode.org</a> website.
145 * JDK 1.4 uses Unicode version 3.0.0.
147 * @author scripts/unicode-blocks.pl (written by Eric Blake)
148 * @since 1.2
150 public static final class UnicodeBlock extends Subset
152 /** The start of the subset. */
153 private final char start;
155 /** The end of the subset. */
156 private final char end;
159 * Constructor for strictly defined blocks.
161 * @param start the start character of the range
162 * @param end the end character of the range
163 * @param name the block name
165 private UnicodeBlock(char start, char end, String name)
167 super(name);
168 this.start = start;
169 this.end = end;
173 * Returns the Unicode character block which a character belongs to.
175 * @param ch the character to look up
176 * @return the set it belongs to, or null if it is not in one
178 public static UnicodeBlock of(char ch)
180 // Special case, since SPECIALS contains two ranges.
181 if (ch == '\uFEFF')
182 return SPECIALS;
183 // Simple binary search for the correct block.
184 int low = 0;
185 int hi = sets.length - 1;
186 while (low <= hi)
188 int mid = (low + hi) >> 1;
189 UnicodeBlock b = sets[mid];
190 if (ch < b.start)
191 hi = mid - 1;
192 else if (ch > b.end)
193 low = mid + 1;
194 else
195 return b;
197 return null;
201 * Basic Latin.
202 * '\u0000' - '\u007F'.
204 public static final UnicodeBlock BASIC_LATIN
205 = new UnicodeBlock('\u0000', '\u007F',
206 "BASIC_LATIN");
209 * Latin-1 Supplement.
210 * '\u0080' - '\u00FF'.
212 public static final UnicodeBlock LATIN_1_SUPPLEMENT
213 = new UnicodeBlock('\u0080', '\u00FF',
214 "LATIN_1_SUPPLEMENT");
217 * Latin Extended-A.
218 * '\u0100' - '\u017F'.
220 public static final UnicodeBlock LATIN_EXTENDED_A
221 = new UnicodeBlock('\u0100', '\u017F',
222 "LATIN_EXTENDED_A");
225 * Latin Extended-B.
226 * '\u0180' - '\u024F'.
228 public static final UnicodeBlock LATIN_EXTENDED_B
229 = new UnicodeBlock('\u0180', '\u024F',
230 "LATIN_EXTENDED_B");
233 * IPA Extensions.
234 * '\u0250' - '\u02AF'.
236 public static final UnicodeBlock IPA_EXTENSIONS
237 = new UnicodeBlock('\u0250', '\u02AF',
238 "IPA_EXTENSIONS");
241 * Spacing Modifier Letters.
242 * '\u02B0' - '\u02FF'.
244 public static final UnicodeBlock SPACING_MODIFIER_LETTERS
245 = new UnicodeBlock('\u02B0', '\u02FF',
246 "SPACING_MODIFIER_LETTERS");
249 * Combining Diacritical Marks.
250 * '\u0300' - '\u036F'.
252 public static final UnicodeBlock COMBINING_DIACRITICAL_MARKS
253 = new UnicodeBlock('\u0300', '\u036F',
254 "COMBINING_DIACRITICAL_MARKS");
257 * Greek.
258 * '\u0370' - '\u03FF'.
260 public static final UnicodeBlock GREEK
261 = new UnicodeBlock('\u0370', '\u03FF',
262 "GREEK");
265 * Cyrillic.
266 * '\u0400' - '\u04FF'.
268 public static final UnicodeBlock CYRILLIC
269 = new UnicodeBlock('\u0400', '\u04FF',
270 "CYRILLIC");
273 * Armenian.
274 * '\u0530' - '\u058F'.
276 public static final UnicodeBlock ARMENIAN
277 = new UnicodeBlock('\u0530', '\u058F',
278 "ARMENIAN");
281 * Hebrew.
282 * '\u0590' - '\u05FF'.
284 public static final UnicodeBlock HEBREW
285 = new UnicodeBlock('\u0590', '\u05FF',
286 "HEBREW");
289 * Arabic.
290 * '\u0600' - '\u06FF'.
292 public static final UnicodeBlock ARABIC
293 = new UnicodeBlock('\u0600', '\u06FF',
294 "ARABIC");
297 * Syriac.
298 * '\u0700' - '\u074F'.
299 * @since 1.4
301 public static final UnicodeBlock SYRIAC
302 = new UnicodeBlock('\u0700', '\u074F',
303 "SYRIAC");
306 * Thaana.
307 * '\u0780' - '\u07BF'.
308 * @since 1.4
310 public static final UnicodeBlock THAANA
311 = new UnicodeBlock('\u0780', '\u07BF',
312 "THAANA");
315 * Devanagari.
316 * '\u0900' - '\u097F'.
318 public static final UnicodeBlock DEVANAGARI
319 = new UnicodeBlock('\u0900', '\u097F',
320 "DEVANAGARI");
323 * Bengali.
324 * '\u0980' - '\u09FF'.
326 public static final UnicodeBlock BENGALI
327 = new UnicodeBlock('\u0980', '\u09FF',
328 "BENGALI");
331 * Gurmukhi.
332 * '\u0A00' - '\u0A7F'.
334 public static final UnicodeBlock GURMUKHI
335 = new UnicodeBlock('\u0A00', '\u0A7F',
336 "GURMUKHI");
339 * Gujarati.
340 * '\u0A80' - '\u0AFF'.
342 public static final UnicodeBlock GUJARATI
343 = new UnicodeBlock('\u0A80', '\u0AFF',
344 "GUJARATI");
347 * Oriya.
348 * '\u0B00' - '\u0B7F'.
350 public static final UnicodeBlock ORIYA
351 = new UnicodeBlock('\u0B00', '\u0B7F',
352 "ORIYA");
355 * Tamil.
356 * '\u0B80' - '\u0BFF'.
358 public static final UnicodeBlock TAMIL
359 = new UnicodeBlock('\u0B80', '\u0BFF',
360 "TAMIL");
363 * Telugu.
364 * '\u0C00' - '\u0C7F'.
366 public static final UnicodeBlock TELUGU
367 = new UnicodeBlock('\u0C00', '\u0C7F',
368 "TELUGU");
371 * Kannada.
372 * '\u0C80' - '\u0CFF'.
374 public static final UnicodeBlock KANNADA
375 = new UnicodeBlock('\u0C80', '\u0CFF',
376 "KANNADA");
379 * Malayalam.
380 * '\u0D00' - '\u0D7F'.
382 public static final UnicodeBlock MALAYALAM
383 = new UnicodeBlock('\u0D00', '\u0D7F',
384 "MALAYALAM");
387 * Sinhala.
388 * '\u0D80' - '\u0DFF'.
389 * @since 1.4
391 public static final UnicodeBlock SINHALA
392 = new UnicodeBlock('\u0D80', '\u0DFF',
393 "SINHALA");
396 * Thai.
397 * '\u0E00' - '\u0E7F'.
399 public static final UnicodeBlock THAI
400 = new UnicodeBlock('\u0E00', '\u0E7F',
401 "THAI");
404 * Lao.
405 * '\u0E80' - '\u0EFF'.
407 public static final UnicodeBlock LAO
408 = new UnicodeBlock('\u0E80', '\u0EFF',
409 "LAO");
412 * Tibetan.
413 * '\u0F00' - '\u0FFF'.
415 public static final UnicodeBlock TIBETAN
416 = new UnicodeBlock('\u0F00', '\u0FFF',
417 "TIBETAN");
420 * Myanmar.
421 * '\u1000' - '\u109F'.
422 * @since 1.4
424 public static final UnicodeBlock MYANMAR
425 = new UnicodeBlock('\u1000', '\u109F',
426 "MYANMAR");
429 * Georgian.
430 * '\u10A0' - '\u10FF'.
432 public static final UnicodeBlock GEORGIAN
433 = new UnicodeBlock('\u10A0', '\u10FF',
434 "GEORGIAN");
437 * Hangul Jamo.
438 * '\u1100' - '\u11FF'.
440 public static final UnicodeBlock HANGUL_JAMO
441 = new UnicodeBlock('\u1100', '\u11FF',
442 "HANGUL_JAMO");
445 * Ethiopic.
446 * '\u1200' - '\u137F'.
447 * @since 1.4
449 public static final UnicodeBlock ETHIOPIC
450 = new UnicodeBlock('\u1200', '\u137F',
451 "ETHIOPIC");
454 * Cherokee.
455 * '\u13A0' - '\u13FF'.
456 * @since 1.4
458 public static final UnicodeBlock CHEROKEE
459 = new UnicodeBlock('\u13A0', '\u13FF',
460 "CHEROKEE");
463 * Unified Canadian Aboriginal Syllabics.
464 * '\u1400' - '\u167F'.
465 * @since 1.4
467 public static final UnicodeBlock UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS
468 = new UnicodeBlock('\u1400', '\u167F',
469 "UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS");
472 * Ogham.
473 * '\u1680' - '\u169F'.
474 * @since 1.4
476 public static final UnicodeBlock OGHAM
477 = new UnicodeBlock('\u1680', '\u169F',
478 "OGHAM");
481 * Runic.
482 * '\u16A0' - '\u16FF'.
483 * @since 1.4
485 public static final UnicodeBlock RUNIC
486 = new UnicodeBlock('\u16A0', '\u16FF',
487 "RUNIC");
490 * Khmer.
491 * '\u1780' - '\u17FF'.
492 * @since 1.4
494 public static final UnicodeBlock KHMER
495 = new UnicodeBlock('\u1780', '\u17FF',
496 "KHMER");
499 * Mongolian.
500 * '\u1800' - '\u18AF'.
501 * @since 1.4
503 public static final UnicodeBlock MONGOLIAN
504 = new UnicodeBlock('\u1800', '\u18AF',
505 "MONGOLIAN");
508 * Latin Extended Additional.
509 * '\u1E00' - '\u1EFF'.
511 public static final UnicodeBlock LATIN_EXTENDED_ADDITIONAL
512 = new UnicodeBlock('\u1E00', '\u1EFF',
513 "LATIN_EXTENDED_ADDITIONAL");
516 * Greek Extended.
517 * '\u1F00' - '\u1FFF'.
519 public static final UnicodeBlock GREEK_EXTENDED
520 = new UnicodeBlock('\u1F00', '\u1FFF',
521 "GREEK_EXTENDED");
524 * General Punctuation.
525 * '\u2000' - '\u206F'.
527 public static final UnicodeBlock GENERAL_PUNCTUATION
528 = new UnicodeBlock('\u2000', '\u206F',
529 "GENERAL_PUNCTUATION");
532 * Superscripts and Subscripts.
533 * '\u2070' - '\u209F'.
535 public static final UnicodeBlock SUPERSCRIPTS_AND_SUBSCRIPTS
536 = new UnicodeBlock('\u2070', '\u209F',
537 "SUPERSCRIPTS_AND_SUBSCRIPTS");
540 * Currency Symbols.
541 * '\u20A0' - '\u20CF'.
543 public static final UnicodeBlock CURRENCY_SYMBOLS
544 = new UnicodeBlock('\u20A0', '\u20CF',
545 "CURRENCY_SYMBOLS");
548 * Combining Marks for Symbols.
549 * '\u20D0' - '\u20FF'.
551 public static final UnicodeBlock COMBINING_MARKS_FOR_SYMBOLS
552 = new UnicodeBlock('\u20D0', '\u20FF',
553 "COMBINING_MARKS_FOR_SYMBOLS");
556 * Letterlike Symbols.
557 * '\u2100' - '\u214F'.
559 public static final UnicodeBlock LETTERLIKE_SYMBOLS
560 = new UnicodeBlock('\u2100', '\u214F',
561 "LETTERLIKE_SYMBOLS");
564 * Number Forms.
565 * '\u2150' - '\u218F'.
567 public static final UnicodeBlock NUMBER_FORMS
568 = new UnicodeBlock('\u2150', '\u218F',
569 "NUMBER_FORMS");
572 * Arrows.
573 * '\u2190' - '\u21FF'.
575 public static final UnicodeBlock ARROWS
576 = new UnicodeBlock('\u2190', '\u21FF',
577 "ARROWS");
580 * Mathematical Operators.
581 * '\u2200' - '\u22FF'.
583 public static final UnicodeBlock MATHEMATICAL_OPERATORS
584 = new UnicodeBlock('\u2200', '\u22FF',
585 "MATHEMATICAL_OPERATORS");
588 * Miscellaneous Technical.
589 * '\u2300' - '\u23FF'.
591 public static final UnicodeBlock MISCELLANEOUS_TECHNICAL
592 = new UnicodeBlock('\u2300', '\u23FF',
593 "MISCELLANEOUS_TECHNICAL");
596 * Control Pictures.
597 * '\u2400' - '\u243F'.
599 public static final UnicodeBlock CONTROL_PICTURES
600 = new UnicodeBlock('\u2400', '\u243F',
601 "CONTROL_PICTURES");
604 * Optical Character Recognition.
605 * '\u2440' - '\u245F'.
607 public static final UnicodeBlock OPTICAL_CHARACTER_RECOGNITION
608 = new UnicodeBlock('\u2440', '\u245F',
609 "OPTICAL_CHARACTER_RECOGNITION");
612 * Enclosed Alphanumerics.
613 * '\u2460' - '\u24FF'.
615 public static final UnicodeBlock ENCLOSED_ALPHANUMERICS
616 = new UnicodeBlock('\u2460', '\u24FF',
617 "ENCLOSED_ALPHANUMERICS");
620 * Box Drawing.
621 * '\u2500' - '\u257F'.
623 public static final UnicodeBlock BOX_DRAWING
624 = new UnicodeBlock('\u2500', '\u257F',
625 "BOX_DRAWING");
628 * Block Elements.
629 * '\u2580' - '\u259F'.
631 public static final UnicodeBlock BLOCK_ELEMENTS
632 = new UnicodeBlock('\u2580', '\u259F',
633 "BLOCK_ELEMENTS");
636 * Geometric Shapes.
637 * '\u25A0' - '\u25FF'.
639 public static final UnicodeBlock GEOMETRIC_SHAPES
640 = new UnicodeBlock('\u25A0', '\u25FF',
641 "GEOMETRIC_SHAPES");
644 * Miscellaneous Symbols.
645 * '\u2600' - '\u26FF'.
647 public static final UnicodeBlock MISCELLANEOUS_SYMBOLS
648 = new UnicodeBlock('\u2600', '\u26FF',
649 "MISCELLANEOUS_SYMBOLS");
652 * Dingbats.
653 * '\u2700' - '\u27BF'.
655 public static final UnicodeBlock DINGBATS
656 = new UnicodeBlock('\u2700', '\u27BF',
657 "DINGBATS");
660 * Braille Patterns.
661 * '\u2800' - '\u28FF'.
662 * @since 1.4
664 public static final UnicodeBlock BRAILLE_PATTERNS
665 = new UnicodeBlock('\u2800', '\u28FF',
666 "BRAILLE_PATTERNS");
669 * CJK Radicals Supplement.
670 * '\u2E80' - '\u2EFF'.
671 * @since 1.4
673 public static final UnicodeBlock CJK_RADICALS_SUPPLEMENT
674 = new UnicodeBlock('\u2E80', '\u2EFF',
675 "CJK_RADICALS_SUPPLEMENT");
678 * Kangxi Radicals.
679 * '\u2F00' - '\u2FDF'.
680 * @since 1.4
682 public static final UnicodeBlock KANGXI_RADICALS
683 = new UnicodeBlock('\u2F00', '\u2FDF',
684 "KANGXI_RADICALS");
687 * Ideographic Description Characters.
688 * '\u2FF0' - '\u2FFF'.
689 * @since 1.4
691 public static final UnicodeBlock IDEOGRAPHIC_DESCRIPTION_CHARACTERS
692 = new UnicodeBlock('\u2FF0', '\u2FFF',
693 "IDEOGRAPHIC_DESCRIPTION_CHARACTERS");
696 * CJK Symbols and Punctuation.
697 * '\u3000' - '\u303F'.
699 public static final UnicodeBlock CJK_SYMBOLS_AND_PUNCTUATION
700 = new UnicodeBlock('\u3000', '\u303F',
701 "CJK_SYMBOLS_AND_PUNCTUATION");
704 * Hiragana.
705 * '\u3040' - '\u309F'.
707 public static final UnicodeBlock HIRAGANA
708 = new UnicodeBlock('\u3040', '\u309F',
709 "HIRAGANA");
712 * Katakana.
713 * '\u30A0' - '\u30FF'.
715 public static final UnicodeBlock KATAKANA
716 = new UnicodeBlock('\u30A0', '\u30FF',
717 "KATAKANA");
720 * Bopomofo.
721 * '\u3100' - '\u312F'.
723 public static final UnicodeBlock BOPOMOFO
724 = new UnicodeBlock('\u3100', '\u312F',
725 "BOPOMOFO");
728 * Hangul Compatibility Jamo.
729 * '\u3130' - '\u318F'.
731 public static final UnicodeBlock HANGUL_COMPATIBILITY_JAMO
732 = new UnicodeBlock('\u3130', '\u318F',
733 "HANGUL_COMPATIBILITY_JAMO");
736 * Kanbun.
737 * '\u3190' - '\u319F'.
739 public static final UnicodeBlock KANBUN
740 = new UnicodeBlock('\u3190', '\u319F',
741 "KANBUN");
744 * Bopomofo Extended.
745 * '\u31A0' - '\u31BF'.
746 * @since 1.4
748 public static final UnicodeBlock BOPOMOFO_EXTENDED
749 = new UnicodeBlock('\u31A0', '\u31BF',
750 "BOPOMOFO_EXTENDED");
753 * Enclosed CJK Letters and Months.
754 * '\u3200' - '\u32FF'.
756 public static final UnicodeBlock ENCLOSED_CJK_LETTERS_AND_MONTHS
757 = new UnicodeBlock('\u3200', '\u32FF',
758 "ENCLOSED_CJK_LETTERS_AND_MONTHS");
761 * CJK Compatibility.
762 * '\u3300' - '\u33FF'.
764 public static final UnicodeBlock CJK_COMPATIBILITY
765 = new UnicodeBlock('\u3300', '\u33FF',
766 "CJK_COMPATIBILITY");
769 * CJK Unified Ideographs Extension A.
770 * '\u3400' - '\u4DB5'.
771 * @since 1.4
773 public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
774 = new UnicodeBlock('\u3400', '\u4DB5',
775 "CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A");
778 * CJK Unified Ideographs.
779 * '\u4E00' - '\u9FFF'.
781 public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS
782 = new UnicodeBlock('\u4E00', '\u9FFF',
783 "CJK_UNIFIED_IDEOGRAPHS");
786 * Yi Syllables.
787 * '\uA000' - '\uA48F'.
788 * @since 1.4
790 public static final UnicodeBlock YI_SYLLABLES
791 = new UnicodeBlock('\uA000', '\uA48F',
792 "YI_SYLLABLES");
795 * Yi Radicals.
796 * '\uA490' - '\uA4CF'.
797 * @since 1.4
799 public static final UnicodeBlock YI_RADICALS
800 = new UnicodeBlock('\uA490', '\uA4CF',
801 "YI_RADICALS");
804 * Hangul Syllables.
805 * '\uAC00' - '\uD7A3'.
807 public static final UnicodeBlock HANGUL_SYLLABLES
808 = new UnicodeBlock('\uAC00', '\uD7A3',
809 "HANGUL_SYLLABLES");
812 * Surrogates Area.
813 * '\uD800' - '\uDFFF'.
815 public static final UnicodeBlock SURROGATES_AREA
816 = new UnicodeBlock('\uD800', '\uDFFF',
817 "SURROGATES_AREA");
820 * Private Use Area.
821 * '\uE000' - '\uF8FF'.
823 public static final UnicodeBlock PRIVATE_USE_AREA
824 = new UnicodeBlock('\uE000', '\uF8FF',
825 "PRIVATE_USE_AREA");
828 * CJK Compatibility Ideographs.
829 * '\uF900' - '\uFAFF'.
831 public static final UnicodeBlock CJK_COMPATIBILITY_IDEOGRAPHS
832 = new UnicodeBlock('\uF900', '\uFAFF',
833 "CJK_COMPATIBILITY_IDEOGRAPHS");
836 * Alphabetic Presentation Forms.
837 * '\uFB00' - '\uFB4F'.
839 public static final UnicodeBlock ALPHABETIC_PRESENTATION_FORMS
840 = new UnicodeBlock('\uFB00', '\uFB4F',
841 "ALPHABETIC_PRESENTATION_FORMS");
844 * Arabic Presentation Forms-A.
845 * '\uFB50' - '\uFDFF'.
847 public static final UnicodeBlock ARABIC_PRESENTATION_FORMS_A
848 = new UnicodeBlock('\uFB50', '\uFDFF',
849 "ARABIC_PRESENTATION_FORMS_A");
852 * Combining Half Marks.
853 * '\uFE20' - '\uFE2F'.
855 public static final UnicodeBlock COMBINING_HALF_MARKS
856 = new UnicodeBlock('\uFE20', '\uFE2F',
857 "COMBINING_HALF_MARKS");
860 * CJK Compatibility Forms.
861 * '\uFE30' - '\uFE4F'.
863 public static final UnicodeBlock CJK_COMPATIBILITY_FORMS
864 = new UnicodeBlock('\uFE30', '\uFE4F',
865 "CJK_COMPATIBILITY_FORMS");
868 * Small Form Variants.
869 * '\uFE50' - '\uFE6F'.
871 public static final UnicodeBlock SMALL_FORM_VARIANTS
872 = new UnicodeBlock('\uFE50', '\uFE6F',
873 "SMALL_FORM_VARIANTS");
876 * Arabic Presentation Forms-B.
877 * '\uFE70' - '\uFEFE'.
879 public static final UnicodeBlock ARABIC_PRESENTATION_FORMS_B
880 = new UnicodeBlock('\uFE70', '\uFEFE',
881 "ARABIC_PRESENTATION_FORMS_B");
884 * Halfwidth and Fullwidth Forms.
885 * '\uFF00' - '\uFFEF'.
887 public static final UnicodeBlock HALFWIDTH_AND_FULLWIDTH_FORMS
888 = new UnicodeBlock('\uFF00', '\uFFEF',
889 "HALFWIDTH_AND_FULLWIDTH_FORMS");
892 * Specials.
893 * '\uFEFF', '\uFFF0' - '\uFFFD'.
895 public static final UnicodeBlock SPECIALS
896 = new UnicodeBlock('\uFFF0', '\uFFFD',
897 "SPECIALS");
900 * The defined subsets.
902 private static final UnicodeBlock sets[] = {
903 BASIC_LATIN,
904 LATIN_1_SUPPLEMENT,
905 LATIN_EXTENDED_A,
906 LATIN_EXTENDED_B,
907 IPA_EXTENSIONS,
908 SPACING_MODIFIER_LETTERS,
909 COMBINING_DIACRITICAL_MARKS,
910 GREEK,
911 CYRILLIC,
912 ARMENIAN,
913 HEBREW,
914 ARABIC,
915 SYRIAC,
916 THAANA,
917 DEVANAGARI,
918 BENGALI,
919 GURMUKHI,
920 GUJARATI,
921 ORIYA,
922 TAMIL,
923 TELUGU,
924 KANNADA,
925 MALAYALAM,
926 SINHALA,
927 THAI,
928 LAO,
929 TIBETAN,
930 MYANMAR,
931 GEORGIAN,
932 HANGUL_JAMO,
933 ETHIOPIC,
934 CHEROKEE,
935 UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS,
936 OGHAM,
937 RUNIC,
938 KHMER,
939 MONGOLIAN,
940 LATIN_EXTENDED_ADDITIONAL,
941 GREEK_EXTENDED,
942 GENERAL_PUNCTUATION,
943 SUPERSCRIPTS_AND_SUBSCRIPTS,
944 CURRENCY_SYMBOLS,
945 COMBINING_MARKS_FOR_SYMBOLS,
946 LETTERLIKE_SYMBOLS,
947 NUMBER_FORMS,
948 ARROWS,
949 MATHEMATICAL_OPERATORS,
950 MISCELLANEOUS_TECHNICAL,
951 CONTROL_PICTURES,
952 OPTICAL_CHARACTER_RECOGNITION,
953 ENCLOSED_ALPHANUMERICS,
954 BOX_DRAWING,
955 BLOCK_ELEMENTS,
956 GEOMETRIC_SHAPES,
957 MISCELLANEOUS_SYMBOLS,
958 DINGBATS,
959 BRAILLE_PATTERNS,
960 CJK_RADICALS_SUPPLEMENT,
961 KANGXI_RADICALS,
962 IDEOGRAPHIC_DESCRIPTION_CHARACTERS,
963 CJK_SYMBOLS_AND_PUNCTUATION,
964 HIRAGANA,
965 KATAKANA,
966 BOPOMOFO,
967 HANGUL_COMPATIBILITY_JAMO,
968 KANBUN,
969 BOPOMOFO_EXTENDED,
970 ENCLOSED_CJK_LETTERS_AND_MONTHS,
971 CJK_COMPATIBILITY,
972 CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A,
973 CJK_UNIFIED_IDEOGRAPHS,
974 YI_SYLLABLES,
975 YI_RADICALS,
976 HANGUL_SYLLABLES,
977 SURROGATES_AREA,
978 PRIVATE_USE_AREA,
979 CJK_COMPATIBILITY_IDEOGRAPHS,
980 ALPHABETIC_PRESENTATION_FORMS,
981 ARABIC_PRESENTATION_FORMS_A,
982 COMBINING_HALF_MARKS,
983 CJK_COMPATIBILITY_FORMS,
984 SMALL_FORM_VARIANTS,
985 ARABIC_PRESENTATION_FORMS_B,
986 HALFWIDTH_AND_FULLWIDTH_FORMS,
987 SPECIALS,
989 } // class UnicodeBlock
992 * The immutable value of this Character.
994 * @serial the value of this Character
996 private final char value;
999 * Compatible with JDK 1.0+.
1001 private static final long serialVersionUID = 3786198910865385080L;
1004 * Smallest value allowed for radix arguments in Java. This value is 2.
1006 * @see #digit(char, int)
1007 * @see #forDigit(int, int)
1008 * @see Integer#toString(int, int)
1009 * @see Integer#valueOf(String)
1011 public static final int MIN_RADIX = 2;
1014 * Largest value allowed for radix arguments in Java. This value is 36.
1016 * @see #digit(char, int)
1017 * @see #forDigit(int, int)
1018 * @see Integer#toString(int, int)
1019 * @see Integer#valueOf(String)
1021 public static final int MAX_RADIX = 36;
1024 * The minimum value the char data type can hold.
1025 * This value is <code>'\\u0000'</code>.
1027 public static final char MIN_VALUE = '\u0000';
1030 * The maximum value the char data type can hold.
1031 * This value is <code>'\\uFFFF'</code>.
1033 public static final char MAX_VALUE = '\uFFFF';
1036 * Class object representing the primitive char data type.
1038 * @since 1.1
1040 public static final Class TYPE = VMClassLoader.getPrimitiveClass('C');
1043 * Lu = Letter, Uppercase (Informative).
1045 * @since 1.1
1047 public static final byte UPPERCASE_LETTER = 1;
1050 * Ll = Letter, Lowercase (Informative).
1052 * @since 1.1
1054 public static final byte LOWERCASE_LETTER = 2;
1057 * Lt = Letter, Titlecase (Informative).
1059 * @since 1.1
1061 public static final byte TITLECASE_LETTER = 3;
1064 * Mn = Mark, Non-Spacing (Normative).
1066 * @since 1.1
1068 public static final byte NON_SPACING_MARK = 6;
1071 * Mc = Mark, Spacing Combining (Normative).
1073 * @since 1.1
1075 public static final byte COMBINING_SPACING_MARK = 8;
1078 * Me = Mark, Enclosing (Normative).
1080 * @since 1.1
1082 public static final byte ENCLOSING_MARK = 7;
1085 * Nd = Number, Decimal Digit (Normative).
1087 * @since 1.1
1089 public static final byte DECIMAL_DIGIT_NUMBER = 9;
1092 * Nl = Number, Letter (Normative).
1094 * @since 1.1
1096 public static final byte LETTER_NUMBER = 10;
1099 * No = Number, Other (Normative).
1101 * @since 1.1
1103 public static final byte OTHER_NUMBER = 11;
1106 * Zs = Separator, Space (Normative).
1108 * @since 1.1
1110 public static final byte SPACE_SEPARATOR = 12;
1113 * Zl = Separator, Line (Normative).
1115 * @since 1.1
1117 public static final byte LINE_SEPARATOR = 13;
1120 * Zp = Separator, Paragraph (Normative).
1122 * @since 1.1
1124 public static final byte PARAGRAPH_SEPARATOR = 14;
1127 * Cc = Other, Control (Normative).
1129 * @since 1.1
1131 public static final byte CONTROL = 15;
1134 * Cf = Other, Format (Normative).
1136 * @since 1.1
1138 public static final byte FORMAT = 16;
1141 * Cs = Other, Surrogate (Normative).
1143 * @since 1.1
1145 public static final byte SURROGATE = 19;
1148 * Co = Other, Private Use (Normative).
1150 * @since 1.1
1152 public static final byte PRIVATE_USE = 18;
1155 * Cn = Other, Not Assigned (Normative).
1157 * @since 1.1
1159 public static final byte UNASSIGNED = 0;
1162 * Lm = Letter, Modifier (Informative).
1164 * @since 1.1
1166 public static final byte MODIFIER_LETTER = 4;
1169 * Lo = Letter, Other (Informative).
1171 * @since 1.1
1173 public static final byte OTHER_LETTER = 5;
1176 * Pc = Punctuation, Connector (Informative).
1178 * @since 1.1
1180 public static final byte CONNECTOR_PUNCTUATION = 23;
1183 * Pd = Punctuation, Dash (Informative).
1185 * @since 1.1
1187 public static final byte DASH_PUNCTUATION = 20;
1190 * Ps = Punctuation, Open (Informative).
1192 * @since 1.1
1194 public static final byte START_PUNCTUATION = 21;
1197 * Pe = Punctuation, Close (Informative).
1199 * @since 1.1
1201 public static final byte END_PUNCTUATION = 22;
1204 * Pi = Punctuation, Initial Quote (Informative).
1206 * @since 1.4
1208 public static final byte INITIAL_QUOTE_PUNCTUATION = 29;
1211 * Pf = Punctuation, Final Quote (Informative).
1213 * @since 1.4
1215 public static final byte FINAL_QUOTE_PUNCTUATION = 30;
1218 * Po = Punctuation, Other (Informative).
1220 * @since 1.1
1222 public static final byte OTHER_PUNCTUATION = 24;
1225 * Sm = Symbol, Math (Informative).
1227 * @since 1.1
1229 public static final byte MATH_SYMBOL = 25;
1232 * Sc = Symbol, Currency (Informative).
1234 * @since 1.1
1236 public static final byte CURRENCY_SYMBOL = 26;
1239 * Sk = Symbol, Modifier (Informative).
1241 * @since 1.1
1243 public static final byte MODIFIER_SYMBOL = 27;
1246 * So = Symbol, Other (Informative).
1248 * @since 1.1
1250 public static final byte OTHER_SYMBOL = 28;
1253 * Undefined bidirectional character type. Undefined char values have
1254 * undefined directionality in the Unicode specification.
1256 * @since 1.4
1258 public static final byte DIRECTIONALITY_UNDEFINED = -1;
1261 * Strong bidirectional character type "L".
1263 * @since 1.4
1265 public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0;
1268 * Strong bidirectional character type "R".
1270 * @since 1.4
1272 public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1;
1275 * Strong bidirectional character type "AL".
1277 * @since 1.4
1279 public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2;
1282 * Weak bidirectional character type "EN".
1284 * @since 1.4
1286 public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3;
1289 * Weak bidirectional character type "ES".
1291 * @since 1.4
1293 public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4;
1296 * Weak bidirectional character type "ET".
1298 * @since 1.4
1300 public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5;
1303 * Weak bidirectional character type "AN".
1305 * @since 1.4
1307 public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6;
1310 * Weak bidirectional character type "CS".
1312 * @since 1.4
1314 public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7;
1317 * Weak bidirectional character type "NSM".
1319 * @since 1.4
1321 public static final byte DIRECTIONALITY_NONSPACING_MARK = 8;
1324 * Weak bidirectional character type "BN".
1326 * @since 1.4
1328 public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9;
1331 * Neutral bidirectional character type "B".
1333 * @since 1.4
1335 public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10;
1338 * Neutral bidirectional character type "S".
1340 * @since 1.4
1342 public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11;
1345 * Strong bidirectional character type "WS".
1347 * @since 1.4
1349 public static final byte DIRECTIONALITY_WHITESPACE = 12;
1352 * Neutral bidirectional character type "ON".
1354 * @since 1.4
1356 public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13;
1359 * Strong bidirectional character type "LRE".
1361 * @since 1.4
1363 public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14;
1366 * Strong bidirectional character type "LRO".
1368 * @since 1.4
1370 public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15;
1373 * Strong bidirectional character type "RLE".
1375 * @since 1.4
1377 public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16;
1380 * Strong bidirectional character type "RLO".
1382 * @since 1.4
1384 public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17;
1387 * Weak bidirectional character type "PDF".
1389 * @since 1.4
1391 public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18;
1394 * Mask for grabbing the type out of the result of readChar.
1395 * @see #readChar(char)
1397 private static final int TYPE_MASK = 0x1F;
1400 * Mask for grabbing the non-breaking space flag out of the result of
1401 * readChar.
1402 * @see #readChar(char)
1404 private static final int NO_BREAK_MASK = 0x20;
1407 * Mask for grabbing the mirrored directionality flag out of the result
1408 * of readChar.
1409 * @see #readChar(char)
1411 private static final int MIRROR_MASK = 0x40;
1414 * Min value for supplementary code point.
1416 * @since 1.5
1418 public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x10000;
1421 * Min value for code point.
1423 * @since 1.5
1425 public static final int MIN_CODE_POINT = 0;
1429 * Max value for code point.
1431 * @since 1.5
1433 public static final int MAX_CODE_POINT = 0x010ffff;
1437 * Minimum high surrrogate code in UTF-16 encoding.
1439 * @since 1.5
1441 public static final char MIN_HIGH_SURROGATE = '\ud800';
1444 * Maximum high surrrogate code in UTF-16 encoding.
1446 * @since 1.5
1448 public static final char MAX_HIGH_SURROGATE = '\udbff';
1451 * Minimum low surrrogate code in UTF-16 encoding.
1453 * @since 1.5
1455 public static final char MIN_LOW_SURROGATE = '\udc00';
1458 * Maximum low surrrogate code in UTF-16 encoding.
1460 * @since 1.5
1462 public static final char MAX_LOW_SURROGATE = '\udfff';
1465 * Grabs an attribute offset from the Unicode attribute database. The lower
1466 * 5 bits are the character type, the next 2 bits are flags, and the top
1467 * 9 bits are the offset into the attribute tables. Note that the top 9
1468 * bits are meaningless in this context; they are useful only in the native
1469 * code.
1471 * @param ch the character to look up
1472 * @return the character's attribute offset and type
1473 * @see #TYPE_MASK
1474 * @see #NO_BREAK_MASK
1475 * @see #MIRROR_MASK
1477 private static native char readChar(char ch);
1480 * Wraps up a character.
1482 * @param value the character to wrap
1484 public Character(char value)
1486 this.value = value;
1490 * Returns the character which has been wrapped by this class.
1492 * @return the character wrapped
1494 public char charValue()
1496 return value;
1500 * Returns the numerical value (unsigned) of the wrapped character.
1501 * Range of returned values: 0x0000-0xFFFF.
1503 * @return the value of the wrapped character
1505 public int hashCode()
1507 return value;
1511 * Determines if an object is equal to this object. This is only true for
1512 * another Character object wrapping the same value.
1514 * @param o object to compare
1515 * @return true if o is a Character with the same value
1517 public boolean equals(Object o)
1519 return o instanceof Character && value == ((Character) o).value;
1523 * Converts the wrapped character into a String.
1525 * @return a String containing one character -- the wrapped character
1526 * of this instance
1528 public String toString()
1530 // This assumes that String.valueOf(char) can create a single-character
1531 // String more efficiently than through the public API.
1532 return String.valueOf(value);
1536 * Returns a String of length 1 representing the specified character.
1538 * @param ch the character to convert
1539 * @return a String containing the character
1540 * @since 1.4
1542 public static String toString(char ch)
1544 // This assumes that String.valueOf(char) can create a single-character
1545 // String more efficiently than through the public API.
1546 return String.valueOf(ch);
1550 * Determines if a character is a Unicode lowercase letter. For example,
1551 * <code>'a'</code> is lowercase.
1552 * <br>
1553 * lowercase = [Ll]
1555 * @param ch character to test
1556 * @return true if ch is a Unicode lowercase letter, else false
1557 * @see #isUpperCase(char)
1558 * @see #isTitleCase(char)
1559 * @see #toLowerCase(char)
1560 * @see #getType(char)
1562 public static boolean isLowerCase(char ch)
1564 return getType(ch) == LOWERCASE_LETTER;
1568 * Determines if a character is a Unicode uppercase letter. For example,
1569 * <code>'A'</code> is uppercase.
1570 * <br>
1571 * uppercase = [Lu]
1573 * @param ch character to test
1574 * @return true if ch is a Unicode uppercase letter, else false
1575 * @see #isLowerCase(char)
1576 * @see #isTitleCase(char)
1577 * @see #toUpperCase(char)
1578 * @see #getType(char)
1580 public static boolean isUpperCase(char ch)
1582 return getType(ch) == UPPERCASE_LETTER;
1586 * Determines if a character is a Unicode titlecase letter. For example,
1587 * the character "Lj" (Latin capital L with small letter j) is titlecase.
1588 * <br>
1589 * titlecase = [Lt]
1591 * @param ch character to test
1592 * @return true if ch is a Unicode titlecase letter, else false
1593 * @see #isLowerCase(char)
1594 * @see #isUpperCase(char)
1595 * @see #toTitleCase(char)
1596 * @see #getType(char)
1598 public static boolean isTitleCase(char ch)
1600 return getType(ch) == TITLECASE_LETTER;
1604 * Determines if a character is a Unicode decimal digit. For example,
1605 * <code>'0'</code> is a digit.
1606 * <br>
1607 * Unicode decimal digit = [Nd]
1609 * @param ch character to test
1610 * @return true if ch is a Unicode decimal digit, else false
1611 * @see #digit(char, int)
1612 * @see #forDigit(int, int)
1613 * @see #getType(char)
1615 public static boolean isDigit(char ch)
1617 return getType(ch) == DECIMAL_DIGIT_NUMBER;
1621 * Determines if a character is part of the Unicode Standard. This is an
1622 * evolving standard, but covers every character in the data file.
1623 * <br>
1624 * defined = not [Cn]
1626 * @param ch character to test
1627 * @return true if ch is a Unicode character, else false
1628 * @see #isDigit(char)
1629 * @see #isLetter(char)
1630 * @see #isLetterOrDigit(char)
1631 * @see #isLowerCase(char)
1632 * @see #isTitleCase(char)
1633 * @see #isUpperCase(char)
1635 public static boolean isDefined(char ch)
1637 return getType(ch) != UNASSIGNED;
1641 * Determines if a character is a Unicode letter. Not all letters have case,
1642 * so this may return true when isLowerCase and isUpperCase return false.
1643 * <br>
1644 * letter = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]
1646 * @param ch character to test
1647 * @return true if ch is a Unicode letter, else false
1648 * @see #isDigit(char)
1649 * @see #isJavaIdentifierStart(char)
1650 * @see #isJavaLetter(char)
1651 * @see #isJavaLetterOrDigit(char)
1652 * @see #isLetterOrDigit(char)
1653 * @see #isLowerCase(char)
1654 * @see #isTitleCase(char)
1655 * @see #isUnicodeIdentifierStart(char)
1656 * @see #isUpperCase(char)
1658 public static boolean isLetter(char ch)
1660 return ((1 << getType(ch))
1661 & ((1 << UPPERCASE_LETTER)
1662 | (1 << LOWERCASE_LETTER)
1663 | (1 << TITLECASE_LETTER)
1664 | (1 << MODIFIER_LETTER)
1665 | (1 << OTHER_LETTER))) != 0;
1669 * Determines if a character is a Unicode letter or a Unicode digit. This
1670 * is the combination of isLetter and isDigit.
1671 * <br>
1672 * letter or digit = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nd]
1674 * @param ch character to test
1675 * @return true if ch is a Unicode letter or a Unicode digit, else false
1676 * @see #isDigit(char)
1677 * @see #isJavaIdentifierPart(char)
1678 * @see #isJavaLetter(char)
1679 * @see #isJavaLetterOrDigit(char)
1680 * @see #isLetter(char)
1681 * @see #isUnicodeIdentifierPart(char)
1683 public static boolean isLetterOrDigit(char ch)
1685 return ((1 << getType(ch))
1686 & ((1 << UPPERCASE_LETTER)
1687 | (1 << LOWERCASE_LETTER)
1688 | (1 << TITLECASE_LETTER)
1689 | (1 << MODIFIER_LETTER)
1690 | (1 << OTHER_LETTER)
1691 | (1 << DECIMAL_DIGIT_NUMBER))) != 0;
1695 * Determines if a character can start a Java identifier. This is the
1696 * combination of isLetter, any character where getType returns
1697 * LETTER_NUMBER, currency symbols (like '$'), and connecting punctuation
1698 * (like '_').
1700 * @param ch character to test
1701 * @return true if ch can start a Java identifier, else false
1702 * @deprecated Replaced by {@link #isJavaIdentifierStart(char)}
1703 * @see #isJavaLetterOrDigit(char)
1704 * @see #isJavaIdentifierStart(char)
1705 * @see #isJavaIdentifierPart(char)
1706 * @see #isLetter(char)
1707 * @see #isLetterOrDigit(char)
1708 * @see #isUnicodeIdentifierStart(char)
1710 public static boolean isJavaLetter(char ch)
1712 return isJavaIdentifierStart(ch);
1716 * Determines if a character can follow the first letter in
1717 * a Java identifier. This is the combination of isJavaLetter (isLetter,
1718 * type of LETTER_NUMBER, currency, connecting punctuation) and digit,
1719 * numeric letter (like Roman numerals), combining marks, non-spacing marks,
1720 * or isIdentifierIgnorable.
1722 * @param ch character to test
1723 * @return true if ch can follow the first letter in a Java identifier
1724 * @deprecated Replaced by {@link #isJavaIdentifierPart(char)}
1725 * @see #isJavaLetter(char)
1726 * @see #isJavaIdentifierStart(char)
1727 * @see #isJavaIdentifierPart(char)
1728 * @see #isLetter(char)
1729 * @see #isLetterOrDigit(char)
1730 * @see #isUnicodeIdentifierPart(char)
1731 * @see #isIdentifierIgnorable(char)
1733 public static boolean isJavaLetterOrDigit(char ch)
1735 return isJavaIdentifierPart(ch);
1739 * Determines if a character can start a Java identifier. This is the
1740 * combination of isLetter, any character where getType returns
1741 * LETTER_NUMBER, currency symbols (like '$'), and connecting punctuation
1742 * (like '_').
1743 * <br>
1744 * Java identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc]
1746 * @param ch character to test
1747 * @return true if ch can start a Java identifier, else false
1748 * @see #isJavaIdentifierPart(char)
1749 * @see #isLetter(char)
1750 * @see #isUnicodeIdentifierStart(char)
1751 * @since 1.1
1753 public static boolean isJavaIdentifierStart(char ch)
1755 return ((1 << getType(ch))
1756 & ((1 << UPPERCASE_LETTER)
1757 | (1 << LOWERCASE_LETTER)
1758 | (1 << TITLECASE_LETTER)
1759 | (1 << MODIFIER_LETTER)
1760 | (1 << OTHER_LETTER)
1761 | (1 << LETTER_NUMBER)
1762 | (1 << CURRENCY_SYMBOL)
1763 | (1 << CONNECTOR_PUNCTUATION))) != 0;
1767 * Determines if a character can follow the first letter in
1768 * a Java identifier. This is the combination of isJavaLetter (isLetter,
1769 * type of LETTER_NUMBER, currency, connecting punctuation) and digit,
1770 * numeric letter (like Roman numerals), combining marks, non-spacing marks,
1771 * or isIdentifierIgnorable.
1772 * <br>
1773 * Java identifier extender =
1774 * [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc]|[Mn]|[Mc]|[Nd]|[Cf]
1775 * |U+0000-U+0008|U+000E-U+001B|U+007F-U+009F
1777 * @param ch character to test
1778 * @return true if ch can follow the first letter in a Java identifier
1779 * @see #isIdentifierIgnorable(char)
1780 * @see #isJavaIdentifierStart(char)
1781 * @see #isLetterOrDigit(char)
1782 * @see #isUnicodeIdentifierPart(char)
1783 * @since 1.1
1785 public static boolean isJavaIdentifierPart(char ch)
1787 int category = getType(ch);
1788 return ((1 << category)
1789 & ((1 << UPPERCASE_LETTER)
1790 | (1 << LOWERCASE_LETTER)
1791 | (1 << TITLECASE_LETTER)
1792 | (1 << MODIFIER_LETTER)
1793 | (1 << OTHER_LETTER)
1794 | (1 << NON_SPACING_MARK)
1795 | (1 << COMBINING_SPACING_MARK)
1796 | (1 << DECIMAL_DIGIT_NUMBER)
1797 | (1 << LETTER_NUMBER)
1798 | (1 << CURRENCY_SYMBOL)
1799 | (1 << CONNECTOR_PUNCTUATION)
1800 | (1 << FORMAT))) != 0
1801 || (category == CONTROL && isIdentifierIgnorable(ch));
1805 * Determines if a character can start a Unicode identifier. Only
1806 * letters can start a Unicode identifier, but this includes characters
1807 * in LETTER_NUMBER.
1808 * <br>
1809 * Unicode identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]
1811 * @param ch character to test
1812 * @return true if ch can start a Unicode identifier, else false
1813 * @see #isJavaIdentifierStart(char)
1814 * @see #isLetter(char)
1815 * @see #isUnicodeIdentifierPart(char)
1816 * @since 1.1
1818 public static boolean isUnicodeIdentifierStart(char ch)
1820 return ((1 << getType(ch))
1821 & ((1 << UPPERCASE_LETTER)
1822 | (1 << LOWERCASE_LETTER)
1823 | (1 << TITLECASE_LETTER)
1824 | (1 << MODIFIER_LETTER)
1825 | (1 << OTHER_LETTER)
1826 | (1 << LETTER_NUMBER))) != 0;
1830 * Determines if a character can follow the first letter in
1831 * a Unicode identifier. This includes letters, connecting punctuation,
1832 * digits, numeric letters, combining marks, non-spacing marks, and
1833 * isIdentifierIgnorable.
1834 * <br>
1835 * Unicode identifier extender =
1836 * [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Mn]|[Mc]|[Nd]|[Pc]|[Cf]|
1837 * |U+0000-U+0008|U+000E-U+001B|U+007F-U+009F
1839 * @param ch character to test
1840 * @return true if ch can follow the first letter in a Unicode identifier
1841 * @see #isIdentifierIgnorable(char)
1842 * @see #isJavaIdentifierPart(char)
1843 * @see #isLetterOrDigit(char)
1844 * @see #isUnicodeIdentifierStart(char)
1845 * @since 1.1
1847 public static boolean isUnicodeIdentifierPart(char ch)
1849 int category = getType(ch);
1850 return ((1 << category)
1851 & ((1 << UPPERCASE_LETTER)
1852 | (1 << LOWERCASE_LETTER)
1853 | (1 << TITLECASE_LETTER)
1854 | (1 << MODIFIER_LETTER)
1855 | (1 << OTHER_LETTER)
1856 | (1 << NON_SPACING_MARK)
1857 | (1 << COMBINING_SPACING_MARK)
1858 | (1 << DECIMAL_DIGIT_NUMBER)
1859 | (1 << LETTER_NUMBER)
1860 | (1 << CONNECTOR_PUNCTUATION)
1861 | (1 << FORMAT))) != 0
1862 || (category == CONTROL && isIdentifierIgnorable(ch));
1866 * Determines if a character is ignorable in a Unicode identifier. This
1867 * includes the non-whitespace ISO control characters (<code>'\u0000'</code>
1868 * through <code>'\u0008'</code>, <code>'\u000E'</code> through
1869 * <code>'\u001B'</code>, and <code>'\u007F'</code> through
1870 * <code>'\u009F'</code>), and FORMAT characters.
1871 * <br>
1872 * Unicode identifier ignorable = [Cf]|U+0000-U+0008|U+000E-U+001B
1873 * |U+007F-U+009F
1875 * @param ch character to test
1876 * @return true if ch is ignorable in a Unicode or Java identifier
1877 * @see #isJavaIdentifierPart(char)
1878 * @see #isUnicodeIdentifierPart(char)
1879 * @since 1.1
1881 public static boolean isIdentifierIgnorable(char ch)
1883 return (ch <= '\u009F' && (ch < '\t' || ch >= '\u007F'
1884 || (ch <= '\u001B' && ch >= '\u000E')))
1885 || getType(ch) == FORMAT;
1889 * Converts a Unicode character into its lowercase equivalent mapping.
1890 * If a mapping does not exist, then the character passed is returned.
1891 * Note that isLowerCase(toLowerCase(ch)) does not always return true.
1893 * @param ch character to convert to lowercase
1894 * @return lowercase mapping of ch, or ch if lowercase mapping does
1895 * not exist
1896 * @see #isLowerCase(char)
1897 * @see #isUpperCase(char)
1898 * @see #toTitleCase(char)
1899 * @see #toUpperCase(char)
1901 public static native char toLowerCase(char ch);
1904 * Converts a Unicode character into its uppercase equivalent mapping.
1905 * If a mapping does not exist, then the character passed is returned.
1906 * Note that isUpperCase(toUpperCase(ch)) does not always return true.
1908 * @param ch character to convert to uppercase
1909 * @return uppercase mapping of ch, or ch if uppercase mapping does
1910 * not exist
1911 * @see #isLowerCase(char)
1912 * @see #isUpperCase(char)
1913 * @see #toLowerCase(char)
1914 * @see #toTitleCase(char)
1916 public static native char toUpperCase(char ch);
1919 * Converts a Unicode character into its titlecase equivalent mapping.
1920 * If a mapping does not exist, then the character passed is returned.
1921 * Note that isTitleCase(toTitleCase(ch)) does not always return true.
1923 * @param ch character to convert to titlecase
1924 * @return titlecase mapping of ch, or ch if titlecase mapping does
1925 * not exist
1926 * @see #isTitleCase(char)
1927 * @see #toLowerCase(char)
1928 * @see #toUpperCase(char)
1930 public static native char toTitleCase(char ch);
1933 * Converts a character into a digit of the specified radix. If the radix
1934 * exceeds MIN_RADIX or MAX_RADIX, or if the result of getNumericValue(ch)
1935 * exceeds the radix, or if ch is not a decimal digit or in the case
1936 * insensitive set of 'a'-'z', the result is -1.
1937 * <br>
1938 * character argument boundary = [Nd]|U+0041-U+005A|U+0061-U+007A
1939 * |U+FF21-U+FF3A|U+FF41-U+FF5A
1941 * @param ch character to convert into a digit
1942 * @param radix radix in which ch is a digit
1943 * @return digit which ch represents in radix, or -1 not a valid digit
1944 * @see #MIN_RADIX
1945 * @see #MAX_RADIX
1946 * @see #forDigit(int, int)
1947 * @see #isDigit(char)
1948 * @see #getNumericValue(char)
1950 public static native int digit(char ch, int radix);
1953 * Returns the Unicode numeric value property of a character. For example,
1954 * <code>'\\u216C'</code> (the Roman numeral fifty) returns 50.
1956 * <p>This method also returns values for the letters A through Z, (not
1957 * specified by Unicode), in these ranges: <code>'\u0041'</code>
1958 * through <code>'\u005A'</code> (uppercase); <code>'\u0061'</code>
1959 * through <code>'\u007A'</code> (lowercase); and <code>'\uFF21'</code>
1960 * through <code>'\uFF3A'</code>, <code>'\uFF41'</code> through
1961 * <code>'\uFF5A'</code> (full width variants).
1963 * <p>If the character lacks a numeric value property, -1 is returned.
1964 * If the character has a numeric value property which is not representable
1965 * as a nonnegative integer, such as a fraction, -2 is returned.
1967 * character argument boundary = [Nd]|[Nl]|[No]|U+0041-U+005A|U+0061-U+007A
1968 * |U+FF21-U+FF3A|U+FF41-U+FF5A
1970 * @param ch character from which the numeric value property will
1971 * be retrieved
1972 * @return the numeric value property of ch, or -1 if it does not exist, or
1973 * -2 if it is not representable as a nonnegative integer
1974 * @see #forDigit(int, int)
1975 * @see #digit(char, int)
1976 * @see #isDigit(char)
1977 * @since 1.1
1979 public static native int getNumericValue(char ch);
1982 * Determines if a character is a ISO-LATIN-1 space. This is only the five
1983 * characters <code>'\t'</code>, <code>'\n'</code>, <code>'\f'</code>,
1984 * <code>'\r'</code>, and <code>' '</code>.
1985 * <br>
1986 * Java space = U+0020|U+0009|U+000A|U+000C|U+000D
1988 * @param ch character to test
1989 * @return true if ch is a space, else false
1990 * @deprecated Replaced by {@link #isWhitespace(char)}
1991 * @see #isSpaceChar(char)
1992 * @see #isWhitespace(char)
1994 public static boolean isSpace(char ch)
1996 // Performing the subtraction up front alleviates need to compare longs.
1997 return ch-- <= ' ' && ((1 << ch)
1998 & ((1 << (' ' - 1))
1999 | (1 << ('\t' - 1))
2000 | (1 << ('\n' - 1))
2001 | (1 << ('\r' - 1))
2002 | (1 << ('\f' - 1)))) != 0;
2006 * Determines if a character is a Unicode space character. This includes
2007 * SPACE_SEPARATOR, LINE_SEPARATOR, and PARAGRAPH_SEPARATOR.
2008 * <br>
2009 * Unicode space = [Zs]|[Zp]|[Zl]
2011 * @param ch character to test
2012 * @return true if ch is a Unicode space, else false
2013 * @see #isWhitespace(char)
2014 * @since 1.1
2016 public static boolean isSpaceChar(char ch)
2018 return ((1 << getType(ch))
2019 & ((1 << SPACE_SEPARATOR)
2020 | (1 << LINE_SEPARATOR)
2021 | (1 << PARAGRAPH_SEPARATOR))) != 0;
2025 * Determines if a character is Java whitespace. This includes Unicode
2026 * space characters (SPACE_SEPARATOR, LINE_SEPARATOR, and
2027 * PARAGRAPH_SEPARATOR) except the non-breaking spaces
2028 * (<code>'\u00A0'</code>, <code>'\u2007'</code>, and <code>'\u202F'</code>);
2029 * and these characters: <code>'\u0009'</code>, <code>'\u000A'</code>,
2030 * <code>'\u000B'</code>, <code>'\u000C'</code>, <code>'\u000D'</code>,
2031 * <code>'\u001C'</code>, <code>'\u001D'</code>, <code>'\u001E'</code>,
2032 * and <code>'\u001F'</code>.
2033 * <br>
2034 * Java whitespace = ([Zs] not Nb)|[Zl]|[Zp]|U+0009-U+000D|U+001C-U+001F
2036 * @param ch character to test
2037 * @return true if ch is Java whitespace, else false
2038 * @see #isSpaceChar(char)
2039 * @since 1.1
2041 public static boolean isWhitespace(char ch)
2043 int attr = readChar(ch);
2044 return ((((1 << (attr & TYPE_MASK))
2045 & ((1 << SPACE_SEPARATOR)
2046 | (1 << LINE_SEPARATOR)
2047 | (1 << PARAGRAPH_SEPARATOR))) != 0)
2048 && (attr & NO_BREAK_MASK) == 0)
2049 || (ch <= '\u001F' && ((1 << ch)
2050 & ((1 << '\t')
2051 | (1 << '\n')
2052 | (1 << '\u000B')
2053 | (1 << '\u000C')
2054 | (1 << '\r')
2055 | (1 << '\u001C')
2056 | (1 << '\u001D')
2057 | (1 << '\u001E')
2058 | (1 << '\u001F'))) != 0);
2062 * Determines if a character has the ISO Control property.
2063 * <br>
2064 * ISO Control = [Cc]
2066 * @param ch character to test
2067 * @return true if ch is an ISO Control character, else false
2068 * @see #isSpaceChar(char)
2069 * @see #isWhitespace(char)
2070 * @since 1.1
2072 public static boolean isISOControl(char ch)
2074 return getType(ch) == CONTROL;
2078 * Returns the Unicode general category property of a character.
2080 * @param ch character from which the general category property will
2081 * be retrieved
2082 * @return the character category property of ch as an integer
2083 * @see #UNASSIGNED
2084 * @see #UPPERCASE_LETTER
2085 * @see #LOWERCASE_LETTER
2086 * @see #TITLECASE_LETTER
2087 * @see #MODIFIER_LETTER
2088 * @see #OTHER_LETTER
2089 * @see #NON_SPACING_MARK
2090 * @see #ENCLOSING_MARK
2091 * @see #COMBINING_SPACING_MARK
2092 * @see #DECIMAL_DIGIT_NUMBER
2093 * @see #LETTER_NUMBER
2094 * @see #OTHER_NUMBER
2095 * @see #SPACE_SEPARATOR
2096 * @see #LINE_SEPARATOR
2097 * @see #PARAGRAPH_SEPARATOR
2098 * @see #CONTROL
2099 * @see #FORMAT
2100 * @see #PRIVATE_USE
2101 * @see #SURROGATE
2102 * @see #DASH_PUNCTUATION
2103 * @see #START_PUNCTUATION
2104 * @see #END_PUNCTUATION
2105 * @see #CONNECTOR_PUNCTUATION
2106 * @see #OTHER_PUNCTUATION
2107 * @see #MATH_SYMBOL
2108 * @see #CURRENCY_SYMBOL
2109 * @see #MODIFIER_SYMBOL
2110 * @see #INITIAL_QUOTE_PUNCTUATION
2111 * @see #FINAL_QUOTE_PUNCTUATION
2112 * @since 1.1
2114 public static native int getType(char ch);
2117 * Converts a digit into a character which represents that digit
2118 * in a specified radix. If the radix exceeds MIN_RADIX or MAX_RADIX,
2119 * or the digit exceeds the radix, then the null character <code>'\0'</code>
2120 * is returned. Otherwise the return value is in '0'-'9' and 'a'-'z'.
2121 * <br>
2122 * return value boundary = U+0030-U+0039|U+0061-U+007A
2124 * @param digit digit to be converted into a character
2125 * @param radix radix of digit
2126 * @return character representing digit in radix, or '\0'
2127 * @see #MIN_RADIX
2128 * @see #MAX_RADIX
2129 * @see #digit(char, int)
2131 public static char forDigit(int digit, int radix)
2133 if (radix < MIN_RADIX || radix > MAX_RADIX
2134 || digit < 0 || digit >= radix)
2135 return '\0';
2136 return (char) (digit < 10 ? ('0' + digit) : ('a' - 10 + digit));
2140 * Returns the Unicode directionality property of the character. This
2141 * is used in the visual ordering of text.
2143 * @param ch the character to look up
2144 * @return the directionality constant, or DIRECTIONALITY_UNDEFINED
2145 * @see #DIRECTIONALITY_UNDEFINED
2146 * @see #DIRECTIONALITY_LEFT_TO_RIGHT
2147 * @see #DIRECTIONALITY_RIGHT_TO_LEFT
2148 * @see #DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC
2149 * @see #DIRECTIONALITY_EUROPEAN_NUMBER
2150 * @see #DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR
2151 * @see #DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR
2152 * @see #DIRECTIONALITY_ARABIC_NUMBER
2153 * @see #DIRECTIONALITY_COMMON_NUMBER_SEPARATOR
2154 * @see #DIRECTIONALITY_NONSPACING_MARK
2155 * @see #DIRECTIONALITY_BOUNDARY_NEUTRAL
2156 * @see #DIRECTIONALITY_PARAGRAPH_SEPARATOR
2157 * @see #DIRECTIONALITY_SEGMENT_SEPARATOR
2158 * @see #DIRECTIONALITY_WHITESPACE
2159 * @see #DIRECTIONALITY_OTHER_NEUTRALS
2160 * @see #DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING
2161 * @see #DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE
2162 * @see #DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING
2163 * @see #DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE
2164 * @see #DIRECTIONALITY_POP_DIRECTIONAL_FORMAT
2165 * @since 1.4
2167 public static native byte getDirectionality(char ch);
2170 * Determines whether the character is mirrored according to Unicode. For
2171 * example, <code>\u0028</code> (LEFT PARENTHESIS) appears as '(' in
2172 * left-to-right text, but ')' in right-to-left text.
2174 * @param ch the character to look up
2175 * @return true if the character is mirrored
2176 * @since 1.4
2178 public static boolean isMirrored(char ch)
2180 return (readChar(ch) & MIRROR_MASK) != 0;
2184 * Compares another Character to this Character, numerically.
2186 * @param anotherCharacter Character to compare with this Character
2187 * @return a negative integer if this Character is less than
2188 * anotherCharacter, zero if this Character is equal, and
2189 * a positive integer if this Character is greater
2190 * @throws NullPointerException if anotherCharacter is null
2191 * @since 1.2
2193 public int compareTo(Character anotherCharacter)
2195 return value - anotherCharacter.value;
2199 * Compares an object to this Character. Assuming the object is a
2200 * Character object, this method performs the same comparison as
2201 * compareTo(Character).
2203 * @param o object to compare
2204 * @return the comparison value
2205 * @throws ClassCastException if o is not a Character object
2206 * @throws NullPointerException if o is null
2207 * @see #compareTo(Character)
2208 * @since 1.2
2210 public int compareTo(Object o)
2212 return compareTo((Character) o);
2216 * Converts a unicode code point to a UTF-16 representation of that
2217 * code point.
2219 * @param codePoint the unicode code point
2221 * @return the UTF-16 representation of that code point
2223 * @throws IllegalArgumentException if the code point is not a valid
2224 * unicode code point
2226 * @since 1.5
2228 public static char[] toChars(int codePoint)
2230 char[] result = new char[charCount(codePoint)];
2231 int ignore = toChars(codePoint, result, 0);
2232 return result;
2236 * Converts a unicode code point to its UTF-16 representation.
2238 * @param codePoint the unicode code point
2239 * @param dst the target char array
2240 * @param dstIndex the start index for the target
2242 * @return number of characters written to <code>dst</code>
2244 * @throws IllegalArgumentException if <code>codePoint</code> is not a
2245 * valid unicode code point
2246 * @throws NullPointerException if <code>dst</code> is <code>null</code>
2247 * @throws IndexOutOfBoundsException if <code>dstIndex</code> is not valid
2248 * in <code>dst</code> or if the UTF-16 representation does not
2249 * fit into <code>dst</code>
2251 * @since 1.5
2253 public static int toChars(int codePoint, char[] dst, int dstIndex)
2255 if (!isValidCodePoint(codePoint))
2257 throw new IllegalArgumentException("not a valid code point: "
2258 + codePoint);
2261 int result;
2262 if (isSupplementaryCodePoint(codePoint))
2264 // Write second char first to cause IndexOutOfBoundsException
2265 // immediately.
2266 dst[dstIndex + 1] = (char) ((codePoint & 0x3ff)
2267 + (int) MIN_LOW_SURROGATE );
2268 dst[dstIndex] = (char) ((codePoint >> 10) + (int) MIN_HIGH_SURROGATE);
2269 result = 2;
2271 else
2273 dst[dstIndex] = (char) codePoint;
2274 result = 1;
2276 return result;
2280 * Return number of 16-bit characters required to represent the given
2281 * code point.
2283 * @param codePoint a uncode code point
2285 * @return 2 if codePoint >= 0x10000, 1 otherwise.
2287 * @since 1.5
2289 public static int charCount(int codePoint)
2291 return
2292 (codePoint >= MIN_SUPPLEMENTARY_CODE_POINT)
2293 ? 2
2294 : 1;
2298 * Determines whether the specified code point is
2299 * in the range 0x10000 .. 0x10FFFF, i.e. the character is within the Unicode
2300 * supplementary character range.
2302 * @param codePoint a Unicode code point
2304 * @return <code>true</code> if code point is in supplementary range
2306 * @since 1.5
2308 public static boolean isSupplementaryCodePoint(int codePoint)
2310 return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
2311 && codePoint <= MAX_CODE_POINT;
2315 * Determines whether the specified code point is
2316 * in the range 0x0000 .. 0x10FFFF, i.e. it is a valid Unicode code point.
2318 * @param codePoint a Unicode code point
2320 * @return <code>true</code> if code point is valid
2322 * @since 1.5
2324 public static boolean isValidCodePoint(int codePoint)
2326 return codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT;
2328 } // class Character