Character.java 59.1 KB
Newer Older
1 2
/* java.lang.Character -- Wrapper class for char, and Unicode subsets
   Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
Tom Tromey committed
3

4
This file is part of GNU Classpath.
Tom Tromey committed
5

6 7 8 9
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Tom Tromey committed
10

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

/*
 * Note: This class must not be merged with Classpath.  Gcj uses C-style
 * arrays (see include/java-chartables.h) to store the Unicode character
 * database, whereas Classpath uses Java objects (char[] extracted from
 * String constants) in gnu.java.lang.CharData.  Gcj's approach is more
 * efficient, because there is no vtable or data relocation to worry about.
 * However, despite the difference in the database interface, the two
 * versions share identical algorithms.
 */
Tom Tromey committed
47 48 49 50 51 52

package java.lang;

import java.io.Serializable;

/**
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
 * Wrapper class for the primitive char data type.  In addition, this class
 * allows one to retrieve property information and perform transformations
 * on the 57,707 defined characters in the Unicode Standard, Version 3.0.0.
 * java.lang.Character is designed to be very dynamic, and as such, it
 * retrieves information on the Unicode character set from a separate
 * database, gnu.java.lang.CharData, which can be easily upgraded.
 *
 * <p>For predicates, boundaries are used to describe
 * the set of characters for which the method will return true.
 * This syntax uses fairly normal regular expression notation.
 * See 5.13 of the Unicode Standard, Version 3.0, for the
 * boundary specification.
 *
 * <p>See <a href="http://www.unicode.org">http://www.unicode.org</a>
 * for more information on the Unicode Standard.
 *
69
 * @author Tom Tromey (tromey@cygnus.com)
70 71
 * @author Paul N. Fisher
 * @author Jochen Hoenicke
72
 * @author Eric Blake (ebb9@email.byu.edu)
73 74
 * @since 1.0
 * @status updated to 1.4
Tom Tromey committed
75 76 77
 */
