Search in sources :

Example 6 with Transliterator

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

the class ErrorTest method TestRBTErrors.

// public void TestUniToHexErrors() {
// Transliterator t = null;
// try {
// t = new UnicodeToHexTransliterator("", true, null);
// if (t != null) {
// errln("FAIL: Created a UnicodeToHexTransliterator with an empty pattern.");
// }
// } catch (IllegalArgumentException e) {
// }
// try {
// t = new UnicodeToHexTransliterator("\\x", true, null);
// if (t != null) {
// errln("FAIL: Created a UnicodeToHexTransliterator with a bad pattern.");
// }
// } catch (IllegalArgumentException e) {
// }
// t = new UnicodeToHexTransliterator();
// try {
// ((UnicodeToHexTransliterator) t).applyPattern("\\x");
// errln("FAIL: UnicodeToHexTransliterator::applyPattern succeeded with a bad pattern.");
// } catch (Exception e) {
// }
// }
@Test
public void TestRBTErrors() {
    String rules = "ab>y";
    String id = "MyRandom-YReverse";
    String goodPattern = "[[:L:]&[\\u0000-\\uFFFF]]";
    /* all BMP letters */
    UnicodeSet set = null;
    try {
        set = new UnicodeSet(goodPattern);
        try {
            Transliterator t = Transliterator.createFromRules(id, rules, Transliterator.REVERSE);
            t.setFilter(set);
            Transliterator.registerClass(id, t.getClass(), null);
            Transliterator.unregister(id);
            try {
                Transliterator.getInstance(id, Transliterator.REVERSE);
                errln("FAIL: construction of unregistered ID should have failed.");
            } catch (IllegalArgumentException e) {
            }
        } catch (IllegalArgumentException e) {
            errln("FAIL: Was not able to create a good RBT to test registration.");
        }
    } catch (IllegalArgumentException e) {
        errln("FAIL: Was not able to create a good UnicodeSet based on valid patterns.");
        return;
    }
}
Also used : ReplaceableString(android.icu.text.ReplaceableString) UnicodeSet(android.icu.text.UnicodeSet) Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 7 with Transliterator

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

the class JamoTest method TestPiecemeal.

/**
 * Test various step-at-a-time transformation of hangul to jamo to
 * latin and back.
 */
@Test
public void TestPiecemeal() {
    String hangul = "\uBC0F";
    String jamo = nameToJamo("(Mi)(I)(Cf)");
    String latin = "mic";
    String latin2 = "mich";
    Transliterator t = null;
    // was Hangul-Jamo
    t = Transliterator.getInstance("NFD");
    TransliteratorTest.expect(t, hangul, jamo);
    // was Jamo-Hangul
    t = Transliterator.getInstance("NFC");
    TransliteratorTest.expect(t, jamo, hangul);
    t = Transliterator.getInstance("Latin-Jamo");
    TransliteratorTest.expect(t, latin, jamo);
    t = Transliterator.getInstance("Jamo-Latin");
    TransliteratorTest.expect(t, jamo, latin2);
    t = Transliterator.getInstance("Hangul-Latin");
    TransliteratorTest.expect(t, hangul, latin2);
    t = Transliterator.getInstance("Latin-Hangul");
    TransliteratorTest.expect(t, latin, hangul);
    t = Transliterator.getInstance("Hangul-Latin; Latin-Jamo");
    TransliteratorTest.expect(t, hangul, jamo);
    t = Transliterator.getInstance("Jamo-Latin; Latin-Hangul");
    TransliteratorTest.expect(t, jamo, hangul);
    t = Transliterator.getInstance("Hangul-Latin; Latin-Hangul");
    TransliteratorTest.expect(t, hangul, hangul);
}
Also used : Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 8 with Transliterator

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

the class JamoTest method TestJamo.

