Search in sources :

Example 11 with Normalizer2

use of android.icu.text.Normalizer2 in project j2objc by google.

the class BasicTest method TestCustomComp.

@Test
public void TestCustomComp() {
    String[][] pairs = { { "\\uD801\\uE000\\uDFFE", "" }, { "\\uD800\\uD801\\uE000\\uDFFE\\uDFFF", "\\uD7FF\\uFFFF" }, { "\\uD800\\uD801\\uDFFE\\uDFFF", "\\uD7FF\\U000107FE\\uFFFF" }, { "\\uE001\\U000110B9\\u0345\\u0308\\u0327", "\\uE002\\U000110B9\\u0327\\u0345" }, { "\\uE010\\U000F0011\\uE012", "\\uE011\\uE012" }, { "\\uE010\\U000F0011\\U000F0011\\uE012", "\\uE011\\U000F0010" }, { "\\uE111\\u1161\\uE112\\u1162", "\\uAE4C\\u1102\\u0062\\u1162" }, { "\\uFFF3\\uFFF7\\U00010036\\U00010077", "\\U00010037\\U00010037\\uFFF6\\U00010037" } };
    Normalizer2 customNorm2;
    customNorm2 = Normalizer2.getInstance(BasicTest.class.getResourceAsStream("/android/icu/dev/data/testdata/testnorm.nrm"), "testnorm", Normalizer2.Mode.COMPOSE);
    for (int i = 0; i < pairs.length; ++i) {
        String[] pair = pairs[i];
        String input = Utility.unescape(pair[0]);
        String expected = Utility.unescape(pair[1]);
        String result = customNorm2.normalize(input);
        if (!result.equals(expected)) {
            errln("custom compose Normalizer2 did not normalize input " + i + " as expected");
        }
    }
}
Also used : Normalizer2(android.icu.text.Normalizer2) FilteredNormalizer2(android.icu.text.FilteredNormalizer2) Test(org.junit.Test)

Example 12 with Normalizer2

use of android.icu.text.Normalizer2 in project j2objc by google.

the class BasicTest method TestNFC.

@Test
public void TestNFC() {
    // Coverage tests.
    Normalizer2 nfc = Normalizer2.getNFCInstance();
    assertTrue("nfc.hasBoundaryAfter(space)", nfc.hasBoundaryAfter(' '));
    assertFalse("nfc.hasBoundaryAfter(ä)", nfc.hasBoundaryAfter('ä'));
}
Also used : Normalizer2(android.icu.text.Normalizer2) FilteredNormalizer2(android.icu.text.FilteredNormalizer2) Test(org.junit.Test)

Example 13 with Normalizer2

use of android.icu.text.Normalizer2 in project j2objc by google.

the class BasicTest method TestFilteredNormalizer2.

@Test
public void TestFilteredNormalizer2() {
    Normalizer2 nfcNorm2 = Normalizer2.getNFCInstance();
    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);
    }
    // More coverage.
    StringBuilder sb = new StringBuilder();
    assertEquals("filtered normalize()", "ää\u0304", fn2.normalize("a\u0308ä\u0304", (Appendable) sb).toString());
    assertTrue("filtered hasBoundaryAfter()", fn2.hasBoundaryAfter('ä'));
    assertTrue("filtered isInert()", fn2.isInert(0x0313));
}
Also used : FilteredNormalizer2(android.icu.text.FilteredNormalizer2) Normalizer2(android.icu.text.Normalizer2) FilteredNormalizer2(android.icu.text.FilteredNormalizer2) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 14 with Normalizer2

use of android.icu.text.Normalizer2 in project j2objc by google.

the class BasicTest method TestCustomFCC.

@Test
public void TestCustomFCC() {
    String[][] pairs = { { "\\uD801\\uE000\\uDFFE", "" }, { "\\uD800\\uD801\\uE000\\uDFFE\\uDFFF", "\\uD7FF\\uFFFF" }, { "\\uD800\\uD801\\uDFFE\\uDFFF", "\\uD7FF\\U000107FE\\uFFFF" }, // because of only-contiguous composition.
    { "\\uE001\\U000110B9\\u0345\\u0308\\u0327", "\\uE001\\U000110B9\\u0327\\u0308\\u0345" }, { "\\uE010\\U000F0011\\uE012", "\\uE011\\uE012" }, { "\\uE010\\U000F0011\\U000F0011\\uE012", "\\uE011\\U000F0010" }, { "\\uE111\\u1161\\uE112\\u1162", "\\uAE4C\\u1102\\u0062\\u1162" }, { "\\uFFF3\\uFFF7\\U00010036\\U00010077", "\\U00010037\\U00010037\\uFFF6\\U00010037" } };
    Normalizer2 customNorm2;
    customNorm2 = Normalizer2.getInstance(BasicTest.class.getResourceAsStream("/android/icu/dev/data/testdata/testnorm.nrm"), "testnorm", Normalizer2.Mode.COMPOSE_CONTIGUOUS);
    for (int i = 0; i < pairs.length; ++i) {
        String[] pair = pairs[i];
        String input = Utility.unescape(pair[0]);
        String expected = Utility.unescape(pair[1]);
        String result = customNorm2.normalize(input);
        if (!result.equals(expected)) {
            errln("custom FCC Normalizer2 did not normalize input " + i + " as expected");
        }
    }
}
Also used : Normalizer2(android.icu.text.Normalizer2) FilteredNormalizer2(android.icu.text.FilteredNormalizer2) Test(org.junit.Test)

Example 15 with Normalizer2

use of android.icu.text.Normalizer2 in project j2objc by google.

the class BasicTest method TestNFD.

@Test
public void TestNFD() {
    // Coverage tests.
    Normalizer2 nfd = Normalizer2.getNFDInstance();
    assertTrue("nfd.hasBoundaryAfter(space)", nfd.hasBoundaryAfter(' '));
    assertFalse("nfd.hasBoundaryAfter(ä)", nfd.hasBoundaryAfter('ä'));
}
Also used : Normalizer2(android.icu.text.Normalizer2) FilteredNormalizer2(android.icu.text.FilteredNormalizer2) Test(org.junit.Test)

Aggregations

Normalizer2 (android.icu.text.Normalizer2)18 Test (org.junit.Test)16 FilteredNormalizer2 (android.icu.text.FilteredNormalizer2)13 UnicodeSet (android.icu.text.UnicodeSet)7 UnicodeSetIterator (android.icu.text.UnicodeSetIterator)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 UnicodeMap (android.icu.dev.util.UnicodeMap)1 Norm2AllModes (android.icu.impl.Norm2AllModes)1 Normalizer2Impl (android.icu.impl.Normalizer2Impl)1 CanonicalIterator (android.icu.text.CanonicalIterator)1 ReplaceableString (android.icu.text.ReplaceableString)1 SpoofChecker (android.icu.text.SpoofChecker)1 Transliterator (android.icu.text.Transliterator)1 UTF16 (android.icu.text.UTF16)1 CaseInsensitiveString (android.icu.util.CaseInsensitiveString)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1