use of android.icu.text.CollationElementIterator in project j2objc by google.
the class CollationMiscTest method TestVariableTop.
@Test
public void TestVariableTop() {
// ICU 53+: The character must be in a supported reordering group,
// and the variable top is pinned to the end of that group.
// parseNextToken is not released as public so i create my own rules
String rules = "& ' ' < b < c < de < fg & hi = j";
try {
RuleBasedCollator coll = new RuleBasedCollator(rules);
String[] tokens = { " ", "b", "c", "de", "fg", "hi", "j", "ab" };
coll.setAlternateHandlingShifted(true);
for (int i = 0; i < tokens.length; i++) {
int varTopOriginal = coll.getVariableTop();
try {
int varTop = coll.setVariableTop(tokens[i]);
if (i > 4) {
errln("Token " + tokens[i] + " expected to fail");
}
if (varTop != coll.getVariableTop()) {
errln("Error setting and getting variable top");
}
CollationKey key1 = coll.getCollationKey(tokens[i]);
for (int j = 0; j < i; j++) {
CollationKey key2 = coll.getCollationKey(tokens[j]);
if (key2.compareTo(key1) < 0) {
errln("Setting variable top shouldn't change the comparison sequence");
}
byte[] sortorder = key2.toByteArray();
if (sortorder.length > 0 && (key2.toByteArray())[0] > 1) {
errln("Primary sort order should be 0");
}
}
} catch (Exception e) {
CollationElementIterator iter = coll.getCollationElementIterator(tokens[i]);
/*int ce =*/
iter.next();
int ce2 = iter.next();
if (ce2 == CollationElementIterator.NULLORDER) {
errln("Token " + tokens[i] + " not expected to fail");
}
if (coll.getVariableTop() != varTopOriginal) {
errln("When exception is thrown variable top should " + "not be changed");
}
}
coll.setVariableTop(varTopOriginal);
if (varTopOriginal != coll.getVariableTop()) {
errln("Couldn't restore old variable top\n");
}
}
// Testing calling with error set
try {
coll.setVariableTop("");
errln("Empty string should throw an IllegalArgumentException");
} catch (IllegalArgumentException e) {
logln("PASS: Empty string failed as expected");
}
try {
coll.setVariableTop(null);
errln("Null string should throw an IllegalArgumentException");
} catch (IllegalArgumentException e) {
logln("PASS: null string failed as expected");
}
} catch (Exception e) {
warnln("Error creating RuleBasedCollator");
}
}
use of android.icu.text.CollationElementIterator in project j2objc by google.
the class CollationMiscTest method TestJ3087.
@Test
public void TestJ3087() {
String[] rule = { "&h<H&CH=\u0427", /*
* The ICU 53 builder adheres to the principle that
* a rule is affected by previous rules but not following ones.
* Therefore, setting CH=\u0427 and then re-tailoring H makes CH != \u0427.
"&CH=\u0427&h<H", */
"&CH=\u0427" };
RuleBasedCollator rbc = null;
CollationElementIterator iter1;
CollationElementIterator iter2;
for (int i = 0; i < rule.length; i++) {
try {
rbc = new RuleBasedCollator(rule[i]);
} catch (Exception e) {
warnln(e.getMessage());
continue;
}
iter1 = rbc.getCollationElementIterator("CH");
iter2 = rbc.getCollationElementIterator("\u0427");
int ce1 = CollationElementIterator.IGNORABLE;
int ce2 = CollationElementIterator.IGNORABLE;
// The ICU 53 builder code sets the uppercase flag only on the first CE.
int mask = ~0;
while (ce1 != CollationElementIterator.NULLORDER && ce2 != CollationElementIterator.NULLORDER) {
ce1 = iter1.next();
ce2 = iter2.next();
if ((ce1 & mask) != (ce2 & mask)) {
errln("Error generating RuleBasedCollator with the rule " + rule[i]);
errln("CH != \\u0427");
}
// mask off case/continuation bits
mask = ~0xc0;
}
}
}
use of android.icu.text.CollationElementIterator in project j2objc by google.
the class CollationRegressionTest method Test4663220.
// CollationElementIterator set doesn't work propertly with next/prev
@Test
public void Test4663220() {
RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(Locale.US);
java.text.StringCharacterIterator stringIter = new java.text.StringCharacterIterator("fox");
CollationElementIterator iter = collator.getCollationElementIterator(stringIter);
int[] elements_next = new int[3];
logln("calling next:");
for (int i = 0; i < 3; ++i) {
logln("[" + i + "] " + (elements_next[i] = iter.next()));
}
int[] elements_fwd = new int[3];
logln("calling set/next:");
for (int i = 0; i < 3; ++i) {
iter.setOffset(i);
logln("[" + i + "] " + (elements_fwd[i] = iter.next()));
}
for (int i = 0; i < 3; ++i) {
if (elements_next[i] != elements_fwd[i]) {
errln("mismatch at position " + i + ": " + elements_next[i] + " != " + elements_fwd[i]);
}
}
}
use of android.icu.text.CollationElementIterator 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);
}
use of android.icu.text.CollationElementIterator 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());
}
Aggregations