Index: src/test/java/org/apache/harmony/luni/tests/java/lang/CharacterTest.java =================================================================== --- src/test/java/org/apache/harmony/luni/tests/java/lang/CharacterTest.java (revision 442507) +++ src/test/java/org/apache/harmony/luni/tests/java/lang/CharacterTest.java (working copy) @@ -676,6 +676,22 @@ assertEquals("Returned incorrect digit", 1, Character.digit('1', 10)); assertEquals("Returned incorrect digit", 15, Character.digit('F', 16)); } + + /** + * @tests java.lang.Character#digit(int, int) + */ + public void test_digit_II() { + assertEquals(1, Character.digit((int)'1', 10)); + assertEquals(15, Character.digit((int)'F', 16)); + + assertEquals(-1, Character.digit(0x0000, 37)); + assertEquals(-1, Character.digit(0x0045, 10)); + + assertEquals(10, Character.digit(0x0041, 20)); + assertEquals(10, Character.digit(0x0061, 20)); + + assertEquals(-1, Character.digit(0x110000, 20)); + } /** * @tests java.lang.Character#equals(java.lang.Object) @@ -862,8 +878,52 @@ assertTrue("Non-Ignorable returned true", !Character .isIdentifierIgnorable('\u0065')); } + + /** + * @tests java.lang.Character#isIdentifierIgnorable(int) + */ + public void test_isIdentifierIgnorable_I() { + assertTrue(Character.isIdentifierIgnorable(0x0000)); + assertTrue(Character.isIdentifierIgnorable(0x0004)); + assertTrue(Character.isIdentifierIgnorable(0x0008)); + + assertTrue(Character.isIdentifierIgnorable(0x000E)); + assertTrue(Character.isIdentifierIgnorable(0x0013)); + assertTrue(Character.isIdentifierIgnorable(0x001B)); + + assertTrue(Character.isIdentifierIgnorable(0x007F)); + assertTrue(Character.isIdentifierIgnorable(0x008F)); + assertTrue(Character.isIdentifierIgnorable(0x009F)); + assertTrue(Character.isIdentifierIgnorable(0x202b)); + assertTrue(Character.isIdentifierIgnorable(0x206c)); + assertTrue(Character.isIdentifierIgnorable(0xfeff)); + assertFalse(Character.isIdentifierIgnorable(0x0065)); + + assertTrue(Character.isIdentifierIgnorable(0x1D173)); + + assertFalse(Character.isIdentifierIgnorable(0x10FFFD)); + assertFalse(Character.isIdentifierIgnorable(0x110000)); + } + /** + * @tests java.lang.Character#isMirrored(char) + */ + public void test_isMirrored_C() { + assertTrue(Character.isMirrored('\u0028')); + assertFalse(Character.isMirrored('\uFFFF')); + } + + /** + * @tests java.lang.Character#isMirrored(int) + */ + public void test_isMirrored_I() { + assertTrue(Character.isMirrored(0x0028)); + assertFalse(Character.isMirrored(0xFFFF)); + assertFalse(Character.isMirrored(0x110000)); + } + + /** * @tests java.lang.Character#isISOControl(char) */ public void test_isISOControlC() { @@ -1064,6 +1124,22 @@ assertTrue("space returned false", Character.isSpaceChar('\u0020')); assertTrue("non-space returned true", !Character.isSpaceChar('\n')); } + + /** + * @tests java.lang.Character#isSpaceChar(int) + */ + public void test_isSpaceChar_I() { + assertTrue(Character.isSpaceChar((int)'\u0020')); + assertFalse(Character.isSpaceChar((int)'\n')); + + assertTrue(Character.isSpaceChar(0x2000)); + assertTrue(Character.isSpaceChar(0x200A)); + + assertTrue(Character.isSpaceChar(0x2028)); + assertTrue(Character.isSpaceChar(0x2029)); + + assertFalse(Character.isSpaceChar(0x110000)); + } /** * @tests java.lang.Character#isTitleCase(char) @@ -1094,6 +1170,24 @@ } assertTrue("Failed to find all Title Case chars", tnum == tChars.length); } + + /** + * @tests java.lang.Character#isTitleCase(int) + */ + public void test_isTitleCase_I() { + //all the titlecase characters + int[] titleCaseCharacters = { 0x01c5, 0x01c8, 0x01cb, 0x01f2, 0x1f88, + 0x1f89, 0x1f8a, 0x1f8b, 0x1f8c, 0x1f8d, 0x1f8e, 0x1f8f, 0x1f98, + 0x1f99, 0x1f9a, 0x1f9b, 0x1f9c, 0x1f9d, 0x1f9e, 0x1f9f, 0x1fa8, + 0x1fa9, 0x1faa, 0x1fab, 0x1fac, 0x1fad, 0x1fae, 0x1faf, 0x1fbc, + 0x1fcc, 0x1ffc }; + + for (int i = 0; i < titleCaseCharacters.length; i++) { + assertTrue(Character.isTitleCase(titleCaseCharacters[i])); + } + + assertFalse(Character.isTitleCase(0x110000)); + } /** * @tests java.lang.Character#isUnicodeIdentifierPart(char) @@ -1152,6 +1246,40 @@ assertTrue("space returned false", Character.isWhitespace('\n')); assertTrue("non-space returned true", !Character.isWhitespace('T')); } + + /** + * @tests java.lang.Character#isWhitespace(int) + */ + public void test_isWhitespace_I() { + assertTrue(Character.isWhitespace((int)'\n')); + assertFalse(Character.isWhitespace((int)'T')); + + assertTrue(Character.isWhitespace(0x0009)); + assertTrue(Character.isWhitespace(0x000A)); + assertTrue(Character.isWhitespace(0x000B)); + assertTrue(Character.isWhitespace(0x000C)); + assertTrue(Character.isWhitespace(0x000D)); + assertTrue(Character.isWhitespace(0x001C)); + assertTrue(Character.isWhitespace(0x001D)); + assertTrue(Character.isWhitespace(0x001F)); + assertTrue(Character.isWhitespace(0x001E)); + + assertTrue(Character.isWhitespace(0x2000)); + assertTrue(Character.isWhitespace(0x200A)); + + assertTrue(Character.isWhitespace(0x2028)); + assertTrue(Character.isWhitespace(0x2029)); + + assertFalse(Character.isWhitespace(0x00A0)); + assertFalse(Character.isWhitespace(0x202F)); + assertFalse(Character.isWhitespace(0x110000)); + + assertFalse(Character.isWhitespace(0xFEFF)); + + //FIXME depend on ICU4J + //assertFalse(Character.isWhitespace(0x2007)); + + } /** * @tests java.lang.Character#reverseBytes(char) Index: src/main/java/java/lang/Character.java =================================================================== --- src/main/java/java/lang/Character.java (revision 442507) +++ src/main/java/java/lang/Character.java (working copy) @@ -2399,12 +2399,14 @@ } /** - * Convenience method to determine the value of character c - * in the supplied radix. The value of radix is must be - * between MIN_RADIX and MAX_RADIX inclusive. + * Convenient method to determine the value of character c in + * the supplied radix. The value of radix must be between + * MIN_RADIX and MAX_RADIX. * - * @param c the character - * @param radix the radix + * @param c + * the character + * @param radix + * the radix * @return if radix lies between {@link #MIN_RADIX} and * {@link #MAX_RADIX} then the value of the character in the radix, * otherwise -1. @@ -2434,6 +2436,23 @@ } return -1; } + + /** + * Convenient method to determine the value of character + * codePoint in the supplied radix. The value of + * radix must be between MIN_RADIX and MAX_RADIX. + * + * @param codePoint + * the character, including supplementary characters + * @param radix + * the radix + * @return if radix lies between {@link #MIN_RADIX} and + * {@link #MAX_RADIX} then the value of the character in the radix, + * otherwise -1. + */ + public static int digit(int codePoint, int radix) { + return UCharacter.digit(codePoint, radix); + } /** * Compares the argument to the receiver, and answers true if they represent @@ -2552,12 +2571,12 @@ } /** - * Gets the Unicode directionality of the specified character. - * - * @param c - * the character - * @return the Unicode directionality - */ + * Answers whether the specified character is mirrored + * + * @param c + * the character + * @return true if the character is mirrored, false otherwise + */ public static boolean isMirrored(char c) { int value = c / 16; if (value >= mirrored.length) { @@ -2566,6 +2585,17 @@ int bit = 1 << (c % 16); return (mirrored[value] & bit) != 0; } + + /** + * Answers whether the specified character is mirrored + * + * @param codePoint + * the character, including supplementary characters + * @return true if the character is mirrored, false otherwise + */ + public static boolean isMirrored(int codePoint) { + return UCharacter.isMirrored(codePoint); + } /** * Answers an integer hash code for the receiver. Any two objects which @@ -2648,6 +2678,18 @@ return (c >= 0 && c <= 8) || (c >= 0xe && c <= 0x1b) || (c >= 0x7f && c <= 0x9f) || getType(c) == FORMAT; } + + /** + * Answers whether the specified character is ignorable in a Java or Unicode + * identifier. + * + * @param codePoint + * the character, including supplementary characters + * @return true when the character is ignorable, false otherwise + */ + public static boolean isIdentifierIgnorable(int codePoint) { + return UCharacter.isIdentifierIgnorable(codePoint); + } /** * Answers whether the character is an ISO control character. @@ -2850,13 +2892,27 @@ return c <= 0x200b || c == 0x2028 || c == 0x2029 || c == 0x202f || c == 0x3000; } + + /** + * Answers whether the character is a Unicode space character. A member of + * one of the Unicode categories Space Separator, Line Separator, or + * Paragraph Separator. + * + * @param codePoint + * the character, including supplementary characters + * @return true when the character is a Unicode space character, false + * otherwise + */ + public static boolean isSpaceChar(int codePoint) { + return UCharacter.isSpaceChar(codePoint); + } /** - * Answers whether the character is an title case character. + * Answers whether the character is a titlecase character. * * @param c * the character - * @return true when the character is a title case character, false + * @return true when the character is a titlecase character, false * otherwise */ public static boolean isTitleCase(char c) { @@ -2873,6 +2929,18 @@ } return false; } + + /** + * Answers whether the character is a titlecase character. + * + * @param codePoint + * the character, including supplementary characters + * @return true when the character is a titlecase character, false + * otherwise + */ + public static boolean isTitleCase(int codePoint) { + return UCharacter.isTitleCase(codePoint); + } /** * Answers whether the character is valid as any character except the first @@ -2938,13 +3006,13 @@ } /** - * Answers whether the character is a whitespace character in Java. - * - * @param c - * the character - * @return true if the supplied c is a - * whitespace character in Java, otherwise false. - */ + * Answers whether the character is a whitespace character in Java. + * + * @param c + * the character + * @return true if the supplied c is a whitespace character + * in Java, otherwise false. + */ public static boolean isWhitespace(char c) { // Optimized case for ASCII if ((c >= 0x1c && c <= 0x20) || (c >= 0x9 && c <= 0xd)) { @@ -2958,6 +3026,20 @@ } return c <= 0x200b || c == 0x2028 || c == 0x2029 || c == 0x3000; } + + /** + * Answers whether the character is a whitespace character in Java. + * + * @param codePoint + * the character, including supplementary characters + * @return true if the supplied c is a whitespace character + * in Java, otherwise false. + */ + public static boolean isWhitespace(int codePoint) { + //FIXME depends on ICU when the codePoint is '\u2007' + return UCharacter.isWhitespace(codePoint); + + } /** * Reverse the order of the first and second bytes in character