Character.java 136 KB
Newer Older
Tom Tromey committed
1
/* java.lang.Character -- Wrapper class for char, and Unicode subsets
2
   Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
Tom Tromey committed
3 4 5 6 7 8 9 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

This file is part of GNU Classpath.

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.

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., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 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. */


package java.lang;

import gnu.java.lang.CharData;

import java.io.Serializable;
44 45
import java.text.Collator;
import java.util.Locale;
Tom Tromey committed
46 47 48 49

/**
 * Wrapper class for the primitive char data type.  In addition, this class
 * allows one to retrieve property information and perform transformations
50
 * on the defined characters in the Unicode Standard, Version 4.0.0.
Tom Tromey committed
51 52 53 54 55 56 57
 * 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.
58
 * See 5.13 of the Unicode Standard, Version 4.0, for the
Tom Tromey committed
59 60 61 62 63 64 65 66 67
 * boundary specification.
 *
 * <p>See <a href="http://www.unicode.org">http://www.unicode.org</a>
 * for more information on the Unicode Standard.
 *
 * @author Tom Tromey (tromey@cygnus.com)
 * @author Paul N. Fisher
 * @author Jochen Hoenicke
 * @author Eric Blake (ebb9@email.byu.edu)
68
 * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
Tom Tromey committed
69 70
 * @see CharData
 * @since 1.0
71
 * @status partly updated to 1.5; some things still missing
Tom Tromey committed
72
 */
