Search in sources :

Example 71 with Transliterator

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

the class TransliteratorTest method TestDevanagariLatinRT.

// ======================================================================
// Ram's tests
// ======================================================================
/* this test performs  test of rules in ISO 15915 */
@Test
public void TestDevanagariLatinRT() {
    String[] source = { "bh\u0101rata", "kra", "k\u1E63a", "khra", "gra", "\u1E45ra", "cra", "chra", "j\u00F1a", "jhra", "\u00F1ra", "\u1E6Dya", "\u1E6Dhra", "\u1E0Dya", // "r\u0323ya", // \u095c is not valid in Devanagari
    "\u1E0Dhya", "\u1E5Bhra", "\u1E47ra", "tta", "thra", "dda", "dhra", "nna", "pra", "phra", "bra", "bhra", "mra", "\u1E49ra", // "l\u0331ra",
    "yra", "\u1E8Fra", // "l-",
    "vra", "\u015Bra", "\u1E63ra", "sra", "hma", "\u1E6D\u1E6Da", "\u1E6D\u1E6Dha", "\u1E6Dh\u1E6Dha", "\u1E0D\u1E0Da", "\u1E0D\u1E0Dha", "\u1E6Dya", "\u1E6Dhya", "\u1E0Dya", "\u1E0Dhya", // CharsToUnicodeString("hma"),
    "hya", "\u015Br\u0325", "\u015Bca", "\u0115", "san\u0304j\u012Bb s\u0113nagupta", "\u0101nand vaddir\u0101ju" };
    String[] expected = { "\u092D\u093E\u0930\u0924", /* bha\u0304rata */
    "\u0915\u094D\u0930", /* kra         */
    "\u0915\u094D\u0937", /* ks\u0323a  */
    "\u0916\u094D\u0930", /* khra        */
    "\u0917\u094D\u0930", /* gra         */
    "\u0919\u094D\u0930", /* n\u0307ra  */
    "\u091A\u094D\u0930", /* cra         */
    "\u091B\u094D\u0930", /* chra        */
    "\u091C\u094D\u091E", /* jn\u0303a  */
    "\u091D\u094D\u0930", /* jhra        */
    "\u091E\u094D\u0930", /* n\u0303ra  */
    "\u091F\u094D\u092F", /* t\u0323ya  */
    "\u0920\u094D\u0930", /* t\u0323hra */
    "\u0921\u094D\u092F", // "\u095C\u094D\u092F",          /* r\u0323ya  */ // \u095c is not valid in Devanagari
    "\u0922\u094D\u092F", /* d\u0323hya */
    "\u0922\u093C\u094D\u0930", /* r\u0323hra */
    "\u0923\u094D\u0930", /* n\u0323ra  */
    "\u0924\u094D\u0924", /* tta         */
    "\u0925\u094D\u0930", /* thra        */
    "\u0926\u094D\u0926", /* dda         */
    "\u0927\u094D\u0930", /* dhra        */
    "\u0928\u094D\u0928", /* nna         */
    "\u092A\u094D\u0930", /* pra         */
    "\u092B\u094D\u0930", /* phra        */
    "\u092C\u094D\u0930", /* bra         */
    "\u092D\u094D\u0930", /* bhra        */
    "\u092E\u094D\u0930", /* mra         */
    "\u0929\u094D\u0930", // "\u0934\u094D\u0930",          /* l\u0331ra  */
    "\u092F\u094D\u0930", /* yra         */
    "\u092F\u093C\u094D\u0930", // "l-",
    "\u0935\u094D\u0930", /* vra         */
    "\u0936\u094D\u0930", /* s\u0301ra  */
    "\u0937\u094D\u0930", /* s\u0323ra  */
    "\u0938\u094D\u0930", /* sra         */
    "\u0939\u094d\u092E", /* hma         */
    "\u091F\u094D\u091F", /* t\u0323t\u0323a  */
    "\u091F\u094D\u0920", /* t\u0323t\u0323ha */
    "\u0920\u094D\u0920", /* t\u0323ht\u0323ha*/
    "\u0921\u094D\u0921", /* d\u0323d\u0323a  */
    "\u0921\u094D\u0922", /* d\u0323d\u0323ha */
    "\u091F\u094D\u092F", /* t\u0323ya  */
    "\u0920\u094D\u092F", /* t\u0323hya */
    "\u0921\u094D\u092F", /* d\u0323ya  */
    "\u0922\u094D\u092F", // "hma",                         /* hma         */
    "\u0939\u094D\u092F", /* hya         */
    "\u0936\u0943", /* s\u0301r\u0325a  */
    "\u0936\u094D\u091A", /* s\u0301ca  */
    "\u090d", /* e\u0306    */
    "\u0938\u0902\u091C\u0940\u092C\u094D \u0938\u0947\u0928\u0917\u0941\u092A\u094D\u0924", "\u0906\u0928\u0902\u0926\u094D \u0935\u0926\u094D\u0926\u093F\u0930\u093E\u091C\u0941" };
    Transliterator latinToDev = Transliterator.getInstance("Latin-Devanagari", Transliterator.FORWARD);
    Transliterator devToLatin = Transliterator.getInstance("Devanagari-Latin", Transliterator.FORWARD);
    for (int i = 0; i < source.length; i++) {
        expect(latinToDev, (source[i]), (expected[i]));
        expect(devToLatin, (expected[i]), (source[i]));
    }
}
Also used : CaseInsensitiveString(android.icu.util.CaseInsensitiveString) ReplaceableString(android.icu.text.ReplaceableString) Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 72 with Transliterator

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

