Search in sources :

Example 21 with CollationKey

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

the class CollationDummyTest method TestJB581.

@Test
public void TestJB581() {
    String source = "THISISATEST.";
    String target = "Thisisatest.";
    Collator coll = null;
    try {
        coll = Collator.getInstance(Locale.ENGLISH);
    } catch (Exception e) {
        errln("ERROR: Failed to create the collator for : en_US\n");
        return;
    }
    int result = coll.compare(source, target);
    // result is 1, secondary differences only for ignorable space characters
    if (result != 1) {
        errln("Comparing two strings with only secondary differences in C failed.\n");
        return;
    }
    // To compare them with just primary differences
    coll.setStrength(Collator.PRIMARY);
    result = coll.compare(source, target);
    // result is 0
    if (result != 0) {
        errln("Comparing two strings with no differences in C failed.\n");
        return;
    }
    // Now, do the same comparison with keys
    CollationKey sourceKeyOut, targetKeyOut;
    sourceKeyOut = coll.getCollationKey(source);
    targetKeyOut = coll.getCollationKey(target);
    result = sourceKeyOut.compareTo(targetKeyOut);
    if (result != 0) {
        errln("Comparing two strings with sort keys in C failed.\n");
        return;
    }
}
Also used : CollationKey(android.icu.text.CollationKey) RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) Test(org.junit.Test)

Example 22 with CollationKey

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

the class CollationSpanishTest method doTest.

// amin test routine, tests rules specific to the spanish locale
private void doTest(char[] source, char[] target, int result) {
    String s = new String(source);
    String t = new String(target);
    int compareResult = myCollation.compare(s, t);
    CollationKey sortKey1, sortKey2;
    sortKey1 = myCollation.getCollationKey(s);
    sortKey2 = myCollation.getCollationKey(t);
    int keyResult = sortKey1.compareTo(sortKey2);
    reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
}
Also used : CollationKey(android.icu.text.CollationKey)

Example 23 with CollationKey

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

the class CollationCurrencyTest method TestCurrency.

@Test
public void TestCurrency() {
    // All the currency symbols, in collation order
    char[][] currency = { { 0x00A4 }, /*00A4; L; [14 36, 03, 03]    # [082B.0020.0002] # CURRENCY SIGN*/
    { 0x00A2 }, /*00A2; L; [14 38, 03, 03]    # [082C.0020.0002] # CENT SIGN*/
    { 0xFFE0 }, /*FFE0; L; [14 38, 03, 05]    # [082C.0020.0003] # FULLWIDTH CENT SIGN*/
    { 0x0024 }, /*0024; L; [14 3A, 03, 03]    # [082D.0020.0002] # DOLLAR SIGN*/
    { 0xFF04 }, /*FF04; L; [14 3A, 03, 05]    # [082D.0020.0003] # FULLWIDTH DOLLAR SIGN*/
    { 0xFE69 }, /*FE69; L; [14 3A, 03, 1D]    # [082D.0020.000F] # SMALL DOLLAR SIGN*/
    { 0x00A3 }, /*00A3; L; [14 3C, 03, 03]    # [082E.0020.0002] # POUND SIGN*/
    { 0xFFE1 }, /*FFE1; L; [14 3C, 03, 05]    # [082E.0020.0003] # FULLWIDTH POUND SIGN*/
    { 0x00A5 }, /*00A5; L; [14 3E, 03, 03]    # [082F.0020.0002] # YEN SIGN*/
    { 0xFFE5 }, /*FFE5; L; [14 3E, 03, 05]    # [082F.0020.0003] # FULLWIDTH YEN SIGN*/
    { 0x09F2 }, /*09F2; L; [14 40, 03, 03]    # [0830.0020.0002] # BENGALI RUPEE MARK*/
    { 0x09F3 }, /*09F3; L; [14 42, 03, 03]    # [0831.0020.0002] # BENGALI RUPEE SIGN*/
    { 0x0E3F }, /*0E3F; L; [14 44, 03, 03]    # [0832.0020.0002] # THAI CURRENCY SYMBOL BAHT*/
    { 0x17DB }, /*17DB; L; [14 46, 03, 03]    # [0833.0020.0002] # KHMER CURRENCY SYMBOL RIEL*/
    { 0x20A0 }, /*20A0; L; [14 48, 03, 03]    # [0834.0020.0002] # EURO-CURRENCY SIGN*/
    { 0x20A1 }, /*20A1; L; [14 4A, 03, 03]    # [0835.0020.0002] # COLON SIGN*/
    { 0x20A2 }, /*20A2; L; [14 4C, 03, 03]    # [0836.0020.0002] # CRUZEIRO SIGN*/
    { 0x20A3 }, /*20A3; L; [14 4E, 03, 03]    # [0837.0020.0002] # FRENCH FRANC SIGN*/
    { 0x20A4 }, /*20A4; L; [14 50, 03, 03]    # [0838.0020.0002] # LIRA SIGN*/
    { 0x20A5 }, /*20A5; L; [14 52, 03, 03]    # [0839.0020.0002] # MILL SIGN*/
    { 0x20A6 }, /*20A6; L; [14 54, 03, 03]    # [083A.0020.0002] # NAIRA SIGN*/
    { 0x20A7 }, /*20A7; L; [14 56, 03, 03]    # [083B.0020.0002] # PESETA SIGN*/
    { 0x20A9 }, /*20A9; L; [14 58, 03, 03]    # [083C.0020.0002] # WON SIGN*/
    { 0xFFE6 }, /*FFE6; L; [14 58, 03, 05]    # [083C.0020.0003] # FULLWIDTH WON SIGN*/
    { 0x20AA }, /*20AA; L; [14 5A, 03, 03]    # [083D.0020.0002] # NEW SHEQEL SIGN*/
    { 0x20AB }, /*20AB; L; [14 5C, 03, 03]    # [083E.0020.0002] # DONG SIGN*/
    { 0x20AC }, /*20AC; L; [14 5E, 03, 03]    # [083F.0020.0002] # EURO SIGN*/
    { 0x20AD }, /*20AD; L; [14 60, 03, 03]    # [0840.0020.0002] # KIP SIGN*/
    { 0x20AE }, /*20AE; L; [14 62, 03, 03]    # [0841.0020.0002] # TUGRIK SIGN*/
    { 0x20AF } /*20AF; L; [14 64, 03, 03]    # [0842.0020.0002] # DRACHMA SIGN*/
    };
    int i, j;
    int expectedResult = 0;
    RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.ENGLISH);
    // Compare each currency symbol against all the
    // currency symbols, including itself
    String source;
    String target;
    for (i = 0; i < currency.length; i += 1) {
        for (j = 0; j < currency.length; j += 1) {
            source = new String(currency[i]);
            target = new String(currency[j]);
            if (i < j) {
                expectedResult = -1;
            } else if (i == j) {
                expectedResult = 0;
            } else {
                expectedResult = 1;
            }
            int compareResult = c.compare(source, target);
            CollationKey sourceKey = null;
            sourceKey = c.getCollationKey(source);
            if (sourceKey == null) {
                errln("Couldn't get collationKey for source");
                continue;
            }
            CollationKey targetKey = null;
            targetKey = c.getCollationKey(target);
            if (targetKey == null) {
                errln("Couldn't get collationKey for source");
                continue;
            }
            int keyResult = sourceKey.compareTo(targetKey);
            reportCResult(source, target, sourceKey, targetKey, compareResult, keyResult, compareResult, expectedResult);
        }
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) CollationKey(android.icu.text.CollationKey) Test(org.junit.Test)

