/[classpath]/classpath/java/lang/Character.java
ViewVC logotype

Diff of /classpath/java/lang/Character.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.26 by ericb, Sat Mar 9 21:20:04 2002 UTC revision 1.27 by mark, Sun Apr 7 07:46:19 2002 UTC
# Line 35  this exception to your version of the li Line 35  this exception to your version of the li
35  obligated to do so.  If you do not wish to do so, delete this  obligated to do so.  If you do not wish to do so, delete this
36  exception statement from your version. */  exception statement from your version. */
37    
38    /*
39     * Note: This class must not be merged with Classpath.  Gcj uses C-style
40     * arrays (see include/java-chartables.h) to store the Unicode character
41     * database, whereas Classpath uses Java objects (char[] extracted from
42     * String constants) in gnu.java.lang.CharData.  Gcj's approach is more
43     * efficient, because there is no vtable or data relocation to worry about.
44     * However, despite the difference in the database interface, the two
45     * versions share identical algorithms.
46     */
47    
48  package java.lang;  package java.lang;
49    
50  import java.io.Serializable;  import java.io.Serializable;
 import gnu.java.lang.CharData;  
51    
52  /**  /**
53   * Wrapper class for the primitive char data type.  In addition, this class   * Wrapper class for the primitive char data type.  In addition, this class
# Line 62  import gnu.java.lang.CharData; Line 70  import gnu.java.lang.CharData;
70   * @author Paul N. Fisher   * @author Paul N. Fisher
71   * @author Jochen Hoenicke   * @author Jochen Hoenicke
72   * @author Eric Blake <ebb9@email.byu.edu>   * @author Eric Blake <ebb9@email.byu.edu>
  * @see CharData  
73   * @since 1.0   * @since 1.0
74   * @status updated to 1.4   * @status updated to 1.4
75   */   */
# Line 132  public final class Character implements Line 139  public final class Character implements
139     * is in at most one of these blocks.     * is in at most one of these blocks.
140     *     *
141     * This inner class was generated automatically from     * This inner class was generated automatically from
142     * <code>doc/unicode/Block-3.txt</code>, by some perl scripts.     * <code>libjava/gnu/gcj/convert/Blocks-3.txt</code>, by some perl scripts.
143     * This Unicode definition file can be found on the     * This Unicode definition file can be found on the
144     * <a href="http://www.unicode.org">http://www.unicode.org</a> website.     * <a href="http://www.unicode.org">http://www.unicode.org</a> website.
145     * JDK 1.4 uses Unicode version 3.0.0.     * JDK 1.4 uses Unicode version 3.0.0.
# Line 1384  public final class Character implements Line 1391  public final class Character implements
1391    public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18;    public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18;
1392    
1393    /**    /**
1394     * Stores unicode block offset lookup table. Exploit package visibility of     * Mask for grabbing the type out of the result of readChar.
    * String.value to avoid copying the array.  
1395     * @see #readChar(char)     * @see #readChar(char)
    * @see CharData#BLOCKS  
    */  
   private static final char[] blocks = CharData.BLOCKS.value;  
   
   /**  
    * Stores unicode attribute offset lookup table. Exploit package visibility  
    * of String.value to avoid copying the array.  
    * @see CharData#DATA  
    */  
   private static final char[] data = CharData.DATA.value;  
   
   /**  
    * Stores unicode numeric value attribute table. Exploit package visibility  
    * of String.value to avoid copying the array.  
    * @see CharData#NUM_VALUE  
    */  
   private static final char[] numValue = CharData.NUM_VALUE.value;  
   
   /**  
    * Stores unicode uppercase attribute table. Exploit package visibility  
    * of String.value to avoid copying the array.  
    * @see CharData#UPPER  
    */  
   private static final char[] upper = CharData.UPPER.value;  
   
   /**  
    * Stores unicode lowercase attribute table. Exploit package visibility  
    * of String.value to avoid copying the array.  
    * @see CharData#LOWER  
    */  
   private static final char[] lower = CharData.LOWER.value;  
   
   /**  
    * 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.  
   static final char[] direction = CharData.DIRECTION.value;  
   
   /**  
    * Stores unicode titlecase table. Exploit package visibility of  
    * String.value to avoid copying the array.  
    * @see CharData#TITLE  
    */  
   private static final char[] title = CharData.TITLE.value;  
   
   /**  
    * Mask for grabbing the type out of the contents of data.  
    * @see CharData#DATA  
1396     */     */
1397    private static final int TYPE_MASK = 0x1F;    private static final int TYPE_MASK = 0x1F;
1398    
1399    /**    /**
1400     * Mask for grabbing the non-breaking space flag out of the contents of     * Mask for grabbing the non-breaking space flag out of the result of
1401     * data.     * readChar.
1402     * @see CharData#DATA     * @see #readChar(char)
1403     */     */
1404    private static final int NO_BREAK_MASK = 0x20;    private static final int NO_BREAK_MASK = 0x20;
1405    
1406    /**    /**
1407     * Mask for grabbing the mirrored directionality flag out of the contents     * Mask for grabbing the mirrored directionality flag out of the result
1408     * of data.     * of readChar.
1409     * @see CharData#DATA     * @see #readChar(char)
1410     */     */
1411    private static final int MIRROR_MASK = 0x40;    private static final int MIRROR_MASK = 0x40;
1412    
1413    /**    /**
1414     * Grabs an attribute offset from the Unicode attribute database. The lower     * Grabs an attribute offset from the Unicode attribute database. The lower
1415     * 5 bits are the character type, the next 2 bits are flags, and the top     * 5 bits are the character type, the next 2 bits are flags, and the top
1416     * 9 bits are the offset into the attribute tables.     * 9 bits are the offset into the attribute tables. Note that the top 9
1417       * bits are meaningless in this context; they are useful only in the native
1418       * code.
1419     *     *
1420     * @param ch the character to look up     * @param ch the character to look up
1421     * @return the character's attribute offset and type     * @return the character's attribute offset and type
1422     * @see #TYPE_MASK     * @see #TYPE_MASK
1423     * @see #NO_BREAK_MASK     * @see #NO_BREAK_MASK
1424     * @see #MIRROR_MASK     * @see #MIRROR_MASK
    * @see CharData#DATA  
    * @see CharData#SHIFT  
1425     */     */
1426    // Package visible for use in String.    private static native char readChar(char ch);
   static char readChar(char ch)  
   {  
     // Perform 16-bit addition to find the correct entry in data.  
     return data[(char) (blocks[ch >> CharData.SHIFT] + ch)];  
   }  