the class TransliteratorTest method TestCompoundInverseID.

/**
 * Test IDs of inverses of compound transliterators. (J20)
 */
@Test
public void TestCompoundInverseID() {
    String ID = "Latin-Jamo;NFC(NFD)";
    Transliterator t = Transliterator.getInstance(ID);
    Transliterator u = t.getInverse();
    String exp = "NFD(NFC);Jamo-Latin";
    String got = u.getID();
    if (!got.equals(exp)) {
        errln("FAIL: Inverse of " + ID + " is " + got + ", expected " + exp);
    }
}
Also used : CaseInsensitiveString(android.icu.util.CaseInsensitiveString) ReplaceableString(android.icu.text.ReplaceableString) Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 73 with Transliterator

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

the class TransliteratorTest method TestQuantifiedSegment.

/**
 * Test quantified segment behavior.  We want:
 * ([abc])+ > x $1 x; applied to "cba" produces "xax"
 */
@Test
public void TestQuantifiedSegment() {
    // The normal case
    expect("([abc]+) > x $1 x;", "cba", "xcbax");
    // The tricky case; the quantifier is around the segment
    expect("([abc])+ > x $1 x;", "cba", "xax");
    // Tricky case in reverse direction
    expect("([abc])+ { q > x $1 x;", "cbaq", "cbaxax");
    // Check post-context segment
    expect("{q} ([a-d])+ > '(' $1 ')';", "ddqcba", "dd(a)cba");
    // Test toRule/toPattern for non-quantified segment.
    // Careful with spacing here.
    String r = "([a-c]){q} > x $1 x;";
    Transliterator t = Transliterator.createFromRules("ID", r, Transliterator.FORWARD);
    String rr = t.toRules(true);
    if (!r.equals(rr)) {
        errln("FAIL: \"" + r + "\" x toRules() => \"" + rr + "\"");
    } else {
        logln("Ok: \"" + r + "\" x toRules() => \"" + rr + "\"");
    }
    // Test toRule/toPattern for quantified segment.
    // Careful with spacing here.
    r = "([a-c])+{q} > x $1 x;";
    t = Transliterator.createFromRules("ID", r, Transliterator.FORWARD);
    rr = t.toRules(true);
    if (!r.equals(rr)) {
        errln("FAIL: \"" + r + "\" x toRules() => \"" + rr + "\"");
    } else {
        logln("Ok: \"" + r + "\" x toRules() => \"" + rr + "\"");
    }
}
Also used : CaseInsensitiveString(android.icu.util.CaseInsensitiveString) ReplaceableString(android.icu.text.ReplaceableString) Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 74 with Transliterator

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

