/[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.36 by mark, Sat Jul 2 20:32:38 2005 UTC revision 1.37 by rabbit78, Wed Aug 17 14:12:27 2005 UTC
# Line 1457  public final class Character implements Line 1457  public final class Character implements
1457    private static final int MIRROR_MASK = 0x40;    private static final int MIRROR_MASK = 0x40;
1458    
1459    /**    /**
1460       * Min value for supplementary code point.
1461       *
1462       * @since 1.5
1463       */
1464      public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x10000;
1465    
1466      /**
1467       * Min value for code point.
1468       *
1469       * @since 1.5
1470       */
1471      public static final int MIN_CODE_POINT = 0;
1472    
1473    
1474      /**
1475       * Max value for code point.
1476       *
1477       * @since 1.5
1478       */
1479      public static final int MAX_CODE_POINT = 0x010ffff;
1480    
1481    
1482      /**
1483       * Minimum high surrrogate code in UTF-16 encoding.
1484       *
1485       * @since 1.5
1486       */
1487      public static final char MIN_HIGH_SURROGATE = '\ud800';
1488    
1489      /**
1490       * Maximum high surrrogate code in UTF-16 encoding.
1491       *
1492       * @since 1.5
1493       */
1494      public static final char MAX_HIGH_SURROGATE = '\udbff';
1495    
1496      /**
1497       * Minimum low surrrogate code in UTF-16 encoding.
1498       *
1499       * @since 1.5
1500       */
1501      public static final char MIN_LOW_SURROGATE = '\udc00';
1502    
1503      /**
1504       * Maximum low surrrogate code in UTF-16 encoding.
1505       *
1506       * @since 1.5
1507       */
1508      public static final char MAX_LOW_SURROGATE = '\udfff';
1509    
1510      /**
1511     * Grabs an attribute offset from the Unicode attribute database. The lower     * Grabs an attribute offset from the Unicode attribute database. The lower
1512     * 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
1513     * 9 bits are the offset into the attribute tables.     * 9 bits are the offset into the attribute tables.
# Line 2250  public final class Character implements Line 2301  public final class Character implements
2301    {    {
2302      return compareTo((Character) o);      return compareTo((Character) o);
2303    }    }
2304    
2305      /**
2306       * Converts a unicode code point to a UTF-16 representation of that
2307       * code point.
2308       *
2309       * @param codePoint the unicode code point
2310       *
2311       * @return the UTF-16 representation of that code point
2312       *
2313       * @throws IllegalArgumentException if the code point is not a valid
2314       *         unicode code point
2315       *
2316       * @since 1.5
2317       */
2318      public static char[] toChars(int codePoint)
2319      {
2320        char[] result = new char[charCount(codePoint)];
2321        int ignore = toChars(codePoint, result, 0);
2322        return result;
2323      }
2324    
2325      /**
2326       * Converts a unicode code point to its UTF-16 representation.
2327       *
2328       * @param codePoint the unicode code point
2329       * @param dst the target char array
2330       * @param dstIndex the start index for the target
2331       *
2332       * @return number of characters written to <code>dst</code>
2333       *
2334       * @throws IllegalArgumentException if <code>codePoint</code> is not a
2335       *         valid unicode code point
2336       * @throws NullPointerException if <code>dst</code> is <code>null</code>
2337       * @throws IndexOutOfBoundsException if <code>dstIndex</code> is not valid
2338       *         in <code>dst</code> or if the UTF-16 representation does not
2339       *         fit into <code>dst</code>
2340       *
2341       * @since 1.5
2342       */
2343      public static int toChars(int codePoint, char[] dst, int dstIndex)
2344      {
2345        if (!isValidCodePoint(codePoint))
2346          {
2347            throw new IllegalArgumentException("not a valid code point: "
2348                                               + codePoint);
2349          }
2350    
2351        int result;
2352        if (isSupplementaryCodePoint(codePoint))
2353          {
2354            // Write second char first to cause IndexOutOfBoundsException
2355            // immediately.
2356            dst[dstIndex + 1] = (char) ((codePoint & 0x3ff)
2357                                        + (int) MIN_LOW_SURROGATE );
2358            dst[dstIndex] = (char) ((codePoint >> 10) + (int) MIN_HIGH_SURROGATE);
2359            result = 2;
2360        }
2361        else
2362          {
2363            dst[dstIndex] = (char) codePoint;
2364            result = 1;
2365          }
2366        return result;
2367      }
2368    
2369      /**
2370       * Return number of 16-bit characters required to represent the given
2371       * code point.
2372       *
2373       * @param codePoint a uncode code point
2374       *
2375       * @return 2 if codePoint >= 0x10000, 1 otherwise.
2376       *
2377       * @since 1.5
2378       */
2379      public static int charCount(int codePoint)
2380      {
2381        return
2382          (codePoint >= MIN_SUPPLEMENTARY_CODE_POINT)
2383          ? 2
2384          : 1;
2385      }
2386    
2387      /**
2388       * Determines whether the specified code point is
2389       * in the range 0x10000 .. 0x10FFFF, i.e. the character is within the Unicode
2390       * supplementary character range.
2391       *
2392       * @param codePoint a Unicode code point
2393       *
2394       * @return <code>true</code> if code point is in supplementary range
2395       *
2396       * @since 1.5
2397       */
2398      public static boolean isSupplementaryCodePoint(int codePoint)
2399      {
2400        return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
2401          && codePoint <= MAX_CODE_POINT;
2402      }
2403    
2404      /**
2405       * Determines whether the specified code point is
2406       * in the range 0x0000 .. 0x10FFFF, i.e. it is a valid Unicode code point.
2407       *
2408       * @param codePoint a Unicode code point
2409       *
2410       * @return <code>true</code> if code point is valid
2411       *
2412       * @since 1.5
2413       */
2414      public static boolean isValidCodePoint(int codePoint)
2415      {
2416        return codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT;
2417      }
2418  } // class Character  } // class Character

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.37

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