1427    
1428    /**    /**
1429     * Wraps up a character.     * Wraps up a character.
# Line 1525  public final class Character implements Line 1476  public final class Character implements
1476     */     */
1477    public String toString()    public String toString()
1478    {    {
1479      // Package constructor avoids an array copy.      // This assumes that String.valueOf(char) can create a single-character
1480      return new String(new char[] { value }, 0, 1, true);      // String more efficiently than through the public API.
1481        return String.valueOf(value);
1482    }    }
1483    
1484    /**    /**
# Line 1538  public final class Character implements Line 1490  public final class Character implements
1490     */     */
1491    public String toString(char ch)    public String toString(char ch)
1492    {    {
1493      // Package constructor avoids an array copy.      // This assumes that String.valueOf(char) can create a single-character
1494      return new String(new char[] { value }, 0, 1, true);      // String more efficiently than through the public API.
1495        return String.valueOf(ch);
1496    }    }
1497    
1498    /**    /**
# Line 1630  public final class Character implements Line 1583  public final class Character implements
1583     */     */
1584    public static boolean isDefined(char ch)    public static boolean isDefined(char ch)
1585    {    {
1586      return getType(ch) == UNASSIGNED;      return getType(ch) != UNASSIGNED;
1587    }    }
1588    
1589    /**    /**
# Line 1894  public final class Character implements Line 1847  public final class Character implements
1847     * @see #toTitleCase(char)     * @see #toTitleCase(char)
1848     * @see #toUpperCase(char)     * @see #toUpperCase(char)
1849     */     */
1850    public static char toLowerCase(char ch)    public static native char toLowerCase(char ch);
   {  
     // Signedness doesn't matter, as result is cast back to char.  
     return (char) (ch + lower[readChar(ch) >> 7]);  
   }  
