Search in sources :

Example 6 with StringSearch

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

the class SearchTest method TestIgnorable.

@Test
public void TestIgnorable() {
    String rules = IGNORABLERULE;
    int count = 0;
    RuleBasedCollator collator = null;
    try {
        collator = new RuleBasedCollator(rules);
        collator.setStrength(IGNORABLE[count].strength);
        collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    } catch (Exception e) {
        errln("Error opening collator ");
        return;
    }
    String pattern = "pattern";
    String text = "text";
    StringSearch strsrch = null;
    try {
        strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, null);
    } catch (Exception e) {
        errln("Error opening string search ");
        return;
    }
    for (; count < IGNORABLE.length; count++) {
        text = IGNORABLE[count].text;
        pattern = IGNORABLE[count].pattern;
        strsrch.setTarget(new StringCharacterIterator(text));
        strsrch.setPattern(pattern);
        if (!assertEqualWithStringSearch(strsrch, IGNORABLE[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 7 with StringSearch

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

the class SearchTest method TestOverlap.

@Test
public void TestOverlap() {
    int count;
    for (count = 0; count < OVERLAP.length; count++) {
        if (!assertEqualWithAttribute(OVERLAP[count], false, true)) {
            errln("Error at overlap test number " + count);
        }
    }
    for (count = 0; count < NONOVERLAP.length; count++) {
        if (!assertEqual(NONOVERLAP[count])) {
            errln("Error at non overlap test number " + count);
        }
    }
    for (count = 0; count < OVERLAP.length && count < NONOVERLAP.length; count++) {
        SearchData search = (OVERLAP[count]);
        String text = search.text;
        String pattern = search.pattern;
        RuleBasedCollator collator = getCollator(search.collator);
        StringSearch strsrch = null;
        try {
            strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, null);
        } catch (Exception e) {
            errln("error open StringSearch");
            return;
        }
        strsrch.setOverlapping(true);
        if (!strsrch.isOverlapping()) {
            errln("Error setting overlap option");
        }
        if (!assertEqualWithStringSearch(strsrch, search)) {
            return;
        }
        search = NONOVERLAP[count];
        strsrch.setOverlapping(false);
        if (strsrch.isOverlapping()) {
            errln("Error setting overlap option");
        }
        strsrch.reset();
        if (!assertEqualWithStringSearch(strsrch, search)) {
            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 8 with StringSearch

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

the class SearchTest method TestBreakIteratorCanonical.

@Test
public void TestBreakIteratorCanonical() {
    int count = 0;
    while (count < 4) {
        // special purposes for tests numbers 0-3
        SearchData search = BREAKITERATORCANONICAL[count];
        String text = search.text;
        String pattern = search.pattern;
        RuleBasedCollator collator = getCollator(search.collator);
        collator.setStrength(search.strength);
        BreakIterator breaker = getBreakIterator(search.breaker);
        StringSearch strsrch = null;
        try {
            strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, breaker);
        } catch (Exception e) {
            errln("Error creating string search data");
            return;
        }
        strsrch.setCanonical(true);
        if (!strsrch.getBreakIterator().equals(breaker)) {
            errln("Error setting break iterator");
            return;
        }
        if (!assertEqualWithStringSearch(strsrch, search)) {
            collator.setStrength(TERTIARY);
            return;
        }
        search = BREAKITERATOREXACT[count + 1];
        breaker = getBreakIterator(search.breaker);
        breaker.setText(strsrch.getTarget());
        strsrch.setBreakIterator(breaker);
        if (!strsrch.getBreakIterator().equals(breaker)) {
            errln("Error setting break iterator");
            return;
        }
        strsrch.reset();
        strsrch.setCanonical(true);
        if (!assertEqualWithStringSearch(strsrch, search)) {
            errln("Error at test number " + count);
            return;
        }
        count += 2;
    }
    for (count = 0; count < BREAKITERATORCANONICAL.length; count++) {
        if (!assertEqual(BREAKITERATORCANONICAL[count])) {
            errln("Error at test number " + count);
            return;
        }
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) StringCharacterIterator(java.text.StringCharacterIterator) StringSearch(android.icu.text.StringSearch) BreakIterator(android.icu.text.BreakIterator) Test(org.junit.Test)

Example 9 with StringSearch

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

the class SearchTest method TestText.

@Test
public void TestText() {
    SearchData[] TEXT = { SD("the foxy brown fox", "fox", null, TERTIARY, STANDARD_ELEMENT_COMPARISON, null, IA(4, 15, -1), IA(3, 3)), SD("the quick brown fox", "fox", null, TERTIARY, STANDARD_ELEMENT_COMPARISON, null, IA(16, -1), IA(3)) };
    StringCharacterIterator t = new StringCharacterIterator(TEXT[0].text);
    StringSearch strsrch = new StringSearch(TEXT[0].pattern, t, m_en_us_, null);
    if (!t.equals(strsrch.getTarget())) {
        errln("Error setting text");
    }
    if (!assertEqualWithStringSearch(strsrch, TEXT[0])) {
        errln("Error at assertEqualWithStringSearch");
        return;
    }
    t = new StringCharacterIterator(TEXT[1].text);
    strsrch.setTarget(t);
    if (!t.equals(strsrch.getTarget())) {
        errln("Error setting text");
        return;
    }
    if (!assertEqualWithStringSearch(strsrch, TEXT[1])) {
        errln("Error at assertEqualWithStringSearch");
        return;
    }
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator) StringSearch(android.icu.text.StringSearch) Test(org.junit.Test)

Example 10 with StringSearch

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

the class SearchTest method TestConstructor.

@Test
public void TestConstructor() {
    String pattern = "pattern";
    String text = "text";
    StringCharacterIterator textiter = new StringCharacterIterator(text);
    Collator defaultcollator = Collator.getInstance();
    BreakIterator breaker = BreakIterator.getCharacterInstance();
    breaker.setText(text);
    StringSearch search = new StringSearch(pattern, text);
    if (!search.getPattern().equals(pattern) || !search.getTarget().equals(textiter) || !search.getCollator().equals(defaultcollator)) /*|| !search.getBreakIterator().equals(breaker)*/
    {
        errln("StringSearch(String, String) error");
    }
    search = new StringSearch(pattern, textiter, m_fr_fr_);
    if (!search.getPattern().equals(pattern) || !search.getTarget().equals(textiter) || !search.getCollator().equals(m_fr_fr_)) /*|| !search.getBreakIterator().equals(breaker)*/
    {
        errln("StringSearch(String, StringCharacterIterator, " + "RuleBasedCollator) error");
    }
    Locale de = new Locale("de", "DE");
    breaker = BreakIterator.getCharacterInstance(de);
    breaker.setText(text);
    search = new StringSearch(pattern, textiter, de);
    if (!search.getPattern().equals(pattern) || !search.getTarget().equals(textiter) || !search.getCollator().equals(Collator.getInstance(de))) /*|| !search.getBreakIterator().equals(breaker)*/
    {
        errln("StringSearch(String, StringCharacterIterator, Locale) " + "error");
    }
    search = new StringSearch(pattern, textiter, m_fr_fr_, m_en_wordbreaker_);
    if (!search.getPattern().equals(pattern) || !search.getTarget().equals(textiter) || !search.getCollator().equals(m_fr_fr_) || !search.getBreakIterator().equals(m_en_wordbreaker_)) {
        errln("StringSearch(String, StringCharacterIterator, Locale) " + "error");
    }
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) StringCharacterIterator(java.text.StringCharacterIterator) StringSearch(android.icu.text.StringSearch) Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) BreakIterator(android.icu.text.BreakIterator) 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