@Test
public void TestJamo() {
    Transliterator latinJamo = Transliterator.getInstance("Latin-Jamo");
    Transliterator jamoLatin = latinJamo.getInverse();
    String[] CASE = { // see also http://www.unicode.org/cldr/data/charts/transforms/Latin-Hangul.html
    "gach", "(Gi)(A)(Cf)", null, "geumhui", "(Gi)(EU)(Mf)(Hi)(YI)", null, "choe", "(Ci)(OE)", null, "wo", "(IEUNG)(WEO)", null, "Wonpil", "(IEUNG)(WEO)(Nf)(Pi)(I)(L)", "wonpil", "GIPPEUM", "(Gi)(I)(BB)(EU)(Mf)", "gippeum", "EUTTEUM", "(IEUNG)(EU)(DD)(EU)(Mf)", "eutteum", "KKOTNAE", "(GGi)(O)(Tf)(Ni)(AE)", "kkotnae", "gaga", "(Gi)(A)(Gi)(A)", null, "gag-a", "(Gi)(A)(Gf)(IEUNG)(A)", null, "gak-ka", "(Gi)(A)(Kf)(Ki)(A)", null, "gakka", "(Gi)(A)(GGi)(A)", null, "gakk-a", "(Gi)(A)(GGf)(IEUNG)(A)", null, "gakkka", "(Gi)(A)(GGf)(Ki)(A)", null, "gak-kka", "(Gi)(A)(Kf)(GGi)(A)", null, "bab", "(Bi)(A)(Bf)", null, "babb", "(Bi)(A)(Bf)(Bi)(EU)", "babbeu", "babbba", "(Bi)(A)(Bf)(Bi)(EU)(Bi)(A)", "babbeuba", "bagg", "(Bi)(A)(Gf)(Gi)(EU)", "baggeu", "baggga", "(Bi)(A)(Gf)(Gi)(EU)(Gi)(A)", "baggeuga", // "bag"+SEP+"gga", "(Bi)(A)(Gf)"+SEP+"(Gi)(EU)(Gi)(A)", "bag"+SEP+"geuga",
    "kabsa", "(Ki)(A)(Bf)(Si)(A)", null, "kabska", "(Ki)(A)(BS)(Ki)(A)", null, // not (Kf)
    "gabsbka", // not (Kf)
    "(Gi)(A)(BS)(Bi)(EU)(Ki)(A)", // not (Kf)
    "gabsbeuka", "gga", "(Gi)(EU)(Gi)(A)", "geuga", "bsa", "(Bi)(EU)(Si)(A)", "beusa", "agg", "(IEUNG)(A)(Gf)(Gi)(EU)", "aggeu", "agga", "(IEUNG)(A)(Gf)(Gi)(A)", null, "la", "(R)(A)", null, "bs", "(Bi)(EU)(Sf)", "beus", "kalgga", "(Ki)(A)(L)(Gi)(EU)(Gi)(A)", "kalgeuga", // 'r' in a final position is treated like 'l'
    "karka", "(Ki)(A)(L)(Ki)(A)", "kalka" };
    for (int i = 0; i < CASE.length; i += 3) {
        String jamo = nameToJamo(CASE[i + 1]);
        if (CASE[i + 2] == null) {
            TransliteratorTest.expect(latinJamo, CASE[i], jamo, jamoLatin);
        } else {
            // Handle case where round-trip is expected to fail
            TransliteratorTest.expect(latinJamo, CASE[i], jamo);
            TransliteratorTest.expect(jamoLatin, jamo, CASE[i + 2]);
        }
    }
}
Also used : Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 9 with Transliterator

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

the class ReplaceableTest method Test5789.

@org.junit.Test
public void Test5789() {
    String rules = "IETR > IET | \\' R; # (1) do split ietr between t and r\r\n" + "I[EH] > I; # (2) friedrich";
    Transliterator trans = Transliterator.createFromRules("foo", rules, Transliterator.FORWARD);
    String result = trans.transliterate("BLENKDIETRICH");
    assertEquals("Rule breakage", "BLENKDIET'RICH", result);
}
Also used : ReplaceableString(android.icu.text.ReplaceableString) Transliterator(android.icu.text.Transliterator)

Example 10 with Transliterator

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

the class TransliteratorTest method TestAliasInverseID.

/**
 * Check ID of inverse of alias. (J22)
 */
@Test
public void TestAliasInverseID() {
    // This should be any alias ID with an inverse
    String ID = "Latin-Hangul";
    Transliterator t = Transliterator.getInstance(ID);
    Transliterator u = t.getInverse();
    String exp = "Hangul-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)

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