Search in sources :

Example 96 with RuleBasedCollator

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

the class CollationDummyTest method init.

@Before
public void init() throws Exception {
    String ruleset = "& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";
    // String ruleset = "& Four, 4";
    myCollation = new RuleBasedCollator(ruleset);
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Before(org.junit.Before)

Example 97 with RuleBasedCollator

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

the class CollationDummyTest method TestSurrogates.

// TestSurrogates() is ported from cintltst/callcoll.c
/**
 * Tests surrogate support.
 */
@Test
public void TestSurrogates() {
    String rules = "&z<'\ud800\udc00'<'\ud800\udc0a\u0308'<A";
    String[] source = { "z", "\uD800\uDC00", "\ud800\udc0a\u0308", "\ud800\udc02" };
    String[] target = { "\uD800\uDC00", "\ud800\udc0a\u0308", "A", "\ud800\udc03" };
    // this test is to verify the supplementary sort key order in the english
    // collator
    Collator enCollation;
    try {
        enCollation = Collator.getInstance(Locale.ENGLISH);
    } catch (Exception e) {
        errln("ERROR: Failed to create the collator for ENGLISH");
        return;
    }
    myCollation.setStrength(Collator.TERTIARY);
    int count = 0;
    // logln("start of english collation supplementary characters test\n");
    while (count < 2) {
        doTest(enCollation, source[count], target[count], -1);
        count++;
    }
    doTest(enCollation, source[count], target[count], 1);
    // logln("start of tailored collation supplementary characters test\n");
    count = 0;
    Collator newCollation;
    try {
        newCollation = new RuleBasedCollator(rules);
    } catch (Exception e) {
        errln("ERROR: Failed to create the collator for rules");
        return;
    }
    // tests getting collation elements for surrogates for tailored rules
    while (count < 4) {
        doTest(newCollation, source[count], target[count], -1);
        count++;
    }
    // tests that \uD801\uDC01 still has the same value, not changed
    CollationKey enKey = enCollation.getCollationKey(source[3]);
    CollationKey newKey = newCollation.getCollationKey(source[3]);
    int keyResult = enKey.compareTo(newKey);
    if (keyResult != 0) {
        errln("Failed : non-tailored supplementary characters should have the same value\n");
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) CollationKey(android.icu.text.CollationKey) RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) Test(org.junit.Test)

Example 98 with RuleBasedCollator

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

the class CollationFrozenMonkeyTest method TestRules.

@Test
public void TestRules() {
    String[] testSourceCases = { "\u0061\u0062\u007a", "\u0061\u0062\u007a" };
    String[] testTargetCases = { "\u0061\u0062\u00e4", "\u0061\u0062\u0061\u0308" };
    int i = 0;
    logln("Demo Test 1 : Create a new table collation with rules \"& z < 0x00e4\"");
    Collator col = Collator.getInstance(new Locale("en", "US"));
    String baseRules = ((RuleBasedCollator) col).getRules();
    String newRules = " & z < ";
    newRules = baseRules + newRules + String.valueOf(0x00e4);
    RuleBasedCollator myCollation = null;
    try {
        myCollation = new RuleBasedCollator(newRules);
    } catch (Exception e) {
        warnln("Demo Test 1 Table Collation object creation failed.");
        return;
    }
    for (i = 0; i < 2; i++) {
        doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
    }
    logln("Demo Test 2 : Create a new table collation with rules \"& z < a 0x0308\"");
    newRules = "";
    newRules = baseRules + " & z < a" + String.valueOf(0x0308);
    try {
        myCollation = new RuleBasedCollator(newRules);
    } catch (Exception e) {
        errln("Demo Test 1 Table Collation object creation failed.");
        return;
    }
    for (i = 0; i < 2; i++) {
        doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
    }
}
Also used : Locale(java.util.Locale) RuleBasedCollator(android.icu.text.RuleBasedCollator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) Test(org.junit.Test)

Example 99 with RuleBasedCollator

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

the class CollationIteratorTest method TestClearBuffers.

/*
     * @bug 4157299
     */
@Test
public void TestClearBuffers() /* char* par */
{
    RuleBasedCollator c = null;
    try {
        c = new RuleBasedCollator("&a < b < c & ab = d");
    } catch (Exception e) {
        warnln("Couldn't create a RuleBasedCollator.");
        return;
    }
    String source = "abcd";
    CollationElementIterator i = c.getCollationElementIterator(source);
    int e0 = 0;
    try {
        // save the first collation element
        e0 = i.next();
    } catch (Exception e) {
        errln("call to i.next() failed.");
        return;
    }
    try {
        // go to the expanding character
        i.setOffset(3);
    } catch (Exception e) {
        errln("call to i.setOffset(3) failed.");
        return;
    }
    try {
        // but only use up half of it
        i.next();
    } catch (Exception e) {
        errln("call to i.next() failed.");
        return;
    }
    try {
        // go back to the beginning
        i.setOffset(0);
    } catch (Exception e) {
        errln("call to i.setOffset(0) failed. ");
    }
    int e = 0;
    try {
        // and get this one again
        e = i.next();
    } catch (Exception ee) {
        errln("call to i.next() failed. ");
        return;
    }
    if (e != e0) {
        errln("got 0x" + Integer.toHexString(e) + ", expected 0x" + Integer.toHexString(e0));
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) CollationElementIterator(android.icu.text.CollationElementIterator) Test(org.junit.Test)

Example 100 with RuleBasedCollator

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

the class CollationIteratorTest method TestSetText.

/**
 * Test for setText()
 */
@Test
public void TestSetText() /* char* par */
{
    RuleBasedCollator en_us = (RuleBasedCollator) Collator.getInstance(Locale.US);
    CollationElementIterator iter1 = en_us.getCollationElementIterator(test1);
    CollationElementIterator iter2 = en_us.getCollationElementIterator(test2);
    // Run through the second iterator just to exercise it
    int c = iter2.next();
    int i = 0;
    while (++i < 10 && c != CollationElementIterator.NULLORDER) {
        try {
            c = iter2.next();
        } catch (Exception e) {
            errln("iter2.next() returned an error.");
            break;
        }
    }
    // Now set it to point to the same string as the first iterator
    try {
        iter2.setText(test1);
    } catch (Exception e) {
        errln("call to iter2->setText(test1) failed.");
        return;
    }
    assertEqual(iter1, iter2);
    iter1.reset();
    // now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text
    CharacterIterator chariter = new StringCharacterIterator(test1);
    try {
        iter2.setText(chariter);
    } catch (Exception e) {
        errln("call to iter2->setText(chariter(test1)) failed.");
        return;
    }
    assertEqual(iter1, iter2);
    iter1.reset();
    // now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text
    UCharacterIterator uchariter = UCharacterIterator.getInstance(test1);
    try {
        iter2.setText(uchariter);
    } catch (Exception e) {
        errln("call to iter2->setText(uchariter(test1)) failed.");
        return;
    }
    assertEqual(iter1, iter2);
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) StringCharacterIterator(java.text.StringCharacterIterator) UCharacterIterator(android.icu.text.UCharacterIterator) StringCharacterIterator(java.text.StringCharacterIterator) CharacterIterator(java.text.CharacterIterator) UCharacterIterator(android.icu.text.UCharacterIterator) CollationElementIterator(android.icu.text.CollationElementIterator) Test(org.junit.Test)

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