use of android.icu.text.CollationKey in project j2objc by google.
the class CollationMiscTest method TestMergeSortKeys.
@Test
public void TestMergeSortKeys() {
String[] cases = { "abc", "abcd", "abcde" };
String prefix = "foo";
String suffix = "egg";
CollationKey[] mergedPrefixKeys = new CollationKey[cases.length];
CollationKey[] mergedSuffixKeys = new CollationKey[cases.length];
Collator coll = Collator.getInstance(Locale.ENGLISH);
genericLocaleStarter(Locale.ENGLISH, cases);
int strength = Collator.PRIMARY;
while (strength <= Collator.IDENTICAL) {
coll.setStrength(strength);
CollationKey prefixKey = coll.getCollationKey(prefix);
CollationKey suffixKey = coll.getCollationKey(suffix);
for (int i = 0; i < cases.length; i++) {
CollationKey key = coll.getCollationKey(cases[i]);
mergedPrefixKeys[i] = prefixKey.merge(key);
mergedSuffixKeys[i] = suffixKey.merge(key);
if (mergedPrefixKeys[i].getSourceString() != null || mergedSuffixKeys[i].getSourceString() != null) {
errln("Merged source string error: expected null");
}
if (i > 0) {
if (mergedPrefixKeys[i - 1].compareTo(mergedPrefixKeys[i]) >= 0) {
errln("Error while comparing prefixed keys @ strength " + strength);
errln(CollationTest.prettify(mergedPrefixKeys[i - 1]));
errln(CollationTest.prettify(mergedPrefixKeys[i]));
}
if (mergedSuffixKeys[i - 1].compareTo(mergedSuffixKeys[i]) >= 0) {
errln("Error while comparing suffixed keys @ strength " + strength);
errln(CollationTest.prettify(mergedSuffixKeys[i - 1]));
errln(CollationTest.prettify(mergedSuffixKeys[i]));
}
}
}
if (strength == Collator.QUATERNARY) {
strength = Collator.IDENTICAL;
} else {
strength++;
}
}
}
use of android.icu.text.CollationKey in project j2objc by google.
the class CollationMiscTest method TestBocsuCoverage.
@Test
public void TestBocsuCoverage() {
String test = "\u0041\u0441\u4441\\U00044441\u4441\u0441\u0041";
Collator coll = Collator.getInstance();
coll.setStrength(Collator.IDENTICAL);
CollationKey key = coll.getCollationKey(test);
logln("source:" + key.getSourceString());
}
use of android.icu.text.CollationKey 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\"");
}
}
use of android.icu.text.CollationKey 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.");
}
use of android.icu.text.CollationKey in project j2objc by google.
the class CollationRegressionTest method compareArray.
void compareArray(Collator c, String[] tests) {
int expectedResult = 0;
for (int i = 0; i < tests.length; i += 3) {
String source = tests[i];
String comparison = tests[i + 1];
String target = tests[i + 2];
if (comparison.equals("<")) {
expectedResult = -1;
} else if (comparison.equals(">")) {
expectedResult = 1;
} else if (comparison.equals("=")) {
expectedResult = 0;
} else {
errln("Bogus comparison string \"" + comparison + "\"");
}
int compareResult = 0;
logln("i = " + i);
logln(source);
logln(target);
try {
compareResult = c.compare(source, target);
} catch (Exception e) {
errln(e.toString());
}
CollationKey sourceKey = null, targetKey = null;
try {
sourceKey = c.getCollationKey(source);
} catch (Exception e) {
errln("Couldn't get collationKey for source");
continue;
}
try {
targetKey = c.getCollationKey(target);
} catch (Exception e) {
errln("Couldn't get collationKey for target");
continue;
}
int keyResult = sourceKey.compareTo(targetKey);
reportCResult(source, target, sourceKey, targetKey, compareResult, keyResult, compareResult, expectedResult);
}
}
Aggregations