public final class Character implements Serializable, Comparable
{
78 79 80 81
  /**
   * A subset of Unicode blocks.
   *
   * @author Paul N. Fisher
82
   * @author Eric Blake (ebb9@email.byu.edu)
83 84 85 86 87 88
   * @since 1.2
   */
  public static class Subset
  {
    /** The name of the subset. */
    private final String name;
Tom Tromey committed
89

90 91 92 93 94 95 96 97 98 99 100
    /**
     * Construct a new subset of characters.
     *
     * @param name the name of the subset
     * @throws NullPointerException if name is null
     */
    protected Subset(String name)
    {
      // Note that name.toString() is name, unless name was null.
      this.name = name.toString();
    }
Tom Tromey committed
101

102 103 104 105 106 107 108 109 110 111 112 113
    /**
     * Compares two Subsets for equality. This is <code>final</code>, and
     * restricts the comparison on the <code>==</code> operator, so it returns
     * true only for the same object.
     *
     * @param o the object to compare
     * @return true if o is this
     */
    public final boolean equals(Object o)
    {
      return o == this;
    }
Tom Tromey committed
114

115 116 117 118 119 120 121 122 123 124
    /**
     * Makes the original hashCode of Object final, to be consistent with
     * equals.
     *
     * @return the hash code for this object
     */
    public final int hashCode()
    {
      return super.hashCode();
    }
Tom Tromey committed
125

126 127 128 129 130 131 132 133 134 135
    /**
     * Returns the name of the subset.
     *
     * @return the name
     */
    public final String toString()
    {
      return name;
    }
  } // class Subset
Tom Tromey committed
136

137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  /**
   * A family of character subsets in the Unicode specification. A character
   * is in at most one of these blocks.
   *
   * This inner class was generated automatically from
   * <code>libjava/gnu/gcj/convert/Blocks-3.txt</code>, by some perl scripts.
   * This Unicode definition file can be found on the
   * <a href="http://www.unicode.org">http://www.unicode.org</a> website.
   * JDK 1.4 uses Unicode version 3.0.0.
   *
   * @author scripts/unicode-blocks.pl (written by Eric Blake)
   * @since 1.2
   */
  public static final class UnicodeBlock extends Subset
  {
    /** The start of the subset. */
    private final char start;
Tom Tromey committed
154

155 156
    /** The end of the subset. */
    private final char end;
Tom Tromey committed
157

158 159 160 161 162 163 164 165 166 167 168 169 170
    /**
     * Constructor for strictly defined blocks.
     *
     * @param start the start character of the range
     * @param end the end character of the range
     * @param name the block name
     */
    private UnicodeBlock(char start, char end, String name)
    {
      super(name);
      this.start = start;
      this.end = end;
    }
Tom Tromey committed
171

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
    /**
     * Returns the Unicode character block which a character belongs to.
     *
     * @param ch the character to look up
     * @return the set it belongs to, or null if it is not in one
     */
    public static UnicodeBlock of(char ch)
    {
      // Special case, since SPECIALS contains two ranges.
      if (ch == '\uFEFF')
        return SPECIALS;
      // Simple binary search for the correct block.
      int low = 0;
      int hi = sets.length - 1;
      while (low <= hi)
        {
          int mid = (low + hi) >> 1;
          UnicodeBlock b = sets[mid];
          if (ch < b.start)
            hi = mid - 1;
          else if (ch > b.end)
            low = mid + 1;
          else
            return b;
        }
      return null;
    }
Tom Tromey committed
199

200 201 202 203
    /**
     * Basic Latin.
     * '\u0000' - '\u007F'.
     */
204
    public static final UnicodeBlock BASIC_LATIN
205 206
      = new UnicodeBlock('\u0000', '\u007F',
                         "BASIC_LATIN");
Tom Tromey committed
207

208 209 210 211
    /**
     * Latin-1 Supplement.
     * '\u0080' - '\u00FF'.
     */
212
    public static final UnicodeBlock LATIN_1_SUPPLEMENT
213 214
      = new UnicodeBlock('\u0080', '\u00FF',
                         "LATIN_1_SUPPLEMENT");
Tom Tromey committed
215

216 217 218 219
    /**
     * Latin Extended-A.
     * '\u0100' - '\u017F'.
     */
220
    public static final UnicodeBlock LATIN_EXTENDED_A
221 222
      = new UnicodeBlock('\u0100', '\u017F',
                         "LATIN_EXTENDED_A");
Tom Tromey committed
223

224 225 226 227
    /**
     * Latin Extended-B.
     * '\u0180' - '\u024F'.
     */
228
    public static final UnicodeBlock LATIN_EXTENDED_B
229 230
      = new UnicodeBlock('\u0180', '\u024F',
                         "LATIN_EXTENDED_B");
Tom Tromey committed
231

232 233 234 235
    /**
     * IPA Extensions.
     * '\u0250' - '\u02AF'.
     */
236
    public static final UnicodeBlock IPA_EXTENSIONS
237 238
      = new UnicodeBlock('\u0250', '\u02AF',
                         "IPA_EXTENSIONS");
Tom Tromey committed
239

240 241 242 243
    /**
     * Spacing Modifier Letters.
     * '\u02B0' - '\u02FF'.
     */
244
    public static final UnicodeBlock SPACING_MODIFIER_LETTERS
245 246
      = new UnicodeBlock('\u02B0', '\u02FF',
                         "SPACING_MODIFIER_LETTERS");
Tom Tromey committed
247

248 249 250 251
    /**
     * Combining Diacritical Marks.
     * '\u0300' - '\u036F'.
     */
252
    public static final UnicodeBlock COMBINING_DIACRITICAL_MARKS
253 254
      = new UnicodeBlock('\u0300', '\u036F',
                         "COMBINING_DIACRITICAL_MARKS");
Tom Tromey committed
255

256 257 258 259
    /**
     * Greek.
     * '\u0370' - '\u03FF'.
     */
260
    public static final UnicodeBlock GREEK
261 262
      = new UnicodeBlock('\u0370', '\u03FF',
                         "GREEK");
Tom Tromey committed
263

264 265 266 267
    /**
     * Cyrillic.
     * '\u0400' - '\u04FF'.
     */
268
    public static final UnicodeBlock CYRILLIC
269 270
      = new UnicodeBlock('\u0400', '\u04FF',
                         "CYRILLIC");
Tom Tromey committed
271

272 273 274 275
    /**
     * Armenian.
     * '\u0530' - '\u058F'.
     */
276
    public static final UnicodeBlock ARMENIAN
277 278
      = new UnicodeBlock('\u0530', '\u058F',
                         "ARMENIAN");
Tom Tromey committed
279

280 281 282 283
    /**
     * Hebrew.
     * '\u0590' - '\u05FF'.
     */
284
    public static final UnicodeBlock HEBREW
285 286
      = new UnicodeBlock('\u0590', '\u05FF',
                         "HEBREW");
Tom Tromey committed
287

288 289 290 291
    /**
     * Arabic.
     * '\u0600' - '\u06FF'.
     */
292
    public static final UnicodeBlock ARABIC
293 294
      = new UnicodeBlock('\u0600', '\u06FF',
                         "ARABIC");
Tom Tromey committed
295

296 297 298 299 300
    /**
     * Syriac.
     * '\u0700' - '\u074F'.
     * @since 1.4
     */
301
    public static final UnicodeBlock SYRIAC
302 303
      = new UnicodeBlock('\u0700', '\u074F',
                         "SYRIAC");
Tom Tromey committed
304

305 306 307 308 309
    /**
     * Thaana.
     * '\u0780' - '\u07BF'.
     * @since 1.4
     */
310
    public static final UnicodeBlock THAANA
311 312
      = new UnicodeBlock('\u0780', '\u07BF',
                         "THAANA");
Tom Tromey committed
313

314 315 316 317
    /**
     * Devanagari.
     * '\u0900' - '\u097F'.
     */
318
    public static final UnicodeBlock DEVANAGARI
319 320
      = new UnicodeBlock('\u0900', '\u097F',
                         "DEVANAGARI");
Tom Tromey committed
321

322 323 324 325
    /**
     * Bengali.
     * '\u0980' - '\u09FF'.
     */
326
    public static final UnicodeBlock BENGALI
327 328
      = new UnicodeBlock('\u0980', '\u09FF',
                         "BENGALI");
Tom Tromey committed
329

330 331 332 333
    /**
     * Gurmukhi.
     * '\u0A00' - '\u0A7F'.
     */
334
    public static final UnicodeBlock GURMUKHI
335 336
      = new UnicodeBlock('\u0A00', '\u0A7F',
                         "GURMUKHI");
Tom Tromey committed
337

338 339 340 341
    /**
     * Gujarati.
     * '\u0A80' - '\u0AFF'.
     */
342
    public static final UnicodeBlock GUJARATI
343 344
      = new UnicodeBlock('\u0A80', '\u0AFF',
                         "GUJARATI");
Tom Tromey committed
345

346 347 348 349
    /**
     * Oriya.
     * '\u0B00' - '\u0B7F'.
     */
350
    public static final UnicodeBlock ORIYA
351 352
      = new UnicodeBlock('\u0B00', '\u0B7F',
                         "ORIYA");
Tom Tromey committed
353

354 355 356 357
    /**
     * Tamil.
     * '\u0B80' - '\u0BFF'.
     */
358
    public static final UnicodeBlock TAMIL
359 360
      = new UnicodeBlock('\u0B80', '\u0BFF',
                         "TAMIL");
Tom Tromey committed
361

362 363 364 365
    /**
     * Telugu.
     * '\u0C00' - '\u0C7F'.
     */
366
    public static final UnicodeBlock TELUGU
367 368
      = new UnicodeBlock('\u0C00', '\u0C7F',
                         "TELUGU");
Tom Tromey committed
369

370 371 372 373
    /**
     * Kannada.
     * '\u0C80' - '\u0CFF'.
     */
374
    public static final UnicodeBlock KANNADA
375 376
      = new UnicodeBlock('\u0C80', '\u0CFF',
                         "KANNADA");
Tom Tromey committed
377

378 379 380 381
    /**
     * Malayalam.
     * '\u0D00' - '\u0D7F'.
     */
382
    public static final UnicodeBlock MALAYALAM
383 384
      = new UnicodeBlock('\u0D00', '\u0D7F',
                         "MALAYALAM");
Tom Tromey committed
385

386 387 388 389 390
    /**
     * Sinhala.
     * '\u0D80' - '\u0DFF'.
     * @since 1.4
     */
391
    public static final UnicodeBlock SINHALA
392 393
      = new UnicodeBlock('\u0D80', '\u0DFF',
                         "SINHALA");
Tom Tromey committed
394

395 396 397 398
    /**
     * Thai.
     * '\u0E00' - '\u0E7F'.
     */
399
    public static final UnicodeBlock THAI
400 401
      = new UnicodeBlock('\u0E00', '\u0E7F',
                         "THAI");
Tom Tromey committed
402

403 404 405 406
    /**
     * Lao.
     * '\u0E80' - '\u0EFF'.
     */
407
    public static final UnicodeBlock LAO
408 409
      = new UnicodeBlock('\u0E80', '\u0EFF',
                         "LAO");
Tom Tromey committed
410

411 412 413 414
    /**
     * Tibetan.
     * '\u0F00' - '\u0FFF'.
     */
415
    public static final UnicodeBlock TIBETAN
416 417
      = new UnicodeBlock('\u0F00', '\u0FFF',
                         "TIBETAN");
Tom Tromey committed
418

419 420 421 422 423
    /**
     * Myanmar.
     * '\u1000' - '\u109F'.
     * @since 1.4
     */
424
    public static final UnicodeBlock MYANMAR
425 426
      = new UnicodeBlock('\u1000', '\u109F',
                         "MYANMAR");
Tom Tromey committed
427

428 429 430 431
    /**
     * Georgian.
     * '\u10A0' - '\u10FF'.
     */
432
    public static final UnicodeBlock GEORGIAN
433 434
      = new UnicodeBlock('\u10A0', '\u10FF',
                         "GEORGIAN");
Tom Tromey committed
435

436 437 438 439
    /**
     * Hangul Jamo.
     * '\u1100' - '\u11FF'.
     */
440
    public static final UnicodeBlock HANGUL_JAMO
441 442
      = new UnicodeBlock('\u1100', '\u11FF',
                         "HANGUL_JAMO");
Tom Tromey committed
443

444 445 446 447 448
    /**
     * Ethiopic.
     * '\u1200' - '\u137F'.
     * @since 1.4
     */
449
    public static final UnicodeBlock ETHIOPIC
450 451
      = new UnicodeBlock('\u1200', '\u137F',
                         "ETHIOPIC");
Tom Tromey committed
452

453 454 455 456 457
    /**
     * Cherokee.
     * '\u13A0' - '\u13FF'.
     * @since 1.4
     */
458
    public static final UnicodeBlock CHEROKEE
459 460
      = new UnicodeBlock('\u13A0', '\u13FF',
                         "CHEROKEE");
Tom Tromey committed
461

462 463 464 465 466
    /**
     * Unified Canadian Aboriginal Syllabics.
     * '\u1400' - '\u167F'.
     * @since 1.4
     */
467
    public static final UnicodeBlock UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS
468 469
      = new UnicodeBlock('\u1400', '\u167F',
                         "UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS");
470

471 472 473 474 475
    /**
     * Ogham.
     * '\u1680' - '\u169F'.
     * @since 1.4
     */
476
    public static final UnicodeBlock OGHAM
477 478
      = new UnicodeBlock('\u1680', '\u169F',
                         "OGHAM");
479

480 481 482 483 484
    /**
     * Runic.
     * '\u16A0' - '\u16FF'.
     * @since 1.4
     */
485
    public static final UnicodeBlock RUNIC
486 487
      = new UnicodeBlock('\u16A0', '\u16FF',
                         "RUNIC");
488

489 490 491 492 493
    /**
     * Khmer.
     * '\u1780' - '\u17FF'.
     * @since 1.4
     */
494
    public static final UnicodeBlock KHMER
495 496
      = new UnicodeBlock('\u1780', '\u17FF',
                         "KHMER");
497

498 499 500 501 502
    /**
     * Mongolian.
     * '\u1800' - '\u18AF'.
     * @since 1.4
     */
503
    public static final UnicodeBlock MONGOLIAN
504 505
      = new UnicodeBlock('\u1800', '\u18AF',
                         "MONGOLIAN");
506

507 508 509 510
    /**
     * Latin Extended Additional.
     * '\u1E00' - '\u1EFF'.
     */
511
    public static final UnicodeBlock LATIN_EXTENDED_ADDITIONAL
512 513
      = new UnicodeBlock('\u1E00', '\u1EFF',
                         "LATIN_EXTENDED_ADDITIONAL");
514

515 516 517 518
    /**
     * Greek Extended.
     * '\u1F00' - '\u1FFF'.
     */
519
    public static final UnicodeBlock GREEK_EXTENDED
520 521
      = new UnicodeBlock('\u1F00', '\u1FFF',
                         "GREEK_EXTENDED");
522

523 524 525 526
    /**
     * General Punctuation.
     * '\u2000' - '\u206F'.
     */
527
    public static final UnicodeBlock GENERAL_PUNCTUATION
528 529
      = new UnicodeBlock('\u2000', '\u206F',
                         "GENERAL_PUNCTUATION");
530

531 532 533 534
    /**
     * Superscripts and Subscripts.
     * '\u2070' - '\u209F'.
     */
535
    public static final UnicodeBlock SUPERSCRIPTS_AND_SUBSCRIPTS
536 537 538 539 540 541 542
      = new UnicodeBlock('\u2070', '\u209F',
                         "SUPERSCRIPTS_AND_SUBSCRIPTS");

