Search in sources :

Example 26 with StringSearch

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

the class SearchTest method TestContractionCanonical.

@Test
public void TestContractionCanonical() {
    String rules = CONTRACTIONRULE;
    RuleBasedCollator collator = null;
    try {
        collator = new RuleBasedCollator(rules);
        collator.setStrength(TERTIARY);
        collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    } catch (Exception e) {
        errln("Error opening collator ");
    }
    String text = "text";
    String pattern = "pattern";
    StringSearch strsrch = null;
    try {
        strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, null);
        strsrch.setCanonical(true);
    } catch (Exception e) {
        errln("Error opening string search");
    }
    for (int count = 0; count < CONTRACTIONCANONICAL.length; count++) {
        text = CONTRACTIONCANONICAL[count].text;
        pattern = CONTRACTIONCANONICAL[count].pattern;
        strsrch.setTarget(new StringCharacterIterator(text));
        strsrch.setPattern(pattern);
        if (!assertEqualWithStringSearch(strsrch, CONTRACTIONCANONICAL[count])) {
            errln("Error at test number " + count);
        }
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) StringCharacterIterator(java.text.StringCharacterIterator) StringSearch(android.icu.text.StringSearch) Test(org.junit.Test)

Example 27 with StringSearch

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

the class SearchTest method TestTextCanonical.

@Test
public void TestTextCanonical() {
    StringCharacterIterator t = new StringCharacterIterator(TEXTCANONICAL[0].text);
    StringSearch strsrch = new StringSearch(TEXTCANONICAL[0].pattern, t, m_en_us_, null);
    strsrch.setCanonical(true);
    if (!t.equals(strsrch.getTarget())) {
        errln("Error setting text");
    }
    if (!assertEqualWithStringSearch(strsrch, TEXTCANONICAL[0])) {
        strsrch = null;
        return;
    }
    t = new StringCharacterIterator(TEXTCANONICAL[1].text);
    strsrch.setTarget(t);
    if (!t.equals(strsrch.getTarget())) {
        errln("Error setting text");
        strsrch = null;
        return;
    }
    if (!assertEqualWithStringSearch(strsrch, TEXTCANONICAL[1])) {
        strsrch = null;
        return;
    }
    t = new StringCharacterIterator(TEXTCANONICAL[0].text);
    strsrch.setTarget(t);
    if (!t.equals(strsrch.getTarget())) {
        errln("Error setting text");
        strsrch = null;
        return;
    }
    if (!assertEqualWithStringSearch(strsrch, TEXTCANONICAL[0])) {
        errln("Error at assertEqualWithStringSearch");
        strsrch = null;
        return;
    }
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator) StringSearch(android.icu.text.StringSearch) Test(org.junit.Test)

Aggregations

StringSearch (android.icu.text.StringSearch)27 StringCharacterIterator (java.text.StringCharacterIterator)27 Test (org.junit.Test)24 RuleBasedCollator (android.icu.text.RuleBasedCollator)14 BreakIterator (android.icu.text.BreakIterator)7 Collator (android.icu.text.Collator)4 ULocale (android.icu.util.ULocale)2 Locale (java.util.Locale)1