use of android.icu.text.CollationKey in project j2objc by google.
the class CollationFrenchTest method doTest.
// main test routine, test rules specific to the french 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);
}
use of android.icu.text.CollationKey in project j2objc by google.
the class CollationKanaTest method TestCommonCharacters.
/*
* Test common Hiragana and Katakana characters (e.g. 0x3099) (ticket:6140)
*/
@Test
public void TestCommonCharacters() {
char[] tmp1 = { 0x3058, 0x30B8 };
char[] tmp2 = { 0x3057, 0x3099, 0x30B7, 0x3099 };
CollationKey key1, key2;
int result;
String string1 = new String(tmp1);
String string2 = new String(tmp2);
RuleBasedCollator rb = (RuleBasedCollator) Collator.getInstance(ULocale.JAPANESE);
rb.setStrength(Collator.QUATERNARY);
rb.setAlternateHandlingShifted(false);
result = rb.compare(string1, string2);
key1 = rb.getCollationKey(string1);
key2 = rb.getCollationKey(string2);
if (result != 0 || !key1.equals(key2)) {
errln("Failed Hiragana and Katakana common characters test. Expected results to be equal.");
}
}
use of android.icu.text.CollationKey in project j2objc by google.
the class CollationMonkeyTest method TestCollationKey.
@Test
public void TestCollationKey() {
if (source.length() == 0) {
errln("CollationMonkeyTest.TestCollationKey(): source is empty - ICU_DATA not set or data missing?");
return;
}
Collator myCollator;
try {
myCollator = Collator.getInstance(new Locale("en", "US"));
} catch (Exception e) {
warnln("ERROR: in creation of collator of ENGLISH locale");
return;
}
// use test framework's random seed
Random rand = createRandom();
int s = rand.nextInt(0x7fff) % source.length();
int t = rand.nextInt(0x7fff) % source.length();
int slen = Math.abs(rand.nextInt(0x7fff) % source.length() - source.length()) % source.length();
int tlen = Math.abs(rand.nextInt(0x7fff) % source.length() - source.length()) % source.length();
String subs = source.substring(Math.min(s, slen), Math.min(s + slen, source.length()));
String subt = source.substring(Math.min(t, tlen), Math.min(t + tlen, source.length()));
CollationKey collationKey1, collationKey2;
myCollator.setStrength(Collator.TERTIARY);
collationKey1 = myCollator.getCollationKey(subs);
collationKey2 = myCollator.getCollationKey(subt);
// Tertiary
int result = collationKey1.compareTo(collationKey2);
// Tertiary
int revResult = collationKey2.compareTo(collationKey1);
report(subs, subt, result, revResult);
myCollator.setStrength(Collator.SECONDARY);
collationKey1 = myCollator.getCollationKey(subs);
collationKey2 = myCollator.getCollationKey(subt);
// Secondary
result = collationKey1.compareTo(collationKey2);
// Secondary
revResult = collationKey2.compareTo(collationKey1);
report(subs, subt, result, revResult);
myCollator.setStrength(Collator.PRIMARY);
collationKey1 = myCollator.getCollationKey(subs);
collationKey2 = myCollator.getCollationKey(subt);
// Primary
result = collationKey1.compareTo(collationKey2);
// Primary
revResult = collationKey2.compareTo(collationKey1);
report(subs, subt, result, revResult);
String msg = "";
String addOne = subs + String.valueOf(0xE000);
collationKey1 = myCollator.getCollationKey(subs);
collationKey2 = myCollator.getCollationKey(addOne);
result = collationKey1.compareTo(collationKey2);
if (result != -1) {
msg += "CollationKey(";
msg += subs;
msg += ") .LT. CollationKey(";
msg += addOne;
msg += ") Failed.";
errln(msg);
}
msg = "";
result = collationKey2.compareTo(collationKey1);
if (result != 1) {
msg += "CollationKey(";
msg += addOne;
msg += ") .GT. CollationKey(";
msg += subs;
msg += ") Failed.";
errln(msg);
}
}
use of android.icu.text.CollationKey in project j2objc by google.
the class CollationMonkeyTest method doTest.
void doTest(RuleBasedCollator myCollation, String mysource, String target, int result) {
int compareResult = myCollation.compare(source, target);
CollationKey sortKey1, sortKey2;
try {
sortKey1 = myCollation.getCollationKey(source);
sortKey2 = myCollation.getCollationKey(target);
} catch (Exception e) {
errln("SortKey generation Failed.\n");
return;
}
int keyResult = sortKey1.compareTo(sortKey2);
reportCResult(mysource, target, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
}
use of android.icu.text.CollationKey in project j2objc by google.
the class CollationTest method getMergedCollationKey.
/**
* Changes the key to the merged segments of the U+FFFE-separated substrings of s.
* Leaves key unchanged if s does not contain U+FFFE.
* @return true if the key was successfully changed
*/
private boolean getMergedCollationKey(String s, Output<CollationKey> key) {
CollationKey mergedKey = null;
int sLength = s.length();
int segmentStart = 0;
for (int i = 0; ; ) {
if (i == sLength) {
if (segmentStart == 0) {
// s does not contain any U+FFFE.
return false;
}
} else if (s.charAt(i) != '\uFFFE') {
++i;
continue;
}
// Get the sort key for another segment and merge it into mergedKey.
CollationKey tmpKey = coll.getCollationKey(s.substring(segmentStart, i));
if (mergedKey == null) {
mergedKey = tmpKey;
} else {
mergedKey = mergedKey.merge(tmpKey);
}
if (i == sLength) {
break;
}
segmentStart = ++i;
}
key.value = mergedKey;
return true;
}
Aggregations