    /**
     * Currency Symbols.
     * '\u20A0' - '\u20CF'.
     */
543
    public static final UnicodeBlock CURRENCY_SYMBOLS
544 545 546 547 548 549 550
      = new UnicodeBlock('\u20A0', '\u20CF',
                         "CURRENCY_SYMBOLS");

    /**
     * Combining Marks for Symbols.
     * '\u20D0' - '\u20FF'.
     */
551
    public static final UnicodeBlock COMBINING_MARKS_FOR_SYMBOLS
552 553 554 555 556 557 558
      = new UnicodeBlock('\u20D0', '\u20FF',
                         "COMBINING_MARKS_FOR_SYMBOLS");

    /**
     * Letterlike Symbols.
     * '\u2100' - '\u214F'.
     */
559
    public static final UnicodeBlock LETTERLIKE_SYMBOLS
560 561 562 563 564 565 566
      = new UnicodeBlock('\u2100', '\u214F',
                         "LETTERLIKE_SYMBOLS");

    /**
     * Number Forms.
     * '\u2150' - '\u218F'.
     */
567
    public static final UnicodeBlock NUMBER_FORMS
568 569 570 571 572 573 574
      = new UnicodeBlock('\u2150', '\u218F',
                         "NUMBER_FORMS");

    /**
     * Arrows.
     * '\u2190' - '\u21FF'.
     */
575
    public static final UnicodeBlock ARROWS
576 577 578 579 580 581 582
      = new UnicodeBlock('\u2190', '\u21FF',
                         "ARROWS");

    /**
     * Mathematical Operators.
     * '\u2200' - '\u22FF'.
     */
583
    public static final UnicodeBlock MATHEMATICAL_OPERATORS
584 585 586 587 588 589 590
      = new UnicodeBlock('\u2200', '\u22FF',
                         "MATHEMATICAL_OPERATORS");

    /**
     * Miscellaneous Technical.
     * '\u2300' - '\u23FF'.
     */
591
    public static final UnicodeBlock MISCELLANEOUS_TECHNICAL
592 593 594 595 596 597 598
      = new UnicodeBlock('\u2300', '\u23FF',
                         "MISCELLANEOUS_TECHNICAL");

    /**
     * Control Pictures.
     * '\u2400' - '\u243F'.
     */
599
    public static final UnicodeBlock CONTROL_PICTURES
600 601 602 603 604 605 606
      = new UnicodeBlock('\u2400', '\u243F',
                         "CONTROL_PICTURES");

    /**
     * Optical Character Recognition.
     * '\u2440' - '\u245F'.
     */
607
    public static final UnicodeBlock OPTICAL_CHARACTER_RECOGNITION
608 609
      = new UnicodeBlock('\u2440', '\u245F',
                         "OPTICAL_CHARACTER_RECOGNITION");
610

611 612 613 614
    /**
     * Enclosed Alphanumerics.
     * '\u2460' - '\u24FF'.
     */
615
    public static final UnicodeBlock ENCLOSED_ALPHANUMERICS
616 617 618 619 620 621 622
      = new UnicodeBlock('\u2460', '\u24FF',
                         "ENCLOSED_ALPHANUMERICS");

    /**
     * Box Drawing.
     * '\u2500' - '\u257F'.
     */
623
    public static final UnicodeBlock BOX_DRAWING
624 625 626 627 628 629 630
      = new UnicodeBlock('\u2500', '\u257F',
                         "BOX_DRAWING");

    /**
     * Block Elements.
     * '\u2580' - '\u259F'.
     */
631
    public static final UnicodeBlock BLOCK_ELEMENTS
632 633 634 635 636 637 638
      = new UnicodeBlock('\u2580', '\u259F',
                         "BLOCK_ELEMENTS");

    /**
     * Geometric Shapes.
     * '\u25A0' - '\u25FF'.
     */
639
    public static final UnicodeBlock GEOMETRIC_SHAPES
640 641 642 643 644 645 646
      = new UnicodeBlock('\u25A0', '\u25FF',
                         "GEOMETRIC_SHAPES");

    /**
     * Miscellaneous Symbols.
     * '\u2600' - '\u26FF'.
     */
647
    public static final UnicodeBlock MISCELLANEOUS_SYMBOLS
648 649 650 651 652 653 654
      = new UnicodeBlock('\u2600', '\u26FF',
                         "MISCELLANEOUS_SYMBOLS");

    /**
     * Dingbats.
     * '\u2700' - '\u27BF'.
     */
655
    public static final UnicodeBlock DINGBATS
656 657 658 659 660 661 662 663
      = new UnicodeBlock('\u2700', '\u27BF',
                         "DINGBATS");

    /**
     * Braille Patterns.
     * '\u2800' - '\u28FF'.
     * @since 1.4
     */
664
    public static final UnicodeBlock BRAILLE_PATTERNS
665 666 667 668 669 670 671 672
      = new UnicodeBlock('\u2800', '\u28FF',
                         "BRAILLE_PATTERNS");

    /**
     * CJK Radicals Supplement.
     * '\u2E80' - '\u2EFF'.
     * @since 1.4
     */
673
    public static final UnicodeBlock CJK_RADICALS_SUPPLEMENT
674 675 676 677 678 679 680 681
      = new UnicodeBlock('\u2E80', '\u2EFF',
                         "CJK_RADICALS_SUPPLEMENT");

    /**
     * Kangxi Radicals.
     * '\u2F00' - '\u2FDF'.
     * @since 1.4
     */
682
    public static final UnicodeBlock KANGXI_RADICALS
683 684 685 686 687 688 689 690
      = new UnicodeBlock('\u2F00', '\u2FDF',
                         "KANGXI_RADICALS");

    /**
     * Ideographic Description Characters.
     * '\u2FF0' - '\u2FFF'.
     * @since 1.4
     */
691
    public static final UnicodeBlock IDEOGRAPHIC_DESCRIPTION_CHARACTERS
692 693 694 695 696 697 698
      = new UnicodeBlock('\u2FF0', '\u2FFF',
                         "IDEOGRAPHIC_DESCRIPTION_CHARACTERS");

    /**
     * CJK Symbols and Punctuation.
     * '\u3000' - '\u303F'.
     */
699
    public static final UnicodeBlock CJK_SYMBOLS_AND_PUNCTUATION
700 701 702 703 704 705 706
      = new UnicodeBlock('\u3000', '\u303F',
                         "CJK_SYMBOLS_AND_PUNCTUATION");

    /**
     * Hiragana.
     * '\u3040' - '\u309F'.
     */
707
    public static final UnicodeBlock HIRAGANA
708 709 710 711 712 713 714
      = new UnicodeBlock('\u3040', '\u309F',
                         "HIRAGANA");

    /**
     * Katakana.
     * '\u30A0' - '\u30FF'.
     */
715
    public static final UnicodeBlock KATAKANA
716 717 718 719 720 721 722
      = new UnicodeBlock('\u30A0', '\u30FF',
                         "KATAKANA");

    /**
     * Bopomofo.
     * '\u3100' - '\u312F'.
     */
723
    public static final UnicodeBlock BOPOMOFO
724 725 726 727 728 729 730
      = new UnicodeBlock('\u3100', '\u312F',
                         "BOPOMOFO");

    /**
     * Hangul Compatibility Jamo.
     * '\u3130' - '\u318F'.
     */
731
    public static final UnicodeBlock HANGUL_COMPATIBILITY_JAMO
732 733 734 735 736 737 738
      = new UnicodeBlock('\u3130', '\u318F',
                         "HANGUL_COMPATIBILITY_JAMO");

    /**
     * Kanbun.
     * '\u3190' - '\u319F'.
     */
739
    public static final UnicodeBlock KANBUN
740 741 742 743 744 745 746 747
      = new UnicodeBlock('\u3190', '\u319F',
                         "KANBUN");

    /**
     * Bopomofo Extended.
     * '\u31A0' - '\u31BF'.
     * @since 1.4
     */
748
    public static final UnicodeBlock BOPOMOFO_EXTENDED
749 750 751 752 753 754 755
      = new UnicodeBlock('\u31A0', '\u31BF',
                         "BOPOMOFO_EXTENDED");

    /**
     * Enclosed CJK Letters and Months.
     * '\u3200' - '\u32FF'.
     */
756
    public static final UnicodeBlock ENCLOSED_CJK_LETTERS_AND_MONTHS
757 758 759 760 761 762 763
      = new UnicodeBlock('\u3200', '\u32FF',
                         "ENCLOSED_CJK_LETTERS_AND_MONTHS");

