use of android.icu.text.ReplaceableString in project j2objc by google.
the class TransliteratorTest method expect.
static void expect(Transliterator t, String source, String expectedResult, Transliterator.Position pos) {
if (pos == null) {
String result = t.transliterate(source);
if (!expectAux(t.getID() + ":String", source, result, expectedResult))
return;
}
Transliterator.Position index = null;
if (pos == null) {
index = new Transliterator.Position(0, source.length(), 0, source.length());
} else {
index = new Transliterator.Position(pos.contextStart, pos.contextLimit, pos.start, pos.limit);
}
ReplaceableString rsource = new ReplaceableString(source);
t.finishTransliteration(rsource, index);
if (index.start != index.limit) {
expectAux(t.getID() + ":UNFINISHED", source, "start: " + index.start + ", limit: " + index.limit, false, expectedResult);
return;
}
String result = rsource.toString();
if (!expectAux(t.getID() + ":Replaceable", source, result, expectedResult))
return;
if (pos == null) {
index = new Transliterator.Position();
} else {
index = new Transliterator.Position(pos.contextStart, pos.contextLimit, pos.start, pos.limit);
}
// Test incremental transliteration -- this result
// must be the same after we finalize (see below).
List<String> v = new ArrayList<String>();
v.add(source);
rsource.replace(0, rsource.length(), "");
if (pos != null) {
rsource.replace(0, 0, source);
v.add(UtilityExtensions.formatInput(rsource, index));
t.transliterate(rsource, index);
v.add(UtilityExtensions.formatInput(rsource, index));
} else {
for (int i = 0; i < source.length(); ++i) {
// v.add(i == 0 ? "" : " + " + source.charAt(i) + "");
// log.append(source.charAt(i)).append(" -> "));
t.transliterate(rsource, index, source.charAt(i));
// v.add(UtilityExtensions.formatInput(rsource, index) + source.substring(i+1));
v.add(UtilityExtensions.formatInput(rsource, index) + ((i < source.length() - 1) ? (" + '" + source.charAt(i + 1) + "' ->") : " =>"));
}
}
// As a final step in keyboard transliteration, we must call
// transliterate to finish off any pending partial matches that
// were waiting for more input.
t.finishTransliteration(rsource, index);
result = rsource.toString();
// log.append(" => ").append(rsource.toString());
v.add(result);
String[] results = new String[v.size()];
v.toArray(results);
expectAux(t.getID() + ":Incremental", results, result.equals(expectedResult), expectedResult);
}
use of android.icu.text.ReplaceableString in project j2objc by google.
the class TestUCharacterIterator method TestPreviousNext.
@Test
public void TestPreviousNext() {
// src and expect strings
char[] src = { UTF16.getLeadSurrogate(0x2f999), UTF16.getTrailSurrogate(0x2f999), UTF16.getLeadSurrogate(0x1d15f), UTF16.getTrailSurrogate(0x1d15f), 0xc4, 0x1ed0 };
// iterators
UCharacterIterator iter1 = UCharacterIterator.getInstance(new ReplaceableString(new String(src)));
UCharacterIterator iter2 = UCharacterIterator.getInstance(src);
UCharacterIterator iter3 = UCharacterIterator.getInstance(new StringCharacterIterator(new String(src)));
UCharacterIterator iter4 = UCharacterIterator.getInstance(new StringBuffer(new String(src)));
previousNext(iter1);
previousNext(iter2);
previousNext(iter3);
previousNext(iter4);
getText(iter1, new String(src));
getText(iter2, new String(src));
getText(iter3, new String(src));
/* getCharacterIterator */
CharacterIterator citer1 = iter1.getCharacterIterator();
CharacterIterator citer2 = iter2.getCharacterIterator();
CharacterIterator citer3 = iter3.getCharacterIterator();
if (citer1.first() != iter1.current()) {
errln("getCharacterIterator for iter1 failed");
}
if (citer2.first() != iter2.current()) {
errln("getCharacterIterator for iter2 failed");
}
if (citer3.first() != iter3.current()) {
errln("getCharacterIterator for iter3 failed");
}
/* Test clone() && moveIndex()*/
try {
UCharacterIterator clone1 = (UCharacterIterator) iter1.clone();
UCharacterIterator clone2 = (UCharacterIterator) iter2.clone();
UCharacterIterator clone3 = (UCharacterIterator) iter3.clone();
if (clone1.moveIndex(3) != iter1.moveIndex(3)) {
errln("moveIndex for iter1 failed");
}
if (clone2.moveIndex(3) != iter2.moveIndex(3)) {
errln("moveIndex for iter2 failed");
}
if (clone3.moveIndex(3) != iter3.moveIndex(3)) {
errln("moveIndex for iter1 failed");
}
} catch (Exception e) {
errln("could not clone the iterator");
}
}
Aggregations