Search in sources :

Example 96 with Transliterator

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

the class JamoTest method TestRoundTrip.

/**
 * These are problems turned up by the Hangul-Jamo;Jamo-Latin
 * round trip test.
 */
@Test
public void TestRoundTrip() {
    String[] HANGUL = { "\uAC03\uC2F8", "\uC544\uC5B4" };
    Transliterator latinJamo = Transliterator.getInstance("Latin-Jamo");
    Transliterator jamoLatin = latinJamo.getInverse();
    Transliterator jamoHangul = Transliterator.getInstance("NFC");
    Transliterator hangulJamo = Transliterator.getInstance("NFD");
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < HANGUL.length; ++i) {
        String hangul = HANGUL[i];
        String jamo = hangulJamo.transliterate(hangul);
        String latin = jamoLatin.transliterate(jamo);
        String jamo2 = latinJamo.transliterate(latin);
        String hangul2 = jamoHangul.transliterate(jamo2);
        buf.setLength(0);
        buf.append(hangul + " => " + jamoToName(jamo) + " => " + latin + " => " + jamoToName(jamo2) + " => " + hangul2);
        if (!hangul.equals(hangul2)) {
            errln("FAIL: " + Utility.escape(buf.toString()));
        } else {
            logln(Utility.escape(buf.toString()));
        }
    }
}
Also used : Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 97 with Transliterator

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

the class ReplaceableTest method check.

void check(String transliteratorName, String test, String shouldProduceStyles) {
    TestReplaceable tr = new TestReplaceable(test, null);
    String original = tr.toString();
    Transliterator t;
    if (transliteratorName.startsWith("*")) {
        transliteratorName = transliteratorName.substring(1);
        t = Transliterator.createFromRules("test", transliteratorName, Transliterator.FORWARD);
    } else {
        t = Transliterator.getInstance(transliteratorName);
    }
    t.transliterate(tr);
    String newStyles = tr.getStyles();
    if (!newStyles.equals(shouldProduceStyles)) {
        errln("FAIL Styles: " + transliteratorName + " ( " + original + " ) => " + tr.toString() + "; should be {" + shouldProduceStyles + "}!");
    } else {
        logln("OK: " + transliteratorName + " ( " + original + " ) => " + tr.toString());
    }
    if (!tr.hasMetaData() || tr.chars.hasMetaData() || tr.styles.hasMetaData()) {
        errln("Fail hasMetaData()");
    }
}
Also used : ReplaceableString(android.icu.text.ReplaceableString) Transliterator(android.icu.text.Transliterator)

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