73
public final class Character implements Serializable, Comparable<Character>
Tom Tromey committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
{
  /**
   * A subset of Unicode blocks.
   *
   * @author Paul N. Fisher
   * @author Eric Blake (ebb9@email.byu.edu)
   * @since 1.2
   */
  public static class Subset
  {
    /** The name of the subset. */
    private final String name;

    /**
     * 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();
    }

    /**
     * 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;
    }

    /**
     * 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();
    }

    /**
     * Returns the name of the subset.
     *
     * @return the name
     */
    public final String toString()
    {
      return name;
    }
  } // class Subset

  /**
   * 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
139
   * <code>doc/unicode/Blocks-4.0.0.txt</code>, by some perl scripts.
Tom Tromey committed
140 141
   * This Unicode definition file can be found on the
   * <a href="http://www.unicode.org">http://www.unicode.org</a> website.
142
   * JDK 1.5 uses Unicode version 4.0.0.
Tom Tromey committed
143 144 145 146 147 148 149
   *
   * @author scripts/unicode-blocks.pl (written by Eric Blake)
   * @since 1.2
   */
  public static final class UnicodeBlock extends Subset
  {
    /** The start of the subset. */
150
    private final int start;
Tom Tromey committed
151 152

    /** The end of the subset. */
153 154 155 156 157
    private final int end;

    /** The canonical name of the block according to the Unicode standard. */
    private final String canonicalName;

158
    /** Enumeration for the <code>forName()</code> method */
159
    private enum NameType { CANONICAL, NO_SPACES, CONSTANT; }
Tom Tromey committed
160 161 162 163 164 165 166

    /**
     * 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
167 168
     * @param canonicalName the name of the block as defined in the Unicode
     *        standard.
Tom Tromey committed
169
     */
170
    private UnicodeBlock(int start, int end, String name,
171
                         String canonicalName)
Tom Tromey committed
172 173 174 175
    {
      super(name);
      this.start = start;
      this.end = end;
176
      this.canonicalName = canonicalName;
Tom Tromey committed
177 178 179 180
    }

    /**
     * Returns the Unicode character block which a character belongs to.
181 182 183
     * <strong>Note</strong>: This method does not support the use of
     * supplementary characters.  For such support, <code>of(int)</code>
     * should be used instead.
Tom Tromey committed
184 185 186 187 188 189
     *
     * @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)
    {
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
      return of((int) ch);
    }

    /**
     * Returns the Unicode character block which a code point belongs to.
     *
     * @param codePoint the character to look up
     * @return the set it belongs to, or null if it is not in one.
     * @throws IllegalArgumentException if the specified code point is
     *         invalid.
     * @since 1.5
     */
    public static UnicodeBlock of(int codePoint)
    {
      if (codePoint > MAX_CODE_POINT)
205 206
        throw new IllegalArgumentException("The supplied integer value is " +
                                           "too large to be a codepoint.");
Tom Tromey committed
207 208 209 210 211 212 213
      // 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];
214
          if (codePoint < b.start)
Tom Tromey committed
215
            hi = mid - 1;
216
          else if (codePoint > b.end)
Tom Tromey committed
217 218 219 220 221 222 223 224
            low = mid + 1;
          else
            return b;
        }
      return null;
    }

    /**
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
     * <p>
     * Returns the <code>UnicodeBlock</code> with the given name, as defined
     * by the Unicode standard.  The version of Unicode in use is defined by
     * the <code>Character</code> class, and the names are given in the
     * <code>Blocks-<version>.txt</code> file corresponding to that version.
     * The name may be specified in one of three ways:
     * </p>
     * <ol>
     * <li>The canonical, human-readable name used by the Unicode standard.
     * This is the name with all spaces and hyphens retained.  For example,
     * `Basic Latin' retrieves the block, UnicodeBlock.BASIC_LATIN.</li>
     * <li>The canonical name with all spaces removed e.g. `BasicLatin'.</li>
     * <li>The name used for the constants specified by this class, which
     * is the canonical name with all spaces and hyphens replaced with
     * underscores e.g. `BASIC_LATIN'</li>
     * </ol>
     * <p>
     * The names are compared case-insensitively using the case comparison
     * associated with the U.S. English locale.  The method recognises the
     * previous names used for blocks as well as the current ones.  At
     * present, this simply means that the deprecated `SURROGATES_AREA'
     * will be recognised by this method (the <code>of()</code> methods
     * only return one of the three new surrogate blocks).
     * </p>
     *
     * @param blockName the name of the block to look up.
     * @return the specified block.
     * @throws NullPointerException if the <code>blockName</code> is
     *         <code>null</code>.
     * @throws IllegalArgumentException if the name does not match any Unicode
     *         block.
     * @since 1.5
     */
    public static final UnicodeBlock forName(String blockName)
    {
260
      NameType type;
261
      if (blockName.indexOf(' ') != -1)
262
        type = NameType.CANONICAL;
263
      else if (blockName.indexOf('_') != -1)
264
        type = NameType.CONSTANT;
265
      else
266
        type = NameType.NO_SPACES;
267 268 269 270 271
      Collator usCollator = Collator.getInstance(Locale.US);
      usCollator.setStrength(Collator.PRIMARY);
      /* Special case for deprecated blocks not in sets */
      switch (type)
      {
272
        case CANONICAL:
273 274 275
          if (usCollator.compare(blockName, "Surrogates Area") == 0)
            return SURROGATES_AREA;
          break;
276
        case NO_SPACES:
277 278 279
          if (usCollator.compare(blockName, "SurrogatesArea") == 0)
            return SURROGATES_AREA;
          break;
280
        case CONSTANT:
281
          if (usCollator.compare(blockName, "SURROGATES_AREA") == 0)
282 283 284 285 286 287
            return SURROGATES_AREA;
          break;
      }
      /* Other cases */
      switch (type)
      {
288 289 290 291
        case CANONICAL:
          for (UnicodeBlock block : sets)
            if (usCollator.compare(blockName, block.canonicalName) == 0)
              return block;
292
          break;
293 294
        case NO_SPACES:
          for (UnicodeBlock block : sets)
295 296 297 298 299 300
            {
              String nsName = block.canonicalName.replaceAll(" ","");
              if (usCollator.compare(blockName, nsName) == 0)
                return block;
            }
          break;
301 302 303 304
        case CONSTANT:
          for (UnicodeBlock block : sets)
            if (usCollator.compare(blockName, block.toString()) == 0)
              return block;
305 306 307 308 309 310 311
          break;
      }
      throw new IllegalArgumentException("No Unicode block found for " +
                                         blockName + ".");
    }

    /**
Tom Tromey committed
312
     * Basic Latin.
313
     * 0x0000 - 0x007F.
Tom Tromey committed
314 315
     */
    public static final UnicodeBlock BASIC_LATIN
316
      = new UnicodeBlock(0x0000, 0x007F,
317
                         "BASIC_LATIN",
318
                         "Basic Latin");
Tom Tromey committed
319 320 321

    /**
     * Latin-1 Supplement.
322
     * 0x0080 - 0x00FF.
Tom Tromey committed
323 324
     */
    public static final UnicodeBlock LATIN_1_SUPPLEMENT
325
      = new UnicodeBlock(0x0080, 0x00FF,
326
                         "LATIN_1_SUPPLEMENT",
327
                         "Latin-1 Supplement");
Tom Tromey committed
328 329 330

    /**
     * Latin Extended-A.
331
     * 0x0100 - 0x017F.
Tom Tromey committed
332 333
     */
    public static final UnicodeBlock LATIN_EXTENDED_A
334
      = new UnicodeBlock(0x0100, 0x017F,
335
                         "LATIN_EXTENDED_A",
336
                         "Latin Extended-A");
Tom Tromey committed
337 338 339

    /**
     * Latin Extended-B.
340
     * 0x0180 - 0x024F.
Tom Tromey committed
341 342
     */
    public static final UnicodeBlock LATIN_EXTENDED_B
343
      = new UnicodeBlock(0x0180, 0x024F,
344
                         "LATIN_EXTENDED_B",
345
                         "Latin Extended-B");
Tom Tromey committed
346 347 348

    /**
     * IPA Extensions.
349
     * 0x0250 - 0x02AF.
Tom Tromey committed
350 351
     */
    public static final UnicodeBlock IPA_EXTENSIONS
352
      = new UnicodeBlock(0x0250, 0x02AF,
353
                         "IPA_EXTENSIONS",
354
                         "IPA Extensions");
Tom Tromey committed
355 356 357

    /**
     * Spacing Modifier Letters.
358
     * 0x02B0 - 0x02FF.
Tom Tromey committed
359 360
     */
    public static final UnicodeBlock SPACING_MODIFIER_LETTERS
361
      = new UnicodeBlock(0x02B0, 0x02FF,
362
                         "SPACING_MODIFIER_LETTERS",
363
                         "Spacing Modifier Letters");
Tom Tromey committed
364 365 366

    /**
     * Combining Diacritical Marks.
367
     * 0x0300 - 0x036F.
Tom Tromey committed
368 369
     */
    public static final UnicodeBlock COMBINING_DIACRITICAL_MARKS
370
      = new UnicodeBlock(0x0300, 0x036F,
371
                         "COMBINING_DIACRITICAL_MARKS",
372
                         "Combining Diacritical Marks");
Tom Tromey committed
373 374 375

    /**
     * Greek.
376
     * 0x0370 - 0x03FF.
Tom Tromey committed
377 378
     */
    public static final UnicodeBlock GREEK
379
      = new UnicodeBlock(0x0370, 0x03FF,
380
                         "GREEK",
381
                         "Greek");
Tom Tromey committed
382 383 384

    /**
     * Cyrillic.
385
     * 0x0400 - 0x04FF.
Tom Tromey committed
386 387
     */
    public static final UnicodeBlock CYRILLIC
388
      = new UnicodeBlock(0x0400, 0x04FF,
389
                         "CYRILLIC",
390 391 392 393 394 395 396 397 398
                         "Cyrillic");

    /**
     * Cyrillic Supplementary.
     * 0x0500 - 0x052F.
     * @since 1.5
     */
    public static final UnicodeBlock CYRILLIC_SUPPLEMENTARY
      = new UnicodeBlock(0x0500, 0x052F,
399
                         "CYRILLIC_SUPPLEMENTARY",
400
                         "Cyrillic Supplementary");
Tom Tromey committed
401 402 403

    /**
     * Armenian.
404
     * 0x0530 - 0x058F.
Tom Tromey committed
405 406
     */
    public static final UnicodeBlock ARMENIAN
407
      = new UnicodeBlock(0x0530, 0x058F,
408
                         "ARMENIAN",
409
                         "Armenian");
Tom Tromey committed
410 411 412

    /**
     * Hebrew.
413
     * 0x0590 - 0x05FF.
Tom Tromey committed
414 415
     */
    public static final UnicodeBlock HEBREW
416
      = new UnicodeBlock(0x0590, 0x05FF,
417
                         "HEBREW",
418
                         "Hebrew");
Tom Tromey committed
419 420 421

    /**
     * Arabic.
422
     * 0x0600 - 0x06FF.
Tom Tromey committed
423 424
     */
    public static final UnicodeBlock ARABIC
425
      = new UnicodeBlock(0x0600, 0x06FF,
426
                         "ARABIC",
427
                         "Arabic");
Tom Tromey committed
428 429 430

    /**
     * Syriac.
431
     * 0x0700 - 0x074F.
Tom Tromey committed
432 433 434
     * @since 1.4
     */
    public static final UnicodeBlock SYRIAC
435
      = new UnicodeBlock(0x0700, 0x074F,
436
                         "SYRIAC",
437
                         "Syriac");
Tom Tromey committed
438 439 440

    /**
     * Thaana.
441
     * 0x0780 - 0x07BF.
Tom Tromey committed
442 443 444
     * @since 1.4
     */
    public static final UnicodeBlock THAANA
445
      = new UnicodeBlock(0x0780, 0x07BF,
446
                         "THAANA",
447
                         "Thaana");
Tom Tromey committed
448 449 450

    /**
     * Devanagari.
451
     * 0x0900 - 0x097F.
Tom Tromey committed
452 453
     */
    public static final UnicodeBlock DEVANAGARI
454
      = new UnicodeBlock(0x0900, 0x097F,
455
                         "DEVANAGARI",
456
                         "Devanagari");
Tom Tromey committed
457 458 459

    /**
     * Bengali.
460
     * 0x0980 - 0x09FF.
Tom Tromey committed
461 462
     */
    public static final UnicodeBlock BENGALI
463
      = new UnicodeBlock(0x0980, 0x09FF,
464
                         "BENGALI",
465
                         "Bengali");
Tom Tromey committed
466 467 468

    /**
     * Gurmukhi.
469
     * 0x0A00 - 0x0A7F.
Tom Tromey committed
470 471
     */
    public static final UnicodeBlock GURMUKHI
472
      = new UnicodeBlock(0x0A00, 0x0A7F,
473
                         "GURMUKHI",
474
                         "Gurmukhi");
Tom Tromey committed
475 476 477

    /**
     * Gujarati.
478
     * 0x0A80 - 0x0AFF.
Tom Tromey committed
479 480
     */
    public static final UnicodeBlock GUJARATI
481
      = new UnicodeBlock(0x0A80, 0x0AFF,
482
                         "GUJARATI",
483
                         "Gujarati");
Tom Tromey committed
484 485 486

    /**
     * Oriya.
487
     * 0x0B00 - 0x0B7F.
Tom Tromey committed
488 489
     */
    public static final UnicodeBlock ORIYA
490
      = new UnicodeBlock(0x0B00, 0x0B7F,
491
                         "ORIYA",
492
                         "Oriya");
Tom Tromey committed
493 494 495

    /**
     * Tamil.
496
     * 0x0B80 - 0x0BFF.
Tom Tromey committed
497 498
     */
    public static final UnicodeBlock TAMIL
499
      = new UnicodeBlock(0x0B80, 0x0BFF,
500
                         "TAMIL",
501
                         "Tamil");
Tom Tromey committed
502 503 504

    /**
     * Telugu.
505
     * 0x0C00 - 0x0C7F.
Tom Tromey committed
506 507
     */
    public static final UnicodeBlock TELUGU
508
      = new UnicodeBlock(0x0C00, 0x0C7F,
509
                         "TELUGU",
510
                         "Telugu");
Tom Tromey committed
511 512 513

    /**
     * Kannada.
514
     * 0x0C80 - 0x0CFF.
Tom Tromey committed
515 516
     */
    public static final UnicodeBlock KANNADA
517
      = new UnicodeBlock(0x0C80, 0x0CFF,
518
                         "KANNADA",
519
                         "Kannada");
Tom Tromey committed
520 521 522

    /**
     * Malayalam.
523
     * 0x0D00 - 0x0D7F.
Tom Tromey committed
524 525
     */
    public static final UnicodeBlock MALAYALAM
526
      = new UnicodeBlock(0x0D00, 0x0D7F,
527
                         "MALAYALAM",
528
                         "Malayalam");
Tom Tromey committed
529 530 531

    /**
     * Sinhala.
532
     * 0x0D80 - 0x0DFF.
Tom Tromey committed
533 534 535
     * @since 1.4
     */
    public static final UnicodeBlock SINHALA
536
      = new UnicodeBlock(0x0D80, 0x0DFF,
537
                         "SINHALA",
538
                         "Sinhala");
Tom Tromey committed
539 540 541

    /**
     * Thai.
542
     * 0x0E00 - 0x0E7F.
Tom Tromey committed
543 544
     */
    public static final UnicodeBlock THAI
545
      = new UnicodeBlock(0x0E00, 0x0E7F,
546
                         "THAI",
547
                         "Thai");
Tom Tromey committed
548 549 550

    /**
     * Lao.
551
     * 0x0E80 - 0x0EFF.
Tom Tromey committed
552 553
     */
    public static final UnicodeBlock LAO
554
      = new UnicodeBlock(0x0E80, 0x0EFF,
555
                         "LAO",
556
                         "Lao");
Tom Tromey committed
557 558 559

    /**
     * Tibetan.
560
     * 0x0F00 - 0x0FFF.
Tom Tromey committed
561 562
     */
    public static final UnicodeBlock TIBETAN
563
      = new UnicodeBlock(0x0F00, 0x0FFF,
564
                         "TIBETAN",
565
                         "Tibetan");
Tom Tromey committed
566 567 568

    /**
     * Myanmar.
569
     * 0x1000 - 0x109F.
Tom Tromey committed
570 571 572
     * @since 1.4
     */
    public static final UnicodeBlock MYANMAR
573
      = new UnicodeBlock(0x1000, 0x109F,
574
                         "MYANMAR",
575
                         "Myanmar");
Tom Tromey committed
576 577 578

    /**
     * Georgian.
579
     * 0x10A0 - 0x10FF.
Tom Tromey committed
580 581
     */
    public static final UnicodeBlock GEORGIAN
582
      = new UnicodeBlock(0x10A0, 0x10FF,
583
                         "GEORGIAN",
584
                         "Georgian");
Tom Tromey committed
585 586 587

    /**
     * Hangul Jamo.
588
     * 0x1100 - 0x11FF.
Tom Tromey committed
589 590
     */
    public static final UnicodeBlock HANGUL_JAMO
591
      = new UnicodeBlock(0x1100, 0x11FF,
592
                         "HANGUL_JAMO",
593
                         "Hangul Jamo");
Tom Tromey committed
594 595 596

    /**
     * Ethiopic.
597
     * 0x1200 - 0x137F.
Tom Tromey committed
598 599 600
     * @since 1.4
     */
    public static final UnicodeBlock ETHIOPIC
601
      = new UnicodeBlock(0x1200, 0x137F,
602
                         "ETHIOPIC",
603
                         "Ethiopic");
Tom Tromey committed
604 605 606

    /**
     * Cherokee.
607
     * 0x13A0 - 0x13FF.
Tom Tromey committed
608 609 610
     * @since 1.4
     */
    public static final UnicodeBlock CHEROKEE
611
      = new UnicodeBlock(0x13A0, 0x13FF,
612
                         "CHEROKEE",
613
                         "Cherokee");
Tom Tromey committed
614 615 616

    /**
     * Unified Canadian Aboriginal Syllabics.
617
     * 0x1400 - 0x167F.
Tom Tromey committed
618 619 620
     * @since 1.4
     */
    public static final UnicodeBlock UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS
621
      = new UnicodeBlock(0x1400, 0x167F,
622
                         "UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS",
623
                         "Unified Canadian Aboriginal Syllabics");
Tom Tromey committed
624 625 626

    /**
     * Ogham.
627
     * 0x1680 - 0x169F.
Tom Tromey committed
628 629 630
     * @since 1.4
     */
    public static final UnicodeBlock OGHAM
631
      = new UnicodeBlock(0x1680, 0x169F,
632
                         "OGHAM",
633
                         "Ogham");
Tom Tromey committed
634 635 636

    /**
     * Runic.
637
     * 0x16A0 - 0x16FF.
Tom Tromey committed
638 639 640
     * @since 1.4
     */
    public static final UnicodeBlock RUNIC
641
      = new UnicodeBlock(0x16A0, 0x16FF,
642
                         "RUNIC",
643 644 645 646 647 648 649 650 651
                         "Runic");

    /**
     * Tagalog.
     * 0x1700 - 0x171F.
     * @since 1.5
     */
    public static final UnicodeBlock TAGALOG
      = new UnicodeBlock(0x1700, 0x171F,
652
                         "TAGALOG",
653 654 655 656 657 658 659 660 661
                         "Tagalog");

    /**
     * Hanunoo.
     * 0x1720 - 0x173F.
     * @since 1.5
     */
    public static final UnicodeBlock HANUNOO
      = new UnicodeBlock(0x1720, 0x173F,
662
                         "HANUNOO",
663 664 665 666 667 668 669 670 671
                         "Hanunoo");

    /**
     * Buhid.
     * 0x1740 - 0x175F.
     * @since 1.5
     */
    public static final UnicodeBlock BUHID
      = new UnicodeBlock(0x1740, 0x175F,
672
                         "BUHID",
673 674 675 676 677 678 679 680 681
                         "Buhid");

    /**
     * Tagbanwa.
     * 0x1760 - 0x177F.
     * @since 1.5
     */
    public static final UnicodeBlock TAGBANWA
      = new UnicodeBlock(0x1760, 0x177F,
682
                         "TAGBANWA",
683
                         "Tagbanwa");
Tom Tromey committed
684 685 686

    /**
     * Khmer.
687
     * 0x1780 - 0x17FF.
Tom Tromey committed
688 689 690
     * @since 1.4
     */
    public static final UnicodeBlock KHMER
691
      = new UnicodeBlock(0x1780, 0x17FF,
692
                         "KHMER",
693
                         "Khmer");
Tom Tromey committed
694 695 696

    /**
     * Mongolian.
697
     * 0x1800 - 0x18AF.
Tom Tromey committed
698 699 700
     * @since 1.4
     */
    public static final UnicodeBlock MONGOLIAN
701
      = new UnicodeBlock(0x1800, 0x18AF,
702
                         "MONGOLIAN",
703 704 705 706 707 708 709 710 711
                         "Mongolian");

    /**
     * Limbu.
     * 0x1900 - 0x194F.
     * @since 1.5
     */
    public static final UnicodeBlock LIMBU
      = new UnicodeBlock(0x1900, 0x194F,
712
                         "LIMBU",
713 714 715 716 717 718 719 720 721
                         "Limbu");

    /**
     * Tai Le.
     * 0x1950 - 0x197F.
     * @since 1.5
     */
    public static final UnicodeBlock TAI_LE
      = new UnicodeBlock(0x1950, 0x197F,
722
                         "TAI_LE",
723 724 725 726 727 728 729 730 731
                         "Tai Le");

    /**
     * Khmer Symbols.
     * 0x19E0 - 0x19FF.
     * @since 1.5
     */
    public static final UnicodeBlock KHMER_SYMBOLS
      = new UnicodeBlock(0x19E0, 0x19FF,
732
                         "KHMER_SYMBOLS",
733 734 735 736 737 738 739 740 741
                         "Khmer Symbols");

    /**
     * Phonetic Extensions.
     * 0x1D00 - 0x1D7F.
     * @since 1.5
     */
    public static final UnicodeBlock PHONETIC_EXTENSIONS
      = new UnicodeBlock(0x1D00, 0x1D7F,
742
                         "PHONETIC_EXTENSIONS",
743
                         "Phonetic Extensions");
Tom Tromey committed
744 745 746

    /**
     * Latin Extended Additional.
747
     * 0x1E00 - 0x1EFF.
Tom Tromey committed
748 749
     */
    public static final UnicodeBlock LATIN_EXTENDED_ADDITIONAL
750
      = new UnicodeBlock(0x1E00, 0x1EFF,
751
                         "LATIN_EXTENDED_ADDITIONAL",
752
                         "Latin Extended Additional");
Tom Tromey committed
753 754 755

    /**
     * Greek Extended.
756
     * 0x1F00 - 0x1FFF.
Tom Tromey committed
757 758
     */
    public static final UnicodeBlock GREEK_EXTENDED
759
      = new UnicodeBlock(0x1F00, 0x1FFF,
760
                         "GREEK_EXTENDED",
761
                         "Greek Extended");
Tom Tromey committed
762 763 764

    /**
     * General Punctuation.
765
     * 0x2000 - 0x206F.
Tom Tromey committed
766 767
     */
    public static final UnicodeBlock GENERAL_PUNCTUATION
768
      = new UnicodeBlock(0x2000, 0x206F,
769
                         "GENERAL_PUNCTUATION",
770
                         "General Punctuation");
Tom Tromey committed
771 772 773

    /**
     * Superscripts and Subscripts.
774
     * 0x2070 - 0x209F.
Tom Tromey committed
775 776
     */
    public static final UnicodeBlock SUPERSCRIPTS_AND_SUBSCRIPTS
777
      = new UnicodeBlock(0x2070, 0x209F,
778
                         "SUPERSCRIPTS_AND_SUBSCRIPTS",
779
                         "Superscripts and Subscripts");
Tom Tromey committed
780 781 782

    /**
     * Currency Symbols.
783
     * 0x20A0 - 0x20CF.
Tom Tromey committed
784 785
     */
    public static final UnicodeBlock CURRENCY_SYMBOLS
786
      = new UnicodeBlock(0x20A0, 0x20CF,
787
                         "CURRENCY_SYMBOLS",
788
                         "Currency Symbols");
Tom Tromey committed
789 790 791

    /**
     * Combining Marks for Symbols.
792
     * 0x20D0 - 0x20FF.
Tom Tromey committed
793 794
     */
    public static final UnicodeBlock COMBINING_MARKS_FOR_SYMBOLS
795
      = new UnicodeBlock(0x20D0, 0x20FF,
796
                         "COMBINING_MARKS_FOR_SYMBOLS",
797
                         "Combining Marks for Symbols");
Tom Tromey committed
798 799 800

    /**
     * Letterlike Symbols.
801
     * 0x2100 - 0x214F.
Tom Tromey committed
802 803
     */
    public static final UnicodeBlock LETTERLIKE_SYMBOLS
804
      = new UnicodeBlock(0x2100, 0x214F,
805
                         "LETTERLIKE_SYMBOLS",
806
                         "Letterlike Symbols");
Tom Tromey committed
807 808 809

    /**
     * Number Forms.
810
     * 0x2150 - 0x218F.
Tom Tromey committed
811 812
     */
    public static final UnicodeBlock NUMBER_FORMS
813
      = new UnicodeBlock(0x2150, 0x218F,
814
                         "NUMBER_FORMS",
815
                         "Number Forms");
Tom Tromey committed
816 817 818

    /**
     * Arrows.
819
     * 0x2190 - 0x21FF.
Tom Tromey committed
820 821
     */
    public static final UnicodeBlock ARROWS
822
      = new UnicodeBlock(0x2190, 0x21FF,
823
                         "ARROWS",
824
                         "Arrows");
Tom Tromey committed
825 826 827

    /**
     * Mathematical Operators.
828
     * 0x2200 - 0x22FF.
Tom Tromey committed
829 830
     */
    public static final UnicodeBlock MATHEMATICAL_OPERATORS
831
      = new UnicodeBlock(0x2200, 0x22FF,
832
                         "MATHEMATICAL_OPERATORS",
833
                         "Mathematical Operators");
Tom Tromey committed
834 835 836

    /**
     * Miscellaneous Technical.
837
     * 0x2300 - 0x23FF.
Tom Tromey committed
838 839
     */
    public static final UnicodeBlock MISCELLANEOUS_TECHNICAL
840
      = new UnicodeBlock(0x2300, 0x23FF,
841
                         "MISCELLANEOUS_TECHNICAL",
842
                         "Miscellaneous Technical");
Tom Tromey committed
843 844 845

    /**
     * Control Pictures.
846
     * 0x2400 - 0x243F.
Tom Tromey committed
847 848
     */
    public static final UnicodeBlock CONTROL_PICTURES
849
      = new UnicodeBlock(0x2400, 0x243F,
850
                         "CONTROL_PICTURES",
851
                         "Control Pictures");
Tom Tromey committed
852 853 854

    /**
     * Optical Character Recognition.
855
     * 0x2440 - 0x245F.
Tom Tromey committed
856 857
     */
    public static final UnicodeBlock OPTICAL_CHARACTER_RECOGNITION
858
      = new UnicodeBlock(0x2440, 0x245F,
859
                         "OPTICAL_CHARACTER_RECOGNITION",
860
                         "Optical Character Recognition");
Tom Tromey committed
861 862 863

    /**
     * Enclosed Alphanumerics.
864
     * 0x2460 - 0x24FF.
Tom Tromey committed
865 866
     */
    public static final UnicodeBlock ENCLOSED_ALPHANUMERICS
867
      = new UnicodeBlock(0x2460, 0x24FF,
868
                         "ENCLOSED_ALPHANUMERICS",
869
                         "Enclosed Alphanumerics");
Tom Tromey committed
870 871 872

    /**
     * Box Drawing.
873
     * 0x2500 - 0x257F.
Tom Tromey committed
874 875
     */
    public static final UnicodeBlock BOX_DRAWING
876
      = new UnicodeBlock(0x2500, 0x257F,
877
                         "BOX_DRAWING",
878
                         "Box Drawing");
Tom Tromey committed
879 880 881

    /**
     * Block Elements.
882
     * 0x2580 - 0x259F.
Tom Tromey committed
883 884
     */
    public static final UnicodeBlock BLOCK_ELEMENTS
885
      = new UnicodeBlock(0x2580, 0x259F,
886
                         "BLOCK_ELEMENTS",
887
                         "Block Elements");
Tom Tromey committed
888 889 890

    /**
     * Geometric Shapes.
891
     * 0x25A0 - 0x25FF.
Tom Tromey committed
892 893
     */
    public static final UnicodeBlock GEOMETRIC_SHAPES
894
      = new UnicodeBlock(0x25A0, 0x25FF,
895
                         "GEOMETRIC_SHAPES",
896
                         "Geometric Shapes");
Tom Tromey committed
897 898 899

    /**
     * Miscellaneous Symbols.
900
     * 0x2600 - 0x26FF.
Tom Tromey committed
901 902
     */
    public static final UnicodeBlock MISCELLANEOUS_SYMBOLS
903
      = new UnicodeBlock(0x2600, 0x26FF,
904
                         "MISCELLANEOUS_SYMBOLS",
905
                         "Miscellaneous Symbols");
Tom Tromey committed
906 907 908

    /**
     * Dingbats.
909
     * 0x2700 - 0x27BF.
Tom Tromey committed
910 911
     */
    public static final UnicodeBlock DINGBATS
912
      = new UnicodeBlock(0x2700, 0x27BF,
913
                         "DINGBATS",
914 915 916 917 918 919 920 921 922
                         "Dingbats");

    /**
     * Miscellaneous Mathematical Symbols-A.
     * 0x27C0 - 0x27EF.
     * @since 1.5
     */
    public static final UnicodeBlock MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A
      = new UnicodeBlock(0x27C0, 0x27EF,
923
                         "MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A",
924 925 926 927 928 929 930 931 932
                         "Miscellaneous Mathematical Symbols-A");

    /**
     * Supplemental Arrows-A.
     * 0x27F0 - 0x27FF.
     * @since 1.5
     */
    public static final UnicodeBlock SUPPLEMENTAL_ARROWS_A
      = new UnicodeBlock(0x27F0, 0x27FF,
933
                         "SUPPLEMENTAL_ARROWS_A",
934
                         "Supplemental Arrows-A");
Tom Tromey committed
935 936 937

    /**
     * Braille Patterns.
938
     * 0x2800 - 0x28FF.
Tom Tromey committed
939 940 941
     * @since 1.4
     */
    public static final UnicodeBlock BRAILLE_PATTERNS
942
      = new UnicodeBlock(0x2800, 0x28FF,
943
                         "BRAILLE_PATTERNS",
944 945 946 947 948 949 950 951 952
                         "Braille Patterns");

    /**
     * Supplemental Arrows-B.
     * 0x2900 - 0x297F.
     * @since 1.5
     */
    public static final UnicodeBlock SUPPLEMENTAL_ARROWS_B
      = new UnicodeBlock(0x2900, 0x297F,
953
                         "SUPPLEMENTAL_ARROWS_B",
954 955 956 957 958 959 960 961 962
                         "Supplemental Arrows-B");

    /**
     * Miscellaneous Mathematical Symbols-B.
     * 0x2980 - 0x29FF.
     * @since 1.5
     */
    public static final UnicodeBlock MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B
      = new UnicodeBlock(0x2980, 0x29FF,
963
                         "MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B",
964 965 966 967 968 969 970 971 972
                         "Miscellaneous Mathematical Symbols-B");

    /**
     * Supplemental Mathematical Operators.
     * 0x2A00 - 0x2AFF.
     * @since 1.5
     */
    public static final UnicodeBlock SUPPLEMENTAL_MATHEMATICAL_OPERATORS
      = new UnicodeBlock(0x2A00, 0x2AFF,
973
                         "SUPPLEMENTAL_MATHEMATICAL_OPERATORS",
974 975 976 977 978 979 980 981 982
                         "Supplemental Mathematical Operators");

    /**
     * Miscellaneous Symbols and Arrows.
     * 0x2B00 - 0x2BFF.
     * @since 1.5
     */
    public static final UnicodeBlock MISCELLANEOUS_SYMBOLS_AND_ARROWS
      = new UnicodeBlock(0x2B00, 0x2BFF,
983
                         "MISCELLANEOUS_SYMBOLS_AND_ARROWS",
984
                         "Miscellaneous Symbols and Arrows");
Tom Tromey committed
985 986 987

    /**
     * CJK Radicals Supplement.
988
     * 0x2E80 - 0x2EFF.
Tom Tromey committed
989 990 991
     * @since 1.4
     */
    public static final UnicodeBlock CJK_RADICALS_SUPPLEMENT
992
      = new UnicodeBlock(0x2E80, 0x2EFF,
993
                         "CJK_RADICALS_SUPPLEMENT",
994
                         "CJK Radicals Supplement");
Tom Tromey committed
995 996 997

    /**
     * Kangxi Radicals.
998
     * 0x2F00 - 0x2FDF.
Tom Tromey committed
999 1000 1001
     * @since 1.4
     */
    public static final UnicodeBlock KANGXI_RADICALS
1002
      = new UnicodeBlock(0x2F00, 0x2FDF,
1003
                         "KANGXI_RADICALS",
1004
                         "Kangxi Radicals");
Tom Tromey committed
1005 1006 1007

    /**
     * Ideographic Description Characters.
1008
     * 0x2FF0 - 0x2FFF.
Tom Tromey committed
1009 1010 1011
     * @since 1.4
     */
    public static final UnicodeBlock IDEOGRAPHIC_DESCRIPTION_CHARACTERS
1012
      = new UnicodeBlock(0x2FF0, 0x2FFF,
1013
                         "IDEOGRAPHIC_DESCRIPTION_CHARACTERS",
1014
                         "Ideographic Description Characters");
Tom Tromey committed
1015 1016 1017

    /**
     * CJK Symbols and Punctuation.
1018
     * 0x3000 - 0x303F.
Tom Tromey committed
1019 1020
     */
    public static final UnicodeBlock CJK_SYMBOLS_AND_PUNCTUATION
1021
      = new UnicodeBlock(0x3000, 0x303F,
1022
                         "CJK_SYMBOLS_AND_PUNCTUATION",
1023
                         "CJK Symbols and Punctuation");
Tom Tromey committed
1024 1025 1026

    /**
     * Hiragana.
1027
     * 0x3040 - 0x309F.
Tom Tromey committed
1028 1029
     */
    public static final UnicodeBlock HIRAGANA
1030
      = new UnicodeBlock(0x3040, 0x309F,
1031
                         "HIRAGANA",
1032
                         "Hiragana");
Tom Tromey committed
1033 1034 1035

    /**
     * Katakana.
1036
     * 0x30A0 - 0x30FF.
Tom Tromey committed
1037 1038
     */
    public static final UnicodeBlock KATAKANA
1039
      = new UnicodeBlock(0x30A0, 0x30FF,
1040
                         "KATAKANA",
1041
                         "Katakana");
Tom Tromey committed
1042 1043 1044

    /**
     * Bopomofo.
1045
     * 0x3100 - 0x312F.
Tom Tromey committed
1046 1047
     */
    public static final UnicodeBlock BOPOMOFO
1048
      = new UnicodeBlock(0x3100, 0x312F,
1049
                         "BOPOMOFO",
1050
                         "Bopomofo");
Tom Tromey committed
1051 1052 1053

    /**
     * Hangul Compatibility Jamo.
1054
     * 0x3130 - 0x318F.
Tom Tromey committed
1055 1056
     */
    public static final UnicodeBlock HANGUL_COMPATIBILITY_JAMO
1057
      = new UnicodeBlock(0x3130, 0x318F,
1058
                         "HANGUL_COMPATIBILITY_JAMO",
1059
                         "Hangul Compatibility Jamo");
Tom Tromey committed
1060 1061 1062

    /**
     * Kanbun.
1063
     * 0x3190 - 0x319F.
Tom Tromey committed
1064 1065
     */
    public static final UnicodeBlock KANBUN
1066
      = new UnicodeBlock(0x3190, 0x319F,
1067
                         "KANBUN",
1068
                         "Kanbun");
Tom Tromey committed
1069 1070 1071

    /**
     * Bopomofo Extended.
1072
     * 0x31A0 - 0x31BF.
Tom Tromey committed
1073 1074 1075
     * @since 1.4
     */
    public static final UnicodeBlock BOPOMOFO_EXTENDED
1076
      = new UnicodeBlock(0x31A0, 0x31BF,
1077
                         "BOPOMOFO_EXTENDED",
1078 1079 1080 1081 1082 1083 1084 1085 1086
                         "Bopomofo Extended");

    /**
     * Katakana Phonetic Extensions.
     * 0x31F0 - 0x31FF.
     * @since 1.5
     */
    public static final UnicodeBlock KATAKANA_PHONETIC_EXTENSIONS
      = new UnicodeBlock(0x31F0, 0x31FF,
1087
                         "KATAKANA_PHONETIC_EXTENSIONS",
1088
                         "Katakana Phonetic Extensions");
Tom Tromey committed
1089 1090 1091

    /**
     * Enclosed CJK Letters and Months.
1092
     * 0x3200 - 0x32FF.
Tom Tromey committed
1093 1094
     */
    public static final UnicodeBlock ENCLOSED_CJK_LETTERS_AND_MONTHS
1095
      = new UnicodeBlock(0x3200, 0x32FF,
1096
                         "ENCLOSED_CJK_LETTERS_AND_MONTHS",
1097
                         "Enclosed CJK Letters and Months");
Tom Tromey committed
1098 1099 1100

    /**
     * CJK Compatibility.
1101
     * 0x3300 - 0x33FF.
Tom Tromey committed
1102 1103
     */
    public static final UnicodeBlock CJK_COMPATIBILITY
1104
      = new UnicodeBlock(0x3300, 0x33FF,
1105
                         "CJK_COMPATIBILITY",
1106
                         "CJK Compatibility");
Tom Tromey committed
1107 1108 1109

    /**
     * CJK Unified Ideographs Extension A.
1110
     * 0x3400 - 0x4DBF.
Tom Tromey committed
1111 1112 1113
     * @since 1.4
     */
    public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
1114
      = new UnicodeBlock(0x3400, 0x4DBF,
1115
                         "CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A",
1116 1117 1118 1119 1120 1121 1122 1123 1124
                         "CJK Unified Ideographs Extension A");

    /**
     * Yijing Hexagram Symbols.
     * 0x4DC0 - 0x4DFF.
     * @since 1.5
     */
    public static final UnicodeBlock YIJING_HEXAGRAM_SYMBOLS
      = new UnicodeBlock(0x4DC0, 0x4DFF,
1125
                         "YIJING_HEXAGRAM_SYMBOLS",
1126
                         "Yijing Hexagram Symbols");
Tom Tromey committed
1127 1128 1129

    /**
     * CJK Unified Ideographs.
1130
     * 0x4E00 - 0x9FFF.
Tom Tromey committed
1131 1132
     */
    public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS
1133
      = new UnicodeBlock(0x4E00, 0x9FFF,
1134
                         "CJK_UNIFIED_IDEOGRAPHS",
1135
                         "CJK Unified Ideographs");
Tom Tromey committed
1136 1137 1138

    /**
     * Yi Syllables.
1139
     * 0xA000 - 0xA48F.
Tom Tromey committed
1140 1141 1142
     * @since 1.4
     */
    public static final UnicodeBlock YI_SYLLABLES
1143
      = new UnicodeBlock(0xA000, 0xA48F,
1144
                         "YI_SYLLABLES",
1145
                         "Yi Syllables");
Tom Tromey committed
1146 1147 1148

    /**
     * Yi Radicals.
1149
     * 0xA490 - 0xA4CF.
Tom Tromey committed
1150 1151 1152
     * @since 1.4
     */
    public static final UnicodeBlock YI_RADICALS
1153
      = new UnicodeBlock(0xA490, 0xA4CF,
1154
                         "YI_RADICALS",
1155
                         "Yi Radicals");
Tom Tromey committed
1156 1157 1158

    /**
     * Hangul Syllables.
1159
     * 0xAC00 - 0xD7AF.
Tom Tromey committed
1160 1161
     */
    public static final UnicodeBlock HANGUL_SYLLABLES
1162
      = new UnicodeBlock(0xAC00, 0xD7AF,
1163
                         "HANGUL_SYLLABLES",
1164
                         "Hangul Syllables");
Tom Tromey committed
1165 1166

    /**
1167 1168 1169
     * High Surrogates.
     * 0xD800 - 0xDB7F.
     * @since 1.5
Tom Tromey committed
1170
     */
1171 1172
    public static final UnicodeBlock HIGH_SURROGATES
      = new UnicodeBlock(0xD800, 0xDB7F,
1173
                         "HIGH_SURROGATES",
1174 1175 1176 1177 1178 1179 1180 1181 1182
                         "High Surrogates");

    /**
     * High Private Use Surrogates.
     * 0xDB80 - 0xDBFF.
     * @since 1.5
     */
    public static final UnicodeBlock HIGH_PRIVATE_USE_SURROGATES
      = new UnicodeBlock(0xDB80, 0xDBFF,
1183
                         "HIGH_PRIVATE_USE_SURROGATES",
1184 1185 1186 1187 1188 1189 1190 1191 1192
                         "High Private Use Surrogates");

    /**
     * Low Surrogates.
     * 0xDC00 - 0xDFFF.
     * @since 1.5
     */
    public static final UnicodeBlock LOW_SURROGATES
      = new UnicodeBlock(0xDC00, 0xDFFF,
1193
                         "LOW_SURROGATES",
1194
                         "Low Surrogates");
Tom Tromey committed
1195 1196 1197

    /**
     * Private Use Area.
1198
     * 0xE000 - 0xF8FF.
Tom Tromey committed
1199 1200
     */
    public static final UnicodeBlock PRIVATE_USE_AREA
1201
      = new UnicodeBlock(0xE000, 0xF8FF,
1202
                         "PRIVATE_USE_AREA",
1203
                         "Private Use Area");
Tom Tromey committed
1204 1205 1206

    /**
     * CJK Compatibility Ideographs.
1207
     * 0xF900 - 0xFAFF.
Tom Tromey committed
1208 1209
     */
    public static final UnicodeBlock CJK_COMPATIBILITY_IDEOGRAPHS
1210
      = new UnicodeBlock(0xF900, 0xFAFF,
1211
                         "CJK_COMPATIBILITY_IDEOGRAPHS",
1212
                         "CJK Compatibility Ideographs");
Tom Tromey committed
1213 1214 1215

    /**
     * Alphabetic Presentation Forms.
1216
     * 0xFB00 - 0xFB4F.
Tom Tromey committed
1217 1218
     */
    public static final UnicodeBlock ALPHABETIC_PRESENTATION_FORMS
1219
      = new UnicodeBlock(0xFB00, 0xFB4F,
1220
                         "ALPHABETIC_PRESENTATION_FORMS",
1221
                         "Alphabetic Presentation Forms");
Tom Tromey committed
1222 1223 1224

    /**
     * Arabic Presentation Forms-A.
1225
     * 0xFB50 - 0xFDFF.
Tom Tromey committed
1226 1227
     */
    public static final UnicodeBlock ARABIC_PRESENTATION_FORMS_A
1228
      = new UnicodeBlock(0xFB50, 0xFDFF,
1229
                         "ARABIC_PRESENTATION_FORMS_A",
1230 1231 1232 1233 1234 1235 1236 1237 1238
                         "Arabic Presentation Forms-A");

    /**
     * Variation Selectors.
     * 0xFE00 - 0xFE0F.
     * @since 1.5
     */
    public static final UnicodeBlock VARIATION_SELECTORS
      = new UnicodeBlock(0xFE00, 0xFE0F,
1239
                         "VARIATION_SELECTORS",
1240
                         "Variation Selectors");
Tom Tromey committed
1241 1242 1243

    /**
     * Combining Half Marks.
1244
     * 0xFE20 - 0xFE2F.
Tom Tromey committed
1245 1246
     */
    public static final UnicodeBlock COMBINING_HALF_MARKS
1247
      = new UnicodeBlock(0xFE20, 0xFE2F,
1248
                         "COMBINING_HALF_MARKS",
1249
                         "Combining Half Marks");
Tom Tromey committed
1250 1251 1252

    /**
     * CJK Compatibility Forms.
1253
     * 0xFE30 - 0xFE4F.
Tom Tromey committed
1254 1255
     */
    public static final UnicodeBlock CJK_COMPATIBILITY_FORMS
1256
      = new UnicodeBlock(0xFE30, 0xFE4F,
1257
                         "CJK_COMPATIBILITY_FORMS",
1258
                         "CJK Compatibility Forms");
Tom Tromey committed
1259 1260 1261

    /**
     * Small Form Variants.
1262
     * 0xFE50 - 0xFE6F.
Tom Tromey committed
1263 1264
     */
    public static final UnicodeBlock SMALL_FORM_VARIANTS
1265
      = new UnicodeBlock(0xFE50, 0xFE6F,
1266
                         "SMALL_FORM_VARIANTS",
1267
                         "Small Form Variants");
Tom Tromey committed
1268 1269 1270

    /**
     * Arabic Presentation Forms-B.
1271
     * 0xFE70 - 0xFEFF.
Tom Tromey committed
1272 1273
     */
    public static final UnicodeBlock ARABIC_PRESENTATION_FORMS_B
1274
      = new UnicodeBlock(0xFE70, 0xFEFF,
1275
                         "ARABIC_PRESENTATION_FORMS_B",
1276
                         "Arabic Presentation Forms-B");
Tom Tromey committed
1277 1278 1279

    /**
     * Halfwidth and Fullwidth Forms.
1280
     * 0xFF00 - 0xFFEF.
Tom Tromey committed
1281 1282
     */
    public static final UnicodeBlock HALFWIDTH_AND_FULLWIDTH_FORMS
1283
      = new UnicodeBlock(0xFF00, 0xFFEF,
1284
                         "HALFWIDTH_AND_FULLWIDTH_FORMS",
1285
                         "Halfwidth and Fullwidth Forms");
Tom Tromey committed
1286 1287 1288

    /**
     * Specials.
1289
     * 0xFFF0 - 0xFFFF.
Tom Tromey committed
1290 1291
     */
    public static final UnicodeBlock SPECIALS
1292
      = new UnicodeBlock(0xFFF0, 0xFFFF,
1293
                         "SPECIALS",
1294 1295 1296 1297 1298 1299 1300 1301 1302
                         "Specials");

    /**
     * Linear B Syllabary.
     * 0x10000 - 0x1007F.
     * @since 1.5
     */
    public static final UnicodeBlock LINEAR_B_SYLLABARY
      = new UnicodeBlock(0x10000, 0x1007F,
1303
                         "LINEAR_B_SYLLABARY",
1304 1305 1306 1307 1308 1309 1310 1311 1312
                         "Linear B Syllabary");

    /**
     * Linear B Ideograms.
     * 0x10080 - 0x100FF.
     * @since 1.5
     */
    public static final UnicodeBlock LINEAR_B_IDEOGRAMS
      = new UnicodeBlock(0x10080, 0x100FF,
1313
                         "LINEAR_B_IDEOGRAMS",
1314 1315 1316 1317 1318 1319 1320 1321 1322
                         "Linear B Ideograms");

    /**
     * Aegean Numbers.
     * 0x10100 - 0x1013F.
     * @since 1.5
     */
    public static final UnicodeBlock AEGEAN_NUMBERS
      = new UnicodeBlock(0x10100, 0x1013F,
1323
                         "AEGEAN_NUMBERS",
1324 1325 1326 1327 1328 1329 1330 1331 1332
                         "Aegean Numbers");

    /**
     * Old Italic.
     * 0x10300 - 0x1032F.
     * @since 1.5
     */
    public static final UnicodeBlock OLD_ITALIC
      = new UnicodeBlock(0x10300, 0x1032F,
1333
                         "OLD_ITALIC",
1334 1335 1336 1337 1338 1339 1340 1341 1342
                         "Old Italic");

    /**
     * Gothic.
     * 0x10330 - 0x1034F.
     * @since 1.5
     */
    public static final UnicodeBlock GOTHIC
      = new UnicodeBlock(0x10330, 0x1034F,
1343
                         "GOTHIC",
1344 1345 1346 1347 1348 1349 1350 1351 1352
                         "Gothic");

    /**
     * Ugaritic.
     * 0x10380 - 0x1039F.
     * @since 1.5
     */
    public static final UnicodeBlock UGARITIC
      = new UnicodeBlock(0x10380, 0x1039F,
1353
                         "UGARITIC",
1354 1355 1356 1357 1358 1359 1360 1361 1362
                         "Ugaritic");

    /**
     * Deseret.
     * 0x10400 - 0x1044F.
     * @since 1.5
     */
    public static final UnicodeBlock DESERET
      = new UnicodeBlock(0x10400, 0x1044F,
1363
                         "DESERET",
1364 1365 1366 1367 1368 1369 1370 1371 1372
                         "Deseret");

    /**
     * Shavian.
     * 0x10450 - 0x1047F.
     * @since 1.5
     */
    public static final UnicodeBlock SHAVIAN
      = new UnicodeBlock(0x10450, 0x1047F,
1373
                         "SHAVIAN",
1374 1375 1376 1377 1378 1379 1380 1381 1382
                         "Shavian");

    /**
     * Osmanya.
     * 0x10480 - 0x104AF.
     * @since 1.5
     */
    public static final UnicodeBlock OSMANYA
      = new UnicodeBlock(0x10480, 0x104AF,
1383
                         "OSMANYA",
1384 1385 1386 1387 1388 1389 1390 1391 1392
                         "Osmanya");

    /**
     * Cypriot Syllabary.
     * 0x10800 - 0x1083F.
     * @since 1.5
     */
    public static final UnicodeBlock CYPRIOT_SYLLABARY
      = new UnicodeBlock(0x10800, 0x1083F,
1393
                         "CYPRIOT_SYLLABARY",
1394 1395 1396 1397 1398 1399 1400 1401 1402
                         "Cypriot Syllabary");

    /**
     * Byzantine Musical Symbols.
     * 0x1D000 - 0x1D0FF.
     * @since 1.5
     */
    public static final UnicodeBlock BYZANTINE_MUSICAL_SYMBOLS
      = new UnicodeBlock(0x1D000, 0x1D0FF,
1403
                         "BYZANTINE_MUSICAL_SYMBOLS",
1404 1405 1406 1407 1408 1409 1410 1411 1412
                         "Byzantine Musical Symbols");

    /**
     * Musical Symbols.
     * 0x1D100 - 0x1D1FF.
     * @since 1.5
     */
    public static final UnicodeBlock MUSICAL_SYMBOLS
      = new UnicodeBlock(0x1D100, 0x1D1FF,
1413
                         "MUSICAL_SYMBOLS",
1414 1415 1416 1417 1418 1419 1420 1421 1422
                         "Musical Symbols");

    /**
     * Tai Xuan Jing Symbols.
     * 0x1D300 - 0x1D35F.
     * @since 1.5
     */
    public static final UnicodeBlock TAI_XUAN_JING_SYMBOLS
      = new UnicodeBlock(0x1D300, 0x1D35F,
1423
                         "TAI_XUAN_JING_SYMBOLS",
1424 1425 1426 1427 1428 1429 1430 1431 1432
                         "Tai Xuan Jing Symbols");

    /**
     * Mathematical Alphanumeric Symbols.
     * 0x1D400 - 0x1D7FF.
     * @since 1.5
     */
    public static final UnicodeBlock MATHEMATICAL_ALPHANUMERIC_SYMBOLS
      = new UnicodeBlock(0x1D400, 0x1D7FF,
1433
                         "MATHEMATICAL_ALPHANUMERIC_SYMBOLS",
1434 1435 1436 1437 1438 1439 1440 1441 1442
                         "Mathematical Alphanumeric Symbols");

    /**
     * CJK Unified Ideographs Extension B.
     * 0x20000 - 0x2A6DF.
     * @since 1.5
     */
    public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
      = new UnicodeBlock(0x20000, 0x2A6DF,
1443
                         "CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B",
1444 1445 1446 1447 1448 1449 1450 1451 1452
                         "CJK Unified Ideographs Extension B");

    /**
     * CJK Compatibility Ideographs Supplement.
     * 0x2F800 - 0x2FA1F.
     * @since 1.5
     */
    public static final UnicodeBlock CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT
      = new UnicodeBlock(0x2F800, 0x2FA1F,
1453
                         "CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT",
1454 1455 1456 1457 1458 1459 1460 1461 1462
                         "CJK Compatibility Ideographs Supplement");

    /**
     * Tags.
     * 0xE0000 - 0xE007F.
     * @since 1.5
     */
    public static final UnicodeBlock TAGS
      = new UnicodeBlock(0xE0000, 0xE007F,
1463
                         "TAGS",
1464 1465 1466 1467 1468 1469 1470 1471 1472
                         "Tags");

    /**
     * Variation Selectors Supplement.
     * 0xE0100 - 0xE01EF.
     * @since 1.5
     */
    public static final UnicodeBlock VARIATION_SELECTORS_SUPPLEMENT
      = new UnicodeBlock(0xE0100, 0xE01EF,
1473
                         "VARIATION_SELECTORS_SUPPLEMENT",
1474 1475 1476 1477 1478 1479 1480 1481 1482
                         "Variation Selectors Supplement");

    /**
     * Supplementary Private Use Area-A.
     * 0xF0000 - 0xFFFFF.
     * @since 1.5
     */
    public static final UnicodeBlock SUPPLEMENTARY_PRIVATE_USE_AREA_A
      = new UnicodeBlock(0xF0000, 0xFFFFF,
1483
                         "SUPPLEMENTARY_PRIVATE_USE_AREA_A",
1484 1485 1486 1487 1488 1489 1490 1491 1492
                         "Supplementary Private Use Area-A");

    /**
     * Supplementary Private Use Area-B.
     * 0x100000 - 0x10FFFF.
     * @since 1.5
     */
    public static final UnicodeBlock SUPPLEMENTARY_PRIVATE_USE_AREA_B
      = new UnicodeBlock(0x100000, 0x10FFFF,
1493
                         "SUPPLEMENTARY_PRIVATE_USE_AREA_B",
1494 1495 1496 1497 1498
                         "Supplementary Private Use Area-B");

    /**
     * Surrogates Area.
     * 'D800' - 'DFFF'.
1499
     * @deprecated As of 1.5, the three areas,
1500 1501 1502 1503 1504 1505 1506
     * <a href="#HIGH_SURROGATES">HIGH_SURROGATES</a>,
     * <a href="#HIGH_PRIVATE_USE_SURROGATES">HIGH_PRIVATE_USE_SURROGATES</a>
     * and <a href="#LOW_SURROGATES">LOW_SURROGATES</a>, as defined
     * by the Unicode standard, should be used in preference to
     * this.  These are also returned from calls to <code>of(int)</code>
     * and <code>of(char)</code>.
     */
1507
    @Deprecated
1508 1509 1510
    public static final UnicodeBlock SURROGATES_AREA
      = new UnicodeBlock(0xD800, 0xDFFF,
                         "SURROGATES_AREA",
1511
                         "Surrogates Area");
Tom Tromey committed
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525

    /**
     * The defined subsets.
     */
    private static final UnicodeBlock sets[] = {
      BASIC_LATIN,
      LATIN_1_SUPPLEMENT,
      LATIN_EXTENDED_A,
      LATIN_EXTENDED_B,
      IPA_EXTENSIONS,
      SPACING_MODIFIER_LETTERS,
      COMBINING_DIACRITICAL_MARKS,
      GREEK,
      CYRILLIC,
1526
      CYRILLIC_SUPPLEMENTARY,
Tom Tromey committed
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
      ARMENIAN,
      HEBREW,
      ARABIC,
      SYRIAC,
      THAANA,
      DEVANAGARI,
      BENGALI,
      GURMUKHI,
      GUJARATI,
      ORIYA,
      TAMIL,
      TELUGU,
      KANNADA,
      MALAYALAM,
      SINHALA,
      THAI,
      LAO,
      TIBETAN,
      MYANMAR,
      GEORGIAN,
      HANGUL_JAMO,
      ETHIOPIC,
      CHEROKEE,
      UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS,
      OGHAM,
      RUNIC,
1553 1554 1555 1556
      TAGALOG,
      HANUNOO,
      BUHID,
      TAGBANWA,
Tom Tromey committed
1557 1558
      KHMER,
      MONGOLIAN,
1559 1560 1561 1562
      LIMBU,
      TAI_LE,
      KHMER_SYMBOLS,
      PHONETIC_EXTENSIONS,
Tom Tromey committed
1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581
      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,
1582 1583
      MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A,
      SUPPLEMENTAL_ARROWS_A,
Tom Tromey committed
1584
      BRAILLE_PATTERNS,
1585 1586 1587 1588
      SUPPLEMENTAL_ARROWS_B,
      MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B,
      SUPPLEMENTAL_MATHEMATICAL_OPERATORS,
      MISCELLANEOUS_SYMBOLS_AND_ARROWS,
Tom Tromey committed
1589 1590 1591 1592 1593 1594 1595 1596 1597 1598
      CJK_RADICALS_SUPPLEMENT,
      KANGXI_RADICALS,
      IDEOGRAPHIC_DESCRIPTION_CHARACTERS,
      CJK_SYMBOLS_AND_PUNCTUATION,
      HIRAGANA,
      KATAKANA,
      BOPOMOFO,
      HANGUL_COMPATIBILITY_JAMO,
      KANBUN,
      BOPOMOFO_EXTENDED,
1599
      KATAKANA_PHONETIC_EXTENSIONS,
Tom Tromey committed
1600 1601 1602
      ENCLOSED_CJK_LETTERS_AND_MONTHS,
      CJK_COMPATIBILITY,
      CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A,
1603
      YIJING_HEXAGRAM_SYMBOLS,
Tom Tromey committed
1604 1605 1606 1607
      CJK_UNIFIED_IDEOGRAPHS,
      YI_SYLLABLES,
      YI_RADICALS,
      HANGUL_SYLLABLES,
1608 1609 1610
      HIGH_SURROGATES,
      HIGH_PRIVATE_USE_SURROGATES,
      LOW_SURROGATES,
Tom Tromey committed
1611 1612 1613 1614
      PRIVATE_USE_AREA,
      CJK_COMPATIBILITY_IDEOGRAPHS,
      ALPHABETIC_PRESENTATION_FORMS,
      ARABIC_PRESENTATION_FORMS_A,
1615
      VARIATION_SELECTORS,
Tom Tromey committed
1616 1617 1618 1619 1620 1621
      COMBINING_HALF_MARKS,
      CJK_COMPATIBILITY_FORMS,
      SMALL_FORM_VARIANTS,
      ARABIC_PRESENTATION_FORMS_B,
      HALFWIDTH_AND_FULLWIDTH_FORMS,
      SPECIALS,
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
      LINEAR_B_SYLLABARY,
      LINEAR_B_IDEOGRAMS,
      AEGEAN_NUMBERS,
      OLD_ITALIC,
      GOTHIC,
      UGARITIC,
      DESERET,
      SHAVIAN,
      OSMANYA,
      CYPRIOT_SYLLABARY,
      BYZANTINE_MUSICAL_SYMBOLS,
      MUSICAL_SYMBOLS,
      TAI_XUAN_JING_SYMBOLS,
      MATHEMATICAL_ALPHANUMERIC_SYMBOLS,
      CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B,
      CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT,
      TAGS,
      VARIATION_SELECTORS_SUPPLEMENT,
      SUPPLEMENTARY_PRIVATE_USE_AREA_A,
      SUPPLEMENTARY_PRIVATE_USE_AREA_B,
Tom Tromey committed
1642 1643 1644 1645
    };
  } // class UnicodeBlock

  /**
1646
   * A class to encompass all the properties of characters in the
1647
   * private use blocks in the Unicode standard.  This class extends
1648
   * UnassignedCharacters because the return type from getType() is
1649 1650
   * different.
   * @author Anthony Balkissoon abalkiss at redhat dot com
Tom Tromey committed
1651 1652
   *
   */
