use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestInterIndic.
/**
* Test inter-Indic transliterators. These are composed.
*/
@Test
public void TestInterIndic() {
String ID = "Devanagari-Gujarati";
Transliterator dg = Transliterator.getInstance(ID);
if (dg == null) {
errln("FAIL: getInstance(" + ID + ") returned null");
return;
}
String id = dg.getID();
if (!id.equals(ID)) {
errln("FAIL: getInstance(" + ID + ").getID() => " + id);
}
String dev = "\u0901\u090B\u0925";
String guj = "\u0A81\u0A8B\u0AA5";
expect(dg, dev, guj);
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestHiraganaKatakana.
/**
* Test the Hiragana-Katakana transliterator.
*/
@Test
public void TestHiraganaKatakana() {
Transliterator hk = Transliterator.getInstance("Hiragana-Katakana");
Transliterator kh = Transliterator.getInstance("Katakana-Hiragana");
// Array of 3n items
// Each item is "hk"|"kh"|"both", <Hiragana>, <Katakana>
String[] DATA = { "both", "\u3042\u3090\u3099\u3092\u3050", "\u30A2\u30F8\u30F2\u30B0", "kh", "\u307C\u3051\u3060\u3042\u3093\u30FC", "\u30DC\u30F6\u30C0\u30FC\u30F3\u30FC" };
for (int i = 0; i < DATA.length; i += 3) {
switch(DATA[i].charAt(0)) {
case // Hiragana-Katakana
'h':
expect(hk, DATA[i + 1], DATA[i + 2]);
break;
case // Katakana-Hiragana
'k':
expect(kh, DATA[i + 2], DATA[i + 1]);
break;
case // both
'b':
expect(hk, DATA[i + 1], DATA[i + 2]);
expect(kh, DATA[i + 2], DATA[i + 1]);
break;
}
}
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestSTV.
@Test
public void TestSTV() {
Enumeration es = Transliterator.getAvailableSources();
for (int i = 0; es.hasMoreElements(); ++i) {
String source = (String) es.nextElement();
logln("" + i + ": " + source);
if (source.length() == 0) {
errln("FAIL: empty source");
continue;
}
Enumeration et = Transliterator.getAvailableTargets(source);
for (int j = 0; et.hasMoreElements(); ++j) {
String target = (String) et.nextElement();
logln(" " + j + ": " + target);
if (target.length() == 0) {
errln("FAIL: empty target");
continue;
}
Enumeration ev = Transliterator.getAvailableVariants(source, target);
for (int k = 0; ev.hasMoreElements(); ++k) {
String variant = (String) ev.nextElement();
if (variant.length() == 0) {
logln(" " + k + ": <empty>");
} else {
logln(" " + k + ": " + variant);
}
}
}
}
// Test registration
String[] IDS = { "Fieruwer", "Seoridf-Sweorie", "Oewoir-Oweri/Vsie" };
String[] FULL_IDS = { "Any-Fieruwer", "Seoridf-Sweorie", "Oewoir-Oweri/Vsie" };
String[] SOURCES = { null, "Seoridf", "Oewoir" };
for (int i = 0; i < 3; ++i) {
Transliterator.registerFactory(IDS[i], new TestFact(IDS[i]));
try {
Transliterator t = Transliterator.getInstance(IDS[i]);
if (t.getID().equals(IDS[i])) {
logln("Ok: Registration/creation succeeded for ID " + IDS[i]);
} else {
errln("FAIL: Registration of ID " + IDS[i] + " creates ID " + t.getID());
}
Transliterator.unregister(IDS[i]);
try {
t = Transliterator.getInstance(IDS[i]);
errln("FAIL: Unregistration failed for ID " + IDS[i] + "; still receiving ID " + t.getID());
} catch (IllegalArgumentException e2) {
// Good; this is what we expect
logln("Ok; Unregistered " + IDS[i]);
}
} catch (IllegalArgumentException e) {
errln("FAIL: Registration/creation failed for ID " + IDS[i]);
} finally {
Transliterator.unregister(IDS[i]);
}
}
// Make sure getAvailable API reflects removal
for (Enumeration e = Transliterator.getAvailableIDs(); e.hasMoreElements(); ) {
String id = (String) e.nextElement();
for (int i = 0; i < 3; ++i) {
if (id.equals(FULL_IDS[i])) {
errln("FAIL: unregister(" + id + ") failed");
}
}
}
for (Enumeration e = Transliterator.getAvailableTargets("Any"); e.hasMoreElements(); ) {
String t = (String) e.nextElement();
if (t.equals(IDS[0])) {
errln("FAIL: unregister(Any-" + t + ") failed");
}
}
for (Enumeration e = Transliterator.getAvailableSources(); e.hasMoreElements(); ) {
String s = (String) e.nextElement();
for (int i = 0; i < 3; ++i) {
if (SOURCES[i] == null)
continue;
if (s.equals(SOURCES[i])) {
errln("FAIL: unregister(" + s + "-*) failed");
}
}
}
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestTeluguLatinRT.
@Test
public void TestTeluguLatinRT() {
String[] source = { "raghur\u0101m vi\u015Bvan\u0101dha", /* Raghuram Viswanadha */
"\u0101nand vaddir\u0101ju", /* Anand Vaddiraju */
"r\u0101j\u012Bv ka\u015Barab\u0101da", /* Rajeev Kasarabada */
"san\u0304j\u012Bv ka\u015Barab\u0101da", /* sanjeev kasarabada */
"san\u0304j\u012Bb sen'gupta", /* sanjib sengupata */
"amar\u0113ndra hanum\u0101nula", /* Amarendra hanumanula */
"ravi kum\u0101r vi\u015Bvan\u0101dha", /* Ravi Kumar Viswanadha */
"\u0101ditya kandr\u0113gula", /* Aditya Kandregula */
"\u015Br\u012Bdhar ka\u1E47\u1E6Dama\u015Be\u1E6D\u1E6Di", /* Shridhar Kantamsetty */
"m\u0101dhav de\u015Be\u1E6D\u1E6Di" /* Madhav Desetty */
};
String[] expected = { "\u0c30\u0c18\u0c41\u0c30\u0c3e\u0c2e\u0c4d \u0c35\u0c3f\u0c36\u0c4d\u0c35\u0c28\u0c3e\u0c27", "\u0c06\u0c28\u0c02\u0c26\u0c4d \u0C35\u0C26\u0C4D\u0C26\u0C3F\u0C30\u0C3E\u0C1C\u0C41", "\u0c30\u0c3e\u0c1c\u0c40\u0c35\u0c4d \u0c15\u0c36\u0c30\u0c2c\u0c3e\u0c26", "\u0c38\u0c02\u0c1c\u0c40\u0c35\u0c4d \u0c15\u0c36\u0c30\u0c2c\u0c3e\u0c26", "\u0c38\u0c02\u0c1c\u0c40\u0c2c\u0c4d \u0c38\u0c46\u0c28\u0c4d\u0c17\u0c41\u0c2a\u0c4d\u0c24", "\u0c05\u0c2e\u0c30\u0c47\u0c02\u0c26\u0c4d\u0c30 \u0c39\u0c28\u0c41\u0c2e\u0c3e\u0c28\u0c41\u0c32", "\u0c30\u0c35\u0c3f \u0c15\u0c41\u0c2e\u0c3e\u0c30\u0c4d \u0c35\u0c3f\u0c36\u0c4d\u0c35\u0c28\u0c3e\u0c27", "\u0c06\u0c26\u0c3f\u0c24\u0c4d\u0c2f \u0C15\u0C02\u0C26\u0C4D\u0C30\u0C47\u0C17\u0C41\u0c32", "\u0c36\u0c4d\u0c30\u0c40\u0C27\u0C30\u0C4D \u0c15\u0c02\u0c1f\u0c2e\u0c36\u0c46\u0c1f\u0c4d\u0c1f\u0c3f", "\u0c2e\u0c3e\u0c27\u0c35\u0c4d \u0c26\u0c46\u0c36\u0c46\u0c1f\u0c4d\u0c1f\u0c3f" };
Transliterator latinToDev = Transliterator.getInstance("Latin-Telugu", Transliterator.FORWARD);
Transliterator devToLatin = Transliterator.getInstance("Telugu-Latin", Transliterator.FORWARD);
for (int i = 0; i < source.length; i++) {
expect(latinToDev, (source[i]), (expected[i]));
expect(devToLatin, (expected[i]), (source[i]));
}
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestSourceTargetSet.
/**
* Test the source and target set API. These are only implemented
* for RBT and CompoundTransliterator at this time.
*/
@Test
public void TestSourceTargetSet() {
// Rules
String r = "a > b; " + "r [x{lu}] > q;";
// Expected source
UnicodeSet expSrc = new UnicodeSet("[arx{lu}]");
// Expected target
UnicodeSet expTrg = new UnicodeSet("[bq]");
Transliterator t = Transliterator.createFromRules("test", r, Transliterator.FORWARD);
UnicodeSet src = t.getSourceSet();
UnicodeSet trg = t.getTargetSet();
if (src.equals(expSrc) && trg.equals(expTrg)) {
logln("Ok: " + r + " => source = " + src.toPattern(true) + ", target = " + trg.toPattern(true));
} else {
errln("FAIL: " + r + " => source = " + src.toPattern(true) + ", expected " + expSrc.toPattern(true) + "; target = " + trg.toPattern(true) + ", expected " + expTrg.toPattern(true));
}
}
Aggregations