home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / java.z / Character.java < prev    next >
Text File  |  1996-05-03  |  49KB  |  1,072 lines

  1. /*
  2.  * W% 96/02/05  
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package java.lang;
  21.  
  22. /**
  23.  * The Character class provides an object wrapper for Character data values
  24.  * and serves as a place for character-oriented operations.  A wrapper is useful
  25.  * because most of Java's utility classes require the use of objects.  Since characters
  26.  * are not objects in Java, they need to be "wrapped" in a Character instance.
  27.  * @version     1.30, 05 Feb 1996
  28.  * @author    Lee Boynton, Guy Steele
  29.  */
  30.  
  31. public final
  32. class Character extends Object {
  33.     /**
  34.      * The minimum radix available for conversion to and from Strings.  
  35.      * The minimum value that a radix can be is 2.
  36.      * @see Integer#toString
  37.      */
  38.     public static final int MIN_RADIX = 2;
  39.  
  40.     /**
  41.      * The maximum radix available for conversion to and from Strings.  The
  42.      * maximum value that a radix can be is 36.
  43.      * @see Integer#toString
  44.      */
  45.     public static final int MAX_RADIX = 36;
  46.  
  47.     /**
  48.      * The minimum value a Character can have.  The lowest minimum value a
  49.      * Character can have is \u0000.
  50.      */
  51.     public static final char   MIN_VALUE = '\u0000';
  52.  
  53.     /**
  54.      * The maximum value a Character can have.  The greatest maximum value a
  55.      * Character can have is \uffff.
  56.      */
  57.     public static final char   MAX_VALUE = '\uffff';
  58.     
  59.  
  60.     private static long isLowerCaseTable[] = {
  61.     0x0000000000000000L, 0x07FFFFFE00000000L, 0x0000000000000000L, 0xFF7FFFFF80000000L, // 00xx
  62.     0x55AAAAAAAAAAAAAAL, 0xD4AAAAAAAAAAAB55L, 0x2651292A4E243129L, 0xA829AAAAB5555240L, // 01xx
  63.     0x0000000000AAAAAAL, 0xFFAFFBFBFFFF0000L, 0x000001F9640F7FFCL, 0x0000000000000000L, // 02xx
  64.     0x0000000000000000L, 0x0000000000000000L, 0xFFFFF00000010000L, 0x0003AAA800637FFFL, // 03xx
  65.     0xFFFF000000000000L, 0xAAAAAAAADFFEFFFFL, 0xAAAAAAAAAAAA0002L, 0x022A8AAAAAAA1114L, // 04xx
  66.     0x0000000000000000L, 0xFFFFFFFE00000000L, 0x00000000000000FFL, 0x0000000000000000L, // 05xx
  67.     0xAAAAAAAAAAAAAAAAL, 0xAAAAAAAAAAAAAAAAL, 0xAAAAAAAA07EAAAAAL, 0x02AAAAAAAAAAAAAAL, // 1Exx
  68.     0x00FF00FF003F00FFL, 0x3FFF00FF00FF003FL, 0x00DF00FF00FF00FFL, 0x00DC00FF00CF00DCL, // 1Fxx
  69.     };
  70.  
  71.     /**
  72.      * Determines whether the specified character is a lowercase character.
  73.      * 
  74.      * <p> A character is considered to be lowercase if and only if all
  75.      * of the following are true:
  76.      * <ul>
  77.      * <li>  The character is not in the range 0x2000 through 0x2FFF.
  78.      * <li>  The Unicode 1.1.5 attribute table does not specify a
  79.      *       mapping to lowercase for the character.
  80.      * <li>  At least one of the following is true:
  81.      *       <ul>
  82.      *       <li>  The Unicode 1.1.5 attribute table does specify a
  83.      *             mapping to uppercase for the character.
  84.      *       <li>  The Unicode 1.1.5 name for the character contains
  85.      *             the words "SMALL LETTER".
  86.      *       <li>  The Unicode 1.1.5 name for the character contains
  87.      *             the words "SMALL LIGATURE".
  88.      *       </ul>
  89.      * </ul>
  90.      * Of the ISO-LATIN-1 characters (character codes 0x0000 through 0x00FF),
  91.      * the following are lowercase:
  92.      * a b c d e f g h i j k l m n o p q r s t u v w x y z
  93.      * \u00DF \u00E0 \u00E1 \u00E2 \u00E3 \u00E4 \u00E5 \u00E6 \u00E7
  94.      * \u00E8 \u00E9 \u00EA \u00EB \u00EC \u00ED \u00EE \u00EF \u00F0
  95.      * \u00F1 \u00F2 \u00F3 \u00F4 \u00F5 \u00F6 \u00F8 \u00F9 \u00FA
  96.      * \u00FB \u00FC \u00FD \u00FE \u00FF
  97.      *
  98.      * @param ch    the character to be tested
  99.      * @return     true if the character is lowercase; false otherwise.
  100.      *
  101.      * @see java.lang.Character#isUpperCase
  102.      * @see java.lang.Character#isTitleCase
  103.      * @see java.lang.Character#toLowerCase
  104.      */
  105.  
  106.     public static boolean isLowerCase(char ch) {
  107.     return ((((ch < 0x0600) ? isLowerCaseTable[ch >> 6] :
  108.           ((ch & 0xFE00) == 0x1E00) ? isLowerCaseTable[(ch - (0x1E00 - 0x0600)) >> 6] :
  109.           ((ch & 0xFFC0) == 0xFB00) ? 0x0000000000F8007FL :
  110.           ((ch & 0xFFC0) == 0xFF40) ? 0x0000000007FFFFFEL : 0) >> (ch & 0x3F)) & 0x1L) != 0;
  111.     }
  112.  
  113.     private static long isUpperCaseTable[] = {
  114.     0x0000000000000000L, 0x0000000007FFFFFEL, 0x0000000000000000L, 0x000000007F7FFFFFL, // 00xx
  115.     0xAA55555555555555L, 0x2B555555555554AAL, 0x11AED295B1DBCED6L, 0x541255554AAAA490L, // 01xx
  116.     0x0000000000555555L, 0x0000000000000000L, 0x0000000000000000L, 0x0000000000000000L, // 02xx
  117.     0x0000000000000000L, 0x0000000000000000L, 0x00000FFBFFFED740L, 0x0000555400000000L, // 03xx
  118.     0x0000FFFFFFFFDFFEL, 0x5555555500000000L, 0x5555555555550001L, 0x011545555555088AL, // 04xx
  119.     0xFFFE000000000000L, 0x00000000007FFFFFL, 0x0000000000000000L, 0x0000000000000000L, // 05xx
  120.     0x5555555555555555L, 0x5555555555555555L, 0x5555555500155555L, 0x0155555555555555L, // 1Exx
  121.     0xFF00FF003F00FF00L, 0x0000FF00AA003F00L, 0x1F00FF00FF00FF00L, 0x1F001F000F001F00L, // 1Fxx
  122.     };
  123.  
  124.     /**
  125.      * Determines whether the specified character is an uppercase character.
  126.      * 
  127.      * <p> A character is considered to be uppercase if and only if all
  128.      * of the following are true:
  129.      * <ul>
  130.      * <li>  The character is not in the range 0x2000 through 0x2FFF.
  131.      * <li>  The Unicode 1.1.5 attribute table does not specify a
  132.      *       mapping to uppercase for the character.
  133.      * <li>  At least one of the following is true:
  134.      *       <ul>
  135.      *       <li>  The Unicode 1.1.5 attribute table does specify a
  136.      *             mapping to lowercase for the character.
  137.      *       <li>  The Unicode 1.1.5 name for the character contains
  138.      *             the words "CAPITAL LETTER".
  139.      *       <li>  The Unicode 1.1.5 name for the character contains
  140.      *             the words "CAPITAL LIGATURE".
  141.      *       </ul>
  142.      * </ul>
  143.      * Of the ISO-LATIN-1 characters (character codes 0x0000 through 0x00FF),
  144.      * the following are uppercase:
  145.      * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  146.      *
  147.      * \u00C0 \u00C1 \u00C2 \u00C3 \u00C4 \u00C5 \u00C6 \u00C7
  148.      * \u00C8 \u00C9 \u00CA \u00CB \u00CC \u00CD \u00CE \u00CF \u00D0
  149.      * \u00D1 \u00D2 \u00D3 \u00D4 \u00D5 \u00D6 \u00D8 \u00D9 \u00DA
  150.      * \u00DB \u00DC \u00DD \u00DE
  151.      *
  152.      * @param ch    the character to be tested
  153.      * @return     true if the character is uppercase; false otherwise.
  154.      * @see java.lang.Character#isLowerCase
  155.      * @see java.lang.Character#isTitleCase
  156.      * @see java.lang.Character#toUpperCase
  157.      */
  158.  
  159.     public static boolean isUpperCase(char ch) {
  160.     return ((((ch < 0x0600) ? isUpperCaseTable[ch >> 6] :
  161.           ((ch & 0xFE00) == 0x1E00) ? isUpperCaseTable[(ch - (0x1E00 - 0x0600)) >> 6] :
  162.           ((ch >= 0x10A0) && (ch <= 0x10CF)) ? 0xFFFFFFFF0000003FL :
  163.           ((ch & 0xFFC0) == 0xFF00) ? 0x07FFFFFE00000000L : 0) >> (ch & 0x3F)) & 0x1L) != 0;
  164.     }
  165.  
  166.  
  167.     /**
  168.      * Determines whether the specified character is a titlecase character.
  169.      *
  170.      * <p> A character is considered to be titlecase if and only if all
  171.      * of the following are true:
  172.      * <ul>
  173.      * <li>  The character is not in the range 0x2000 through 0x2FFF.
  174.      * <li>  The Unicode 1.1.5 attribute table does specify a
  175.      *       mapping to uppercase for the  character.
  176.      * <li>  The Unicode 1.1.5 attribute table does specify a
  177.      *       mapping to lowercase for the character.
  178.      * </ul>
  179.      * The basic idea is that there are a few Unicode characters
  180.      * whose printed representations look like pairs of Latin
  181.      * letters.  For example, there is an uppercase letter that
  182.      * looks like "LJ" and the corresponding lowercase letter looks
  183.      * like "lj".  These letters have a third form, a titlecase
  184.      * form, that looks like "Lj".  This is the appropriate form
  185.      * to use when rendering a word in lowercase with initial
  186.      * capitals, as for a book title.
  187.      * 
  188.      * <p> There are exactly four Unicode characters for which this method
  189.      * returns true:
  190.      * <dl>
  191.      * <dt>  \u01C5  <dd>  LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON
  192.      * <dt>  \u01C8  <dd>  LATIN CAPITAL LETTER L WITH SMALL LETTER J
  193.      * <dt>  \u01CB  <dd>  LATIN CAPITAL LETTER N WITH SMALL LETTER J
  194.      * <dt>  \u01F2  <dd>  LATIN CAPITAL LETTER D WITH SMALL LETTER Z
  195.      * </dl>
  196.      * 
  197.      * @param ch    the character to be tested
  198.      * @return     true if the character is titlecase; false otherwise.
  199.      * @see java.lang.Character#isUpperCase
  200.      * @see java.lang.Character#isLowerCase
  201.      * @see java.lang.Character#toTitleCase
  202.      */
  203.  
  204.     /* A code point is considered to be titlecase if it is not in the range 2000-2FFF
  205.        and has both a translation to lowercase and a translation to uppercase
  206.        in the Unicode 1.1.5 attributes table.  There are exactly four such characters.
  207.      */
  208.  
  209.     public static boolean isTitleCase(char ch) {
  210.     return ch == '\u01C5'    // LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON
  211.         || ch == '\u01C8'    // LATIN CAPITAL LETTER L WITH SMALL LETTER J
  212.         || ch == '\u01CB'    // LATIN CAPITAL LETTER N WITH SMALL LETTER J
  213.         || ch == '\u01F2';    // LATIN CAPITAL LETTER D WITH SMALL LETTER Z
  214.     }
  215.  
  216.     /**
  217.      * Determines whether the specified character is a digit.
  218.      * 
  219.      * <p> A character is considered to be a digit if and only if both
  220.      * of the following are true:
  221.      * <ul>
  222.      * <li>  The character is not in the range 0x2000 through 0x2FFF.
  223.      * <li>  The Unicode 1.1.5 name for the character contains
  224.      *       the word "DIGIT".
  225.      * </ul>
  226.      * These are the ranges of Unicode characters that are considered digits:
  227.      * <dl>
  228.      * <dt>  0x0030 through 0x0039  <dd>  ISO-LATIN-1 digits ('0' through '9')
  229.      * <dt>  0x0660 through 0x0669  <dd>  Arabic-Indic digits
  230.      * <dt>  0x06F0 through 0x06F9  <dd>  Extended Arabic-Indic digits
  231.      * <dt>  0x0966 through 0x096F  <dd>  Devanagari digits
  232.      * <dt>  0x09E6 through 0x09EF  <dd>  Bengali digits
  233.      * <dt>  0x0A66 through 0x0A6F  <dd>  Gurmukhi digits
  234.      * <dt>  0x0AE6 through 0x0AEF  <dd>  Gujarati digits
  235.      * <dt>  0x0B66 through 0x0B6F  <dd>  Oriya digits
  236.      * <dt>  0x0BE7 through 0x0BEF  <dd>  Tamil digits
  237.      * <dt>  0x0C66 through 0x0C6F  <dd>  Telugu digits
  238.      * <dt>  0x0CE6 through 0x0CEF  <dd>  Kannada digits
  239.      * <dt>  0x0D66 through 0x0D6F  <dd>  Malayalam digits
  240.      * <dt>  0x0E50 through 0x0E59  <dd>  Thai digits
  241.      * <dt>  0x0ED0 through 0x0ED9  <dd>  Lao digits
  242.      * <dt>  0xFF10 through 0xFF19  <dd>  Fullwidth digits
  243.      * </dl>
  244.      *
  245.      * @param ch    the character to be tested
  246.      * @return     true if the character is a digit; false otherwise.
  247.      * @see java.lang.Character#digit
  248.      * @see java.lang.Character#forDigit
  249.      */
  250.  
  251.     public static boolean isDigit(char ch) {
  252.     if ((ch >= '0') && (ch <= '9'))
  253.         return true;
  254.     switch (ch>>8) {
  255.       case 0x06:
  256.         return 
  257.             ((ch >= 0x0660) && (ch <=0x0669)) ||    // Arabic-Indic
  258.             ((ch >= 0x06F0) && (ch <=0x06F9));    // Extended Arabic-Indic
  259.       case 0x09:
  260.         return
  261.             ((ch >= 0x0966) && (ch <=0x096F)) ||    // Devanagari
  262.             ((ch >= 0x09E6) && (ch <=0x09EF));    // Bengali
  263.           case 0x0A:
  264.         return
  265.             ((ch >= 0x0A66) && (ch <=0x0A6F)) ||    // Gurmukhi
  266.             ((ch >= 0x0AE6) && (ch <=0x0AEF));    // Gujarati
  267.       case 0x0B:
  268.         return
  269.             ((ch >= 0x0B66) && (ch <=0x0B6F)) ||    // Oriya
  270.             ((ch >= 0x0BE7) && (ch <=0x0BEF));    // Tamil
  271.       case 0x0C:
  272.         return
  273.             ((ch >= 0x0C66) && (ch <=0x0C6F)) ||    // Telugu
  274.             ((ch >= 0x0CE6) && (ch <=0x0CEF));    // Kannada
  275.       case 0x0D:
  276.         return
  277.             ((ch >= 0x0D66) && (ch <=0x0D6F));    // Malayalam
  278.       case 0x0E:
  279.         return
  280.             ((ch >= 0x0E50) && (ch <=0x0E59)) ||    // Thai
  281.             ((ch >= 0x0ED0) && (ch <=0x0ED9));    // Lao
  282.       // Unicode 1.0 Tibetan script was withdrawn in Unicode 1.1 for further study
  283.       case 0xFF:
  284.         return
  285.         ((ch >= 0xFF10) && (ch <=0xFF19));    // Fullwidth digits
  286.       default:
  287.         return false;
  288.     }
  289.      }
  290.  
  291.     private static long isDefinedTable01C0through06FF[] = {
  292.                                        0xFC3FFFFFFFFFFFFFL,  // 01xx
  293.     0x0000000000FFFFFFL, 0xFFFFFFFFFFFF0000L, 0xFFFF01FFFFFFFFFFL, 0x000003FF7FFFFFFFL,  // 02xx
  294.     0xFFFFFFFFFFFFFFFFL, 0x443000030000003FL, 0xFFFFFFFBFFFFD7F0L, 0x000FFFFD547F7FFFL,  // 03xx
  295.     0xFFFFFFFFFFFFDFFEL, 0xFFFFFFFFDFFEFFFFL, 0xFFFFFFFFFFFF007FL, 0x033FCFFFFFFF199FL,  // 04xx
  296.     0xFFFE000000000000L, 0xFFFFFFFEFE7FFFFFL, 0xFBFF0000000002FFL, 0x001F07FFFFFF000FL,  // 05xx
  297.     0x07FFFFFE88001000L, 0xFFFF3FFF0007FFFFL, 0x7CFFFFFFFFFFFFFFL, 0x03FF3FFFFFFF7FFFL,  // 06xx
  298.     };
  299.  
  300.     private static long isDefinedTable0900through0EFF[] = {
  301.     0xF3FFFFFFFFFFFFEEL, 0x0001FFFFFF1F3FFFL, 0xD3C5FDFFFFF99FEEL, 0x07FFFFCFB080399FL,  // 09xx
  302.     0xD36DFDFFFFF987E4L, 0x001FFFC05E003987L, 0xF3EDFDFFFFFBAFEEL, 0x0000FFC100013BBFL,  // 0Axx
  303.     0xF3CDFDFFFFF99FEEL, 0x0001FFC3B0C0398FL, 0xC3BFC718D63DC7ECL, 0x0007FF8000803DC7L,  // 0Bxx
  304.     0xC3EFFDFFFFFDDFEEL, 0x0000FFC300603DDFL, 0xC3EFFDFFFFFDDFECL, 0x0000FFC340603DDFL,  // 0Cxx
  305.     0xC3FFFDFFFFFDDFECL, 0x0000FFC300803DCFL, 0x0000000000000000L, 0x0000000000000000L,  // 0Dxx
  306.     0x87FFFFFFFFFFFFFEL, 0x000000000FFFFFFFL, 0x3BFFECAEFEF02596L, 0x0000000033FF3F5FL,  // 0Exx
  307.     };
  308.  
  309.     private static long isDefinedTable1080through11FF[] = {
  310.                           0xFFFFFFFF00000000L, 0x087FFFFFFFFF003FL,  // 10xx
  311.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFF83FFFFFFL, 0xFFFFFF07FFFFFFFFL, 0x03FFFFFFFFFFFFFFL,  // 11xx
  312.     };
  313.  
  314.     private static long isDefinedTable1E00through27BF[] = {
  315.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFF07FFFFFFL, 0x03FFFFFFFFFFFFFFL,  // 1Exx
  316.     0xFFFFFFFF3F3FFFFFL, 0x3FFFFFFFAAFF3F3FL, 0xFFDFFFFFFFFFFFFFL, 0x7FDCFFFFEFCFFFDFL,  // 1Fxx
  317.     0xFFFF7FFFFFFFFFFFL, 0xFFF1FC000000007FL, 0x000007FF00007FFFL, 0x00000003FFFF0000L,  // 20xx
  318.     0x01FFFFFFFFFFFFFFL, 0xFFFFFFFFFFF80000L, 0xFFFFFFFFFFFF0007L, 0x000007FFFFFFFFFFL,  // 21xx
  319.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0x0003FFFFFFFFFFFFL,  // 22xx
  320.     0xFFFFFFFFFFFFFFFDL, 0x07FFFFFFFFFFFFFFL, 0x0000000000000000L, 0x0000000000000000L,  // 23xx
  321.     0x0000001FFFFFFFFFL, 0xFFFFFFFF000007FFL, 0xFFFFFFFFFFFFFFFFL, 0x000007FFFFFFFFFFL,  // 24xx
  322.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFF003FFFFFL, 0x0000FFFFFFFFFFFFL,  // 25xx
  323.     0xFFFFFFFFFC0FFFFFL, 0x0000FFFFFFFFFFFFL, 0x0000000000000000L, 0x0000000000000000L,  // 26xx
  324.     0xFFFFFEFFFFFFF3DEL, 0xFFC000FE7F47AFFFL, 0x7FFEFFFFFF1FFFFFL,                 // 27xx
  325.     };
  326.  
  327.     private static long isDefinedTable3000through33FF[] = {
  328.     0x80FFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFEL, 0xFFFFFFFE7E1FFFFFL, 0x7FFFFFFFFFFFFFFFL,  // 30xx
  329.     0xFFFE1FFFFFFFFFE0L, 0xFFFFFFFFFFFFFFFFL, 0x00000000FFFF7FFFL, 0x0000000000000000L,  // 31xx
  330.     0xFFFFFFFF1FFFFFFFL, 0x8FFFFFFF0000000FL, 0x0001FFFFFFFFFFFFL, 0x7FFFFFFFFFFF0FFFL,  // 32xx
  331.     0xFFFFFFFFFFFFFFFFL, 0xF87FFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0x7FFFFFFF3FFFFFFFL,  // 33xx
  332.     };
  333.  
  334.     private static long isDefinedTableFB00throughFFFF[] = {
  335.     0x5F7FFFFFC0F8007FL, 0xFFFFFFFFFFFFFFDBL, 0x0003FFFFFFFFFFFFL, 0xFFFFFFFFFFF80000L,  // FBxx
  336.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL,  // FCxx
  337.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFF0000L, 0xFFFFFFFFFFFCFFFFL, 0x0FFF0000000000FFL,  // FDxx
  338.     0xFFFF000F00000000L, 0xFFD70F7FFFF7FE1FL, 0xFFFFFFFFFFFFFFFFL, 0x9FFFFFFFFFFFFFFFL,  // FExx
  339.     0xFFFFFFFFFFFFFFFEL, 0xFFFFFFFE7FFFFFFFL, 0x7FFFFFFFFFFFFFFFL, 0x20007F7F1CFCFCFCL,  // FFxx
  340.     };
  341.  
  342.     /**
  343.      * Determines whether the specified character actually has a Unicode definition.
  344.      * 
  345.      * @param ch    the character to be tested
  346.      * @return     true if the character has a defined meaning in Unicode 1.1.5; false otherwise.
  347.      *
  348.      * @see java.lang.Character#isDigit
  349.      * @see java.lang.Character#isLetter
  350.      * @see java.lang.Character#isLetterOrDigit
  351.      * @see java.lang.Character#isUpperCase
  352.      * @see java.lang.Character#isLowerCase
  353.      * @see java.lang.Character#isTitleCase
  354.      */
  355.  
  356.     public static boolean isDefined(char ch) {
  357.     if (ch < 0x01F6)
  358.         return true;
  359.     else if (ch < 0x0700)
  360.         return ((isDefinedTable01C0through06FF[(ch - 0x01C0) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  361.     else if ((ch >= 0x0900) && (ch <= 0x0EFF))
  362.         return ((isDefinedTable0900through0EFF[(ch - 0x0900) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  363.     else if ((ch >= 0x1080) && (ch <= 0x11FF))
  364.         return ((isDefinedTable1080through11FF[(ch - 0x1080) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  365.     else if ((ch >= 0x1E00) && (ch <= 0x27BF))
  366.         return ((isDefinedTable1E00through27BF[(ch - 0x1E00) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  367.     else if ((ch >= 0x3000) && (ch <= 0x33FF))
  368.         return ((isDefinedTable3000through33FF[(ch - 0x3000) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  369.     else if (ch >= 0xFB00)
  370.         return ((isDefinedTableFB00throughFFFF[(ch - 0xFB00) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  371.     else return ((ch >= 0x3400) && (ch <= 0x9FA5)) || ((ch >= 0xF900) && (ch <= 0xFA2D));
  372.     }
  373.  
  374.     private static long isLetterTable0000through06FF[] = {
  375.     0x0000000000000000L, 0x07FFFFFE07FFFFFEL, 0x0000000000000000L, 0xFF7FFFFFFF7FFFFFL,  // 00xx
  376.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFC3FFFFFFFFFFFFFL,  // 01xx
  377.     0x0000000000FFFFFFL, 0xFFFFFFFFFFFF0000L, 0xFFFF01FFFFFFFFFFL, 0x000003FF7FFFFFFFL,  // 02xx
  378.     0xFFFFFFFFFFFFFFFFL, 0x443000030000003FL, 0xFFFFFFFBFFFFD7F0L, 0x000FFFFD547F7FFFL,  // 03xx
  379.     0xFFFFFFFFFFFFDFFEL, 0xFFFFFFFFDFFEFFFFL, 0xFFFFFFFFFFFF007FL, 0x033FCFFFFFFF199FL,  // 04xx
  380.     0xFFFE000000000000L, 0xFFFFFFFEFE7FFFFFL, 0xFBFF0000000002FFL, 0x001F07FFFFFF000FL,  // 05xx
  381.     0x07FFFFFE88001000L, 0xFFFF3C000007FFFFL, 0x7CFFFFFFFFFFFFFFL, 0x00003FFFFFFF7FFFL,  // 06xx
  382.     };
  383.  
  384.     private static long isLetterTable0900through0EFF[] = {
  385.     0xF3FFFFFFFFFFFFEEL, 0x0001003FFF1F3FFFL, 0xD3C5FDFFFFF99FEEL, 0x07FF000FB080399FL,  // 09xx
  386.     0xD36DFDFFFFF987E4L, 0x001F00005E003987L, 0xF3EDFDFFFFFBAFEEL, 0x0000000100013BBFL,  // 0Axx
  387.     0xF3CDFDFFFFF99FEEL, 0x00010003B0C0398FL, 0xC3BFC718D63DC7ECL, 0x0007000000803DC7L,  // 0Bxx
  388.     0xC3EFFDFFFFFDDFEEL, 0x0000000300603DDFL, 0xC3EFFDFFFFFDDFECL, 0x0000000340603DDFL,  // 0Cxx
  389.     0xC3FFFDFFFFFDDFECL, 0x0000000300803DCFL, 0x0000000000000000L, 0x0000000000000000L,  // 0Dxx
  390.     0x87FFFFFFFFFFFFFEL, 0x000000000C00FFFFL, 0x3BFFECAEFEF02596L, 0x0000000030003F5FL,  // 0Exx
  391.     };
  392.  
  393.     private static long isLetterTable1080through11FF[] = isDefinedTable1080through11FF;
  394.  
  395.     private static long isLetterTable1E00through1FFF[] = isDefinedTable1E00through27BF;
  396.  
  397.     private static long isLetterTable3000through33FF[] = isDefinedTable3000through33FF;
  398.  
  399.     private static long isLetterTableFB00throughFFFF[] = {
  400.     0x5F7FFFFFC0F8007FL, 0xFFFFFFFFFFFFFFDBL, 0x0003FFFFFFFFFFFFL, 0xFFFFFFFFFFF80000L,  // FBxx
  401.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL,  // FCxx
  402.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFF0000L, 0xFFFFFFFFFFFCFFFFL, 0x0FFF0000000000FFL,  // FDxx
  403.     0x0000000000000000L, 0xFFD7000000000000L, 0xFFFFFFFFFFFFFFFFL, 0x1FFFFFFFFFFFFFFFL,  // FExx
  404.     0x07FFFFFE00000000L, 0xFFFFFFC007FFFFFEL, 0x7FFFFFFFFFFFFFFFL, 0x000000001CFCFCFCL,  // FFxx
  405.     };
  406.  
  407.     /**
  408.      * Determines whether the specified character is a letter.
  409.      * <p> A character is considered to be a letter if and only if
  410.      * is it a "letter or digit" but is not a "digit".
  411.      *
  412.      * <p> Note that not all letters have case: many Unicode characters are
  413.      * letters but are neither uppercase nor lowercase nor titlecase.
  414.      * 
  415.      * @param ch    the character to be tested
  416.      * @return     true if the character is a letter; false otherwise.
  417.      *
  418.      *
  419.      * @see java.lang.Character#isDigit
  420.      * @see java.lang.Character#isLetterOrDigit
  421.      * @see java.lang.Character#isJavaLetter
  422.      * @see java.lang.Character#isJavaLetterOrDigit
  423.      * @see java.lang.Character#isUpperCase
  424.      * @see java.lang.Character#isLowerCase
  425.      * @see java.lang.Character#isTitleCase
  426.      */
  427.  
  428.     public static boolean isLetter(char ch) {
  429.     if (ch < 0x0700)
  430.         return ((isLetterTable0000through06FF[ch >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  431.     else if ((ch >= 0x0900) && (ch <= 0x0EFF))
  432.         return ((isLetterTable0900through0EFF[(ch - 0x0900) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  433.     else if ((ch >= 0x1080) && (ch <= 0x11FF))
  434.         return ((isLetterTable1080through11FF[(ch - 0x1080) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  435.     else if ((ch >= 0x1E00) && (ch <= 0x1FFF))
  436.         return ((isLetterTable1E00through1FFF[(ch - 0x1E00) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  437.     else if ((ch >= 0x3040) && (ch <= 0x33FF))
  438.         return ((isLetterTable3000through33FF[(ch - 0x3000) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  439.     else if (ch >= 0xFB00)
  440.         return ((isLetterTableFB00throughFFFF[(ch - 0xFB00) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  441.     else return ((ch >= 0x3400) && (ch <= 0x9FA5)) || ((ch >= 0xF900) && (ch <= 0xFA2D));
  442.     }
  443.  
  444.     private static long isLDTable0000through06FF[] = {
  445.     0x03FF000000000000L, 0x07FFFFFE07FFFFFEL, 0x0000000000000000L, 0xFF7FFFFFFF7FFFFFL,  // 00xx
  446.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFC3FFFFFFFFFFFFFL,  // 01xx
  447.     0x0000000000FFFFFFL, 0xFFFFFFFFFFFF0000L, 0xFFFF01FFFFFFFFFFL, 0x000003FF7FFFFFFFL,  // 02xx
  448.     0xFFFFFFFFFFFFFFFFL, 0x443000030000003FL, 0xFFFFFFFBFFFFD7F0L, 0x000FFFFD547F7FFFL,  // 03xx
  449.     0xFFFFFFFFFFFFDFFEL, 0xFFFFFFFFDFFEFFFFL, 0xFFFFFFFFFFFF007FL, 0x033FCFFFFFFF199FL,  // 04xx
  450.     0xFFFE000000000000L, 0xFFFFFFFEFE7FFFFFL, 0xFBFF0000000002FFL, 0x001F07FFFFFF000FL,  // 05xx
  451.     0x07FFFFFE88001000L, 0xFFFF3FFF0007FFFFL, 0x7CFFFFFFFFFFFFFFL, 0x03FF3FFFFFFF7FFFL,  // 06xx
  452.     };
  453.  
  454.     private static long isLDTable0900through0EFF[] = {
  455.     0xF3FFFFFFFFFFFFEEL, 0x0001FFFFFF1F3FFFL, 0xD3C5FDFFFFF99FEEL, 0x07FFFFCFB080399FL,  // 09xx
  456.     0xD36DFDFFFFF987E4L, 0x001FFFC05E003987L, 0xF3EDFDFFFFFBAFEEL, 0x0000FFC100013BBFL,  // 0Axx
  457.     0xF3CDFDFFFFF99FEEL, 0x0001FFC3B0C0398FL, 0xC3BFC718D63DC7ECL, 0x0007FF8000803DC7L,  // 0Bxx
  458.     0xC3EFFDFFFFFDDFEEL, 0x0000FFC300603DDFL, 0xC3EFFDFFFFFDDFECL, 0x0000FFC340603DDFL,  // 0Cxx
  459.     0xC3FFFDFFFFFDDFECL, 0x0000FFC300803DCFL, 0x0000000000000000L, 0x0000000000000000L,  // 0Dxx
  460.     0x87FFFFFFFFFFFFFEL, 0x000000000FFFFFFFL, 0x3BFFECAEFEF02596L, 0x0000000033FF3F5FL,  // 0Exx
  461.     };
  462.  
  463.     private static long isLDTable1080through11FF[] = isDefinedTable1080through11FF;
  464.  
  465.     private static long isLDTable1E00through1FFF[] = isDefinedTable1E00through27BF;
  466.  
  467.     private static long isLDTable3000through33FF[] = isDefinedTable3000through33FF;
  468.  
  469.     private static long isLDTableFB00throughFFFF[] = {
  470.     0x5F7FFFFFC0F8007FL, 0xFFFFFFFFFFFFFFDBL, 0x0003FFFFFFFFFFFFL, 0xFFFFFFFFFFF80000L,  // FBxx
  471.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL,  // FCxx
  472.     0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFF0000L, 0xFFFFFFFFFFFCFFFFL, 0x0FFF0000000000FFL,  // FDxx
  473.     0x0000000000000000L, 0xFFD7000000000000L, 0xFFFFFFFFFFFFFFFFL, 0x1FFFFFFFFFFFFFFFL,  // FExx
  474.     0x07FFFFFE03FF0000L, 0xFFFFFFC007FFFFFEL, 0x7FFFFFFFFFFFFFFFL, 0x000000001CFCFCFCL,  // FFxx
  475.     };
  476.  
  477.     /**
  478.      * Determines whether the specified character is a letter or digit.
  479.      *
  480.      * These are the ranges of Unicode characters that are considered to be letters or digits:
  481.      * <dl>
  482.      * <dt>  0x0030 through 0x0039  <dd>  ISO-LATIN-1 digits ('0' through '9')
  483.      * <dt>  0x0041 through 0x005A  <dd>  ISO-LATIN-1 uppercase Latin letters ('A' through 'Z')
  484.      * <dt>  0x0061 through 0x007A  <dd>  ISO-LATIN-1 lowercase Latin letters ('A' through 'Z')
  485.      * <dt>  0x00C0 through 0x00D6,
  486.      *       0x00D8 through 0x00F6, and
  487.      *       0x00F8 through 0x00FF  <dd>  ISO-LATIN-1 supplementary letters
  488.      * <dt>  0x0100 through 0x1FFF, but only if there is an entry in the Unicode 1.1.5 table
  489.      *                              <dd>  Latin extended-A, Latin extended-B, IPA extensions,
  490.      *                      spacing modifier letters, combining diacritical marks,
  491.      *                      basic Greek, Greek symbols and Coptic, Cyrillic, Armenian,
  492.      *                      Hebrew extended-A, Basic Hebrew, Hebrew extended-B,
  493.      *                      Basic Arabic, Arabic extended, Devanagari, Bengali,
  494.      *                      Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada,
  495.      *                      Malayalam, Thai, Lao, Basic Georgian, Georgian extended,
  496.      *                      Hanguljamo, Latin extended additional, Greek extended
  497.      * <dt>  0x3040 through 0x9FA5  <dd>  Hiragana, Katakana, Bopomofo, Hangul compatibility Jamo,
  498.      *                      CJK miscellaneous, enclosed CJK characters and months,
  499.      *                      CJK compatibility, Hangul, Hangul supplementary-A,
  500.      *                      Hangul supplementary-B, CJK unified ideographs
  501.      * <dt>  0xF900 through 0xFA2D  <dd>  CJK compatibility ideographs
  502.      * <dt>  0xFB00 through 0xFDFF, but only if there is an entry in the Unicode 1.1.5 table
  503.      *                              <dd>  alphabetic presentation forms,
  504.      *                      Arabic presentation forms-A
  505.      * <dt>  0xFE70 through 0xFEFE, but only if there is an entry in the Unicode 1.1.5 table
  506.      *                              <dd>  Arabic presentation forms-B
  507.      * <dt>  0xFF10 through 0xFF19  <dd>  Fullwidth digits
  508.      * <dt>  0xFF21 through 0xFF3A  <dd>  Fullwidth Latin uppercase
  509.      * <dt>  0xFF41 through 0xFF5A  <dd>  Fullwidth Latin lowercase
  510.      * <dt>  0xFF66 through 0xFFDC  <dd>  Halfwidth Katakana and Hangul
  511.      * </dl>
  512.      * 
  513.      * @param ch    the character to be tested
  514.      * @return     true if the character is a letter or digit; false otherwise.
  515.      *
  516.      * @see java.lang.Character#isDigit
  517.      * @see java.lang.Character#isLetter
  518.      * @see java.lang.Character#isJavaLetter
  519.      * @see java.lang.Character#isJavaLetterOrDigit
  520.      */
  521.  
  522.  
  523.     public static boolean isLetterOrDigit(char ch) {
  524.     if (ch < 0x0700)
  525.         return ((isLDTable0000through06FF[ch >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  526.     else if ((ch >= 0x0900) && (ch <= 0x0EFF))
  527.         return ((isLDTable0900through0EFF[(ch - 0x0900) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  528.     else if ((ch >= 0x1080) && (ch <= 0x11FF))
  529.         return ((isLDTable1080through11FF[(ch - 0x1080) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  530.     else if ((ch >= 0x1E00) && (ch <= 0x1FFF))
  531.         return ((isLDTable1E00through1FFF[(ch - 0x1E00) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  532.     else if ((ch >= 0x3040) && (ch <= 0x33FF))
  533.         return ((isLDTable3000through33FF[(ch - 0x3000) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  534.     else if (ch >= 0xFB00)
  535.         return ((isLDTableFB00throughFFFF[(ch - 0xFB00) >> 6] >> (ch & 0x3F)) & 0x1L) != 0;
  536.     else return ((ch >= 0x3400) && (ch <= 0x9FA5)) || ((ch >= 0xF900) && (ch <= 0xFA2D));
  537.     }
  538.  
  539.     /**
  540.      * Determines whether the specified character is a "Java" letter,
  541.      * that is, permissible as the first character in a Java identifier.
  542.      *
  543.      * <p> A character is considered to be a Java letter if and only if
  544.      * it is a letter or the dollar sign "$" or the underscore "_".
  545.      *
  546.      * @param ch    the character to be tested
  547.      * @return     true if the character is a Java letter; false otherwise.
  548.      * @see java.lang.Character#isLetter
  549.      * @see java.lang.Character#isLetterOrDigit
  550.      * @see java.lang.Character#isJavaLetterOrDigit
  551.      */
  552.  
  553.     public static boolean isJavaLetter(char ch) {
  554.       return isLetter(ch) || ch == '$' || ch == '_';
  555.     }
  556.  
  557.     /**
  558.      * Determines whether the specified character is a "Java" letter or digit,
  559.      * that is, permissible as a non-initial character in a Java identifier.
  560.      * <p> A character is considered to be a Java letter or digit if and only if
  561.      * it is a letter or a digit or the dollar sign "$" or the underscore "_".
  562.      *
  563.      * 
  564.      * @param ch    the character to be tested
  565.      * @return     true if the character is a Java letter or digit; 
  566.      *          false otherwise.
  567.      *
  568.      * @see java.lang.Character#isLetter
  569.      * @see java.lang.Character#isLetterOrDigit
  570.      * @see java.lang.Character#isJavaLetter
  571.      */
  572.  
  573.     public static boolean isJavaLetterOrDigit(char ch) {
  574.       return isLetterOrDigit(ch) || ch == '$' || ch == '_';
  575.     }
  576.  
  577.     private static long toLowerCaseTable[] = {
  578.     0xAA54555555555555L, 0x2B555555555554AAL, 0x11AED29531DBCCD6L, 0x541655554AAAADB0L, // 01xx
  579.     0x0000000000555555L, 0x0000000000000000L, 0x0000000000000000L, 0x0000000000000000L, // 02xx
  580.     0x0000000000000000L, 0x0000000000000000L, 0x00000FFBFFFED740L, 0x0000555400000000L, // 03xx
  581.     0x0000FFFFFFFFDFFEL, 0x5555555500000000L, 0x5555555555550001L, 0x011545555555088AL, // 04xx
  582.     0xFFFE000000000000L, 0x00000000007FFFFFL, 0x0000000000000000L, 0x0000000000000000L, // 05xx
  583.     0x5555555555555555L, 0x5555555555555555L, 0x5555555500155555L, 0x0155555555555555L, // 1Exx
  584.     0xFF00FF003F00FF00L, 0x0000FF00AA003F00L, 0x1F00FF00FF00FF00L, 0x1F001F000F001F00L, // 1Fxx
  585.     };
  586.  
  587.     /**
  588.      * The given character is mapped to its lowercase equivalent;
  589.      * if the character has no lowercase equivalent, the character itself is returned.
  590.      * A character has a lowercase equivalent if and only if a lowercase mapping
  591.      * is specified for the character in the Unicode 1.1.5 attribute table.
  592.      *
  593.      * Note that some Unicode characters in the range 0x2000 through 0x2FFF have
  594.      * lowercase mappings; for example, \u2160 (ROMAN NUMERAL ONE) has a lowercase
  595.      * mapping to \u2170 (SMALL ROMAN NUMERAL ONE).  This method does map such
  596.      * characters to their lowercase equivalents even though the method isUpperCase
  597.      * does not return true for such characters.
  598.      *
  599.      * @param ch    the character to be converted
  600.      * @return     the lowercase equivalent of the character, if any;
  601.      *        otherwise the character itself.
  602.      *
  603.      * @see java.lang.Character#isLowerCase
  604.      * @see java.lang.Character#isUpperCase
  605.      * @see java.lang.Character#toUpperCase
  606.      * @see java.lang.Character#toTitleCase
  607.      */
  608.  
  609.     public static char toLowerCase(char ch) {
  610.     // Quick check for ISO-LATIN-1
  611.     if ((ch >= 'A') && (ch <= 'Z'))
  612.         return (char)(ch + ('a' - 'A'));
  613.     if (ch < 0x00C0) return ch;
  614.     if (ch < 0x0100) {
  615.         if (ch >= 0x00DF) return ch;
  616.         if (ch == '\u00D7') return ch;        // MULTIPLICATION SIGN
  617.         return (char)(ch + 0x0020);
  618.     }
  619.     // Okay, it's more complicated
  620.     if (((((ch < 0x0600) ? toLowerCaseTable[(ch - 0x0100) >> 6] :
  621.           ((ch & 0xFE00) == 0x1E00) ? toLowerCaseTable[(ch - (0x1E00 - (0x0600 - 0x0100))) >> 6] :
  622.           ((ch >= 0x10A0) && (ch <= 0x10C5)) ? 0xFFFFFFFF0000003FL :
  623.           ((ch & 0xFFC0) == 0x2140) ? 0x0000FFFF00000000L :
  624.           ((ch >= 0x24B6) && (ch <= 0x24CF)) ? 0xFFC000000000FFFFL :
  625.           ((ch & 0xFFC0) == 0xFF00) ? 0x07FFFFFE00000000L : 0) >> (ch & 0x3F)) & 0x1L) != 0) {
  626.         // It is known to be lowercase; now figure out the conversion
  627.         switch (ch >> 8) {
  628.           case 0x01:
  629.         switch (ch & 0xFF) {
  630.           case 0x78: return '\u00FF';    // LATIN CAPITAL LETTER Y WITH DIAERESIS
  631.           case 0x81: return '\u0253';    // LATIN CAPITAL LETTER B WITH HOOK
  632.           case 0x86: return '\u0254';    // LATIN CAPITAL LETTER OPEN O
  633.           case 0x8A: return '\u0257';    // LATIN CAPITAL LETTER D WITH HOOK
  634.           case 0x8E: return '\u0258';    // LATIN CAPITAL LETTER REVERSED E
  635.           case 0x8F: return '\u0259';    // LATIN CAPITAL LETTER SCHWA
  636.           case 0x90: return '\u025B';    // LATIN CAPITAL LETTER OPEN E
  637.           case 0x93: return '\u0260';    // LATIN CAPITAL LETTER G WITH HOOK
  638.           case 0x94: return '\u0263';    // LATIN CAPITAL LETTER GAMMA
  639.           case 0x96: return '\u0269';    // LATIN CAPITAL LETTER IOTA
  640.           case 0x97: return '\u0268';    // LATIN CAPITAL LETTER I WITH STROKE
  641.           case 0x9C: return '\u026F';    // LATIN CAPITAL LETTER TURNED M
  642.           case 0x9D: return '\u0272';    // LATIN CAPITAL LETTER N WITH LEFT HOOK
  643.           case 0xA9: return '\u0283';    // LATIN CAPITAL LETTER ESH
  644.           case 0xAE: return '\u0288';    // LATIN CAPITAL LETTER T WITH RETROFLEX HOOK
  645.           case 0xB1: return '\u028A';    // LATIN CAPITAL LETTER UPSILON
  646.           case 0xB2: return '\u028B';    // LATIN CAPITAL LETTER V WITH HOOK
  647.           case 0xB7: return '\u0292';    // LATIN CAPITAL LETTER EZH
  648.           case 0xC4: return '\u01C6';    // LATIN CAPITAL LETTER DZ WITH CARON
  649.           case 0xC7: return '\u01C9';    // LATIN CAPITAL LETTER LJ
  650.           case 0xCA: return '\u01CC';    // LATIN CAPITAL LETTER NJ
  651.           case 0xF1: return '\u01F3';    // LATIN CAPITAL LETTER DZ
  652.           default:   return (char)(ch + 1);
  653.         }
  654.           case 0x02:
  655.         return (char)(ch + 1);
  656.           case 0x03:
  657.         switch (ch & 0xFF) {
  658.           case 0x86: return '\u03AC';    // GREEK CAPITAL LETTER ALPHA WITH TONOS
  659.           case 0x88: return '\u03AD';    // GREEK CAPITAL LETTER EPSILON WITH TONOS
  660.           case 0x89: return '\u03AE';    // GREEK CAPITAL LETTER ETA WITH TONOS
  661.           case 0x8A: return '\u03AF';    // GREEK CAPITAL LETTER IOTA WITH TONOS
  662.           case 0x8C: return '\u03CC';    // GREEK CAPITAL LETTER OMICRON WITH TONOS
  663.           case 0x8E: return '\u03CD';    // GREEK CAPITAL LETTER UPSILON WITH TONOS
  664.           case 0x8F: return '\u03CE';    // GREEK CAPITAL LETTER OMEGA WITH TONOS
  665.           default:
  666.             if (ch < 0x03B0)
  667.             return (char)(ch + 0x0020);
  668.             else
  669.             return (char)(ch + 1);
  670.         }
  671.           case 0x04:
  672.         if (ch < 0x0410) return (char)(ch + 0x0050);
  673.         if (ch < 0x0460) return (char)(ch + 0x0020);
  674.         return (char)(ch + 1);
  675.           case 0x05:
  676.         // drop through
  677.           case 0x10:
  678.         return (char)(ch + 0x0030);
  679.           case 0x1E:
  680.         return (char)(ch + 1);
  681.           case 0x1F:
  682.         switch (ch & 0xFF) {
  683.           case 0xBA: return '\u1F70';    // GREEK CAPITAL LETTER ALPHA WITH VARIA
  684.           case 0xBB: return '\u1F71';    // GREEK CAPITAL LETTER ALPHA WITH OXIA
  685.           case 0xBC: return '\u1FB3';    // GREEK CAPITAL LETTER ALPHA WITH PROSGEGRAMMENI
  686.           case 0xC8: return '\u1F72';    // GREEK CAPITAL LETTER EPSILON WITH VARIA
  687.           case 0xC9: return '\u1F73';    // GREEK CAPITAL LETTER EPSILON WITH OXIA
  688.           case 0xCA: return '\u1F74';    // GREEK CAPITAL LETTER ETA WITH VARIA
  689.           case 0xCB: return '\u1F75';    // GREEK CAPITAL LETTER ETA WITH OXIA
  690.           case 0xCC: return '\u1FC3';    // GREEK CAPITAL LETTER ETA WITH PROSGEGRAMMENI
  691.           case 0xDA: return '\u1F76';    // GREEK CAPITAL LETTER IOTA WITH VARIA
  692.           case 0xDB: return '\u1F77';    // GREEK CAPITAL LETTER IOTA WITH OXIA
  693.           case 0xEA: return '\u1F7A';    // GREEK CAPITAL LETTER UPSILON WITH VARIA
  694.           case 0xEB: return '\u1F7B';    // GREEK CAPITAL LETTER UPSILON WITH OXIA
  695.           case 0xEC: return '\u1FE5';    // GREEK CAPITAL LETTER RHO WITH DASIA
  696.           case 0xF8: return '\u1F78';    // GREEK CAPITAL LETTER OMICRON WITH VARIA
  697.           case 0xF9: return '\u1F79';    // GREEK CAPITAL LETTER OMICRON WITH OXIA
  698.           case 0xFA: return '\u1F7C';    // GREEK CAPITAL LETTER OMEGA WITH VARIA
  699.           case 0xFB: return '\u1F7D';    // GREEK CAPITAL LETTER OMEGA WITH OXIA
  700.           case 0xFC: return '\u1FF3';    // GREEK CAPITAL LETTER OMEGA WITH PROSGEGRAMMENI
  701.           default:   return (char)(ch - 8);
  702.         }
  703.           case 0x21:
  704.         return (char)(ch + 0x0010);
  705.           case 0x24:
  706.         return (char)(ch + 0x001A);
  707.           case 0xFF:
  708.         return (char)(ch + 0x0020);
  709.         }
  710.     }
  711.     return ch;
  712.     }
  713.  
  714.     /**
  715.      * The given character is mapped to its uppercase equivalent;
  716.      * if the character has no uppercase equivalent, the character itself is returned.
  717.      * 
  718.      * <p>
  719.      * A character has a uppercase equivalent if and only if a uppercase mapping
  720.      * is specified for the character in the Unicode 1.1.5 attribute table.
  721.      *
  722.      * Note that some Unicode characters in the range 0x2000 through 0x2FFF have
  723.      * uppercase mappings; for example, \u2170 (SMALL ROMAN NUMERAL ONE) has an
  724.      * uppercase mapping to \u2160 (ROMAN NUMERAL ONE).  This method does map such
  725.      * characters to their uppercase equivalents even though the method isLowerCase
  726.      * does not return true for such characters.
  727.      *
  728.      * @param ch    the character to be converted
  729.      * @return     the uppercase equivalent of the character, if any;
  730.      *        otherwise the character itself.
  731.      *
  732.      * @see java.lang.Character#isUpperCase
  733.      * @see java.lang.Character#isLowerCase
  734.      * @see java.lang.Character#toLowerCase
  735.      * @see java.lang.Character#toTitleCase
  736.      */
  737.  
  738.     private static long toUpperCaseTable[] = {
  739.     0x54A8AAAAAAAAAAAAL, 0xD4AAAAAAAAAAA955L, 0x2251212A02041128L, 0xA82CAAAA95555B60L, // 01xx
  740.     0x0000000000AAAAAAL, 0x0004830B0B980000L, 0x0000000000040D08L, 0x0000000000000000L, // 02xx
  741.     0x0000000000000000L, 0x0000000000000000L, 0xFFFEF00000000000L, 0x0003AAA800637FFFL, // 03xx
  742.     0xFFFF000000000000L, 0xAAAAAAAADFFEFFFFL, 0xAAAAAAAAAAAA0002L, 0x022A8AAAAAAA1114L, // 04xx
  743.     0x0000000000000000L, 0xFFFFFFFE00000000L, 0x000000000000007FL, 0x0000000000000000L, // 05xx
  744.     0xAAAAAAAAAAAAAAAAL, 0xAAAAAAAAAAAAAAAAL, 0xAAAAAAAA002AAAAAL, 0x02AAAAAAAAAAAAAAL, // 1Exx
  745.     0x00FF00FF003F00FFL, 0x3FFF00FF00AA003FL, 0x000B00FF00FF00FFL, 0x0008002300030008L, // 1Fxx
  746.     };
  747.  
  748.     public static char toUpperCase(char ch) {
  749.     // Quick check for ISO-LATIN-1
  750.     if ((ch >= 'a') && (ch <= 'z'))
  751.         return (char)(ch + ('A' - 'a'));
  752.     if (ch < 0x00E0) return ch;
  753.     if (ch < 0x0100) {
  754.         if (ch == '\u00F7') return ch;        // DIVISION SIGN
  755.         if (ch == '\u00FF') return '\u0178';    // Y WITH DIAERESIS
  756.         return (char)(ch - 0x0020);
  757.     }
  758.     // Okay, it's more complicated
  759.     if (((((ch < 0x0600) ? toUpperCaseTable[(ch - 0x0100) >> 6] :
  760.           ((ch & 0xFE00) == 0x1E00) ? toUpperCaseTable[(ch - (0x1E00 - (0x0600 - 0x0100))) >> 6] :
  761.           ((ch & 0xFFC0) == 0x2140) ? 0xFFFF000000000000L :
  762.           ((ch & 0xFFC0) == 0x24C0) ? 0x000003FFFFFF0000L :
  763.           ((ch & 0xFFC0) == 0xFF40) ? 0x0000000007FFFFFEL : 0) >> (ch & 0x3F)) & 0x1L) != 0) {
  764.         // It is known to be lowercase; now figure out the conversion
  765.         switch (ch >> 8) {
  766.           case 0x01:
  767.         if (ch == '\u017F') return 'S';
  768.         if ((ch == '\u01C6') || (ch == '\u01C9') || (ch == '\u01CC') || (ch == '\u01F3'))
  769.             return (char)(ch - 2);
  770.         return (char)(ch - 1);
  771.           case 0x02:
  772.         if (ch < 0x0240) return (char)(ch - 1);
  773.         switch (ch & 0xFF) {
  774.           case 0x53: return '\u0181';    // LATIN SMALL LETTER B WITH HOOK
  775.           case 0x54: return '\u0186';    // LATIN SMALL LETTER OPEN O
  776.           case 0x57: return '\u018A';    // LATIN SMALL LETTER D WITH HOOK
  777.           case 0x58: return '\u018E';    // LATIN SMALL LETTER REVERSED E
  778.           case 0x59: return '\u018F';    // LATIN SMALL LETTER SCHWA
  779.           case 0x5B: return '\u0190';    // LATIN SMALL LETTER OPEN E
  780.           case 0x60: return '\u0193';    // LATIN SMALL LETTER G WITH HOOK
  781.           case 0x63: return '\u0194';    // LATIN SMALL LETTER GAMMA
  782.           case 0x68: return '\u0197';    // LATIN SMALL LETTER I WITH STROKE
  783.           case 0x69: return '\u0196';    // LATIN SMALL LETTER IOTA
  784.           case 0x6F: return '\u019C';    // LATIN SMALL LETTER TURNED M
  785.           case 0x72: return '\u019D';    // LATIN SMALL LETTER N WITH LEFT HOOK
  786.           case 0x83: return '\u01A9';    // LATIN SMALL LETTER ESH
  787.           case 0x88: return '\u01AE';    // LATIN SMALL LETTER T WITH RETROFLEX HOOK
  788.           case 0x8A: return '\u01B1';    // LATIN SMALL LETTER UPSILON
  789.           case 0x8B: return '\u01B2';    // LATIN SMALL LETTER V WITH HOOK
  790.           case 0x92: return '\u01B7';    // LATIN SMALL LETTER EZH
  791.           default:   return ch;        // shouldn't happen, actually
  792.         }
  793.           case 0x03:
  794.         switch (ch & 0xFF) {
  795.           case 0xAC: return '\u0386';    // GREEK SMALL LETTER ALPHA WITH TONOS
  796.           case 0xAD: return '\u0388';    // GREEK SMALL LETTER EPSILON WITH TONOS
  797.           case 0xAE: return '\u0389';    // GREEK SMALL LETTER ETA WITH TONOS
  798.           case 0xAF: return '\u038A';    // GREEK SMALL LETTER IOTA WITH TONOS
  799.           case 0xC2: return '\u03A3';    // GREEK SMALL LETTER FINAL SIGMA
  800.           case 0xCC: return '\u038C';    // GREEK SMALL LETTER OMICRON WITH TONOS
  801.           case 0xCD: return '\u038E';    // GREEK SMALL LETTER UPSILON WITH TONOS
  802.           case 0xCE: return '\u038F';    // GREEK SMALL LETTER OMEGA WITH TONOS
  803.           case 0xD0: return '\u0392';    // GREEK BETA SYMBOL
  804.           case 0xD1: return '\u0398';    // GREEK THETA SYMBOL
  805.           case 0xD5: return '\u03A6';    // GREEK PHI SYMBOL
  806.           case 0xD6: return '\u03A0';    // GREEK PI SYMBOL
  807.           case 0xF0: return '\u039A';    // GREEK KAPPA SYMBOL
  808.           case 0xF1: return '\u03A1';    // GREEK RHO SYMBOL
  809.           default:
  810.             if (ch < 0x03E0)
  811.             return (char)(ch - 0x0020);
  812.             else
  813.             return (char)(ch - 1);
  814.         }
  815.           case 0x04:
  816.         if (ch < 0x0450) return (char)(ch - 0x0020);
  817.         if (ch < 0x0460) return (char)(ch - 0x0050);
  818.         return (char)(ch - 1);
  819.           case 0x05:
  820.         return (char)(ch - 0x0030);
  821.           case 0x1E:
  822.         return (char)(ch - 1);
  823.           case 0x1F:
  824.         switch (ch & 0xFF) {
  825.           case 0x70: return '\u1FBA';    // GREEK SMALL LETTER ALPHA WITH VARIA
  826.           case 0x71: return '\u1FBB';    // GREEK SMALL LETTER ALPHA WITH OXIA
  827.           case 0x72: return '\u1FC8';    // GREEK SMALL LETTER EPSILON WITH VARIA
  828.           case 0x73: return '\u1FC9';    // GREEK SMALL LETTER EPSILON WITH OXIA
  829.           case 0x74: return '\u1FCA';    // GREEK SMALL LETTER ETA WITH VARIA
  830.           case 0x75: return '\u1FCB';    // GREEK SMALL LETTER ETA WITH OXIA
  831.           case 0x76: return '\u1FDA';    // GREEK SMALL LETTER IOTA WITH VARIA
  832.           case 0x77: return '\u1FDB';    // GREEK SMALL LETTER IOTA WITH OXIA
  833.           case 0x78: return '\u1FF8';    // GREEK SMALL LETTER OMICRON WITH VARIA
  834.           case 0x79: return '\u1FF9';    // GREEK SMALL LETTER OMICRON WITH OXIA
  835.           case 0x7A: return '\u1FEA';    // GREEK SMALL LETTER UPSILON WITH VARIA
  836.           case 0x7B: return '\u1FEB';    // GREEK SMALL LETTER UPSILON WITH OXIA
  837.           case 0x7C: return '\u1FFA';    // GREEK SMALL LETTER OMEGA WITH VARIA
  838.           case 0x7D: return '\u1FFB';    // GREEK SMALL LETTER OMEGA WITH OXIA
  839.           case 0xB3: return '\u1FBC';    // GREEK SMALL LETTER ALPHA WITH YPOGEGRAMMENI
  840.           case 0xC3: return '\u1FCC';    // GREEK SMALL LETTER ETA WITH YPOGEGRAMMENI
  841.           case 0xE5: return '\u1FEC';    // GREEK SMALL LETTER RHO WITH DASIA
  842.           case 0xF3: return '\u1FFC';    // GREEK SMALL LETTER OMEGA WITH YPOGEGRAMMENI
  843.           default:   return (char)(ch + 8);
  844.         }
  845.           case 0x21:
  846.         return (char)(ch - 0x0010);
  847.           case 0x24:
  848.         return (char)(ch - 0x001A);
  849.           case 0xFF:
  850.         return (char)(ch - 0x0020);
  851.         }
  852.     }
  853.     return ch;
  854.     }
  855.  
  856.     /**
  857.      * The given character is mapped to its titlecase equivalent;
  858.      * if the character has no titlecase equivalent, the character itself is returned.
  859.      *
  860.      * A character has a titlecase equivalent if and only if a titlecase mapping
  861.      * is specified for the character in the Unicode 1.1.5 attribute table.
  862.      *
  863.      * Note that some Unicode characters in the range 0x2000 through 0x2FFF have
  864.      * titlecase mappings; for example, \u2170 (SMALL ROMAN NUMERAL ONE) has an
  865.      * titlecase mapping to \u2160 (ROMAN NUMERAL ONE).  This method does map such
  866.      * characters to their titlecase equivalents.
  867.      *
  868.      * There are only four Unicode characters that are truly titlecase forms
  869.      * that are distinct from uppercase forms.  As a rule, if a character has no
  870.      * true titlecase equivalent but does have an uppercase mapping, then the
  871.      * Unicode 1.1.5 attribute table specifies a titlecase mapping that is the
  872.      * same as the uppercase mapping.
  873.      *
  874.      * 
  875.      * @param ch    the character to be converted
  876.      * @return     the titlecase equivalent of the character, if any;
  877.      *        otherwise the character itself.
  878.      * @see java.lang.Character#isTitleCase
  879.      * @see java.lang.Character#toUpperCase
  880.      * @see java.lang.Character#toLowerCase
  881.      */
  882.  
  883.     public static char toTitleCase(char ch) {
  884.     if ((ch & 0xFFC0) != 0x01C0)
  885.         return toUpperCase(ch);
  886.     if (ch >= '\u01C4' && ch <= '\u01C6') return '\u01C5';        // DZ WITH CARON
  887.     if (ch >= '\u01C7' && ch <= '\u01C9') return '\u01C8';        // LJ
  888.     if (ch >= '\u01CA' && ch <= '\u01CC') return '\u01CB';        // NJ
  889.     if (ch >= '\u01F1' && ch <= '\u01F3') return '\u01F2';        // DZ
  890.     return toUpperCase(ch);
  891.     }
  892.  
  893.     /**
  894.      * Returns the numeric value of the character digit using the specified
  895.      * radix. If the radix is not a valid radix, or the character is not a
  896.      * valid digit in the specified radix, -1 is returned..
  897.      * <p>
  898.      * A radix is valid if its value is not less than Character.MIN_RADIX
  899.      * and not greater than Character.MAX_RADIX.
  900.      *
  901.      * A character is a valid digit iff one of the following is true:
  902.      * <ul>
  903.      * <li>  The method isDigit is true of the character and the Unicode 1.1.5
  904.      *       decimal digit value of the character (or its single-character
  905.      *       decomposition) is less than the specified radix.
  906.      * <li>  The character is an uppercase or lowercase Latin letter and the
  907.      *       position of the letter in the Latin alphabet, plus 9, is less than
  908.      *       the specified radix.
  909.      * </ul>
  910.      *
  911.      *
  912.      * @param ch        the character to be converted
  913.      * @param radix     the radix
  914.      * @see java.lang.Character#isDigit
  915.      * @see java.lang.Character#forDigit
  916.      */
  917.  
  918.     public static int digit(char ch, int radix) {
  919.         int value = -1;
  920.     if (radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX) {
  921.         if ((ch >= '0') && (ch <= '9'))
  922.         value = ch - '0';
  923.         else if ((ch >= 'A') && (ch <= 'Z'))
  924.         value = ch + (10 - 'A');
  925.         else if ((ch >= 'a') && (ch <= 'z'))
  926.         value = ch + (10 - 'a');
  927.         else {
  928.         switch (ch>>8) {
  929.           case 0x06:
  930.             if ((ch >= 0x0660) && (ch <=0x0669))    // Arabic-Indic
  931.             value = ch - 0x0660;
  932.             else
  933.             if ((ch >= 0x06F0) && (ch <=0x06F9))    // Extended Arabic-Indic
  934.             value = ch - 0x06F0;
  935.             break;
  936.           case 0x09:
  937.             if ((ch >= 0x0966) && (ch <=0x096F))    // Devanagari
  938.             value = ch - 0x0966;
  939.             else
  940.             if ((ch >= 0x09E6) && (ch <=0x09EF))    // Bengali
  941.             value = ch - 0x09E6;
  942.             break;
  943.           case 0x0A:
  944.             if ((ch >= 0x0A66) && (ch <=0x0A6F))    // Gurmukhi
  945.             value = ch - 0x0A66;
  946.             else
  947.             if ((ch >= 0x0AE6) && (ch <=0x0AEF))    // Gujarati
  948.             value = ch - 0x0AE6;
  949.             break;
  950.           case 0x0B:
  951.             if ((ch >= 0x0B66) && (ch <=0x0B6F))    // Oriya
  952.             value = ch - 0x0B66;
  953.             else
  954.             if ((ch >= 0x0BE7) && (ch <=0x0BEF))    // Tamil
  955.             value = ch - (0x0BE7 - 1);        // First Tamil digit has value 1, not 0
  956.             break;
  957.           case 0x0C:
  958.             if ((ch >= 0x0C66) && (ch <=0x0C6F))    // Telugu
  959.             value = ch - 0x0C66;
  960.             else
  961.             if ((ch >= 0x0CE6) && (ch <=0x0CEF))    // Kannada
  962.             value = ch - 0x0CE6;
  963.             break;
  964.           case 0x0D:
  965.             if ((ch >= 0x0D66) && (ch <=0x0D6F))    // Malayalam
  966.             value = ch - 0x0D66;
  967.             break;
  968.           case 0x0E:
  969.             if ((ch >= 0x0E50) && (ch <=0x0E59))    // Thai
  970.             value = ch - 0x0E50;
  971.             else
  972.             if ((ch >= 0x0ED0) && (ch <=0x0ED9))    // Lao
  973.             value = ch - 0x0ED0;
  974.             break;
  975.           // Unicode 1.0 Tibetan script was withdrawn in Unicode 1.1 for further study
  976.           case 0xFF:
  977.             if ((ch >= 0xFF10) && (ch <=0xFF19))    // Fullwidth digits
  978.             value = ch - 0xFF10;
  979.             break;
  980.         }
  981.         }
  982.     }
  983.     return (value < radix) ? value : -1;
  984.     }
  985.  
  986.     /**
  987.      * Determines if the specified character is ISO-LATIN-1 white space according to Java.
  988.      * @param ch        the character to be tested
  989.      * @return  true if the character is white space; false otherwise.
  990.      */
  991.     public static boolean isSpace(char ch) {
  992.     switch (ch) {
  993.     case ' ':
  994.     case '\t':
  995.     case '\f': // form feed
  996.     case '\n':
  997.     case '\r':
  998.         return (true);
  999.     }
  1000.     return (false);
  1001.     }
  1002.  
  1003.  
  1004.     /**
  1005.      * Returns the character value for the specified digit in the specified
  1006.      * radix. If the digit is not valid in the radix, the 0 character
  1007.      * is returned.
  1008.      * @param digit    the digit chosen by the character value
  1009.      * @param radix     the radix containing the digit
  1010.      */
  1011.     public static char forDigit(int digit, int radix) {
  1012.     if ((digit >= radix) || (digit < 0)) {
  1013.         return '\0';
  1014.     }
  1015.     if ((radix < MIN_RADIX) || (radix > MAX_RADIX)) {
  1016.         return '\0';
  1017.     }
  1018.     if (digit < 10) {
  1019.         return (char)('0' + digit);
  1020.     } 
  1021.     return (char)('a' + digit - 10);
  1022.     }
  1023.  
  1024.     /**
  1025.      * The value of the Character.
  1026.      */
  1027.     private char value;
  1028.  
  1029.     /**
  1030.      * Constructs a Character object with the specified value.
  1031.      * @param value value of this Character object
  1032.      */
  1033.     public Character(char value) {
  1034.     this.value = value;
  1035.     }
  1036.  
  1037.     /**
  1038.      * Returns the value of this Character object.
  1039.      */
  1040.     public char charValue() {
  1041.     return value;
  1042.     }
  1043.  
  1044.     /**
  1045.      * Returns a hashcode for this Character.
  1046.      */
  1047.     public int hashCode() {
  1048.     return (int)value;
  1049.     }
  1050.  
  1051.     /**
  1052.      * Compares this object against the specified object.
  1053.      * @param obj        the object to compare with
  1054.      * @return         true if the objects are the same; false otherwise.
  1055.      */
  1056.     public boolean equals(Object obj) {
  1057.     if ((obj != null) && (obj instanceof Character)) {
  1058.         return value == ((Character)obj).charValue();
  1059.     } 
  1060.     return false;
  1061.     }
  1062.  
  1063.     /**
  1064.      * Returns a String object representing this character's value.
  1065.      */
  1066.     public String toString() {
  1067.     char buf[] = {value};
  1068.     return String.valueOf(buf);
  1069.     }
  1070. }
  1071.  
  1072.