1653 1654 1655 1656 1657 1658 1659
  private static class PrivateUseCharacters extends UnassignedCharacters
  {
    /**
     * Returns the type of the character cp.
     */
    static int getType(int cp)
    {
1660
      // The upper 2 code points in any plane are considered unassigned,
1661 1662 1663 1664 1665
      // even in the private-use planes.
      if ((cp & 0xffff) >= 0xfffe)
        return UnassignedCharacters.getType(cp);
      return PRIVATE_USE;
    }
1666

1667 1668 1669 1670 1671
    /**
     * Returns true if the character cp is defined.
     */
    static boolean isDefined(int cp)
    {
1672
      // The upper 2 code points in any plane are considered unassigned,
1673 1674 1675 1676 1677
      // even in the private-use planes.
      if ((cp & 0xffff) >= 0xfffe)
        return UnassignedCharacters.isDefined(cp);
      return true;
    }
1678

1679 1680 1681 1682 1683 1684 1685 1686 1687 1688
    /**
     * Gets the directionality for the character cp.
     */
    static byte getDirectionality(int cp)
    {
      if ((cp & 0xffff) >= 0xfffe)
        return UnassignedCharacters.getDirectionality(cp);
      return DIRECTIONALITY_LEFT_TO_RIGHT;
    }
  }
