Search in sources :

Example 61 with RuleBasedCollator

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

the class CollationRegressionTest method Test4066189.

// @bug 4066189
// 
// Unicode characters need to be recursively decomposed to get the
// correct result. For example,
// u1EB1 -> \u0103 + \u0300 -> a + \u0306 + \u0300.
// 
@Test
public void Test4066189() /* char* par */
{
    final String test1 = "\u1EB1";
    final String test2 = "\u0061\u0306\u0300";
    // NOTE: The java code used en_us to create the
    // CollationElementIterator's. I'm pretty sure that
    // was wrong, so I've change the code to use c1 and c2
    RuleBasedCollator c1 = (RuleBasedCollator) Collator.getInstance(Locale.US);
    c1.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    CollationElementIterator i1 = c1.getCollationElementIterator(test1);
    RuleBasedCollator c2 = (RuleBasedCollator) Collator.getInstance(Locale.US);
    c2.setDecomposition(Collator.NO_DECOMPOSITION);
    CollationElementIterator i2 = c2.getCollationElementIterator(test2);
    assertEqual(i1, i2);
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) CollationElementIterator(android.icu.text.CollationElementIterator) Test(org.junit.Test)

Example 62 with RuleBasedCollator

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

the class CollationRegressionTest method Test4060154.

// @bug 4060154
// 
// MergeCollation::fixEntry broken for "& H < \u0131, \u0130, i, I"
// 
@Test
public void Test4060154() /* char* par */
{
    String rules = "&f < g, G < h, H < i, I < j, J & H < \u0131, \u0130, i, I";
    RuleBasedCollator c = null;
    try {
        c = new RuleBasedCollator(rules);
    } catch (Exception e) {
        // System.out.println(e);
        errln("failure building collator:" + e);
        return;
    }
    c.setDecomposition(Collator.NO_DECOMPOSITION);
    String[] tertiary = { "A", "<", "B", "H", "<", "\u0131", "H", "<", "I", "\u0131", "<", "\u0130", "\u0130", "<", "i", "\u0130", ">", "H" };
    c.setStrength(Collator.TERTIARY);
    compareArray(c, tertiary);
    String[] secondary = { "H", "<", "I", "\u0131", "=", "\u0130" };
    c.setStrength(Collator.PRIMARY);
    compareArray(c, secondary);
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 63 with RuleBasedCollator

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

the class CollationRegressionTest method Test4054734.

// @bug 4054734
// 
// Collator::IDENTICAL documented but not implemented
// 
@Test
public void Test4054734() /* char* par */
{
    // Here's the original Java:
    String[] decomp = { "\u0001", "<", "\u0002", "\u0001", "=", "\u0001", // Ensure A and ~ are not compared bitwise
    "A\u0001", // Ensure A and ~ are not compared bitwise
    ">", // Ensure A and ~ are not compared bitwise
    "~\u0002", // Decomp should make these equal
    "\u00C0", // Decomp should make these equal
    "=", // Decomp should make these equal
    "A\u0300" };
    RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.US);
    c.setStrength(Collator.IDENTICAL);
    c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    compareArray(c, decomp);
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 64 with RuleBasedCollator

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

the class CollationRegressionTest method Test4087241.

// @bug 4087241
// 
// string comparison errors in Scandinavian collators
// 
@Test
public void Test4087241() /* char* par */
{
    Locale da_DK = new Locale("da", "DK");
    RuleBasedCollator c = null;
    try {
        c = (RuleBasedCollator) Collator.getInstance(da_DK);
    } catch (Exception e) {
        errln("Failed to create collator for da_DK locale");
        return;
    }
    c.setStrength(Collator.SECONDARY);
    String[] tests = { // z        < ae
    "\u007a", // z        < ae
    "\u003c", // z        < ae
    "\u00E6", // a-umlaut < a-ring
    "\u0061\u0308", // a-umlaut < a-ring
    "\u003c", // a-umlaut < a-ring
    "\u0061\u030A", // Y        < u-umlaut
    "\u0059", // Y        < u-umlaut
    "\u003c", // Y        < u-umlaut
    "\u0075\u0308" };
    compareArray(c, tests);
}
Also used : Locale(java.util.Locale) RuleBasedCollator(android.icu.text.RuleBasedCollator) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 65 with RuleBasedCollator

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

the class CollationRegressionTest method Test4054238.

// @bug 4054238
// 
// CollationElementIterator will not work correctly if the associated
// Collator object's mode is changed
// 
@Test
public void Test4054238() /* char* par */
{
    final char[] chars3 = { 0x61, 0x00FC, 0x62, 0x65, 0x63, 0x6b, 0x20, 0x47, 0x72, 0x00F6, 0x00DF, 0x65, 0x20, 0x4c, 0x00FC, 0x62, 0x63, 0x6b, 0 };
    final String test3 = new String(chars3);
    RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.US);
    // NOTE: The Java code uses en_us to create the CollationElementIterators
    // but I'm pretty sure that's wrong, so I've changed this to use c.
    c.setDecomposition(Collator.NO_DECOMPOSITION);
    CollationElementIterator i1 = c.getCollationElementIterator(test3);
    logln("Offset:" + i1.getOffset());
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) 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