Search in sources :

Example 6 with Normalizer2

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

the class BasicTest method TestFCD.

@Test
public void TestFCD() {
    // Coverage tests.
    Normalizer2 fcd = Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.FCD);
    assertTrue("fcd.hasBoundaryAfter(space)", fcd.hasBoundaryAfter(' '));
    assertFalse("fcd.hasBoundaryAfter(ä)", fcd.hasBoundaryAfter('ä'));
    assertTrue("fcd.isInert(space)", fcd.isInert(' '));
    assertFalse("fcd.isInert(ä)", fcd.isInert('ä'));
    // This implementation method is unreachable via public API.
    Norm2AllModes.FCDNormalizer2 impl = (Norm2AllModes.FCDNormalizer2) fcd;
    assertEquals("fcd impl.getQuickCheck(space)", 1, impl.getQuickCheck(' '));
    assertEquals("fcd impl.getQuickCheck(ä)", 0, impl.getQuickCheck('ä'));
}
Also used : Norm2AllModes(android.icu.impl.Norm2AllModes) Normalizer2(android.icu.text.Normalizer2) FilteredNormalizer2(android.icu.text.FilteredNormalizer2) Test(org.junit.Test)

Example 7 with Normalizer2

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

the class BasicTest method TestGetEasyToUseInstance.

@Test
public void TestGetEasyToUseInstance() {
    // Test input string:
    // U+00A0 -> <noBreak> 0020
    // U+00C7 0301 = 1E08 = 0043 0327 0301
    String in = "\u00A0\u00C7\u0301";
    Normalizer2 n2 = Normalizer2.getNFCInstance();
    String out = n2.normalize(in);
    assertEquals("getNFCInstance() did not return an NFC instance " + "(normalizes to " + prettify(out) + ')', "\u00A0\u1E08", out);
    n2 = Normalizer2.getNFDInstance();
    out = n2.normalize(in);
    assertEquals("getNFDInstance() did not return an NFD instance " + "(normalizes to " + prettify(out) + ')', "\u00A0C\u0327\u0301", out);
    n2 = Normalizer2.getNFKCInstance();
    out = n2.normalize(in);
    assertEquals("getNFKCInstance() did not return an NFKC instance " + "(normalizes to " + prettify(out) + ')', " \u1E08", out);
    n2 = Normalizer2.getNFKDInstance();
    out = n2.normalize(in);
    assertEquals("getNFKDInstance() did not return an NFKD instance " + "(normalizes to " + prettify(out) + ')', " C\u0327\u0301", out);
    n2 = Normalizer2.getNFKCCasefoldInstance();
    out = n2.normalize(in);
    assertEquals("getNFKCCasefoldInstance() did not return an NFKC_Casefold instance " + "(normalizes to " + prettify(out) + ')', " \u1E09", out);
}
Also used : Normalizer2(android.icu.text.Normalizer2) FilteredNormalizer2(android.icu.text.FilteredNormalizer2) Test(org.junit.Test)

Example 8 with Normalizer2

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

the class BasicTest method TestGetDecomposition.

@Test
public void TestGetDecomposition() {
    Normalizer2 n2 = Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.COMPOSE_CONTIGUOUS);
    String decomp = n2.getDecomposition(0x20);
    assertEquals("fcc.getDecomposition(space) failed", null, decomp);
    decomp = n2.getDecomposition(0xe4);
    assertEquals("fcc.getDecomposition(a-umlaut) failed", "a\u0308", decomp);
    decomp = n2.getDecomposition(0xac01);
    assertEquals("fcc.getDecomposition(Hangul syllable U+AC01) failed", "\u1100\u1161\u11a8", decomp);
}
Also used : Normalizer2(android.icu.text.Normalizer2) FilteredNormalizer2(android.icu.text.FilteredNormalizer2) Test(org.junit.Test)

Example 9 with Normalizer2

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

the class BasicTest method TestGetRawDecomposition.

@Test
public void TestGetRawDecomposition() {
    Normalizer2 n2 = Normalizer2.getNFKCInstance();
    /*
         * Raw decompositions from NFKC data are the Unicode Decomposition_Mapping values,
         * without recursive decomposition.
         */
    String decomp = n2.getRawDecomposition(0x20);
    assertEquals("nfkc.getRawDecomposition(space) failed", null, decomp);
    decomp = n2.getRawDecomposition(0xe4);
    assertEquals("nfkc.getRawDecomposition(a-umlaut) failed", "a\u0308", decomp);
    /* U+1E08 LATIN CAPITAL LETTER C WITH CEDILLA AND ACUTE */
    decomp = n2.getRawDecomposition(0x1e08);
    assertEquals("nfkc.getRawDecomposition(c-cedilla-acute) failed", "\u00c7\u0301", decomp);
    /* U+212B ANGSTROM SIGN */
    decomp = n2.getRawDecomposition(0x212b);
    assertEquals("nfkc.getRawDecomposition(angstrom sign) failed", "\u00c5", decomp);
    decomp = n2.getRawDecomposition(0xac00);
    assertEquals("nfkc.getRawDecomposition(Hangul syllable U+AC00) failed", "\u1100\u1161", decomp);
    /* A Hangul LVT syllable has a raw decomposition of an LV syllable + T. */
    decomp = n2.getRawDecomposition(0xac01);
    assertEquals("nfkc.getRawDecomposition(Hangul syllable U+AC01) failed", "\uac00\u11a8", decomp);
}
Also used : Normalizer2(android.icu.text.Normalizer2) FilteredNormalizer2(android.icu.text.FilteredNormalizer2) Test(org.junit.Test)

Example 10 with Normalizer2

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

the class BasicTest method TestNoopNormalizer2.

@Test
public void TestNoopNormalizer2() {
    // Use the internal class directly for coverage of methods that are not publicly reachable.
    Normalizer2 noop = Norm2AllModes.NOOP_NORMALIZER2;
    assertEquals("noop.normalizeSecondAndAppend()", "ä\u0327", noop.normalizeSecondAndAppend(new StringBuilder("ä"), "\u0327").toString());
    assertEquals("noop.getDecomposition()", null, noop.getDecomposition('ä'));
    assertTrue("noop.hasBoundaryAfter()", noop.hasBoundaryAfter(0x0308));
    assertTrue("noop.isInert()", noop.isInert(0x0308));
}
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