Search in sources :

Example 31 with Collator

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

the class CollationRegressionTest method Test4139572.

// @bug 4139572
// 
// getCollationKey throws exception for spanish text
// Cannot reproduce this bug on 1.2, however it DOES fail on 1.1.6
// 
@Test
public void Test4139572() /* char* par */
{
    // 
    // Code pasted straight from the bug report
    // (and then translated to C++ ;-)
    // 
    // create spanish locale and collator
    Locale l = new Locale("es", "es");
    Collator col = null;
    try {
        col = Collator.getInstance(l);
    } catch (Exception e) {
        errln("Failed to create a collator for es_es locale.");
        return;
    }
    CollationKey key = null;
    // this spanish phrase kills it!
    try {
        key = col.getCollationKey("Nombre De Objeto");
        logln("source:" + key.getSourceString());
    } catch (Exception e) {
        errln("Error creating CollationKey for \"Nombre De Ojbeto\"");
    }
}
Also used : Locale(java.util.Locale) CollationKey(android.icu.text.CollationKey) ParseException(java.text.ParseException) RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) Test(org.junit.Test)

Example 32 with Collator

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

the class CollationRegressionTest method Test4132736.

// @bug 4132736
// 
// sort order of french words with multiple accents has errors
// 
@Test
public void Test4132736() /* char* par */
{
    Collator c = null;
    try {
        c = Collator.getInstance(Locale.CANADA_FRENCH);
        c.setStrength(Collator.TERTIARY);
    } catch (Exception e) {
        errln("Failed to create a collator for Locale.CANADA_FRENCH");
    }
    String[] test1 = { "\u0065\u0300\u0065\u0301", "\u003c", "\u0065\u0301\u0065\u0300", "\u0065\u0300\u0301", "\u003c", "\u0065\u0301\u0300" };
    compareArray(c, test1);
}
Also used : ParseException(java.text.ParseException) RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) Test(org.junit.Test)

Example 33 with Collator

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

the class CollationRegressionTest method Test4171974.

@Test
public void Test4171974() {
    // test French accent ordering more thoroughly
    /*String[] frenchList = {
            "\u0075\u0075",     // u u
            "\u00fc\u0075",     // u-umlaut u
            "\u01d6\u0075",     // u-umlaut-macron u
            "\u016b\u0075",     // u-macron u
            "\u1e7b\u0075",     // u-macron-umlaut u
            "\u0075\u00fc",     // u u-umlaut
            "\u00fc\u00fc",     // u-umlaut u-umlaut
            "\u01d6\u00fc",     // u-umlaut-macron u-umlaut
            "\u016b\u00fc",     // u-macron u-umlaut
            "\u1e7b\u00fc",     // u-macron-umlaut u-umlaut
            "\u0075\u01d6",     // u u-umlaut-macron
            "\u00fc\u01d6",     // u-umlaut u-umlaut-macron
            "\u01d6\u01d6",     // u-umlaut-macron u-umlaut-macron
            "\u016b\u01d6",     // u-macron u-umlaut-macron
            "\u1e7b\u01d6",     // u-macron-umlaut u-umlaut-macron
            "\u0075\u016b",     // u u-macron
            "\u00fc\u016b",     // u-umlaut u-macron
            "\u01d6\u016b",     // u-umlaut-macron u-macron
            "\u016b\u016b",     // u-macron u-macron
            "\u1e7b\u016b",     // u-macron-umlaut u-macron
            "\u0075\u1e7b",     // u u-macron-umlaut
            "\u00fc\u1e7b",     // u-umlaut u-macron-umlaut
            "\u01d6\u1e7b",     // u-umlaut-macron u-macron-umlaut
            "\u016b\u1e7b",     // u-macron u-macron-umlaut
            "\u1e7b\u1e7b"      // u-macron-umlaut u-macron-umlaut
        };
        Collator french = Collator.getInstance(Locale.FRENCH);

        logln("Testing French order...");
        checkListOrder(frenchList, french);

        logln("Testing French order without decomposition...");
        french.setDecomposition(Collator.NO_DECOMPOSITION);
        checkListOrder(frenchList, french);*/
    String[] englishList = { // u u
    "\u0075\u0075", // u u-umlaut
    "\u0075\u00fc", // u u-umlaut-macron
    "\u0075\u01d6", // u u-macron
    "\u0075\u016b", // u u-macron-umlaut
    "\u0075\u1e7b", // u-umlaut u
    "\u00fc\u0075", // u-umlaut u-umlaut
    "\u00fc\u00fc", // u-umlaut u-umlaut-macron
    "\u00fc\u01d6", // u-umlaut u-macron
    "\u00fc\u016b", // u-umlaut u-macron-umlaut
    "\u00fc\u1e7b", // u-umlaut-macron u
    "\u01d6\u0075", // u-umlaut-macron u-umlaut
    "\u01d6\u00fc", // u-umlaut-macron u-umlaut-macron
    "\u01d6\u01d6", // u-umlaut-macron u-macron
    "\u01d6\u016b", // u-umlaut-macron u-macron-umlaut
    "\u01d6\u1e7b", // u-macron u
    "\u016b\u0075", // u-macron u-umlaut
    "\u016b\u00fc", // u-macron u-umlaut-macron
    "\u016b\u01d6", // u-macron u-macron
    "\u016b\u016b", // u-macron u-macron-umlaut
    "\u016b\u1e7b", // u-macron-umlaut u
    "\u1e7b\u0075", // u-macron-umlaut u-umlaut
    "\u1e7b\u00fc", // u-macron-umlaut u-umlaut-macron
    "\u1e7b\u01d6", // u-macron-umlaut u-macron
    "\u1e7b\u016b", // u-macron-umlaut u-macron-umlaut
    "\u1e7b\u1e7b" };
    Collator english = Collator.getInstance(Locale.ENGLISH);
    logln("Testing English order...");
    checkListOrder(englishList, english);
    logln("Testing English order without decomposition...");
    english.setDecomposition(Collator.NO_DECOMPOSITION);
    checkListOrder(englishList, english);
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) Test(org.junit.Test)