1689

Tom Tromey committed
1690
  /**
1691
   * A class to encompass all the properties of code points that are
1692 1693
   * currently undefined in the Unicode standard.
   * @author Anthony Balkissoon abalkiss at redhat dot com
Tom Tromey committed
1694 1695
   *
   */
1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
  private static class UnassignedCharacters
  {
    /**
     * Returns the numeric value for the unassigned characters.
     * @param cp the character
     * @param radix the radix (not used)
     * @return the numeric value of this character in this radix
     */
    static int digit(int cp, int radix)
    {
      return -1;
    }
Tom Tromey committed
1708

1709
    /**
1710
     * Returns the Unicode directionality property for unassigned
1711 1712 1713 1714 1715 1716 1717 1718
     * characters.
     * @param cp the character
     * @return DIRECTIONALITY_UNDEFINED
     */
    static byte getDirectionality(int cp)
    {
      return DIRECTIONALITY_UNDEFINED;
    }
Tom Tromey committed
1719

1720 1721 1722 1723 1724 1725 1726 1727 1728
    /**
     * Returns -1, the numeric value for unassigned Unicode characters.
     * @param cp the character
     * @return -1
     */
    static int getNumericValue(int cp)
    {
      return -1;
    }
Tom Tromey committed
1729

1730 1731 1732 1733 1734 1735 1736 1737 1738
    /**
     * Returns UNASSIGNED, the type of unassigned Unicode characters.
     * @param cp the character
     * @return UNASSIGNED
     */
    static int getType(int cp)
    {
      return UNASSIGNED;
    }
1739

1740
    /**
1741
     * Returns false to indiciate that the character is not defined in the
1742 1743 1744 1745 1746 1747 1748 1749
     * Unicode standard.
     * @param cp the character
     * @return false
     */
    static boolean isDefined(int cp)
    {
      return false;
    }
Tom Tromey committed
1750

1751 1752 1753 1754 1755 1756 1757 1758 1759
    /**
     * Returns false to indicate that the character is not a digit.
     * @param cp the character
     * @return false
     */
    static boolean isDigit(int cp)
    {
      return false;
    }
Tom Tromey committed
1760

1761
    /**
1762
     * Returns false to indicate that the character cannot be ignored
1763 1764 1765 1766 1767 1768 1769 1770
     * within an identifier
     * @param cp the character
     * @return false
     */
    static boolean isIdentifierIgnorable(int cp)
    {
      return false;
    }
1771

1772
    /**
1773
     * Returns false to indicate that the character cannot be part of a
1774 1775 1776 1777 1778 1779 1780 1781
     * Java identifier.
     * @param cp the character
     * @return false
     */
    static boolean isJavaIdentifierPart(int cp)
    {
      return false;
    }
1782

1783
    /**
1784
     * Returns false to indicate that the character cannot be start a
1785 1786 1787 1788 1789 1790 1791 1792
     * Java identifier.
     * @param cp the character
     * @return false
     */
    static boolean isJavaIdentiferStart(int cp)
    {
      return false;
    }
Tom Tromey committed
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
    /**
     * Returns false to indicate that the character is not a letter.
     * @param cp the character
     * @return false
     */
    static boolean isLetter(int cp)
    {
      return false;
    }

    /**
     * Returns false to indicate that the character cannot is neither a letter
     * nor a digit.
     * @param cp the character
     * @return false
     */
    static boolean isLetterOrDigit(int cp)
    {
      return false;
    }

    /**
     * Returns false to indicate that the character is not a lowercase letter.
     * @param cp the character
     * @return false
     */
    static boolean isLowerCase(int cp)
    {
      return false;
    }
1824

1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843
    /**
     * Returns false to indicate that the character cannot is not mirrored.
     * @param cp the character
     * @return false
     */
    static boolean isMirrored(int cp)
    {
      return false;
    }

    /**
     * Returns false to indicate that the character is not a space character.
     * @param cp the character
     * @return false
     */
    static boolean isSpaceChar(int cp)
    {
      return false;
    }
1844

1845 1846 1847 1848 1849 1850 1851 1852 1853
    /**
     * Returns false to indicate that the character it not a titlecase letter.
     * @param cp the character
     * @return false
     */
    static boolean isTitleCase(int cp)
    {
      return false;
    }
1854

1855
    /**
1856
     * Returns false to indicate that the character cannot be part of a
1857 1858 1859 1860 1861 1862 1863 1864 1865 1866
     * Unicode identifier.
     * @param cp the character
     * @return false
     */
    static boolean isUnicodeIdentifierPart(int cp)
    {
      return false;
    }

    /**
1867
     * Returns false to indicate that the character cannot start a
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
     * Unicode identifier.
     * @param cp the character
     * @return false
     */
    static boolean isUnicodeIdentifierStart(int cp)
    {
      return false;
    }

    /**
     * Returns false to indicate that the character is not an uppercase letter.
     * @param cp the character
     * @return false
     */
    static boolean isUpperCase(int cp)
    {
      return false;
    }

    /**
     * Returns false to indicate that the character is not a whitespace
     * character.
     * @param cp the character
     * @return false
     */
    static boolean isWhiteSpace(int cp)
    {
      return false;
    }

    /**
     * Returns cp to indicate this character has no lowercase conversion.
     * @param cp the character
     * @return cp
     */
    static int toLowerCase(int cp)
    {
      return cp;
    }
1907

1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925
    /**
     * Returns cp to indicate this character has no titlecase conversion.
     * @param cp the character
     * @return cp
     */
    static int toTitleCase(int cp)
    {
      return cp;
    }

    /**
     * Returns cp to indicate this character has no uppercase conversion.
     * @param cp the character
     * @return cp
     */
    static int toUpperCase(int cp)
    {
      return cp;
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
  }

  /**
   * 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';

  /**
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
   * The minimum Unicode 4.0 code point.  This value is <code>0</code>.
   * @since 1.5
   */
  public static final int MIN_CODE_POINT = 0;

  /**
   * The maximum Unicode 4.0 code point, which is greater than the range
   * of the char data type.
   * This value is <code>0x10FFFF</code>.
   * @since 1.5
   */
  public static final int MAX_CODE_POINT = 0x10FFFF;

  /**
   * The minimum Unicode high surrogate code unit, or
   * <emph>leading-surrogate</emph>, in the UTF-16 character encoding.
   * This value is <code>'\uD800'</code>.
   * @since 1.5
   */
  public static final char MIN_HIGH_SURROGATE = '\uD800';

  /**
   * The maximum Unicode high surrogate code unit, or
   * <emph>leading-surrogate</emph>, in the UTF-16 character encoding.
   * This value is <code>'\uDBFF'</code>.
   * @since 1.5
   */
  public static final char MAX_HIGH_SURROGATE = '\uDBFF';

  /**
   * The minimum Unicode low surrogate code unit, or
   * <emph>trailing-surrogate</emph>, in the UTF-16 character encoding.
   * This value is <code>'\uDC00'</code>.
   * @since 1.5
   */
  public static final char MIN_LOW_SURROGATE = '\uDC00';

  /**
   * The maximum Unicode low surrogate code unit, or
   * <emph>trailing-surrogate</emph>, in the UTF-16 character encoding.
   * This value is <code>'\uDFFF'</code>.
   * @since 1.5
   */
2017
  public static final char MAX_LOW_SURROGATE = '\uDFFF';
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036

  /**
   * The minimum Unicode surrogate code unit in the UTF-16 character encoding.
   * This value is <code>'\uD800'</code>.
   * @since 1.5
   */
  public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;

  /**
   * The maximum Unicode surrogate code unit in the UTF-16 character encoding.
   * This value is <code>'\uDFFF'</code>.
   * @since 1.5
   */
  public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;

  /**
   * The lowest possible supplementary Unicode code point (the first code
   * point outside the basic multilingual plane (BMP)).
   * This value is <code>0x10000</code>.
2037
   */
2038 2039 2040
  public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x10000;

  /**
2041 2042 2043 2044
   * Class object representing the primitive char data type.
   *
   * @since 1.1
   */
2045
  public static final Class<Character> TYPE = (Class<Character>) VMClassLoader.getPrimitiveClass('C');
2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057

  /**
   * The number of bits needed to represent a <code>char</code>.
   * @since 1.5
   */
  public static final int SIZE = 16;

  // This caches some Character values, and is used by boxing
  // conversions via valueOf().  We must cache at least 0..127;
  // this constant controls how much we actually cache.
  private static final int MAX_CACHE = 127;
  private static Character[] charCache = new Character[MAX_CACHE + 1];
2058 2059 2060 2061 2062
  static
  {
     for (char i=0; i <= MAX_CACHE; i++)
       charCache[i] = new Character(i);
  }
2063 2064 2065 2066 2067 2068 2069 2070 2071 2072

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

  /**
   * Ll = Letter, Lowercase (Informative).
Tom Tromey committed
2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 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 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417
   *
   * @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;

  /**
   * Stores unicode block offset lookup table. Exploit package visibility of
   * String.value to avoid copying the array.
2418
   * @see #readCodePoint(int)
Tom Tromey committed
2419 2420
   * @see CharData#BLOCKS
   */
2421
  private static final char[][] blocks =
2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439
    new char[][]{
                 String.zeroBasedStringValue(CharData.BLOCKS[0]),
                 String.zeroBasedStringValue(CharData.BLOCKS[1]),
                 String.zeroBasedStringValue(CharData.BLOCKS[2]),
                 String.zeroBasedStringValue(CharData.BLOCKS[3]),
                 String.zeroBasedStringValue(CharData.BLOCKS[4]),
                 String.zeroBasedStringValue(CharData.BLOCKS[5]),
                 String.zeroBasedStringValue(CharData.BLOCKS[6]),
                 String.zeroBasedStringValue(CharData.BLOCKS[7]),
                 String.zeroBasedStringValue(CharData.BLOCKS[8]),
                 String.zeroBasedStringValue(CharData.BLOCKS[9]),
                 String.zeroBasedStringValue(CharData.BLOCKS[10]),
                 String.zeroBasedStringValue(CharData.BLOCKS[11]),
                 String.zeroBasedStringValue(CharData.BLOCKS[12]),
                 String.zeroBasedStringValue(CharData.BLOCKS[13]),
                 String.zeroBasedStringValue(CharData.BLOCKS[14]),
                 String.zeroBasedStringValue(CharData.BLOCKS[15]),
                 String.zeroBasedStringValue(CharData.BLOCKS[16])};
Tom Tromey committed
2440 2441 2442 2443 2444

  /**
   * Stores unicode attribute offset lookup table. Exploit package visibility
   * of String.value to avoid copying the array.
   * @see CharData#DATA
2445
   */
2446
  private static final char[][] data =
2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464
    new char[][]{
                 String.zeroBasedStringValue(CharData.DATA[0]),
                 String.zeroBasedStringValue(CharData.DATA[1]),
                 String.zeroBasedStringValue(CharData.DATA[2]),
                 String.zeroBasedStringValue(CharData.DATA[3]),
                 String.zeroBasedStringValue(CharData.DATA[4]),
                 String.zeroBasedStringValue(CharData.DATA[5]),
                 String.zeroBasedStringValue(CharData.DATA[6]),
                 String.zeroBasedStringValue(CharData.DATA[7]),
                 String.zeroBasedStringValue(CharData.DATA[8]),
                 String.zeroBasedStringValue(CharData.DATA[9]),
                 String.zeroBasedStringValue(CharData.DATA[10]),
                 String.zeroBasedStringValue(CharData.DATA[11]),
                 String.zeroBasedStringValue(CharData.DATA[12]),
                 String.zeroBasedStringValue(CharData.DATA[13]),
                 String.zeroBasedStringValue(CharData.DATA[14]),
                 String.zeroBasedStringValue(CharData.DATA[15]),
                 String.zeroBasedStringValue(CharData.DATA[16])};
Tom Tromey committed
2465 2466 2467 2468 2469 2470

  /**
   * Stores unicode numeric value attribute table. Exploit package visibility
   * of String.value to avoid copying the array.
   * @see CharData#NUM_VALUE
   */
2471
  private static final char[][] numValue =
2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489
    new char[][]{
                 String.zeroBasedStringValue(CharData.NUM_VALUE[0]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[1]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[2]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[3]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[4]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[5]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[6]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[7]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[8]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[9]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[10]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[11]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[12]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[13]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[14]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[15]),
                 String.zeroBasedStringValue(CharData.NUM_VALUE[16])};
Tom Tromey committed
2490 2491 2492 2493 2494

  /**
   * Stores unicode uppercase attribute table. Exploit package visibility
   * of String.value to avoid copying the array.
   * @see CharData#UPPER
2495 2496
   */
  private static final char[][] upper =
2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514
    new char[][]{
                 String.zeroBasedStringValue(CharData.UPPER[0]),
                 String.zeroBasedStringValue(CharData.UPPER[1]),
                 String.zeroBasedStringValue(CharData.UPPER[2]),
                 String.zeroBasedStringValue(CharData.UPPER[3]),
                 String.zeroBasedStringValue(CharData.UPPER[4]),
                 String.zeroBasedStringValue(CharData.UPPER[5]),
                 String.zeroBasedStringValue(CharData.UPPER[6]),
                 String.zeroBasedStringValue(CharData.UPPER[7]),
                 String.zeroBasedStringValue(CharData.UPPER[8]),
                 String.zeroBasedStringValue(CharData.UPPER[9]),
                 String.zeroBasedStringValue(CharData.UPPER[10]),
                 String.zeroBasedStringValue(CharData.UPPER[11]),
                 String.zeroBasedStringValue(CharData.UPPER[12]),
                 String.zeroBasedStringValue(CharData.UPPER[13]),
                 String.zeroBasedStringValue(CharData.UPPER[14]),
                 String.zeroBasedStringValue(CharData.UPPER[15]),
                 String.zeroBasedStringValue(CharData.UPPER[16])};
Tom Tromey committed
2515 2516 2517 2518 2519 2520

  /**
   * Stores unicode lowercase attribute table. Exploit package visibility
   * of String.value to avoid copying the array.
   * @see CharData#LOWER
   */
2521
  private static final char[][] lower =
2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539
    new char[][]{
                 String.zeroBasedStringValue(CharData.LOWER[0]),
                 String.zeroBasedStringValue(CharData.LOWER[1]),
                 String.zeroBasedStringValue(CharData.LOWER[2]),
                 String.zeroBasedStringValue(CharData.LOWER[3]),
                 String.zeroBasedStringValue(CharData.LOWER[4]),
                 String.zeroBasedStringValue(CharData.LOWER[5]),
                 String.zeroBasedStringValue(CharData.LOWER[6]),
                 String.zeroBasedStringValue(CharData.LOWER[7]),
                 String.zeroBasedStringValue(CharData.LOWER[8]),
                 String.zeroBasedStringValue(CharData.LOWER[9]),
                 String.zeroBasedStringValue(CharData.LOWER[10]),
                 String.zeroBasedStringValue(CharData.LOWER[11]),
                 String.zeroBasedStringValue(CharData.LOWER[12]),
                 String.zeroBasedStringValue(CharData.LOWER[13]),
                 String.zeroBasedStringValue(CharData.LOWER[14]),
                 String.zeroBasedStringValue(CharData.LOWER[15]),
                 String.zeroBasedStringValue(CharData.LOWER[16])};
Tom Tromey committed
2540 2541 2542 2543 2544 2545 2546

  /**
   * Stores unicode direction attribute table. Exploit package visibility
   * of String.value to avoid copying the array.
   * @see CharData#DIRECTION
   */
  // Package visible for use by String.
2547
  static final char[][] direction =
2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565
    new char[][]{
                 String.zeroBasedStringValue(CharData.DIRECTION[0]),
                 String.zeroBasedStringValue(CharData.DIRECTION[1]),
                 String.zeroBasedStringValue(CharData.DIRECTION[2]),
                 String.zeroBasedStringValue(CharData.DIRECTION[3]),
                 String.zeroBasedStringValue(CharData.DIRECTION[4]),
                 String.zeroBasedStringValue(CharData.DIRECTION[5]),
                 String.zeroBasedStringValue(CharData.DIRECTION[6]),
                 String.zeroBasedStringValue(CharData.DIRECTION[7]),
                 String.zeroBasedStringValue(CharData.DIRECTION[8]),
                 String.zeroBasedStringValue(CharData.DIRECTION[9]),
                 String.zeroBasedStringValue(CharData.DIRECTION[10]),
                 String.zeroBasedStringValue(CharData.DIRECTION[11]),
                 String.zeroBasedStringValue(CharData.DIRECTION[12]),
                 String.zeroBasedStringValue(CharData.DIRECTION[13]),
                 String.zeroBasedStringValue(CharData.DIRECTION[14]),
                 String.zeroBasedStringValue(CharData.DIRECTION[15]),
                 String.zeroBasedStringValue(CharData.DIRECTION[16])};
Tom Tromey committed
2566 2567 2568 2569 2570 2571

  /**
   * Stores unicode titlecase table. Exploit package visibility of
   * String.value to avoid copying the array.
   * @see CharData#TITLE
   */
2572
  private static final char[] title = String.zeroBasedStringValue(CharData.TITLE);
Tom Tromey committed
2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598

  /**
   * Mask for grabbing the type out of the contents of data.
   * @see CharData#DATA
   */
  private static final int TYPE_MASK = 0x1F;

  /**
   * Mask for grabbing the non-breaking space flag out of the contents of
   * data.
   * @see CharData#DATA
   */
  private static final int NO_BREAK_MASK = 0x20;

  /**
   * Mask for grabbing the mirrored directionality flag out of the contents
   * of data.
   * @see CharData#DATA
   */
  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.
   *
2599
   * @param codePoint the character to look up
Tom Tromey committed
2600 2601 2602 2603 2604 2605 2606
   * @return the character's attribute offset and type
   * @see #TYPE_MASK
   * @see #NO_BREAK_MASK
   * @see #MIRROR_MASK
   * @see CharData#DATA
   * @see CharData#SHIFT
   */
2607
  // Package visible for use in String.
2608
  static char readCodePoint(int codePoint)
Tom Tromey committed
2609
  {
2610 2611 2612
    int plane = codePoint >>> 16;
    char offset = (char) (codePoint & 0xffff);
    return data[plane][(char) (blocks[plane][offset >> CharData.SHIFT[plane]] + offset)];
Tom Tromey committed
2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684
  }

  /**
   * 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()
  {
    // Package constructor avoids an array copy.
    return new String(new char[] { value }, 0, 1, true);
  }

  /**
   * 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
   */
  public static String toString(char ch)
  {
    // Package constructor avoids an array copy.
    return new String(new char[] { ch }, 0, 1, true);
  }

  /**
   * Determines if a character is a Unicode lowercase letter. For example,
2685 2686
   * <code>'a'</code> is lowercase.  Returns true if getType() returns
   * LOWERCASE_LETTER.
Tom Tromey committed
2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698
   * <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)
  {
2699 2700
    return isLowerCase((int)ch);
  }
2701

2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714
  /**
   * Determines if a character is a Unicode lowercase letter. For example,
   * <code>'a'</code> is lowercase.  Returns true if getType() returns
   * LOWERCASE_LETTER.
   * <br>
   * lowercase = [Ll]
   *
   * @param codePoint 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)
2715
   *
2716 2717 2718 2719 2720
   * @since 1.5
   */
  public static boolean isLowerCase(int codePoint)
  {
    return getType(codePoint) == LOWERCASE_LETTER;
Tom Tromey committed
2721 2722 2723 2724
  }

  /**
   * Determines if a character is a Unicode uppercase letter. For example,
2725 2726
   * <code>'A'</code> is uppercase.  Returns true if getType() returns
   * UPPERCASE_LETTER.
Tom Tromey committed
2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738
   * <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)
  {
2739 2740
    return isUpperCase((int)ch);
  }
2741

2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754
  /**
   * Determines if a character is a Unicode uppercase letter. For example,
   * <code>'A'</code> is uppercase.  Returns true if getType() returns
   * UPPERCASE_LETTER.
   * <br>
   * uppercase = [Lu]
   *
   * @param codePoint 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)
2755
   *
2756 2757 2758 2759 2760
   * @since 1.5
   */
  public static boolean isUpperCase(int codePoint)
  {
    return getType(codePoint) == UPPERCASE_LETTER;
Tom Tromey committed
2761 2762 2763 2764 2765
  }

  /**
   * Determines if a character is a Unicode titlecase letter. For example,
   * the character "Lj" (Latin capital L with small letter j) is titlecase.
2766
   * True if getType() returns TITLECASE_LETTER.
Tom Tromey committed
2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778
   * <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)
  {
2779 2780
    return isTitleCase((int)ch);
  }
2781

2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794
  /**
   * Determines if a character is a Unicode titlecase letter. For example,
   * the character "Lj" (Latin capital L with small letter j) is titlecase.
   * True if getType() returns TITLECASE_LETTER.
   * <br>
   * titlecase = [Lt]
   *
   * @param codePoint 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)
2795
   *
2796 2797 2798 2799 2800
   * @since 1.5
   */
  public static boolean isTitleCase(int codePoint)
  {
    return getType(codePoint) == TITLECASE_LETTER;
Tom Tromey committed
2801
  }
2802

Tom Tromey committed
2803 2804 2805

  /**
   * Determines if a character is a Unicode decimal digit. For example,
2806 2807
   * <code>'0'</code> is a digit.  A character is a Unicode digit if
   * getType() returns DECIMAL_DIGIT_NUMBER.
Tom Tromey committed
2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818
   * <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)
  {
2819 2820
    return isDigit((int)ch);
  }
2821

2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833
  /**
   * Determines if a character is a Unicode decimal digit. For example,
   * <code>'0'</code> is a digit. A character is a Unicode digit if
   * getType() returns DECIMAL_DIGIT_NUMBER.
   * <br>
   * Unicode decimal digit = [Nd]
   *
   * @param codePoint 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)
2834
   *
2835 2836 2837 2838 2839 2840
   * @since 1.5
   */

  public static boolean isDigit(int codePoint)
  {
    return getType(codePoint) == DECIMAL_DIGIT_NUMBER;
Tom Tromey committed
2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859
  }

  /**
   * 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)
  {
2860 2861
    return isDefined((int)ch);
  }
2862

2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876
  /**
   * 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 codePoint 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)
2877
   *
2878 2879 2880 2881 2882
   * @since 1.5
   */
  public static boolean isDefined(int codePoint)
  {
    return getType(codePoint) != UNASSIGNED;
Tom Tromey committed
2883 2884 2885 2886 2887
  }

  /**
   * Determines if a character is a Unicode letter. Not all letters have case,
   * so this may return true when isLowerCase and isUpperCase return false.
2888
   * A character is a Unicode letter if getType() returns one of
2889 2890
   * UPPERCASE_LETTER, LOWERCASE_LETTER, TITLECASE_LETTER, MODIFIER_LETTER,
   * or OTHER_LETTER.
Tom Tromey committed
2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907
   * <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)
  {
2908
    return isLetter((int)ch);
Tom Tromey committed
2909
  }
2910

Tom Tromey committed
2911
  /**
2912 2913
   * Determines if a character is a Unicode letter. Not all letters have case,
   * so this may return true when isLowerCase and isUpperCase return false.
2914
   * A character is a Unicode letter if getType() returns one of
2915 2916
   * UPPERCASE_LETTER, LOWERCASE_LETTER, TITLECASE_LETTER, MODIFIER_LETTER,
   * or OTHER_LETTER.
Tom Tromey committed
2917
   * <br>
2918
   * letter = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]
Tom Tromey committed
2919
   *
2920 2921
   * @param codePoint character to test
   * @return true if ch is a Unicode letter, else false
Tom Tromey committed
2922
   * @see #isDigit(char)
2923
   * @see #isJavaIdentifierStart(char)
Tom Tromey committed
2924 2925
   * @see #isJavaLetter(char)
   * @see #isJavaLetterOrDigit(char)
2926 2927 2928 2929 2930
   * @see #isLetterOrDigit(char)
   * @see #isLowerCase(char)
   * @see #isTitleCase(char)
   * @see #isUnicodeIdentifierStart(char)
   * @see #isUpperCase(char)
2931
   *
2932
   * @since 1.5
Tom Tromey committed
2933
   */
2934
  public static boolean isLetter(int codePoint)
Tom Tromey committed
2935
  {
2936 2937 2938 2939 2940 2941
    return ((1 << getType(codePoint))
        & ((1 << UPPERCASE_LETTER)
            | (1 << LOWERCASE_LETTER)
            | (1 << TITLECASE_LETTER)
            | (1 << MODIFIER_LETTER)
            | (1 << OTHER_LETTER))) != 0;
Tom Tromey committed
2942 2943
  }
  /**
2944 2945 2946 2947 2948 2949
   * Returns the index into the given CharSequence that is offset
   * <code>codePointOffset</code> code points from <code>index</code>.
   * @param seq the CharSequence
   * @param index the start position in the CharSequence
   * @param codePointOffset the number of code points offset from the start
   * position
2950
   * @return the index into the CharSequence that is codePointOffset code
2951
   * points offset from index
2952
   *
2953 2954 2955
   * @throws NullPointerException if seq is null
   * @throws IndexOutOfBoundsException if index is negative or greater than the
   * length of the sequence.
2956
   * @throws IndexOutOfBoundsException if codePointOffset is positive and the
2957 2958 2959
   * subsequence from index to the end of seq has fewer than codePointOffset
   * code points
   * @throws IndexOutOfBoundsException if codePointOffset is negative and the
2960
   * subsequence from the start of seq to index has fewer than
2961 2962 2963 2964 2965 2966 2967 2968 2969 2970
   * (-codePointOffset) code points
   * @since 1.5
   */
  public static int offsetByCodePoints(CharSequence seq,
                                       int index,
                                       int codePointOffset)
  {
    int len = seq.length();
    if (index < 0 || index > len)
      throw new IndexOutOfBoundsException();
2971

2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001
    int numToGo = codePointOffset;
    int offset = index;
    int adjust = 1;
    if (numToGo >= 0)
      {
        for (; numToGo > 0; offset++)
          {
            numToGo--;
            if (Character.isHighSurrogate(seq.charAt(offset))
                && (offset + 1) < len
                && Character.isLowSurrogate(seq.charAt(offset + 1)))
              offset++;
          }
        return offset;
      }
    else
      {
        numToGo *= -1;
        for (; numToGo > 0;)
          {
            numToGo--;
            offset--;
            if (Character.isLowSurrogate(seq.charAt(offset))
                && (offset - 1) >= 0
                && Character.isHighSurrogate(seq.charAt(offset - 1)))
              offset--;
          }
        return offset;
      }
  }
3002

3003 3004 3005 3006 3007 3008 3009 3010 3011 3012
  /**
   * Returns the index into the given char subarray that is offset
   * <code>codePointOffset</code> code points from <code>index</code>.
   * @param a the char array
   * @param start the start index of the subarray
   * @param count the length of the subarray
   * @param index the index to be offset
   * @param codePointOffset the number of code points offset from <code>index
   * </code>
   * @return the index into the char array
3013
   *
3014 3015 3016
   * @throws NullPointerException if a is null
   * @throws IndexOutOfBoundsException if start or count is negative or if
   * start + count is greater than the length of the array
3017
   * @throws IndexOutOfBoundsException if index is less than start or larger
3018 3019 3020 3021 3022 3023 3024
   * than start + count
   * @throws IndexOutOfBoundsException if codePointOffset is positive and the
   * subarray from index to start + count - 1 has fewer than codePointOffset
   * code points.
   * @throws IndexOutOfBoundsException if codePointOffset is negative and the
   * subarray from start to index - 1 has fewer than (-codePointOffset) code
   * points
3025
   *
3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037
   * @since 1.5
   */
  public static int offsetByCodePoints(char[] a,
                                       int start,
                                       int count,
                                       int index,
                                       int codePointOffset)
  {
    int len = a.length;
    int end = start + count;
    if (start < 0 || count < 0 || end > len || index < start || index > end)
      throw new IndexOutOfBoundsException();
3038

3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071
    int numToGo = codePointOffset;
    int offset = index;
    int adjust = 1;
    if (numToGo >= 0)
      {
        for (; numToGo > 0; offset++)
          {
            numToGo--;
            if (Character.isHighSurrogate(a[offset])
                && (offset + 1) < len
                && Character.isLowSurrogate(a[offset + 1]))
              offset++;
          }
        return offset;
      }
    else
      {
        numToGo *= -1;
        for (; numToGo > 0;)
          {
            numToGo--;
            offset--;
            if (Character.isLowSurrogate(a[offset])
                && (offset - 1) >= 0
                && Character.isHighSurrogate(a[offset - 1]))
              offset--;
            if (offset < start)
              throw new IndexOutOfBoundsException();
          }
        return offset;
      }

  }
3072

3073 3074 3075
  /**
   * Returns the number of Unicode code points in the specified range of the
   * given CharSequence.  The first char in the range is at position
3076 3077 3078
   * beginIndex and the last one is at position endIndex - 1.  Paired
   * surrogates (supplementary characters are represented by a pair of chars -
   * one from the high surrogates and one from the low surrogates)
3079 3080 3081 3082
   * count as just one code point.
   * @param seq the CharSequence to inspect
   * @param beginIndex the beginning of the range
   * @param endIndex the end of the range
3083
   * @return the number of Unicode code points in the given range of the
3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095
   * sequence
   * @throws NullPointerException if seq is null
   * @throws IndexOutOfBoundsException if beginIndex is negative, endIndex is
   * larger than the length of seq, or if beginIndex is greater than endIndex.
   * @since 1.5
   */
  public static int codePointCount(CharSequence seq, int beginIndex,
                                   int endIndex)
  {
    int len = seq.length();
    if (beginIndex < 0 || endIndex > len || beginIndex > endIndex)
      throw new IndexOutOfBoundsException();
3096

3097 3098 3099 3100 3101 3102 3103 3104
    int count = 0;
    for (int i = beginIndex; i < endIndex; i++)
      {
        count++;
        // If there is a pairing, count it only once.
        if (isHighSurrogate(seq.charAt(i)) && (i + 1) < endIndex
            && isLowSurrogate(seq.charAt(i + 1)))
          i ++;
3105
      }
3106 3107
    return count;
  }
3108

3109 3110 3111 3112
  /**
   * Returns the number of Unicode code points in the specified range of the
   * given char array.  The first char in the range is at position
   * offset and the length of the range is count.  Paired surrogates
3113 3114
   * (supplementary characters are represented by a pair of chars -
   * one from the high surrogates and one from the low surrogates)
3115 3116 3117 3118
   * count as just one code point.
   * @param a the char array to inspect
   * @param offset the beginning of the range
   * @param count the length of the range
3119
   * @return the number of Unicode code points in the given range of the
3120 3121
   * array
   * @throws NullPointerException if a is null
3122
   * @throws IndexOutOfBoundsException if offset or count is negative or if
3123 3124 3125 3126 3127 3128 3129 3130 3131 3132
   * offset + countendIndex is larger than the length of a.
   * @since 1.5
   */
  public static int codePointCount(char[] a, int offset,
                                   int count)
  {
    int len = a.length;
    int end = offset + count;
    if (offset < 0 || count < 0 || end > len)
      throw new IndexOutOfBoundsException();
3133

3134 3135 3136 3137 3138 3139 3140 3141
    int counter = 0;
    for (int i = offset; i < end; i++)
      {
        counter++;
        // If there is a pairing, count it only once.
        if (isHighSurrogate(a[i]) && (i + 1) < end
            && isLowSurrogate(a[i + 1]))
          i ++;
3142
      }
3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179
    return counter;
  }

  /**
   * 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 isLetterOrDigit((int)ch);
  }

  /**
   * 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 codePoint 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)
3180
   *
3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192
   * @since 1.5
   */
  public static boolean isLetterOrDigit(int codePoint)
  {
    return ((1 << getType(codePoint))
        & ((1 << UPPERCASE_LETTER)
           | (1 << LOWERCASE_LETTER)
           | (1 << TITLECASE_LETTER)
           | (1 << MODIFIER_LETTER)
           | (1 << OTHER_LETTER)
           | (1 << DECIMAL_DIGIT_NUMBER))) != 0;
  }
3193

3194 3195 3196 3197 3198 3199 3200 3201 3202
  /**
   * 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)}
Tom Tromey committed
3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254
   * @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)
  {
3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275
    return isJavaIdentifierStart((int)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 codePoint 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.5
   */
  public static boolean isJavaIdentifierStart(int codePoint)
  {
    return ((1 << getType(codePoint))
Tom Tromey committed
3276 3277 3278 3279 3280 3281 3282 3283 3284
            & ((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;
  }
3285

Tom Tromey committed
3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306
  /**
   * 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)
  {
3307 3308
    return isJavaIdentifierPart((int)ch);
  }
3309

3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331
  /**
   * 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 codePoint 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.5
   */
  public static boolean isJavaIdentifierPart(int codePoint)
  {
    int category = getType(codePoint);
Tom Tromey committed
3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344
    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
3345
      || (category == CONTROL && isIdentifierIgnorable(codePoint));
Tom Tromey committed
3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363
  }

  /**
   * 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)
  {
3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383
    return isUnicodeIdentifierStart((int)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 codePoint 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.5
   */
  public static boolean isUnicodeIdentifierStart(int codePoint)
  {
    return ((1 << getType(codePoint))
Tom Tromey committed
3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411
            & ((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)
  {
3412 3413
    return isUnicodeIdentifierPart((int)ch);
  }
3414

3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435
  /**
   * 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 codePoint 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.5
   */
  public static boolean isUnicodeIdentifierPart(int codePoint)
  {
    int category = getType(codePoint);
Tom Tromey committed
3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447
    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
3448
      || (category == CONTROL && isIdentifierIgnorable(codePoint));
Tom Tromey committed
3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468
  }

  /**
   * 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)
  {
3469 3470
    return isIdentifierIgnorable((int)ch);
  }
3471

3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495
  /**
   * 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 codePoint character to test
   * @return true if ch is ignorable in a Unicode or Java identifier
   * @see #isJavaIdentifierPart(char)
   * @see #isUnicodeIdentifierPart(char)
   * @since 1.5
   */
  public static boolean isIdentifierIgnorable(int codePoint)
  {
    if ((codePoint >= 0 && codePoint <= 0x0008)
        || (codePoint >= 0x000E && codePoint <= 0x001B)
        || (codePoint >= 0x007F && codePoint <= 0x009F)
        || getType(codePoint) == FORMAT)
      return true;
    return false;
Tom Tromey committed
3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512
  }

  /**
   * 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 char toLowerCase(char ch)
  {
3513 3514
    return (char) (lower[0][readCodePoint((int)ch) >>> 7] + ch);
  }
3515

3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527
  /**
   * 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 codePoint 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)
3528
   *
3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539
   * @since 1.5
   */
  public static int toLowerCase(int codePoint)
  {
    // If the code point is unassigned or in one of the private use areas
    // then we delegate the call to the appropriate private static inner class.
    int plane = codePoint >>> 16;
    if (plane > 2 && plane < 14)
      return UnassignedCharacters.toLowerCase(codePoint);
    if (plane > 14)
      return PrivateUseCharacters.toLowerCase(codePoint);
3540

3541 3542 3543
    // The short value stored in lower[plane] is the signed difference between
    // codePoint and its lowercase conversion.
    return ((short)lower[plane][readCodePoint(codePoint) >>> 7]) + codePoint;
Tom Tromey committed
3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560
  }

  /**
   * 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 char toUpperCase(char ch)
  {
3561 3562
    return (char) (upper[0][readCodePoint((int)ch) >>> 7] + ch);
  }
3563

3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575
  /**
   * 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 codePoint 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)
3576
   *
3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587
   * @since 1.5
   */
  public static int toUpperCase(int codePoint)
  {
    // If the code point is unassigned or in one of the private use areas
    // then we delegate the call to the appropriate private static inner class.
    int plane = codePoint >>> 16;
    if (plane > 2 && plane < 14)
      return UnassignedCharacters.toUpperCase(codePoint);
    if (plane > 14)
      return PrivateUseCharacters.toUpperCase(codePoint);
3588

3589 3590 3591
    // The short value stored in upper[plane] is the signed difference between
    // codePoint and its uppercase conversion.
    return ((short)upper[plane][readCodePoint(codePoint) >>> 7]) + codePoint;
Tom Tromey committed
3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613
  }

  /**
   * 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 char toTitleCase(char ch)
  {
    // As title is short, it doesn't hurt to exhaustively iterate over it.
    for (int i = title.length - 2; i >= 0; i -= 2)
      if (title[i] == ch)
        return title[i + 1];
    return toUpperCase(ch);
  }
3614

3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625
  /**
   * 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 codePoint 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)
3626
   *
3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637
   * @since 1.5
   */
  public static int toTitleCase(int codePoint)
  {
    // As of Unicode 4.0.0 no characters outside of plane 0 have
    // titlecase mappings that are different from their uppercase
    // mapping.
    if (codePoint < 0x10000)
      return (int) toTitleCase((char)codePoint);
    return toUpperCase(codePoint);
  }
Tom Tromey committed
3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660

  /**
   * 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 int digit(char ch, int radix)
  {
    if (radix < MIN_RADIX || radix > MAX_RADIX)
      return -1;
3661
    char attr = readCodePoint((int)ch);
Tom Tromey committed
3662 3663 3664 3665 3666 3667
    if (((1 << (attr & TYPE_MASK))
         & ((1 << UPPERCASE_LETTER)
            | (1 << LOWERCASE_LETTER)
            | (1 << DECIMAL_DIGIT_NUMBER))) != 0)
      {
        // Signedness doesn't matter; 0xffff vs. -1 are both rejected.
3668
        int digit = numValue[0][attr >> 7];
Tom Tromey committed
3669 3670 3671 3672 3673 3674
        return (digit < radix) ? digit : -1;
      }
    return -1;
  }

  /**
3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695
   * 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 codePoint 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 int digit(int codePoint, int radix)
  {
    if (radix < MIN_RADIX || radix > MAX_RADIX)
      return -1;
3696

3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711
    // If the code point is unassigned or in one of the private use areas
    // then we delegate the call to the appropriate private static inner class.
    int plane = codePoint >>> 16;
    if (plane > 2 && plane < 14)
      return UnassignedCharacters.digit(codePoint, radix);
    if (plane > 14)
      return PrivateUseCharacters.digit(codePoint, radix);
    char attr = readCodePoint(codePoint);
    if (((1 << (attr & TYPE_MASK))
         & ((1 << UPPERCASE_LETTER)
            | (1 << LOWERCASE_LETTER)
            | (1 << DECIMAL_DIGIT_NUMBER))) != 0)
      {
        // Signedness doesn't matter; 0xffff vs. -1 are both rejected.
        int digit = numValue[plane][attr >> 7];
3712 3713

        // If digit is less than or equal to -3 then the numerical value was
3714 3715 3716 3717 3718 3719 3720
        // too large to fit into numValue and is stored in CharData.LARGENUMS.
        if (digit <= -3)
          digit = CharData.LARGENUMS[-digit - 3];
        return (digit < radix) ? digit : -1;
      }
    return -1;
  }
3721

3722
  /**
Tom Tromey committed
3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751
   * 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 int getNumericValue(char ch)
  {
    // Treat numValue as signed.
3752 3753
    return (short) numValue[0][readCodePoint((int)ch) >> 7];
  }
3754

3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790
  /**
   * 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 codePoint 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.5
   */
  public static int getNumericValue(int codePoint)
  {
    // If the code point is unassigned or in one of the private use areas
    // then we delegate the call to the appropriate private static inner class.
    int plane = codePoint >>> 16;
    if (plane > 2 && plane < 14)
      return UnassignedCharacters.getNumericValue(codePoint);
    if (plane > 14)
      return PrivateUseCharacters.getNumericValue(codePoint);
3791

3792
    // If the value N found in numValue[plane] is less than or equal to -3
3793
    // then the numeric value was too big to fit into 16 bits and is
3794 3795 3796 3797 3798
    // stored in CharData.LARGENUMS at offset (-N - 3).
    short num = (short)numValue[plane][readCodePoint(codePoint) >> 7];
    if (num <= -3)
      return CharData.LARGENUMS[-num - 3];
    return num;
Tom Tromey committed
3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837
  }

  /**
   * 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)
  {
3838 3839
    return isSpaceChar((int)ch);
  }
3840

3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854
  /**
   * 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 codePoint character to test
   * @return true if ch is a Unicode space, else false
   * @see #isWhitespace(char)
   * @since 1.5
   */
  public static boolean isSpaceChar(int codePoint)
  {
    return ((1 << getType(codePoint))
Tom Tromey committed
3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878
            & ((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)
  {
3879 3880
    return isWhitespace((int) ch);
  }
3881

3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905
  /**
   * 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 codePoint character to test
   * @return true if ch is Java whitespace, else false
   * @see #isSpaceChar(char)
   * @since 1.5
   */
  public static boolean isWhitespace(int codePoint)
  {
    int plane = codePoint >>> 16;
    if (plane > 2 && plane < 14)
      return UnassignedCharacters.isWhiteSpace(codePoint);
    if (plane > 14)
      return PrivateUseCharacters.isWhiteSpace(codePoint);
3906

3907
    int attr = readCodePoint(codePoint);
Tom Tromey committed
3908 3909 3910 3911 3912
    return ((((1 << (attr & TYPE_MASK))
              & ((1 << SPACE_SEPARATOR)
                 | (1 << LINE_SEPARATOR)
                 | (1 << PARAGRAPH_SEPARATOR))) != 0)
            && (attr & NO_BREAK_MASK) == 0)
3913
      || (codePoint <= '\u001F' && ((1 << codePoint)
Tom Tromey committed
3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937
                             & ((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)
  {
3938 3939
    return isISOControl((int)ch);
  }
3940

3941 3942 3943 3944 3945 3946
  /**
   * Determines if the character is an ISO Control character.  This is true
   * if the code point is in the range [0, 0x001F] or if it is in the range
   * [0x007F, 0x009F].
   * @param codePoint the character to check
   * @return true if the character is in one of the above ranges
3947
   *
3948 3949 3950 3951 3952 3953 3954
   * @since 1.5
   */
  public static boolean isISOControl(int codePoint)
  {
    if ((codePoint >= 0 && codePoint <= 0x001F)
        || (codePoint >= 0x007F && codePoint <= 0x009F))
      return true;
3955
    return false;
Tom Tromey committed
3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996
  }

  /**
   * 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 int getType(char ch)
  {
3997 3998
    return getType((int)ch);
  }
3999

4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034
  /**
   * Returns the Unicode general category property of a character.
   *
   * @param codePoint 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
4035
   *
4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046
   * @since 1.5
   */
  public static int getType(int codePoint)
  {
    // If the codePoint is unassigned or in one of the private use areas
    // then we delegate the call to the appropriate private static inner class.
    int plane = codePoint >>> 16;
    if (plane > 2 && plane < 14)
      return UnassignedCharacters.getType(codePoint);
    if (plane > 14)
      return PrivateUseCharacters.getType(codePoint);
4047

4048
    return readCodePoint(codePoint) & TYPE_MASK;
Tom Tromey committed
4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104
  }

  /**
   * 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)
  {
    if (radix < MIN_RADIX || radix > MAX_RADIX
        || digit < 0 || digit >= radix)
      return '\0';
    return Number.digits[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 byte getDirectionality(char ch)
  {
    // The result will correctly be signed.
4105
    return getDirectionality((int)ch);
Tom Tromey committed
4106
  }
4107

4108

4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145
  /**
   * Returns the Unicode directionality property of the character. This
   * is used in the visual ordering of text.
   *
   * @param codePoint 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.5
   */
  public static byte getDirectionality(int codePoint)
  {
    // If the code point is unassigned or in one of the private use areas
    // then we delegate the call to the appropriate private static inner class.
    int plane = codePoint >>> 16;
    if (plane > 2 && plane < 14)
      return UnassignedCharacters.getDirectionality(codePoint);
    if (plane > 14)
      return PrivateUseCharacters.getDirectionality(codePoint);
4146

4147 4148 4149
    // The result will correctly be signed.
    return (byte) (direction[plane][readCodePoint(codePoint) >> 7] >> 2);
  }
4150

Tom Tromey committed
4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161
  /**
   * 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)
  {
4162 4163
    return (readCodePoint((int)ch) & MIRROR_MASK) != 0;
  }
4164

4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182
  /**
   * 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 codePoint the character to look up
   * @return true if the character is mirrored
   * @since 1.5
   */
  public static boolean isMirrored(int codePoint)
  {
    // If the code point is unassigned or part of one of the private use areas
    // then we delegate the call to the appropriate private static inner class.
    int plane = codePoint >>> 16;
    if (plane > 2 && plane < 14)
      return UnassignedCharacters.isMirrored(codePoint);
    if (plane > 14)
      return PrivateUseCharacters.isMirrored(codePoint);
4183

4184
    return (readCodePoint(codePoint) & MIRROR_MASK) != 0;
Tom Tromey committed
4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202
  }

  /**
   * 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;
  }

  /**
4203 4204 4205 4206 4207 4208
   * Returns an <code>Character</code> object wrapping the value.
   * In contrast to the <code>Character</code> constructor, this method
   * will cache some values.  It is used by boxing conversion.
   *
   * @param val the value to wrap
   * @return the <code>Character</code>
4209
   *
4210 4211 4212 4213 4214 4215
   * @since 1.5
   */
  public static Character valueOf(char val)
  {
    if (val > MAX_CACHE)
      return new Character(val);
4216 4217
    else
      return charCache[val - MIN_VALUE];
4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229
  }

  /**
   * Reverse the bytes in val.
   * @since 1.5
   */
  public static char reverseBytes(char val)
  {
    return (char) (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
  }

  /**
Tom Tromey committed
4230 4231
   * Converts a unicode code point to a UTF-16 representation of that
   * code point.
4232
   *
Tom Tromey committed
4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243
   * @param codePoint the unicode code point
   *
   * @return the UTF-16 representation of that code point
   *
   * @throws IllegalArgumentException if the code point is not a valid
   *         unicode code point
   *
   * @since 1.5
   */
  public static char[] toChars(int codePoint)
  {
4244 4245 4246
    if (!isValidCodePoint(codePoint))
      throw new IllegalArgumentException("Illegal Unicode code point : "
                                         + codePoint);
Tom Tromey committed
4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282
    char[] result = new char[charCount(codePoint)];
    int ignore = toChars(codePoint, result, 0);
    return result;
  }

  /**
   * Converts a unicode code point to its UTF-16 representation.
   *
   * @param codePoint the unicode code point
   * @param dst the target char array
   * @param dstIndex the start index for the target
   *
   * @return number of characters written to <code>dst</code>
   *
   * @throws IllegalArgumentException if <code>codePoint</code> is not a
   *         valid unicode code point
   * @throws NullPointerException if <code>dst</code> is <code>null</code>
   * @throws IndexOutOfBoundsException if <code>dstIndex</code> is not valid
   *         in <code>dst</code> or if the UTF-16 representation does not
   *         fit into <code>dst</code>
   *
   * @since 1.5
   */
  public static int toChars(int codePoint, char[] dst, int dstIndex)
  {
    if (!isValidCodePoint(codePoint))
      {
        throw new IllegalArgumentException("not a valid code point: "
                                           + codePoint);
      }

    int result;
    if (isSupplementaryCodePoint(codePoint))
      {
        // Write second char first to cause IndexOutOfBoundsException
        // immediately.
4283 4284 4285
        final int cp2 = codePoint - 0x10000;
        dst[dstIndex + 1] = (char) ((cp2 % 0x400) + (int) MIN_LOW_SURROGATE);
        dst[dstIndex] = (char) ((cp2 / 0x400) + (int) MIN_HIGH_SURROGATE);
Tom Tromey committed
4286
        result = 2;
4287
      }
Tom Tromey committed
4288 4289 4290
    else
      {
        dst[dstIndex] = (char) codePoint;
4291
        result = 1;
Tom Tromey committed
4292 4293 4294 4295 4296 4297 4298 4299
      }
    return result;
  }

  /**
   * Return number of 16-bit characters required to represent the given
   * code point.
   *
4300
   * @param codePoint a unicode code point
Tom Tromey committed
4301 4302 4303 4304 4305 4306 4307
   *
   * @return 2 if codePoint >= 0x10000, 1 otherwise.
   *
   * @since 1.5
   */
  public static int charCount(int codePoint)
  {
4308 4309 4310
    return
      (codePoint >= MIN_SUPPLEMENTARY_CODE_POINT)
      ? 2
Tom Tromey committed
4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344
      : 1;
  }

  /**
   * Determines whether the specified code point is
   * in the range 0x10000 .. 0x10FFFF, i.e. the character is within the Unicode
   * supplementary character range.
   *
   * @param codePoint a Unicode code point
   *
   * @return <code>true</code> if code point is in supplementary range
   *
   * @since 1.5
   */
  public static boolean isSupplementaryCodePoint(int codePoint)
  {
    return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
      && codePoint <= MAX_CODE_POINT;
  }

  /**
   * Determines whether the specified code point is
   * in the range 0x0000 .. 0x10FFFF, i.e. it is a valid Unicode code point.
   *
   * @param codePoint a Unicode code point
   *
   * @return <code>true</code> if code point is valid
   *
   * @since 1.5
   */
  public static boolean isValidCodePoint(int codePoint)
  {
    return codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT;
  }
4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395

  /**
   * Return true if the given character is a high surrogate.
   * @param ch the character
   * @return true if the character is a high surrogate character
   *
   * @since 1.5
   */
  public static boolean isHighSurrogate(char ch)
  {
    return ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE;
  }

  /**
   * Return true if the given character is a low surrogate.
   * @param ch the character
   * @return true if the character is a low surrogate character
   *
   * @since 1.5
   */
  public static boolean isLowSurrogate(char ch)
  {
    return ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE;
  }

  /**
   * Return true if the given characters compose a surrogate pair.
   * This is true if the first character is a high surrogate and the
   * second character is a low surrogate.
   * @param ch1 the first character
   * @param ch2 the first character
   * @return true if the characters compose a surrogate pair
   *
   * @since 1.5
   */
  public static boolean isSurrogatePair(char ch1, char ch2)
  {
    return isHighSurrogate(ch1) && isLowSurrogate(ch2);
  }

  /**
   * Given a valid surrogate pair, this returns the corresponding
   * code point.
   * @param high the high character of the pair
   * @param low the low character of the pair
   * @return the corresponding code point
   *
   * @since 1.5
   */
  public static int toCodePoint(char high, char low)
  {
4396 4397
    return ((high - MIN_HIGH_SURROGATE) * 0x400) +
      (low - MIN_LOW_SURROGATE) + 0x10000;
4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463
  }

  /**
   * Get the code point at the specified index in the CharSequence.
   * This is like CharSequence#charAt(int), but if the character is
   * the start of a surrogate pair, and there is a following
   * character, and this character completes the pair, then the
   * corresponding supplementary code point is returned.  Otherwise,
   * the character at the index is returned.
   *
   * @param sequence the CharSequence
   * @param index the index of the codepoint to get, starting at 0
   * @return the codepoint at the specified index
   * @throws IndexOutOfBoundsException if index is negative or &gt;= length()
   * @since 1.5
   */
  public static int codePointAt(CharSequence sequence, int index)
  {
    int len = sequence.length();
    if (index < 0 || index >= len)
      throw new IndexOutOfBoundsException();
    char high = sequence.charAt(index);
    if (! isHighSurrogate(high) || ++index >= len)
      return high;
    char low = sequence.charAt(index);
    if (! isLowSurrogate(low))
      return high;
    return toCodePoint(high, low);
  }

  /**
   * Get the code point at the specified index in the CharSequence.
   * If the character is the start of a surrogate pair, and there is a
   * following character, and this character completes the pair, then
   * the corresponding supplementary code point is returned.
   * Otherwise, the character at the index is returned.
   *
   * @param chars the character array in which to look
   * @param index the index of the codepoint to get, starting at 0
   * @return the codepoint at the specified index
   * @throws IndexOutOfBoundsException if index is negative or &gt;= length()
   * @since 1.5
   */
  public static int codePointAt(char[] chars, int index)
  {
    return codePointAt(chars, index, chars.length);
  }

  /**
   * Get the code point at the specified index in the CharSequence.
   * If the character is the start of a surrogate pair, and there is a
   * following character within the specified range, and this
   * character completes the pair, then the corresponding
   * supplementary code point is returned.  Otherwise, the character
   * at the index is returned.
   *
   * @param chars the character array in which to look
   * @param index the index of the codepoint to get, starting at 0
   * @param limit the limit past which characters should not be examined
   * @return the codepoint at the specified index
   * @throws IndexOutOfBoundsException if index is negative or &gt;=
   * limit, or if limit is negative or &gt;= the length of the array
   * @since 1.5
   */
  public static int codePointAt(char[] chars, int index, int limit)
  {
4464
    if (index < 0 || index >= limit || limit < 0 || limit > chars.length)
4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512
      throw new IndexOutOfBoundsException();
    char high = chars[index];
    if (! isHighSurrogate(high) || ++index >= limit)
      return high;
    char low = chars[index];
    if (! isLowSurrogate(low))
      return high;
    return toCodePoint(high, low);
  }

  /**
   * Get the code point before the specified index.  This is like
   * #codePointAt(char[], int), but checks the characters at
   * <code>index-1</code> and <code>index-2</code> to see if they form
   * a supplementary code point.  If they do not, the character at
   * <code>index-1</code> is returned.
   *
   * @param chars the character array
   * @param index the index just past the codepoint to get, starting at 0
   * @return the codepoint at the specified index
   * @throws IndexOutOfBoundsException if index is negative or &gt;= length()
   * @since 1.5
   */
  public static int codePointBefore(char[] chars, int index)
  {
    return codePointBefore(chars, index, 1);
  }

  /**
   * Get the code point before the specified index.  This is like
   * #codePointAt(char[], int), but checks the characters at
   * <code>index-1</code> and <code>index-2</code> to see if they form
   * a supplementary code point.  If they do not, the character at
   * <code>index-1</code> is returned.  The start parameter is used to
   * limit the range of the array which may be examined.
   *
   * @param chars the character array
   * @param index the index just past the codepoint to get, starting at 0
   * @param start the index before which characters should not be examined
   * @return the codepoint at the specified index
   * @throws IndexOutOfBoundsException if index is &gt; start or &gt;
   * the length of the array, or if limit is negative or &gt;= the
   * length of the array
   * @since 1.5
   */
  public static int codePointBefore(char[] chars, int index, int start)
  {
    if (index < start || index > chars.length
4513
        || start < 0 || start >= chars.length)
4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551
      throw new IndexOutOfBoundsException();
    --index;
    char low = chars[index];
    if (! isLowSurrogate(low) || --index < start)
      return low;
    char high = chars[index];
    if (! isHighSurrogate(high))
      return low;
    return toCodePoint(high, low);
  }

  /**
   * Get the code point before the specified index.  This is like
   * #codePointAt(CharSequence, int), but checks the characters at
   * <code>index-1</code> and <code>index-2</code> to see if they form
   * a supplementary code point.  If they do not, the character at
   * <code>index-1</code> is returned.
   *
   * @param sequence the CharSequence
   * @param index the index just past the codepoint to get, starting at 0
   * @return the codepoint at the specified index
   * @throws IndexOutOfBoundsException if index is negative or &gt;= length()
   * @since 1.5
   */
  public static int codePointBefore(CharSequence sequence, int index)
  {
    int len = sequence.length();
    if (index < 1 || index > len)
      throw new IndexOutOfBoundsException();
    --index;
    char low = sequence.charAt(index);
    if (! isLowSurrogate(low) || --index < 0)
      return low;
    char high = sequence.charAt(index);
    if (! isHighSurrogate(high))
      return low;
    return toCodePoint(high, low);
  }
Tom Tromey committed
4552
} // class Character