    /**
     * CJK Compatibility.
     * '\u3300' - '\u33FF'.
     */
764
    public static final UnicodeBlock CJK_COMPATIBILITY
765 766 767 768 769 770 771 772
      = new UnicodeBlock('\u3300', '\u33FF',
                         "CJK_COMPATIBILITY");

    /**
     * CJK Unified Ideographs Extension A.
     * '\u3400' - '\u4DB5'.
     * @since 1.4
     */
773
    public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
774 775 776 777 778 779 780
      = new UnicodeBlock('\u3400', '\u4DB5',
                         "CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A");

    /**
     * CJK Unified Ideographs.
     * '\u4E00' - '\u9FFF'.
     */
781
    public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS
782 783 784 785 786 787 788 789
      = new UnicodeBlock('\u4E00', '\u9FFF',
                         "CJK_UNIFIED_IDEOGRAPHS");

    /**
     * Yi Syllables.
     * '\uA000' - '\uA48F'.
     * @since 1.4
     */
790
    public static final UnicodeBlock YI_SYLLABLES
791 792 793 794 795 796 797 798
      = new UnicodeBlock('\uA000', '\uA48F',
                         "YI_SYLLABLES");

    /**
     * Yi Radicals.
     * '\uA490' - '\uA4CF'.
     * @since 1.4
     */
799
    public static final UnicodeBlock YI_RADICALS
800 801 802 803 804 805 806
      = new UnicodeBlock('\uA490', '\uA4CF',
                         "YI_RADICALS");

    /**
     * Hangul Syllables.
     * '\uAC00' - '\uD7A3'.
     */
807
    public static final UnicodeBlock HANGUL_SYLLABLES
808 809 810 811 812 813 814
      = new UnicodeBlock('\uAC00', '\uD7A3',
                         "HANGUL_SYLLABLES");

    /**
     * Surrogates Area.
     * '\uD800' - '\uDFFF'.
     */
815
    public static final UnicodeBlock SURROGATES_AREA
816 817 818 819 820 821 822
      = new UnicodeBlock('\uD800', '\uDFFF',
                         "SURROGATES_AREA");

    /**
     * Private Use Area.
     * '\uE000' - '\uF8FF'.
     */
823
    public static final UnicodeBlock PRIVATE_USE_AREA
824 825 826 827 828 829 830
      = new UnicodeBlock('\uE000', '\uF8FF',
                         "PRIVATE_USE_AREA");

    /**
     * CJK Compatibility Ideographs.
     * '\uF900' - '\uFAFF'.
     */
831
    public static final UnicodeBlock CJK_COMPATIBILITY_IDEOGRAPHS
832 833 834 835 836 837 838
      = new UnicodeBlock('\uF900', '\uFAFF',
                         "CJK_COMPATIBILITY_IDEOGRAPHS");

    /**
     * Alphabetic Presentation Forms.
     * '\uFB00' - '\uFB4F'.
     */
839
    public static final UnicodeBlock ALPHABETIC_PRESENTATION_FORMS
840 841 842 843 844 845 846
      = new UnicodeBlock('\uFB00', '\uFB4F',
                         "ALPHABETIC_PRESENTATION_FORMS");

    /**
     * Arabic Presentation Forms-A.
     * '\uFB50' - '\uFDFF'.
     */
847
    public static final UnicodeBlock ARABIC_PRESENTATION_FORMS_A
848 849 850 851 852 853 854
      = new UnicodeBlock('\uFB50', '\uFDFF',
                         "ARABIC_PRESENTATION_FORMS_A");

    /**
     * Combining Half Marks.
     * '\uFE20' - '\uFE2F'.
     */
855
    public static final UnicodeBlock COMBINING_HALF_MARKS
856 857 858 859 860 861 862
      = new UnicodeBlock('\uFE20', '\uFE2F',
                         "COMBINING_HALF_MARKS");

    /**
     * CJK Compatibility Forms.
     * '\uFE30' - '\uFE4F'.
     */
863
    public static final UnicodeBlock CJK_COMPATIBILITY_FORMS
864 865 866 867 868 869 870
      = new UnicodeBlock('\uFE30', '\uFE4F',
                         "CJK_COMPATIBILITY_FORMS");

    /**
     * Small Form Variants.
     * '\uFE50' - '\uFE6F'.
     */
871
    public static final UnicodeBlock SMALL_FORM_VARIANTS
872 873 874 875 876 877 878
      = new UnicodeBlock('\uFE50', '\uFE6F',
                         "SMALL_FORM_VARIANTS");

    /**
     * Arabic Presentation Forms-B.
     * '\uFE70' - '\uFEFE'.
     */
879
    public static final UnicodeBlock ARABIC_PRESENTATION_FORMS_B
880 881 882 883 884 885 886
      = new UnicodeBlock('\uFE70', '\uFEFE',
                         "ARABIC_PRESENTATION_FORMS_B");

    /**
     * Halfwidth and Fullwidth Forms.
     * '\uFF00' - '\uFFEF'.
     */
887
    public static final UnicodeBlock HALFWIDTH_AND_FULLWIDTH_FORMS
888 889 890 891 892 893 894
      = new UnicodeBlock('\uFF00', '\uFFEF',
                         "HALFWIDTH_AND_FULLWIDTH_FORMS");

    /**
     * Specials.
     * '\uFEFF', '\uFFF0' - '\uFFFD'.
     */
895
    public static final UnicodeBlock SPECIALS
896 897 898 899 900 901 902
      = new UnicodeBlock('\uFFF0', '\uFFFD',
                         "SPECIALS");

    /**
     * The defined subsets.
     */
    private static final UnicodeBlock sets[] = {
903 904 905 906 907 908 909 910 911 912 913 914
      BASIC_LATIN,
      LATIN_1_SUPPLEMENT,
      LATIN_EXTENDED_A,
      LATIN_EXTENDED_B,
      IPA_EXTENSIONS,
      SPACING_MODIFIER_LETTERS,
      COMBINING_DIACRITICAL_MARKS,
      GREEK,
      CYRILLIC,
      ARMENIAN,
      HEBREW,
      ARABIC,
915
      SYRIAC,
916
      THAANA,
917 918 919 920 921 922 923 924 925
      DEVANAGARI,
      BENGALI,
      GURMUKHI,
      GUJARATI,
      ORIYA,
      TAMIL,
      TELUGU,
      KANNADA,
      MALAYALAM,
926
      SINHALA,
927 928 929
      THAI,
      LAO,
      TIBETAN,
930
      MYANMAR,
931 932
      GEORGIAN,
      HANGUL_JAMO,
933 934 935 936 937 938 939
      ETHIOPIC,
      CHEROKEE,
      UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS,
      OGHAM,
      RUNIC,
      KHMER,
      MONGOLIAN,
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
      LATIN_EXTENDED_ADDITIONAL,
      GREEK_EXTENDED,
      GENERAL_PUNCTUATION,
      SUPERSCRIPTS_AND_SUBSCRIPTS,
      CURRENCY_SYMBOLS,
      COMBINING_MARKS_FOR_SYMBOLS,
      LETTERLIKE_SYMBOLS,
      NUMBER_FORMS,
      ARROWS,
      MATHEMATICAL_OPERATORS,
      MISCELLANEOUS_TECHNICAL,
      CONTROL_PICTURES,
      OPTICAL_CHARACTER_RECOGNITION,
      ENCLOSED_ALPHANUMERICS,
      BOX_DRAWING,
      BLOCK_ELEMENTS,
      GEOMETRIC_SHAPES,
      MISCELLANEOUS_SYMBOLS,
      DINGBATS,
959 960 961 962
      BRAILLE_PATTERNS,
      CJK_RADICALS_SUPPLEMENT,
      KANGXI_RADICALS,
      IDEOGRAPHIC_DESCRIPTION_CHARACTERS,
963 964 965 966 967 968
      CJK_SYMBOLS_AND_PUNCTUATION,
      HIRAGANA,
      KATAKANA,
      BOPOMOFO,
      HANGUL_COMPATIBILITY_JAMO,
      KANBUN,
969
      BOPOMOFO_EXTENDED,
970 971
      ENCLOSED_CJK_LETTERS_AND_MONTHS,
      CJK_COMPATIBILITY,
972
      CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A,
973
      CJK_UNIFIED_IDEOGRAPHS,
974 975
      YI_SYLLABLES,
      YI_RADICALS,
976
      HANGUL_SYLLABLES,
977 978
      SURROGATES_AREA,
      PRIVATE_USE_AREA,
979 980 981 982 983 984 985 986
      CJK_COMPATIBILITY_IDEOGRAPHS,
      ALPHABETIC_PRESENTATION_FORMS,
      ARABIC_PRESENTATION_FORMS_A,
      COMBINING_HALF_MARKS,
      CJK_COMPATIBILITY_FORMS,
      SMALL_FORM_VARIANTS,
      ARABIC_PRESENTATION_FORMS_B,
      HALFWIDTH_AND_FULLWIDTH_FORMS,
987
      SPECIALS,
988
    };
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
  } // class UnicodeBlock

