Search in sources :

Example 1 with UnicodeFilter

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

the class TransliteratorTest method checkRegistry.

private void checkRegistry(String id) {
    Transliterator fie = Transliterator.getInstance(id);
    final UnicodeSet fae = new UnicodeSet("[a-z5]");
    fie.setFilter(fae);
    Transliterator foe = Transliterator.getInstance(id);
    UnicodeFilter fee = foe.getFilter();
    if (fae.equals(fee)) {
        errln("Changed what is in registry for " + id);
    }
}
Also used : UnicodeFilter(android.icu.text.UnicodeFilter) UnicodeSet(android.icu.text.UnicodeSet) Transliterator(android.icu.text.Transliterator)

Example 2 with UnicodeFilter

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

the class TransliteratorTest method TestFiltering.

/**
 * Do some basic tests of filtering.
 */
@Test
public void TestFiltering() {
    Transliterator tempTrans = Transliterator.createFromRules("temp", "x > y; x{a} > b; ", Transliterator.FORWARD);
    tempTrans.setFilter(new UnicodeSet("[a]"));
    String tempResult = tempTrans.transform("xa");
    assertEquals("context should not be filtered ", "xb", tempResult);
    tempTrans = Transliterator.createFromRules("temp", "::[a]; x > y; x{a} > b; ", Transliterator.FORWARD);
    tempResult = tempTrans.transform("xa");
    assertEquals("context should not be filtered ", "xb", tempResult);
    Transliterator hex = Transliterator.getInstance("Any-Hex");
    hex.setFilter(new UnicodeFilter() {

        public boolean contains(int c) {
            return c != 'c';
        }

        public String toPattern(boolean escapeUnprintable) {
            return "";
        }

        public boolean matchesIndexValue(int v) {
            return false;
        }

        public void addMatchSetTo(UnicodeSet toUnionTo) {
        }
    });
    String s = "abcde";
    String out = hex.transliterate(s);
    String exp = "\\u0061\\u0062c\\u0064\\u0065";
    if (out.equals(exp)) {
        logln("Ok:   \"" + exp + "\"");
    } else {
        logln("FAIL: \"" + out + "\", wanted \"" + exp + "\"");
    }
}
Also used : UnicodeFilter(android.icu.text.UnicodeFilter) CaseInsensitiveString(android.icu.util.CaseInsensitiveString) ReplaceableString(android.icu.text.ReplaceableString) UnicodeSet(android.icu.text.UnicodeSet) Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Aggregations

Transliterator (android.icu.text.Transliterator)2 UnicodeFilter (android.icu.text.UnicodeFilter)2 UnicodeSet (android.icu.text.UnicodeSet)2 ReplaceableString (android.icu.text.ReplaceableString)1 CaseInsensitiveString (android.icu.util.CaseInsensitiveString)1 Test (org.junit.Test)1