]> granicus.if.org Git - icu/commitdiff
ICU-8606 add Normalizer2.getCombiningClass(c)
authorMarkus Scherer <markus.icu@gmail.com>
Thu, 30 Jun 2011 22:07:22 +0000 (22:07 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Thu, 30 Jun 2011 22:07:22 +0000 (22:07 +0000)
X-SVN-Rev: 30261

icu4j/main/classes/core/src/com/ibm/icu/impl/Norm2AllModes.java
icu4j/main/classes/core/src/com/ibm/icu/impl/UCharacterProperty.java
icu4j/main/classes/core/src/com/ibm/icu/impl/UTS46.java
icu4j/main/classes/core/src/com/ibm/icu/lang/UCharacter.java
icu4j/main/classes/core/src/com/ibm/icu/text/FilteredNormalizer2.java
icu4j/main/classes/core/src/com/ibm/icu/text/Normalizer2.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/normalizer/BasicTest.java

index 920e515c80c620828403439c9661c81e533b22fa..9b882f5b19eb18e33d401b882e7a84162f336eb9 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *******************************************************************************
-*   Copyright (C) 2009-2010, International Business Machines
+*   Copyright (C) 2009-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *******************************************************************************
 */
@@ -129,6 +129,11 @@ public final class Norm2AllModes {
             return impl.getDecomposition(c);
         }
 
+        @Override
+        public int getCombiningClass(int c) {
+            return impl.getCC(impl.getNorm16(c));
+        }
+
         // quick checks
         @Override
         public boolean isNormalized(CharSequence s) {
index 9c8e9aaa713c8270bd6ff24d53f41182c21cb099..e2413a9e9e2108c170dbb4249ce8d87437c14549 100644 (file)
@@ -492,8 +492,7 @@ public final class UCharacterProperty
         new IntProperty(0, BLOCK_MASK_, BLOCK_SHIFT_),
         new CombiningClassIntProperty(SRC_NFC) {  // CANONICAL_COMBINING_CLASS
             int getValue(int c) {
-                Normalizer2Impl impl = Norm2AllModes.getNFCInstance().impl;
-                return impl.getCC(impl.getNorm16(c));
+                return Norm2AllModes.getNFCInstance().decomp.getCombiningClass(c);
             }
         },
         new IntProperty(2, DECOMPOSITION_TYPE_MASK_, 0),
index 809b772eda189d72995243be8d9a6bfcb2182b45..800f15a84a2f0344954851fd7961c9113b9abec1 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *******************************************************************************
-* Copyright (C) 2010, International Business Machines
+* Copyright (C) 2011, International Business Machines
 * Corporation and others.  All Rights Reserved.
 *******************************************************************************
 */
@@ -684,7 +684,7 @@ public final class UTS46 extends IDNA {
                 int j=i;
                 c=Character.codePointBefore(label, j);
                 j-=Character.charCount(c);
-                if(UCharacter.getCombiningClass(c)==9) {
+                if(uts46Norm2.getCombiningClass(c)==9) {
                     continue;
                 }
                 // check precontext (Joining_Type:{L,D})(Joining_Type:T)*
index c059b620d5f14b5085b80c316360b352677bbfde..ba424ae008916e846204bda73799b1832b723ab4 100644 (file)
@@ -16,7 +16,6 @@ import java.util.Map;
 
 import com.ibm.icu.impl.IllegalIcuArgumentException;
 import com.ibm.icu.impl.Norm2AllModes;
-import com.ibm.icu.impl.Normalizer2Impl;
 import com.ibm.icu.impl.Trie2;
 import com.ibm.icu.impl.UBiDiProps;
 import com.ibm.icu.impl.UCaseProps;
@@ -3890,8 +3889,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
         if (ch < MIN_VALUE || ch > MAX_VALUE) {
             throw new IllegalArgumentException("Codepoint out of bounds");
         }
-        Normalizer2Impl impl = Norm2AllModes.getNFCInstance().impl;
-        return impl.getCC(impl.getNorm16(ch));
+        return Norm2AllModes.getNFCInstance().decomp.getCombiningClass(ch);
     }
 
     /**
index f53487d70dd6a303343b58dd0350851c50efeee9..c2f5f834b74aa86d8b61edc01ffe9bea61411993 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *******************************************************************************
-*   Copyright (C) 2009-2010, International Business Machines
+*   Copyright (C) 2009-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *******************************************************************************
 */
@@ -89,6 +89,16 @@ public class FilteredNormalizer2 extends Normalizer2 {
         return set.contains(c) ? norm2.getDecomposition(c) : null;
     }
 
+    /**
+     * {@inheritDoc}
+     * @draft ICU 49
+     * @provisional This API might change or be removed in a future release.
+     */
+    @Override
+    public int getCombiningClass(int c) {
+        return set.contains(c) ? norm2.getCombiningClass(c) : 0;
+    }
+
     /**
      * {@inheritDoc}
      * @stable ICU 4.4
index c472edb2b542b6130c1079b42e176acbe2aaf52e..c0e335414606bab149b3612355cd3ffc740a52ff 100644 (file)
@@ -208,6 +208,17 @@ public abstract class Normalizer2 {
      */
     public abstract String getDecomposition(int c);
 
+    /**
+     * Gets the combining class of c.
+     * The default implementation returns 0
+     * but all standard implementations return the Unicode Canonical_Combining_Class value.
+     * @param c code point
+     * @return c's combining class
+     * @draft ICU 49
+     * @provisional This API might change or be removed in a future release.
+     */
+    public int getCombiningClass(int c) { return 0; }
+
     /**
      * Tests if the string is normalized.
      * Internally, in cases where the quickCheck() method would return "maybe"
index 5024473e278ded610a62535cf12eda8114629cbe..12b4aa020577dea25a9a973415d8bc4fed2781be 100644 (file)
@@ -684,6 +684,8 @@ public final class UCharacterTest extends TestFmwk
             type = 0,
             dir = 0;
 
+        Normalizer2 nfkc = Normalizer2.getInstance(null, "nfkc", Normalizer2.Mode.COMPOSE);
+
         try
         {
             BufferedReader input = TestUtil.getDataReader(
@@ -758,6 +760,12 @@ public final class UCharacterTest extends TestFmwk
                             "class " + cc);
                     break;
                 }
+                if (nfkc.getCombiningClass(ch) != cc)
+                {
+                    errln("FAIL \\u" + hex(ch) + " expected NFKC combining " +
+                            "class " + cc);
+                    break;
+                }
 
                 // testing the direction
                 if (d.length() == 1)
index 19338e0f431f0df3e4f232941eb62896cdaf7369..2b615520a39ae8b51fcabce397ae2ceb19771388 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 1996-2010, International Business Machines Corporation and
+ * Copyright (C) 1996-2011, International Business Machines Corporation and
  * others. All Rights Reserved.
  *******************************************************************************
  */
@@ -2572,4 +2572,19 @@ public class BasicTest extends TestFmwk {
             }
         }
     }
+
+    public void TestFilteredNormalizer2() {
+        Normalizer2 nfcNorm2=Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.COMPOSE);
+        UnicodeSet filter=new UnicodeSet("[^\u00a0-\u00ff\u0310-\u031f]");
+        FilteredNormalizer2 fn2=new FilteredNormalizer2(nfcNorm2, filter);
+        int c;
+        for(c=0; c<=0x3ff; ++c) {
+            int expectedCC= filter.contains(c) ? nfcNorm2.getCombiningClass(c) : 0;
+            int cc=fn2.getCombiningClass(c);
+            assertEquals(
+                    "FilteredNormalizer2(NFC, ^A0-FF,310-31F).getCombiningClass(U+"+hex(c)+
+                    ")==filtered NFC.getCC()",
+                    expectedCC, cc);
+        }
+    }
 }