1851    
1852    /**    /**
1853     * Converts a Unicode character into its uppercase equivalent mapping.     * Converts a Unicode character into its uppercase equivalent mapping.
# Line 1913  public final class Character implements Line 1862  public final class Character implements
1862     * @see #toLowerCase(char)     * @see #toLowerCase(char)
1863     * @see #toTitleCase(char)     * @see #toTitleCase(char)
1864     */     */
1865    public static char toUpperCase(char ch)    public static native char toUpperCase(char ch);
   {  
     // Signedness doesn't matter, as result is cast back to char.  
     return (char) (ch + upper[readChar(ch) >> 7]);  
   }  
1866    
1867    /**    /**
1868     * Converts a Unicode character into its titlecase equivalent mapping.     * Converts a Unicode character into its titlecase equivalent mapping.
# Line 1931  public final class Character implements Line 1876  public final class Character implements
1876     * @see #toLowerCase(char)     * @see #toLowerCase(char)
1877     * @see #toUpperCase(char)     * @see #toUpperCase(char)
1878     */     */
1879    public static char toTitleCase(char ch)    public static native 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);  
   }  
1880    
1881    /**    /**
1882     * Converts a character into a digit of the specified radix. If the radix     * Converts a character into a digit of the specified radix. If the radix
# Line 1958  public final class Character implements Line 1896  public final class Character implements
1896     * @see #isDigit(char)     * @see #isDigit(char)
1897     * @see #getNumericValue(char)     * @see #getNumericValue(char)
1898     */     */
1899    public static int digit(char ch, int radix)    public static native int digit(char ch, int radix);
   {  
     if (radix < MIN_RADIX || radix > MAX_RADIX)  
       return -1;  
     char attr = readChar(ch);  
     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[attr >> 7];  
         return (digit >= 0 && digit < radix) ? digit : -1;  
       }  
     return -1;  
   }  
1900    
1901    /**    /**
1902     * Returns the Unicode numeric value property of a character. For example,     * Returns the Unicode numeric value property of a character. For example,
# Line 2002  public final class Character implements Line 1925  public final class Character implements
1925     * @see #isDigit(char)     * @see #isDigit(char)
1926     * @since 1.1     * @since 1.1
1927     */     */
1928    public static int getNumericValue(char ch)    public static native int getNumericValue(char ch);
   {  
     // Treat numValue as signed.  
     return (short) numValue[readChar(ch) >> 7];  
   }  
1929    
1930    /**    /**
1931     * Determines if a character is a ISO-LATIN-1 space. This is only the five     * Determines if a character is a ISO-LATIN-1 space. This is only the five
# Line 2141  public final class Character implements Line 2060  public final class Character implements
2060     * @see #FINAL_QUOTE_PUNCTUATION     * @see #FINAL_QUOTE_PUNCTUATION
2061     * @since 1.1     * @since 1.1
2062     */     */
2063    public static int getType(char ch)    public static native int getType(char ch);
   {  
     return readChar(ch) & TYPE_MASK;  
   }  
2064    
2065    /**    /**
2066     * Converts a digit into a character which represents that digit     * Converts a digit into a character which represents that digit
# Line 2163  public final class Character implements Line 2079  public final class Character implements
2079     */     */
2080    public static char forDigit(int digit, int radix)    public static char forDigit(int digit, int radix)
2081    {    {
2082      if (radix < MIN_RADIX || radix > MAX_RADIX      if (radix < MIN_RADIX || radix > MAX_RADIX ||
2083          || digit < 0 || digit >= radix)          digit < 0 || digit >= radix)
2084        return '\0';        return '\0';
2085      return Number.digits[digit];      return (char) (digit < 10 ? ('0' + digit) : ('a' - 10 + digit));
2086    }    }
2087    
2088    /**    /**
# Line 2197  public final class Character implements Line 2113  public final class Character implements
2113     * @see #DIRECTIONALITY_POP_DIRECTIONAL_FORMAT     * @see #DIRECTIONALITY_POP_DIRECTIONAL_FORMAT
2114     * @since 1.4     * @since 1.4
2115     */     */
2116    public static byte getDirectionality(char ch)    public static native byte getDirectionality(char ch);
   {  
     // The result will correctly be signed.  
     return (byte) (direction[readChar(ch) >> 7] >> 2);  
   }  
2117    
2118    /**    /**
2119     * Determines whether the character is mirrored according to Unicode. For     * Determines whether the character is mirrored according to Unicode. For

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.27

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26