Search in sources :

Example 41 with CollationKey

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

the class LotusCollationKoreanTest method doTest.

// main test routine, tests rules specific to "Korean" 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 42 with CollationKey

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

the class CollationRegressionTest method printKey.

private static StringBuilder printKey(Collator col, String str1) {
    StringBuilder sb = new StringBuilder();
    CollationKey sortk1 = col.getCollationKey(str1);
    byte[] bytes = sortk1.toByteArray();
    for (int i = 0; i < str1.length(); i++) {
        sb.append("\\u" + Integer.toHexString(str1.charAt(i)));
    }
    System.out.print(": ");
    for (int i = 0; i < bytes.length; i++) {
        sb.append(" 0x" + Integer.toHexString(((int) bytes[i]) & 0xff));
    }
    sb.append("\n");
    return sb;
}
Also used : CollationKey(android.icu.text.CollationKey)

Example 43 with CollationKey

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

the class CollationRegressionTest method Test4124632.

// @bug 4124632
// 
// Collator::getCollationKey was hanging on certain character sequences
// 
@Test
public void Test4124632() /* char* par */
{
    Collator coll = null;
    try {
        coll = Collator.getInstance(Locale.JAPAN);
    } catch (Exception e) {
        errln("Failed to create collator for Locale::JAPAN");
        return;
    }
    String test = "\u0041\u0308\u0062\u0063";
    CollationKey key;
    try {
        key = coll.getCollationKey(test);
        logln(key.getSourceString());
    } catch (Exception e) {
        errln("CollationKey creation failed.");
    }
}
Also used : CollationKey(android.icu.text.CollationKey) ParseException(java.text.ParseException) RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) Test(org.junit.Test)

Example 44 with CollationKey

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

the class CollationRegressionTest method caseFirstCompressionSub.

/*
     * Compare two strings - "aaa...A" and "aaa...a" with
     * Collation#compare and CollationKey#compareTo, called from
     * TestCaseFirstCompression.
     */
private void caseFirstCompressionSub(RuleBasedCollator col, String opt) {
    final int maxLength = 50;
    StringBuilder buf1 = new StringBuilder();
    StringBuilder buf2 = new StringBuilder();
    String str1, str2;
    for (int n = 1; n <= maxLength; n++) {
        buf1.setLength(0);
        buf2.setLength(0);
        for (int i = 0; i < n - 1; i++) {
            buf1.append('a');
            buf2.append('a');
        }
        buf1.append('A');
        buf2.append('a');
        str1 = buf1.toString();
        str2 = buf2.toString();
        CollationKey key1 = col.getCollationKey(str1);
        CollationKey key2 = col.getCollationKey(str2);
        int cmpKey = key1.compareTo(key2);
        int cmpCol = col.compare(str1, str2);
        if ((cmpKey < 0 && cmpCol >= 0) || (cmpKey > 0 && cmpCol <= 0) || (cmpKey == 0 && cmpCol != 0)) {
            errln("Inconsistent comparison(" + opt + "): str1=" + str1 + ", str2=" + str2 + ", cmpKey=" + cmpKey + " , cmpCol=" + cmpCol);
        }
    }
}
Also used : CollationKey(android.icu.text.CollationKey)

Example 45 with CollationKey

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

the class G7CollationTest method doTest.

// main test routine, tests comparisons for a set of strings against sets of expected results
private void doTest(Collator myCollation, String source, String target, int result) {
    int compareResult = myCollation.compare(source, target);
    CollationKey sortKey1, sortKey2;
    sortKey1 = myCollation.getCollationKey(source);
    sortKey2 = myCollation.getCollationKey(target);
    int keyResult = sortKey1.compareTo(sortKey2);
    reportCResult(source, target, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
}
Also used : CollationKey(android.icu.text.CollationKey)

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