  /**
   * The immutable value of this Character.
   *
   * @serial the value of this Character
   */
  private final char value;

  /**
   * Compatible with JDK 1.0+.
   */
  private static final long serialVersionUID = 3786198910865385080L;

  /**
   * Smallest value allowed for radix arguments in Java. This value is 2.
   *
   * @see #digit(char, int)
   * @see #forDigit(int, int)
   * @see Integer#toString(int, int)
   * @see Integer#valueOf(String)
   */
  public static final int MIN_RADIX = 2;

  /**
   * Largest value allowed for radix arguments in Java. This value is 36.
   *
   * @see #digit(char, int)
   * @see #forDigit(int, int)
   * @see Integer#toString(int, int)
   * @see Integer#valueOf(String)
   */
  public static final int MAX_RADIX = 36;

  /**
   * The minimum value the char data type can hold.
   * This value is <code>'\\u0000'</code>.
   */
  public static final char MIN_VALUE = '\u0000';

  /**
   * The maximum value the char data type can hold.
   * This value is <code>'\\uFFFF'</code>.
   */
  public static final char MAX_VALUE = '\uFFFF';

  /**
   * Class object representing the primitive char data type.
   *
   * @since 1.1
   */
  public static final Class TYPE = VMClassLoader.getPrimitiveClass('C');

  /**
   * Lu = Letter, Uppercase (Informative).
   *
   * @since 1.1
   */
  public static final byte UPPERCASE_LETTER = 1;

  /**
   * Ll = Letter, Lowercase (Informative).
   *
   * @since 1.1
   */
  public static final byte LOWERCASE_LETTER = 2;

  /**
   * Lt = Letter, Titlecase (Informative).
   *
   * @since 1.1
   */
  public static final byte TITLECASE_LETTER = 3;

  /**
   * Mn = Mark, Non-Spacing (Normative).
   *
   * @since 1.1
   */
  public static final byte NON_SPACING_MARK = 6;

  /**
   * Mc = Mark, Spacing Combining (Normative).
   *
   * @since 1.1
   */
  public static final byte COMBINING_SPACING_MARK = 8;

  /**
   * Me = Mark, Enclosing (Normative).
   *
   * @since 1.1
   */
  public static final byte ENCLOSING_MARK = 7;

  /**
   * Nd = Number, Decimal Digit (Normative).
   *
   * @since 1.1
   */
  public static final byte DECIMAL_DIGIT_NUMBER = 9;

  /**
   * Nl = Number, Letter (Normative).
   *
   * @since 1.1
   */
  public static final byte LETTER_NUMBER = 10;

  /**
   * No = Number, Other (Normative).
   *
   * @since 1.1
   */
  public static final byte OTHER_NUMBER = 11;

  /**
   * Zs = Separator, Space (Normative).
   *
   * @since 1.1
   */
  public static final byte SPACE_SEPARATOR = 12;

  /**
   * Zl = Separator, Line (Normative).
   *
   * @since 1.1
   */
  public static final byte LINE_SEPARATOR = 13;

  /**
   * Zp = Separator, Paragraph (Normative).
   *
   * @since 1.1
   */
  public static final byte PARAGRAPH_SEPARATOR = 14;

  /**
   * Cc = Other, Control (Normative).
   *
   * @since 1.1
   */
  public static final byte CONTROL = 15;

  /**
   * Cf = Other, Format (Normative).
   *
   * @since 1.1
   */
  public static final byte FORMAT = 16;

  /**
   * Cs = Other, Surrogate (Normative).
   *
   * @since 1.1
   */
  public static final byte SURROGATE = 19;

  /**
   * Co = Other, Private Use (Normative).
   *
   * @since 1.1
   */
  public static final byte PRIVATE_USE = 18;

  /**
   * Cn = Other, Not Assigned (Normative).
   *
   * @since 1.1
   */
  public static final byte UNASSIGNED = 0;

  /**
   * Lm = Letter, Modifier (Informative).
   *
   * @since 1.1
   */
  public static final byte MODIFIER_LETTER = 4;

  /**
   * Lo = Letter, Other (Informative).
   *
   * @since 1.1
   */
  public static final byte OTHER_LETTER = 5;

  /**
   * Pc = Punctuation, Connector (Informative).
   *
   * @since 1.1
   */
  public static final byte CONNECTOR_PUNCTUATION = 23;

  /**
   * Pd = Punctuation, Dash (Informative).
   *
   * @since 1.1
   */
  public static final byte DASH_PUNCTUATION = 20;

  /**
   * Ps = Punctuation, Open (Informative).
   *
   * @since 1.1
   */
  public static final byte START_PUNCTUATION = 21;

  /**
   * Pe = Punctuation, Close (Informative).
   *
   * @since 1.1
   */
  public static final byte END_PUNCTUATION = 22;

  /**
   * Pi = Punctuation, Initial Quote (Informative).
   *
   * @since 1.4
   */
  public static final byte INITIAL_QUOTE_PUNCTUATION = 29;

  /**
   * Pf = Punctuation, Final Quote (Informative).
   *
   * @since 1.4
   */
  public static final byte FINAL_QUOTE_PUNCTUATION = 30;

  /**
   * Po = Punctuation, Other (Informative).
   *
   * @since 1.1
   */
  public static final byte OTHER_PUNCTUATION = 24;

  /**
   * Sm = Symbol, Math (Informative).
   *
   * @since 1.1
   */
  public static final byte MATH_SYMBOL = 25;

  /**
   * Sc = Symbol, Currency (Informative).
   *
   * @since 1.1
   */
  public static final byte CURRENCY_SYMBOL = 26;

  /**
   * Sk = Symbol, Modifier (Informative).
   *
   * @since 1.1
   */
  public static final byte MODIFIER_SYMBOL = 27;

  /**
   * So = Symbol, Other (Informative).
   *
   * @since 1.1
   */
  public static final byte OTHER_SYMBOL = 28;

  /**
   * Undefined bidirectional character type. Undefined char values have
   * undefined directionality in the Unicode specification.
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_UNDEFINED = -1;

  /**
   * Strong bidirectional character type "L".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0;

  /**
   * Strong bidirectional character type "R".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1;

  /**
   * Strong bidirectional character type "AL".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2;

  /**
   * Weak bidirectional character type "EN".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3;

  /**
   * Weak bidirectional character type "ES".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4;

  /**
   * Weak bidirectional character type "ET".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5;

  /**
   * Weak bidirectional character type "AN".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6;

  /**
   * Weak bidirectional character type "CS".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7;

  /**
   * Weak bidirectional character type "NSM".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_NONSPACING_MARK = 8;

  /**
   * Weak bidirectional character type "BN".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9;

  /**
   * Neutral bidirectional character type "B".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10;

  /**
   * Neutral bidirectional character type "S".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11;

  /**
   * Strong bidirectional character type "WS".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_WHITESPACE = 12;

  /**
   * Neutral bidirectional character type "ON".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13;

  /**
   * Strong bidirectional character type "LRE".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14;

  /**
   * Strong bidirectional character type "LRO".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15;

  /**
   * Strong bidirectional character type "RLE".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16;

  /**
   * Strong bidirectional character type "RLO".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17;

  /**
   * Weak bidirectional character type "PDF".
   *
   * @since 1.4
   */
  public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18;

  /**
   * Mask for grabbing the type out of the result of readChar.
   * @see #readChar(char)
   */
  private static final int TYPE_MASK = 0x1F;

  /**
   * Mask for grabbing the non-breaking space flag out of the result of
   * readChar.
   * @see #readChar(char)
   */
  private static final int NO_BREAK_MASK = 0x20;

  /**
   * Mask for grabbing the mirrored directionality flag out of the result
   * of readChar.
   * @see #readChar(char)
   */
  private static final int MIRROR_MASK = 0x40;

  /**
   * Grabs an attribute offset from the Unicode attribute database. The lower
   * 5 bits are the character type, the next 2 bits are flags, and the top
   * 9 bits are the offset into the attribute tables. Note that the top 9
   * bits are meaningless in this context; they are useful only in the native
   * code.
   *
   * @param ch the character to look up
   * @return the character's attribute offset and type
   * @see #TYPE_MASK
   * @see #NO_BREAK_MASK
   * @see #MIRROR_MASK
   */
  private static native char readChar(char ch);

  /**
   * Wraps up a character.
   *
   * @param value the character to wrap
   */
  public Character(char value)
  {
    this.value = value;
  }