the class TransliteratorTest method TestNewEngine.

/**
 * Test various failure points of the new 2.0 engine.
 */
@Test
public void TestNewEngine() {
    Transliterator t = Transliterator.getInstance("Latin-Hiragana");
    // Katakana should be untouched
    expect(t, "a\u3042\u30A2", "\u3042\u3042\u30A2");
    if (true) {
        // This test will only work if Transliterator.ROLLBACK is
        // true.  Otherwise, this test will fail, revealing a
        // limitation of global filters in incremental mode.
        Transliterator a = Transliterator.createFromRules("a_to_A", "a > A;", Transliterator.FORWARD);
        Transliterator A = Transliterator.createFromRules("A_to_b", "A > b;", Transliterator.FORWARD);
        try {
            Transliterator.registerInstance(a);
            Transliterator.registerInstance(A);
            t = Transliterator.getInstance("[:Ll:];a_to_A;NFD;A_to_b");
            expect(t, "aAaA", "bAbA");
            Transliterator[] u = t.getElements();
            assertTrue("getElements().length", u.length == 3);
            assertEquals("getElements()[0]", u[0].getID(), "a_to_A");
            assertEquals("getElements()[1]", u[1].getID(), "NFD");
            assertEquals("getElements()[2]", u[2].getID(), "A_to_b");
            t = Transliterator.getInstance("a_to_A;NFD;A_to_b");
            t.setFilter(new UnicodeSet("[:Ll:]"));
            expect(t, "aAaA", "bAbA");
        } finally {
            Transliterator.unregister("a_to_A");
            Transliterator.unregister("A_to_b");
        }
    }
    expect("$smooth = x; $macron = q; [:^L:] { ([aeiouyAEIOUY] $macron?) } [^aeiouyAEIOUY$smooth$macron] > | $1 $smooth ;", "a", "ax");
    String gr = "$ddot = \u0308 ;" + "$lcgvowel = [\u03b1\u03b5\u03b7\u03b9\u03bf\u03c5\u03c9] ;" + "$rough = \u0314 ;" + "($lcgvowel+ $ddot?) $rough > h | $1 ;" + "\u03b1 <> a ;" + "$rough <> h ;";
    expect(gr, "\u03B1\u0314", "ha");
}
Also used : CaseInsensitiveString(android.icu.util.CaseInsensitiveString) ReplaceableString(android.icu.text.ReplaceableString) UnicodeSet(android.icu.text.UnicodeSet) Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 75 with Transliterator

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

the class TransliteratorTest method TestChinese.

@Test
public void TestChinese() {
    Transliterator hanLatin = Transliterator.getInstance("Han-Latin");
    assertTransform("Transform", "z\u00E0o Unicode", hanLatin, "\u9020Unicode");
    assertTransform("Transform", "z\u00E0i chu\u00E0ng z\u00E0o Unicode zh\u012B qi\u00E1n", hanLatin, "\u5728\u5275\u9020Unicode\u4E4B\u524D");
}
Also used : Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Aggregations

Transliterator (android.icu.text.Transliterator)97 Test (org.junit.Test)88 ReplaceableString (android.icu.text.ReplaceableString)66 CaseInsensitiveString (android.icu.util.CaseInsensitiveString)57 UnicodeSet (android.icu.text.UnicodeSet)19 UnicodeSetIterator (android.icu.text.UnicodeSetIterator)5 ULocale (android.icu.util.ULocale)3 Enumeration (java.util.Enumeration)3 UnicodeFilter (android.icu.text.UnicodeFilter)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 UnicodeMap (android.icu.dev.util.UnicodeMap)1 CanonicalIterator (android.icu.text.CanonicalIterator)1 Normalizer2 (android.icu.text.Normalizer2)1 Replaceable (android.icu.text.Replaceable)1 BufferedWriter (java.io.BufferedWriter)1 HashSet (java.util.HashSet)1