Search in sources :

Example 61 with Transliterator

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

the class TransliteratorTest method CheckIncrementalAux.

public void CheckIncrementalAux(Transliterator t, String input) {
    Replaceable test = new ReplaceableString(input);
    Transliterator.Position pos = new Transliterator.Position(0, test.length(), 0, test.length());
    t.transliterate(test, pos);
    boolean gotError = false;
    if (pos.start == 0 && pos.limit != 0 && !t.getID().equals("Hex-Any/Unicode")) {
        errln("No Progress, " + t.getID() + ": " + UtilityExtensions.formatInput(test, pos));
        gotError = true;
    } else {
        logln("PASS Progress, " + t.getID() + ": " + UtilityExtensions.formatInput(test, pos));
    }
    t.finishTransliteration(test, pos);
    if (pos.start != pos.limit) {
        errln("Incomplete, " + t.getID() + ":  " + UtilityExtensions.formatInput(test, pos));
        gotError = true;
    }
    if (!gotError) {
    // errln("FAIL: Did not get expected error");
    }
}
Also used : ReplaceableString(android.icu.text.ReplaceableString) Replaceable(android.icu.text.Replaceable) Transliterator(android.icu.text.Transliterator)

Example 62 with Transliterator

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

the class TransliteratorTest method TestKeyboard3.

/**
 * Test keyboard transliteration with back-replacement.
 */
@Test
public void TestKeyboard3() {
    // We want th>z but t>y.  Furthermore, during keyboard
    // transliteration we want t>y then yh>z if t, then h are
    // typed.
    String RULES = "t>|y;" + "yh>z;" + "";
    String[] DATA = { // keyboard xliteration.
    "a", "a", "b", "ab", // modified for rollback - "aby",
    "t", // modified for rollback - "aby",
    "abt", "c", "abyc", // modified for rollback - "abycy",
    "t", // modified for rollback - "abycy",
    "abyct", "h", "abycz", // null means finishKeyboardTransliteration
    null, // null means finishKeyboardTransliteration
    "abycz" };
    Transliterator t = Transliterator.createFromRules("<ID>", RULES, Transliterator.FORWARD);
    keyboardAux(t, DATA);
}
Also used : CaseInsensitiveString(android.icu.util.CaseInsensitiveString) ReplaceableString(android.icu.text.ReplaceableString) Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 63 with Transliterator

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

the class TransliteratorTest method TestSegments.

/**
 * Test segments and segment references.
 */
@Test
public void TestSegments() {
    // Array of 3n items
    // Each item is <rules>, <input>, <expected output>
    String[] DATA = { "([a-z]) '.' ([0-9]) > $2 '-' $1", "abc.123.xyz.456", "ab1-c23.xy4-z56" };
    for (int i = 0; i < DATA.length; i += 3) {
        logln("Pattern: " + Utility.escape(DATA[i]));
        Transliterator t = Transliterator.createFromRules("<ID>", DATA[i], Transliterator.FORWARD);
        expect(t, DATA[i + 1], DATA[i + 2]);
    }
}
Also used : CaseInsensitiveString(android.icu.util.CaseInsensitiveString) ReplaceableString(android.icu.text.ReplaceableString) Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 64 with Transliterator

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

the class TransliteratorTest method TestCursorOffset.

/**
 * Test cursor positioning outside of the key
 */
@Test
public void TestCursorOffset() {
    // Array of 3n items
    // Each item is <rules>, <input>, <expected output>
    String[] DATA = { "pre {alpha} post > | @ ALPHA ;" + "eALPHA > beta ;" + "pre {beta} post > BETA @@ | ;" + "post > xyz", "prealphapost prebetapost", "prbetaxyz preBETApost" };
    for (int i = 0; i < DATA.length; i += 3) {
        logln("Pattern: " + Utility.escape(DATA[i]));
        Transliterator t = Transliterator.createFromRules("<ID>", DATA[i], Transliterator.FORWARD);
        expect(t, DATA[i + 1], DATA[i + 2]);
    }
}
Also used : CaseInsensitiveString(android.icu.util.CaseInsensitiveString) ReplaceableString(android.icu.text.ReplaceableString) Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 65 with Transliterator

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

the class TransliteratorTest method TestMulticharStringSet.

@Test
public void TestMulticharStringSet() {
    // Basic testing
    String rule = "       [{aa}]       > x;" + "         a          > y;" + "       [b{bc}]      > z;" + "[{gd}] { e          > q;" + "         e } [{fg}] > r;";
    Transliterator t = Transliterator.createFromRules("Test", rule, Transliterator.FORWARD);
    if (t == null) {
        errln("FAIL: createFromRules failed");
        return;
    }
    expect(t, "a aa ab bc d gd de gde gdefg ddefg", "y x yz z d gd de gdq gdqfg ddrfg");
    // Overlapped string test.  Make sure that when multiple
    // strings can match that the longest one is matched.
    rule = "    [a {ab} {abc}]    > x;" + "           b          > y;" + "           c          > z;" + " q [t {st} {rst}] { e > p;";
    t = Transliterator.createFromRules("Test", rule, Transliterator.FORWARD);
    if (t == null) {
        errln("FAIL: createFromRules failed");
        return;
    }
    expect(t, "a ab abc qte qste qrste", "x x x qtp qstp qrstp");
}
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