use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method expect.
// ======================================================================
// Support methods
// ======================================================================
static void expect(String rules, String source, String expectedResult, Transliterator.Position pos) {
Transliterator t = Transliterator.createFromRules("<ID>", rules, Transliterator.FORWARD);
expect(t, source, expectedResult, pos);
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestNormalizationTransliterator.
/**
* Test the normalization transliterator.
*/
@Test
public void TestNormalizationTransliterator() {
// THE FOLLOWING TWO TABLES ARE COPIED FROM android.icu.dev.test.normalizer.BasicTest
// PLEASE KEEP THEM IN SYNC WITH BasicTest.
String[][] CANON = { // Input Decomposed Composed
{ "cat", "cat", "cat" }, { "\u00e0ardvark", "a\u0300ardvark", "\u00e0ardvark" }, // D-dot_above
{ "\u1e0a", "D\u0307", "\u1e0a" }, // D dot_above
{ "D\u0307", "D\u0307", "\u1e0a" }, // D-dot_below dot_above
{ "\u1e0c\u0307", "D\u0323\u0307", "\u1e0c\u0307" }, // D-dot_above dot_below
{ "\u1e0a\u0323", "D\u0323\u0307", "\u1e0c\u0307" }, // D dot_below dot_above
{ "D\u0307\u0323", "D\u0323\u0307", "\u1e0c\u0307" }, // D dot_below cedilla dot_above
{ "\u1e10\u0307\u0323", "D\u0327\u0323\u0307", "\u1e10\u0323\u0307" }, // D dot_above ogonek dot_below
{ "D\u0307\u0328\u0323", "D\u0328\u0323\u0307", "\u1e0c\u0328\u0307" }, // E-macron-grave
{ "\u1E14", "E\u0304\u0300", "\u1E14" }, // E-macron + grave
{ "\u0112\u0300", "E\u0304\u0300", "\u1E14" }, // E-grave + macron
{ "\u00c8\u0304", "E\u0300\u0304", "\u00c8\u0304" }, // angstrom_sign
{ "\u212b", "A\u030a", "\u00c5" }, // A-ring
{ "\u00c5", "A\u030a", "\u00c5" }, // updated with 3.0
{ "\u00fdffin", "y\u0301ffin", "\u00fdffin" }, // updated with 3.0
{ "\u00fd\uFB03n", "y\u0301\uFB03n", "\u00fd\uFB03n" }, { "Henry IV", "Henry IV", "Henry IV" }, { "Henry \u2163", "Henry \u2163", "Henry \u2163" }, // ga (Katakana)
{ "\u30AC", "\u30AB\u3099", "\u30AC" }, // ka + ten
{ "\u30AB\u3099", "\u30AB\u3099", "\u30AC" }, // hw_ka + hw_ten
{ "\uFF76\uFF9E", "\uFF76\uFF9E", "\uFF76\uFF9E" }, // ka + hw_ten
{ "\u30AB\uFF9E", "\u30AB\uFF9E", "\u30AB\uFF9E" }, // hw_ka + ten
{ "\uFF76\u3099", "\uFF76\u3099", "\uFF76\u3099" }, { "A\u0300\u0316", "A\u0316\u0300", "\u00C0\u0316" } };
String[][] COMPAT = { // Alef-Lamed vs. Alef, Lamed
{ "\uFB4f", "\u05D0\u05DC", "\u05D0\u05DC" }, // updated for 3.0
{ "\u00fdffin", "y\u0301ffin", "\u00fdffin" }, // ffi ligature -> f + f + i
{ "\u00fd\uFB03n", "y\u0301ffin", "\u00fdffin" }, { "Henry IV", "Henry IV", "Henry IV" }, { "Henry \u2163", "Henry IV", "Henry IV" }, // ga (Katakana)
{ "\u30AC", "\u30AB\u3099", "\u30AC" }, // ka + ten
{ "\u30AB\u3099", "\u30AB\u3099", "\u30AC" }, // hw_ka + ten
{ "\uFF76\u3099", "\u30AB\u3099", "\u30AC" } };
Transliterator NFD = Transliterator.getInstance("NFD");
Transliterator NFC = Transliterator.getInstance("NFC");
for (int i = 0; i < CANON.length; ++i) {
String in = CANON[i][0];
String expd = CANON[i][1];
String expc = CANON[i][2];
expect(NFD, in, expd);
expect(NFC, in, expc);
}
Transliterator NFKD = Transliterator.getInstance("NFKD");
Transliterator NFKC = Transliterator.getInstance("NFKC");
for (int i = 0; i < COMPAT.length; ++i) {
String in = COMPAT[i][0];
String expkd = COMPAT[i][1];
String expkc = COMPAT[i][2];
expect(NFKD, in, expkd);
expect(NFKC, in, expkc);
}
Transliterator t = Transliterator.getInstance("NFD; [x]Remove");
expect(t, "\u010dx", "c\u030C");
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestLocaleInstantiation.
/**
* Test instantiation from a locale.
*/
@Test
public void TestLocaleInstantiation() {
Transliterator t;
try {
t = Transliterator.getInstance("te_IN-Latin");
// expect(t, "\u0430", "a");
} catch (IllegalArgumentException ex) {
warnln("Could not load locale data for obtaining the script used in the locale te_IN. " + ex.getMessage());
}
try {
t = Transliterator.getInstance("ru_RU-Latin");
expect(t, "\u0430", "a");
} catch (IllegalArgumentException ex) {
warnln("Could not load locale data for obtaining the script used in the locale ru_RU. " + ex.getMessage());
}
try {
t = Transliterator.getInstance("en-el");
expect(t, "a", "\u03B1");
} catch (IllegalArgumentException ex) {
warnln("Could not load locale data for obtaining the script used in the locale el. " + ex.getMessage());
}
}
use of android.icu.text.Transliterator in project j2objc by google.
the class ThreadTest method TestAnyTranslit.
// Test for ticket #10673, race in cache code in AnyTransliterator.
// It's difficult to make the original unsafe code actually fail, but
// this test will fairly reliably take the code path for races in
// populating the cache.
//
@Test
public void TestAnyTranslit() {
final Transliterator tx = Transliterator.getInstance("Any-Latin");
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < 8; i++) {
threads.add(new Thread() {
public void run() {
tx.transliterate("διαφορετικούς");
}
});
}
for (Thread th : threads) {
th.start();
}
for (Thread th : threads) {
try {
th.join();
} catch (InterruptedException e) {
errln("Uexpected exception: " + e);
}
}
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestCompoundHex.
/**
* Compose the hex transliterators forward and reverse.
*/
@Test
public void TestCompoundHex() {
Transliterator a = Transliterator.getInstance("Any-Hex");
Transliterator b = Transliterator.getInstance("Hex-Any");
// Transliterator[] trans = { a, b };
// Transliterator ab = Transliterator.getInstance(trans);
Transliterator ab = Transliterator.getInstance("Any-Hex;Hex-Any");
// Do some basic tests of b
expect(b, "\\u0030\\u0031", "01");
String s = "abcde";
expect(ab, s, s);
// trans = new Transliterator[] { b, a };
// Transliterator ba = Transliterator.getInstance(trans);
Transliterator ba = Transliterator.getInstance("Hex-Any;Any-Hex");
ReplaceableString str = new ReplaceableString(s);
a.transliterate(str);
expect(ba, str.toString(), str.toString());
}
Aggregations