Example 24 with CollationKey

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

the class CollationEnglishTest method doTest.

// main test routine, tests rules defined by the "en" locale
private void doTest(char[] source, char[] target, int result) {
    String s = new String(source);
    String t = new String(target);
    int compareResult = myCollation.compare(s, t);
    CollationKey sortKey1, sortKey2;
    sortKey1 = myCollation.getCollationKey(s);
    sortKey2 = myCollation.getCollationKey(t);
    int keyResult = sortKey1.compareTo(sortKey2);
    reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
}
Also used : CollationKey(android.icu.text.CollationKey)

Example 25 with CollationKey

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

the class CollationFrenchTest method TestContinuationReordering.

@Test
public void TestContinuationReordering() {
    String rule = "&0x2f00 << 0x2f01";
    try {
        RuleBasedCollator collator = new RuleBasedCollator(rule);
        collator.setFrenchCollation(true);
        CollationKey key1 = collator.getCollationKey("a\u0325\u2f00\u2f01b\u0325");
        CollationKey key2 = collator.getCollationKey("a\u0325\u2f01\u2f01b\u0325");
        if (key1.compareTo(key2) >= 0) {
            errln("Error comparing continuation strings");
        }
    } catch (Exception e) {
        errln(e.toString());
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) CollationKey(android.icu.text.CollationKey) Test(org.junit.Test)

Aggregations

CollationKey (android.icu.text.CollationKey)47 RuleBasedCollator (android.icu.text.RuleBasedCollator)28 Test (org.junit.Test)27 RawCollationKey (android.icu.text.RawCollationKey)19 Collator (android.icu.text.Collator)15 Locale (java.util.Locale)8 ULocale (android.icu.util.ULocale)7 UnicodeSet (android.icu.text.UnicodeSet)3 ParseException (java.text.ParseException)3 Random (java.util.Random)3 CollationElementIterator (android.icu.text.CollationElementIterator)2 UnicodeSetIterator (android.icu.text.UnicodeSetIterator)2 MissingResourceException (java.util.MissingResourceException)2 Output (android.icu.util.Output)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1