  /**
   * Returns the character which has been wrapped by this class.
   *
   * @return the character wrapped
   */
  public char charValue()
  {
    return value;
  }

  /**
   * Returns the numerical value (unsigned) of the wrapped character.
   * Range of returned values: 0x0000-0xFFFF.
   *
   * @return the value of the wrapped character
   */
  public int hashCode()
  {
    return value;
  }

  /**
   * Determines if an object is equal to this object. This is only true for
   * another Character object wrapping the same value.
   *
   * @param o object to compare
   * @return true if o is a Character with the same value
   */
  public boolean equals(Object o)
  {
    return o instanceof Character && value == ((Character) o).value;
  }

  /**
   * Converts the wrapped character into a String.
   *
   * @return a String containing one character -- the wrapped character
   *         of this instance
   */
  public String toString()
  {
    // This assumes that String.valueOf(char) can create a single-character
    // String more efficiently than through the public API.
    return String.valueOf(value);
  }

  /**
   * Returns a String of length 1 representing the specified character.
   *
   * @param ch the character to convert
   * @return a String containing the character
   * @since 1.4
   */
Jesse Rosenstock committed
1491
  public static String toString(char ch)
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585
  {
    // This assumes that String.valueOf(char) can create a single-character
    // String more efficiently than through the public API.
    return String.valueOf(ch);
  }

  /**
   * Determines if a character is a Unicode lowercase letter. For example,
   * <code>'a'</code> is lowercase.
   * <br>
   * lowercase = [Ll]
   *
   * @param ch character to test
   * @return true if ch is a Unicode lowercase letter, else false
   * @see #isUpperCase(char)
   * @see #isTitleCase(char)
   * @see #toLowerCase(char)
   * @see #getType(char)
   */
  public static boolean isLowerCase(char ch)
  {
    return getType(ch) == LOWERCASE_LETTER;
  }

  /**
   * Determines if a character is a Unicode uppercase letter. For example,
   * <code>'A'</code> is uppercase.
   * <br>
   * uppercase = [Lu]
   *
   * @param ch character to test
   * @return true if ch is a Unicode uppercase letter, else false
   * @see #isLowerCase(char)
   * @see #isTitleCase(char)
   * @see #toUpperCase(char)
   * @see #getType(char)
   */
  public static boolean isUpperCase(char ch)
  {
    return getType(ch) == UPPERCASE_LETTER;
  }

  /**
   * Determines if a character is a Unicode titlecase letter. For example,
   * the character "Lj" (Latin capital L with small letter j) is titlecase.
   * <br>
   * titlecase = [Lt]
   *
   * @param ch character to test
   * @return true if ch is a Unicode titlecase letter, else false
   * @see #isLowerCase(char)
   * @see #isUpperCase(char)
   * @see #toTitleCase(char)
   * @see #getType(char)
   */
  public static boolean isTitleCase(char ch)
  {
    return getType(ch) == TITLECASE_LETTER;
  }

  /**
   * Determines if a character is a Unicode decimal digit. For example,
   * <code>'0'</code> is a digit.
   * <br>
   * Unicode decimal digit = [Nd]
   *
   * @param ch character to test
   * @return true if ch is a Unicode decimal digit, else false
   * @see #digit(char, int)
   * @see #forDigit(int, int)
   * @see #getType(char)
   */
  public static boolean isDigit(char ch)
  {
    return getType(ch) == DECIMAL_DIGIT_NUMBER;
  }

  /**
   * Determines if a character is part of the Unicode Standard. This is an
   * evolving standard, but covers every character in the data file.
   * <br>
   * defined = not [Cn]
   *
   * @param ch character to test
   * @return true if ch is a Unicode character, else false
   * @see #isDigit(char)
   * @see #isLetter(char)
   * @see #isLetterOrDigit(char)
   * @see #isLowerCase(char)
   * @see #isTitleCase(char)
   * @see #isUpperCase(char)
   */
  public static boolean isDefined(char ch)
  {
1586
    return getType(ch) != UNASSIGNED;
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081
  }

  /**
   * Determines if a character is a Unicode letter. Not all letters have case,
   * so this may return true when isLowerCase and isUpperCase return false.
   * <br>
   * letter = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]
   *
   * @param ch character to test
   * @return true if ch is a Unicode letter, else false
   * @see #isDigit(char)
   * @see #isJavaIdentifierStart(char)
   * @see #isJavaLetter(char)
   * @see #isJavaLetterOrDigit(char)
   * @see #isLetterOrDigit(char)
   * @see #isLowerCase(char)
   * @see #isTitleCase(char)
   * @see #isUnicodeIdentifierStart(char)
   * @see #isUpperCase(char)
   */
  public static boolean isLetter(char ch)
  {
    return ((1 << getType(ch))
            & ((1 << UPPERCASE_LETTER)
               | (1 << LOWERCASE_LETTER)
               | (1 << TITLECASE_LETTER)
               | (1 << MODIFIER_LETTER)
               | (1 << OTHER_LETTER))) != 0;
  }

  /**
   * Determines if a character is a Unicode letter or a Unicode digit. This
   * is the combination of isLetter and isDigit.
   * <br>
   * letter or digit = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nd]
   *
   * @param ch character to test
   * @return true if ch is a Unicode letter or a Unicode digit, else false
   * @see #isDigit(char)
   * @see #isJavaIdentifierPart(char)
   * @see #isJavaLetter(char)
   * @see #isJavaLetterOrDigit(char)
   * @see #isLetter(char)
   * @see #isUnicodeIdentifierPart(char)
   */
  public static boolean isLetterOrDigit(char ch)
  {
    return ((1 << getType(ch))
            & ((1 << UPPERCASE_LETTER)
               | (1 << LOWERCASE_LETTER)
               | (1 << TITLECASE_LETTER)
               | (1 << MODIFIER_LETTER)
               | (1 << OTHER_LETTER)
               | (1 << DECIMAL_DIGIT_NUMBER))) != 0;
  }

  /**
   * Determines if a character can start a Java identifier. This is the
   * combination of isLetter, any character where getType returns
   * LETTER_NUMBER, currency symbols (like '$'), and connecting punctuation
   * (like '_').
   *
   * @param ch character to test
   * @return true if ch can start a Java identifier, else false
   * @deprecated Replaced by {@link #isJavaIdentifierStart(char)}
   * @see #isJavaLetterOrDigit(char)
   * @see #isJavaIdentifierStart(char)
   * @see #isJavaIdentifierPart(char)
   * @see #isLetter(char)
   * @see #isLetterOrDigit(char)
   * @see #isUnicodeIdentifierStart(char)
   */
  public static boolean isJavaLetter(char ch)
  {
    return isJavaIdentifierStart(ch);
  }

  /**
   * Determines if a character can follow the first letter in
   * a Java identifier.  This is the combination of isJavaLetter (isLetter,
   * type of LETTER_NUMBER, currency, connecting punctuation) and digit,
   * numeric letter (like Roman numerals), combining marks, non-spacing marks,
   * or isIdentifierIgnorable.
   *
   * @param ch character to test
   * @return true if ch can follow the first letter in a Java identifier
   * @deprecated Replaced by {@link #isJavaIdentifierPart(char)}
   * @see #isJavaLetter(char)
   * @see #isJavaIdentifierStart(char)
   * @see #isJavaIdentifierPart(char)
   * @see #isLetter(char)
   * @see #isLetterOrDigit(char)
   * @see #isUnicodeIdentifierPart(char)
   * @see #isIdentifierIgnorable(char)
   */
  public static boolean isJavaLetterOrDigit(char ch)
  {
    return isJavaIdentifierPart(ch);
  }

  /**
   * Determines if a character can start a Java identifier. This is the
   * combination of isLetter, any character where getType returns
   * LETTER_NUMBER, currency symbols (like '$'), and connecting punctuation
   * (like '_').
   * <br>
   * Java identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc]
   *
   * @param ch character to test
   * @return true if ch can start a Java identifier, else false
   * @see #isJavaIdentifierPart(char)
   * @see #isLetter(char)
   * @see #isUnicodeIdentifierStart(char)
   * @since 1.1
   */
  public static boolean isJavaIdentifierStart(char ch)
  {
    return ((1 << getType(ch))
            & ((1 << UPPERCASE_LETTER)
               | (1 << LOWERCASE_LETTER)
               | (1 << TITLECASE_LETTER)
               | (1 << MODIFIER_LETTER)
               | (1 << OTHER_LETTER)
               | (1 << LETTER_NUMBER)
               | (1 << CURRENCY_SYMBOL)
               | (1 << CONNECTOR_PUNCTUATION))) != 0;
  }

