harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r650805 - in /harmony/enhanced/classlib/branches/java6/modules/text/src: main/java/java/text/Normalizer.java test/java/org/apache/harmony/text/tests/java/text/NormalizerTest.java
Date Wed, 23 Apr 2008 09:24:02 GMT
Author: lvjing
Date: Wed Apr 23 02:24:01 2008
New Revision: 650805

URL: http://svn.apache.org/viewvc?rev=650805&view=rev
Log:
Apply patch for HARMONY-5767, [java6][classlib][text] - implement Normalizer class

Modified:
    harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/Normalizer.java
    harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NormalizerTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/Normalizer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/Normalizer.java?rev=650805&r1=650804&r2=650805&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/Normalizer.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/Normalizer.java
Wed Apr 23 02:24:01 2008
@@ -17,7 +17,6 @@
 
 package java.text;
 
-import org.apache.harmony.luni.util.NotImplementedException;
 
 /**
  * This class provider Unicode Normalization functions, which transform Unicode
@@ -67,7 +66,28 @@
      *                If <code>src</code> or <code>form</code> is
null.
      */
     public static String normalize(CharSequence src, Form form) {
-        throw new NotImplementedException();
+        if (src == null || form == null) {
+            throw new NullPointerException();
+        }
+        
+        switch (form) {
+        case NFC:
+            return com.ibm.icu.text.Normalizer.normalize(src.toString(),
+                    com.ibm.icu.text.Normalizer.NFC);
+        case NFD:
+            return com.ibm.icu.text.Normalizer.normalize(src.toString(),
+                    com.ibm.icu.text.Normalizer.NFD);
+        case NFKC:
+            return com.ibm.icu.text.Normalizer.normalize(src.toString(),
+                    com.ibm.icu.text.Normalizer.NFKC);
+        case NFKD:
+            return com.ibm.icu.text.Normalizer.normalize(src.toString(),
+                    com.ibm.icu.text.Normalizer.NFKD);
+        default:
+            // never reach
+            return null;
+        }
+        
     }
 
     /**
@@ -84,6 +104,30 @@
      *                If <code>src</code> or <code>form</code> is
null.
      */
     public static boolean isNormalized(CharSequence src, Form form) {
-        throw new NotImplementedException();
+        if (src == null || form == null) {
+            throw new NullPointerException();
+        }
+
+        switch (form) {
+        case NFC:
+            return com.ibm.icu.text.Normalizer.isNormalized(src.toString(),
+                    com.ibm.icu.text.Normalizer.NFC,
+                    com.ibm.icu.text.Normalizer.UNICODE_3_2);
+        case NFD:
+            return com.ibm.icu.text.Normalizer.isNormalized(src.toString(),
+                    com.ibm.icu.text.Normalizer.NFD,
+                    com.ibm.icu.text.Normalizer.UNICODE_3_2);
+        case NFKC:
+            return com.ibm.icu.text.Normalizer.isNormalized(src.toString(),
+                    com.ibm.icu.text.Normalizer.NFKC,
+                    com.ibm.icu.text.Normalizer.UNICODE_3_2);
+        case NFKD:
+            return com.ibm.icu.text.Normalizer.isNormalized(src.toString(),
+                    com.ibm.icu.text.Normalizer.NFKD,
+                    com.ibm.icu.text.Normalizer.UNICODE_3_2);
+        default:
+            // never reach
+            return false;
+        }
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NormalizerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NormalizerTest.java?rev=650805&r1=650804&r2=650805&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NormalizerTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NormalizerTest.java
Wed Apr 23 02:24:01 2008
@@ -17,6 +17,7 @@
 
 package org.apache.harmony.text.tests.java.text;
 
+import java.text.Normalizer;
 import java.text.Normalizer.Form;
 
 import junit.framework.TestCase;
@@ -63,11 +64,119 @@
         } catch (IllegalArgumentException e) {
             // expected
         }
-        
+
         try {
             Form.valueOf("NFC ");
             fail("Should throw IllegalArgumentException");
         } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.text.Normalizer#isNormalized(CharSequence, Form)