Example 34 with Collator

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

the class CollationRegressionTest method Test8484.

// Fixing the infinite loop for surrogates
@Test
public void Test8484() {
    String s = "\u9FE1\uCEF3\u2798\uAAB6\uDA7C";
    Collator coll = Collator.getInstance();
    CollationKey collKey = coll.getCollationKey(s);
    logln("Pass: " + collKey.toString() + " generated OK.");
}
Also used : CollationKey(android.icu.text.CollationKey) RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) Test(org.junit.Test)

Example 35 with Collator

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

the class CollationRegressionTest method TestBengaliSortKey.

@Test
public void TestBengaliSortKey() throws Exception {
    char[] rules = { 0x26, 0x9fa, 0x3c, 0x98c, 0x3c, 0x9e1, 0x3c, 0x98f, 0x3c, 0x990, 0x3c, 0x993, 0x3c, 0x994, 0x3c, 0x9bc, 0x3c, 0x982, 0x3c, 0x983, 0x3c, 0x981, 0x3c, 0x9b0, 0x3c, 0x9b8, 0x3c, 0x9b9, 0x3c, 0x9bd, 0x3c, 0x9be, 0x3c, 0x9bf, 0x3c, 0x9c8, 0x3c, 0x9cb, 0x3d, 0x9cb };
    Collator col = new RuleBasedCollator(String.copyValueOf(rules));
    String str1 = "\u09be";
    String str2 = "\u0b70";
    int result = col.compare(str1, str2);
    System.out.flush();
    if (result >= 0) {
        errln("\nERROR: result is " + result + " , wanted negative.");
        errln(printKey(col, str1).toString());
        errln(printKey(col, str2).toString());
    } else {
        logln("Pass: result is OK.");
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) Test(org.junit.Test)

Aggregations

Collator (android.icu.text.Collator)81 Test (org.junit.Test)72 RuleBasedCollator (android.icu.text.RuleBasedCollator)70 Locale (java.util.Locale)25 ULocale (android.icu.util.ULocale)22 CollationKey (android.icu.text.CollationKey)15 MissingResourceException (java.util.MissingResourceException)11 RawCollationKey (android.icu.text.RawCollationKey)7 ParseException (java.text.ParseException)6 Random (java.util.Random)6 BreakIterator (android.icu.text.BreakIterator)5 StringCharacterIterator (java.text.StringCharacterIterator)5 LocaleDisplayNames (android.icu.text.LocaleDisplayNames)4 StringSearch (android.icu.text.StringSearch)4 CollationElementIterator (android.icu.text.CollationElementIterator)3 ArrayList (java.util.ArrayList)3 UnicodeSet (android.icu.text.UnicodeSet)2 GlobalizationPreferences (android.icu.util.GlobalizationPreferences)2 HashSet (java.util.HashSet)2 TreeSet (java.util.TreeSet)2