  /**
   * Determines if a character can follow the first letter in
   * a Java identifier.  This is the combination of isJavaLetter (isLetter,
   * type of LETTER_NUMBER, currency, connecting punctuation) and digit,
   * numeric letter (like Roman numerals), combining marks, non-spacing marks,
   * or isIdentifierIgnorable.
   * <br>
   * Java identifier extender =
   *   [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc]|[Mn]|[Mc]|[Nd]|[Cf]
   *   |U+0000-U+0008|U+000E-U+001B|U+007F-U+009F
   *
   * @param ch character to test
   * @return true if ch can follow the first letter in a Java identifier
   * @see #isIdentifierIgnorable(char)
   * @see #isJavaIdentifierStart(char)
   * @see #isLetterOrDigit(char)
   * @see #isUnicodeIdentifierPart(char)
   * @since 1.1
   */
  public static boolean isJavaIdentifierPart(char ch)
  {
    int category = getType(ch);
    return ((1 << category)
            & ((1 << UPPERCASE_LETTER)
               | (1 << LOWERCASE_LETTER)
               | (1 << TITLECASE_LETTER)
               | (1 << MODIFIER_LETTER)
               | (1 << OTHER_LETTER)
               | (1 << NON_SPACING_MARK)
               | (1 << COMBINING_SPACING_MARK)
               | (1 << DECIMAL_DIGIT_NUMBER)
               | (1 << LETTER_NUMBER)
               | (1 << CURRENCY_SYMBOL)
               | (1 << CONNECTOR_PUNCTUATION)
               | (1 << FORMAT))) != 0
      || (category == CONTROL && isIdentifierIgnorable(ch));
  }

  /**
   * Determines if a character can start a Unicode identifier.  Only
   * letters can start a Unicode identifier, but this includes characters
   * in LETTER_NUMBER.
   * <br>
   * Unicode identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]
   *
   * @param ch character to test
   * @return true if ch can start a Unicode identifier, else false
   * @see #isJavaIdentifierStart(char)
   * @see #isLetter(char)
   * @see #isUnicodeIdentifierPart(char)
   * @since 1.1
   */
  public static boolean isUnicodeIdentifierStart(char ch)
  {
    return ((1 << getType(ch))
            & ((1 << UPPERCASE_LETTER)
               | (1 << LOWERCASE_LETTER)
               | (1 << TITLECASE_LETTER)
               | (1 << MODIFIER_LETTER)
               | (1 << OTHER_LETTER)
               | (1 << LETTER_NUMBER))) != 0;
  }

  /**
   * Determines if a character can follow the first letter in
   * a Unicode identifier. This includes letters, connecting punctuation,
   * digits, numeric letters, combining marks, non-spacing marks, and
   * isIdentifierIgnorable.
   * <br>
   * Unicode identifier extender =
   *   [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Mn]|[Mc]|[Nd]|[Pc]|[Cf]|
   *   |U+0000-U+0008|U+000E-U+001B|U+007F-U+009F
   *
   * @param ch character to test
   * @return true if ch can follow the first letter in a Unicode identifier
   * @see #isIdentifierIgnorable(char)
   * @see #isJavaIdentifierPart(char)
   * @see #isLetterOrDigit(char)
   * @see #isUnicodeIdentifierStart(char)
   * @since 1.1
   */
  public static boolean isUnicodeIdentifierPart(char ch)
  {
    int category = getType(ch);
    return ((1 << category)
            & ((1 << UPPERCASE_LETTER)
               | (1 << LOWERCASE_LETTER)
               | (1 << TITLECASE_LETTER)
               | (1 << MODIFIER_LETTER)
               | (1 << OTHER_LETTER)
               | (1 << NON_SPACING_MARK)
               | (1 << COMBINING_SPACING_MARK)
               | (1 << DECIMAL_DIGIT_NUMBER)
               | (1 << LETTER_NUMBER)
               | (1 << CONNECTOR_PUNCTUATION)
               | (1 << FORMAT))) != 0
      || (category == CONTROL && isIdentifierIgnorable(ch));
  }

  /**
   * Determines if a character is ignorable in a Unicode identifier. This
   * includes the non-whitespace ISO control characters (<code>'\u0000'</code>
   * through <code>'\u0008'</code>, <code>'\u000E'</code> through
   * <code>'\u001B'</code>, and <code>'\u007F'</code> through
   * <code>'\u009F'</code>), and FORMAT characters.
   * <br>
   * Unicode identifier ignorable = [Cf]|U+0000-U+0008|U+000E-U+001B
   *    |U+007F-U+009F
   *
   * @param ch character to test
   * @return true if ch is ignorable in a Unicode or Java identifier
   * @see #isJavaIdentifierPart(char)
   * @see #isUnicodeIdentifierPart(char)
   * @since 1.1
   */
  public static boolean isIdentifierIgnorable(char ch)
  {
    return (ch <= '\u009F' && (ch < '\t' || ch >= '\u007F'
                               || (ch <= '\u001B' && ch >= '\u000E')))
      || getType(ch) == FORMAT;
  }

  /**
   * Converts a Unicode character into its lowercase equivalent mapping.
   * If a mapping does not exist, then the character passed is returned.
   * Note that isLowerCase(toLowerCase(ch)) does not always return true.
   *
   * @param ch character to convert to lowercase
   * @return lowercase mapping of ch, or ch if lowercase mapping does
   *         not exist
   * @see #isLowerCase(char)
   * @see #isUpperCase(char)
   * @see #toTitleCase(char)
   * @see #toUpperCase(char)
   */
  public static native char toLowerCase(char ch);

  /**
   * Converts a Unicode character into its uppercase equivalent mapping.
   * If a mapping does not exist, then the character passed is returned.
   * Note that isUpperCase(toUpperCase(ch)) does not always return true.
   *
   * @param ch character to convert to uppercase
   * @return uppercase mapping of ch, or ch if uppercase mapping does
   *         not exist
   * @see #isLowerCase(char)
   * @see #isUpperCase(char)
   * @see #toLowerCase(char)
   * @see #toTitleCase(char)
   */
  public static native char toUpperCase(char ch);

  /**
   * Converts a Unicode character into its titlecase equivalent mapping.
   * If a mapping does not exist, then the character passed is returned.
   * Note that isTitleCase(toTitleCase(ch)) does not always return true.
   *
   * @param ch character to convert to titlecase
   * @return titlecase mapping of ch, or ch if titlecase mapping does
   *         not exist
   * @see #isTitleCase(char)
   * @see #toLowerCase(char)
   * @see #toUpperCase(char)
   */
  public static native char toTitleCase(char ch);

  /**
   * Converts a character into a digit of the specified radix. If the radix
   * exceeds MIN_RADIX or MAX_RADIX, or if the result of getNumericValue(ch)
   * exceeds the radix, or if ch is not a decimal digit or in the case
   * insensitive set of 'a'-'z', the result is -1.
   * <br>
   * character argument boundary = [Nd]|U+0041-U+005A|U+0061-U+007A
   *    |U+FF21-U+FF3A|U+FF41-U+FF5A
   *
   * @param ch character to convert into a digit
   * @param radix radix in which ch is a digit
   * @return digit which ch represents in radix, or -1 not a valid digit
   * @see #MIN_RADIX
   * @see #MAX_RADIX
   * @see #forDigit(int, int)
   * @see #isDigit(char)
   * @see #getNumericValue(char)
   */
  public static native int digit(char ch, int radix);

  /**
   * Returns the Unicode numeric value property of a character. For example,
   * <code>'\\u216C'</code> (the Roman numeral fifty) returns 50.
   *
   * <p>This method also returns values for the letters A through Z, (not
   * specified by Unicode), in these ranges: <code>'\u0041'</code>
   * through <code>'\u005A'</code> (uppercase); <code>'\u0061'</code>
   * through <code>'\u007A'</code> (lowercase); and <code>'\uFF21'</code>
   * through <code>'\uFF3A'</code>, <code>'\uFF41'</code> through
   * <code>'\uFF5A'</code> (full width variants).
   *
   * <p>If the character lacks a numeric value property, -1 is returned.
   * If the character has a numeric value property which is not representable
   * as a nonnegative integer, such as a fraction, -2 is returned.
   *
   * character argument boundary = [Nd]|[Nl]|[No]|U+0041-U+005A|U+0061-U+007A
   *    |U+FF21-U+FF3A|U+FF41-U+FF5A
   *
   * @param ch character from which the numeric value property will
   *        be retrieved
   * @return the numeric value property of ch, or -1 if it does not exist, or
   *         -2 if it is not representable as a nonnegative integer
   * @see #forDigit(int, int)
   * @see #digit(char, int)
   * @see #isDigit(char)
   * @since 1.1
   */
  public static native int getNumericValue(char ch);