+     */
+    public void test_isNormalized() throws Exception {
+        String src = "\u00c1";
+        assertTrue(Normalizer.isNormalized(src, Form.NFC));
+        assertFalse(Normalizer.isNormalized(src, Form.NFD));
+        assertTrue(Normalizer.isNormalized(src, Form.NFKC));
+        assertFalse(Normalizer.isNormalized(src, Form.NFKD));
+
+        src = "\u0041\u0301";
+        assertFalse(Normalizer.isNormalized(src, Form.NFC));
+        assertTrue(Normalizer.isNormalized(src, Form.NFD));
+        assertFalse(Normalizer.isNormalized(src, Form.NFKC));
+        assertTrue(Normalizer.isNormalized(src, Form.NFKD));
+
+        src = "\ufb03";
+        assertTrue(Normalizer.isNormalized(src, Form.NFC));
+        assertTrue(Normalizer.isNormalized(src, Form.NFD));
+        assertFalse(Normalizer.isNormalized(src, Form.NFKC));
+        assertFalse(Normalizer.isNormalized(src, Form.NFKD));
+
+        src = "\u0066\u0066\u0069";
+        assertTrue(Normalizer.isNormalized(src, Form.NFC));
+        assertTrue(Normalizer.isNormalized(src, Form.NFD));
+        assertTrue(Normalizer.isNormalized(src, Form.NFKC));
+        assertTrue(Normalizer.isNormalized(src, Form.NFKD));
+
+        src = "";
+        assertTrue(Normalizer.isNormalized(src, Form.NFC));
+        assertTrue(Normalizer.isNormalized(src, Form.NFD));
+        assertTrue(Normalizer.isNormalized(src, Form.NFKC));
+        assertTrue(Normalizer.isNormalized(src, Form.NFKD));
+    }
+
+    /**
+     * @tests java.text.Normalizer#isNormalized(CharSequence, Form)
+     */
+    public void test_isNormalized_exception() throws Exception {
+        try {
+            Normalizer.isNormalized(null, Form.NFC);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            Normalizer.isNormalized("chars", null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.text.Normalizer#normalize(CharSequence, Form)
+     */
+    public void test_normalize() throws Exception {
+        String src = "\u00c1";
+        assertEquals("\u00c1", Normalizer.normalize(src, Form.NFC));
+        assertEquals("\u0041\u0301", Normalizer.normalize(src, Form.NFD));
+        assertEquals("\u00c1", Normalizer.normalize(src, Form.NFKC));
+        assertEquals("\u0041\u0301", Normalizer.normalize(src, Form.NFKD));
+
+        src = "\u0041\u0301";
+        assertEquals("\u00c1", Normalizer.normalize(src, Form.NFC));
+        assertEquals("\u0041\u0301", Normalizer.normalize(src, Form.NFD));
+        assertEquals("\u00c1", Normalizer.normalize(src, Form.NFKC));
+        assertEquals("\u0041\u0301", Normalizer.normalize(src, Form.NFKD));
+
+        src = "\ufb03";
+        assertEquals("\ufb03", Normalizer.normalize(src, Form.NFC));
+        assertEquals("\ufb03", Normalizer.normalize(src, Form.NFD));
+        assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFKC));
+        assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFKD));
+
+        src = "\u0066\u0066\u0069";
+        assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFC));
+        assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFD));
+        assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFKC));
+        assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFKD));
+
+        src = "";
+        assertEquals("", Normalizer.normalize(src, Form.NFC));
+        assertEquals("", Normalizer.normalize(src, Form.NFD));
+        assertEquals("", Normalizer.normalize(src, Form.NFKC));
+        assertEquals("", Normalizer.normalize(src, Form.NFKD));
+    }
+
+    /**
+     * @tests java.text.Normalizer#normalize(CharSequence, Form)
+     */
+    public void test_normalize_exception() throws Exception {
+        try {
+            Normalizer.normalize(null, Form.NFC);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            Normalizer.normalize("chars", null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
             // expected
         }
     }



Mime
View raw message