Search in sources :

Example 11 with RuleBasedCollator

use of android.icu.text.RuleBasedCollator 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 12 with RuleBasedCollator

use of android.icu.text.RuleBasedCollator 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 13 with RuleBasedCollator

use of android.icu.text.RuleBasedCollator 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 14 with RuleBasedCollator

use of android.icu.text.RuleBasedCollator 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)

Example 15 with RuleBasedCollator

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

the class SearchTest method assertCanonicalEqual.

boolean assertCanonicalEqual(SearchData search) {
    Collator collator = getCollator(search.collator);
    BreakIterator breaker = getBreakIterator(search.breaker);
    StringSearch strsrch;
    String text = search.text;
    String pattern = search.pattern;
    if (breaker != null) {
        breaker.setText(text);
    }
    collator.setStrength(search.strength);
    collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    try {
        strsrch = new StringSearch(pattern, new StringCharacterIterator(text), (RuleBasedCollator) collator, breaker);
        strsrch.setElementComparisonType(search.cmpType);
        strsrch.setCanonical(true);
    } catch (Exception e) {
        errln("Error opening string search" + e.getMessage());
        return false;
    }
    if (!assertEqualWithStringSearch(strsrch, search)) {
        collator.setStrength(TERTIARY);
        collator.setDecomposition(Collator.NO_DECOMPOSITION);
        return false;
    }
    collator.setStrength(TERTIARY);
    collator.setDecomposition(Collator.NO_DECOMPOSITION);
    return true;
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator) RuleBasedCollator(android.icu.text.RuleBasedCollator) StringSearch(android.icu.text.StringSearch) Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) BreakIterator(android.icu.text.BreakIterator)

Aggregations

RuleBasedCollator (android.icu.text.RuleBasedCollator)140 Test (org.junit.Test)124 Collator (android.icu.text.Collator)42 ULocale (android.icu.util.ULocale)26 CollationElementIterator (android.icu.text.CollationElementIterator)25 Locale (java.util.Locale)22 CollationKey (android.icu.text.CollationKey)17 StringCharacterIterator (java.text.StringCharacterIterator)16 StringSearch (android.icu.text.StringSearch)14 RawCollationKey (android.icu.text.RawCollationKey)11 ParseException (java.text.ParseException)10 UnicodeSet (android.icu.text.UnicodeSet)8 AlphabeticIndex (android.icu.text.AlphabeticIndex)6 BreakIterator (android.icu.text.BreakIterator)6 MissingResourceException (java.util.MissingResourceException)5 IOException (java.io.IOException)4 UnicodeSetIterator (android.icu.text.UnicodeSetIterator)3 UCharacterIterator (android.icu.text.UCharacterIterator)2 CharacterIterator (java.text.CharacterIterator)2 ArrayList (java.util.ArrayList)2