  /**
   * Determines if a character is a ISO-LATIN-1 space. This is only the five
   * characters <code>'\t'</code>, <code>'\n'</code>, <code>'\f'</code>,
   * <code>'\r'</code>, and <code>' '</code>.
   * <br>
   * Java space = U+0020|U+0009|U+000A|U+000C|U+000D
   *
   * @param ch character to test
   * @return true if ch is a space, else false
   * @deprecated Replaced by {@link #isWhitespace(char)}
   * @see #isSpaceChar(char)
   * @see #isWhitespace(char)
   */
  public static boolean isSpace(char ch)
  {
    // Performing the subtraction up front alleviates need to compare longs.
    return ch-- <= ' ' && ((1 << ch)
                           & ((1 << (' ' - 1))
                              | (1 << ('\t' - 1))
                              | (1 << ('\n' - 1))
                              | (1 << ('\r' - 1))
                              | (1 << ('\f' - 1)))) != 0;
  }

  /**
   * Determines if a character is a Unicode space character. This includes
   * SPACE_SEPARATOR, LINE_SEPARATOR, and PARAGRAPH_SEPARATOR.
   * <br>
   * Unicode space = [Zs]|[Zp]|[Zl]
   *
   * @param ch character to test
   * @return true if ch is a Unicode space, else false
   * @see #isWhitespace(char)
   * @since 1.1
   */
  public static boolean isSpaceChar(char ch)
  {
    return ((1 << getType(ch))
            & ((1 << SPACE_SEPARATOR)
               | (1 << LINE_SEPARATOR)
               | (1 << PARAGRAPH_SEPARATOR))) != 0;
  }

  /**
   * Determines if a character is Java whitespace. This includes Unicode
   * space characters (SPACE_SEPARATOR, LINE_SEPARATOR, and
   * PARAGRAPH_SEPARATOR) except the non-breaking spaces
   * (<code>'\u00A0'</code>, <code>'\u2007'</code>, and <code>'\u202F'</code>);
   * and these characters: <code>'\u0009'</code>, <code>'\u000A'</code>,
   * <code>'\u000B'</code>, <code>'\u000C'</code>, <code>'\u000D'</code>,
   * <code>'\u001C'</code>, <code>'\u001D'</code>, <code>'\u001E'</code>,
   * and <code>'\u001F'</code>.
   * <br>
   * Java whitespace = ([Zs] not Nb)|[Zl]|[Zp]|U+0009-U+000D|U+001C-U+001F
   *
   * @param ch character to test
   * @return true if ch is Java whitespace, else false
   * @see #isSpaceChar(char)
   * @since 1.1
   */
  public static boolean isWhitespace(char ch)
  {
    int attr = readChar(ch);
    return ((((1 << (attr & TYPE_MASK))
              & ((1 << SPACE_SEPARATOR)
                 | (1 << LINE_SEPARATOR)
                 | (1 << PARAGRAPH_SEPARATOR))) != 0)
            && (attr & NO_BREAK_MASK) == 0)
      || (ch <= '\u001F' && ((1 << ch)
                             & ((1 << '\t')
                                | (1 << '\n')
                                | (1 << '\u000B')
                                | (1 << '\u000C')
                                | (1 << '\r')
                                | (1 << '\u001C')
                                | (1 << '\u001D')
                                | (1 << '\u001E')
                                | (1 << '\u001F'))) != 0);
  }

  /**
   * Determines if a character has the ISO Control property.
   * <br>
   * ISO Control = [Cc]
   *
   * @param ch character to test
   * @return true if ch is an ISO Control character, else false
   * @see #isSpaceChar(char)
   * @see #isWhitespace(char)
   * @since 1.1
   */
  public static boolean isISOControl(char ch)
  {
    return getType(ch) == CONTROL;
  }

  /**
   * Returns the Unicode general category property of a character.
   *
   * @param ch character from which the general category property will
   *        be retrieved
   * @return the character category property of ch as an integer
   * @see #UNASSIGNED
   * @see #UPPERCASE_LETTER
   * @see #LOWERCASE_LETTER
   * @see #TITLECASE_LETTER
   * @see #MODIFIER_LETTER
   * @see #OTHER_LETTER
   * @see #NON_SPACING_MARK
   * @see #ENCLOSING_MARK
   * @see #COMBINING_SPACING_MARK
   * @see #DECIMAL_DIGIT_NUMBER
   * @see #LETTER_NUMBER
   * @see #OTHER_NUMBER
   * @see #SPACE_SEPARATOR
   * @see #LINE_SEPARATOR
   * @see #PARAGRAPH_SEPARATOR
   * @see #CONTROL
   * @see #FORMAT
   * @see #PRIVATE_USE
   * @see #SURROGATE
   * @see #DASH_PUNCTUATION
   * @see #START_PUNCTUATION
   * @see #END_PUNCTUATION
   * @see #CONNECTOR_PUNCTUATION
   * @see #OTHER_PUNCTUATION
   * @see #MATH_SYMBOL
   * @see #CURRENCY_SYMBOL
   * @see #MODIFIER_SYMBOL
   * @see #INITIAL_QUOTE_PUNCTUATION
   * @see #FINAL_QUOTE_PUNCTUATION
   * @since 1.1
   */
  public static native int getType(char ch);

  /**
   * Converts a digit into a character which represents that digit
   * in a specified radix. If the radix exceeds MIN_RADIX or MAX_RADIX,
   * or the digit exceeds the radix, then the null character <code>'\0'</code>
   * is returned.  Otherwise the return value is in '0'-'9' and 'a'-'z'.
   * <br>
   * return value boundary = U+0030-U+0039|U+0061-U+007A
   *
   * @param digit digit to be converted into a character
   * @param radix radix of digit
   * @return character representing digit in radix, or '\0'
   * @see #MIN_RADIX
   * @see #MAX_RADIX
   * @see #digit(char, int)
   */
  public static char forDigit(int digit, int radix)
  {
2082
    if (radix < MIN_RADIX || radix > MAX_RADIX
2083
        || digit < 0 || digit >= radix)
2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161
      return '\0';
    return (char) (digit < 10 ? ('0' + digit) : ('a' - 10 + digit));
  }

  /**
   * Returns the Unicode directionality property of the character. This
   * is used in the visual ordering of text.
   *
   * @param ch the character to look up
   * @return the directionality constant, or DIRECTIONALITY_UNDEFINED
   * @see #DIRECTIONALITY_UNDEFINED
   * @see #DIRECTIONALITY_LEFT_TO_RIGHT
   * @see #DIRECTIONALITY_RIGHT_TO_LEFT
   * @see #DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC
   * @see #DIRECTIONALITY_EUROPEAN_NUMBER
   * @see #DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR
   * @see #DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR
   * @see #DIRECTIONALITY_ARABIC_NUMBER
   * @see #DIRECTIONALITY_COMMON_NUMBER_SEPARATOR
   * @see #DIRECTIONALITY_NONSPACING_MARK
   * @see #DIRECTIONALITY_BOUNDARY_NEUTRAL
   * @see #DIRECTIONALITY_PARAGRAPH_SEPARATOR
   * @see #DIRECTIONALITY_SEGMENT_SEPARATOR
   * @see #DIRECTIONALITY_WHITESPACE
   * @see #DIRECTIONALITY_OTHER_NEUTRALS
   * @see #DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING
   * @see #DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE
   * @see #DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING
   * @see #DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE
   * @see #DIRECTIONALITY_POP_DIRECTIONAL_FORMAT
   * @since 1.4
   */
  public static native byte getDirectionality(char ch);

  /**
   * Determines whether the character is mirrored according to Unicode. For
   * example, <code>\u0028</code> (LEFT PARENTHESIS) appears as '(' in
   * left-to-right text, but ')' in right-to-left text.
   *
   * @param ch the character to look up
   * @return true if the character is mirrored
   * @since 1.4
   */
  public static boolean isMirrored(char ch)
  {
    return (readChar(ch) & MIRROR_MASK) != 0;
  }

  /**
   * Compares another Character to this Character, numerically.
   *
   * @param anotherCharacter Character to compare with this Character
   * @return a negative integer if this Character is less than
   *         anotherCharacter, zero if this Character is equal, and
   *         a positive integer if this Character is greater
   * @throws NullPointerException if anotherCharacter is null
   * @since 1.2
   */
  public int compareTo(Character anotherCharacter)
  {
    return value - anotherCharacter.value;
  }

  /**
   * Compares an object to this Character.  Assuming the object is a
   * Character object, this method performs the same comparison as
   * compareTo(Character).
   *
   * @param o object to compare
   * @return the comparison value
   * @throws ClassCastException if o is not a Character object
   * @throws NullPointerException if o is null
   * @see #compareTo(Character)
   * @since 1.2
   */
  public int compareTo(Object o)
  {
    return compareTo((Character) o);
2162
  }
2163
} // class Character