harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r442914 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/Character.java test/java/org/apache/harmony/luni/tests/java/lang/CharacterTest.java
Date Wed, 13 Sep 2006 09:16:02 GMT
Author: pyang
Date: Wed Sep 13 02:16:02 2006
New Revision: 442914

URL: http://svn.apache.org/viewvc?view=rev&rev=442914
Log:
Patch applied for HARMONY-1436 ([classlib][luni]implement new methods digit(int,int),isIdentifierIgnorable(int),isMirrored(int),isSpaceChar(int),isTitleCase(int),isWhiteSpace(int)
in java.lang.Character)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Character.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CharacterTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Character.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Character.java?view=diff&rev=442914&r1=442913&r2=442914
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Character.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Character.java
Wed Sep 13 02:16:02 2006
@@ -2399,12 +2399,14 @@
     }
 
 	/**
-     * Convenience method to determine the value of character <code>c</code>
-     * in the supplied radix. The value of <code>radix</code> is must be
-     * between MIN_RADIX and MAX_RADIX inclusive.
+     * Convenient method to determine the value of character <code>c</code> in
+     * the supplied radix. The value of <code>radix</code> 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 <code>radix</code> 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
+     * <code>codePoint</code> in the supplied radix. The value of
+     * <code>radix</code> must be between MIN_RADIX and MAX_RADIX.
+     * 
+     * @param codePoint
+     *            the character, including supplementary characters
+     * @param radix
+     *            the radix
+     * @return if <code>radix</code> 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 <code>true</code> if the supplied <code>c</code> is a
-	 *         whitespace character in Java, otherwise <code>false</code>.
-	 */
+     * Answers whether the character is a whitespace character in Java.
+     * 
+     * @param c
+     *            the character
+     * @return true if the supplied <code>c</code> 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 <code>c</code> 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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CharacterTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CharacterTest.java?view=diff&rev=442914&r1=442913&r2=442914
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CharacterTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CharacterTest.java
Wed Sep 13 02:16:02 2006
@@ -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,6 +878,50 @@
         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)
@@ -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)
@@ -1151,6 +1245,40 @@
         // Test for method boolean java.lang.Character.isWhitespace(char)
         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));
+        
     }
 
     /**



Mime
View raw message