+/**
+ * Test Any-X transliterators with sample letters from all scripts.
+ */
+void TransliteratorTest::TestAny(void) {
+ UErrorCode status = U_ZERO_ERROR;
+ // Note: there is a lot of implict construction of UnicodeStrings from (char *) in
+ // function call parameters going on in this test.
+ UnicodeSet alphabetic("[:alphabetic:]", status);
+ if (U_FAILURE(status)) {
+ dataerrln("Failure: file %s, line %d, status = %s", __FILE__, __LINE__, u_errorName(status));
+ return;
+ }
+ alphabetic.freeze();
+
+ UnicodeString testString;
+ for (int32_t i = 0; i < USCRIPT_CODE_LIMIT; i++) {
+ const char *scriptName = uscript_getShortName((UScriptCode)i);
+ if (scriptName == NULL) {
+ errln("Failure: file %s, line %d: Script Code %d is invalid, ", __FILE__, __LINE__, i);
+ return;
+ }
+
+ UnicodeSet sample;
+ sample.applyPropertyAlias("script", scriptName, status);
+ if (U_FAILURE(status)) {
+ errln("Failure: file %s, line %d, status = %s", __FILE__, __LINE__, u_errorName(status));
+ return;
+ }
+ sample.retainAll(alphabetic);
+ for (int32_t count=0; count<5; count++) {
+ UChar32 c = sample.charAt(count);
+ if (c == -1) {
+ break;
+ }
+ testString.append(c);
+ }
+ }
+
+ UParseError parseError;
+ Transliterator* anyLatin =
+ Transliterator::createInstance("Any-Latin", UTRANS_FORWARD, parseError, status);
+ if (U_FAILURE(status)) {
+ dataerrln("Failure: file %s, line %d, status = %s", __FILE__, __LINE__, u_errorName(status));
+ return;
+ }
+
+ logln(UnicodeString("Sample set for Any-Latin: ") + testString);
+ anyLatin->transliterate(testString);
+ logln(UnicodeString("Sample result for Any-Latin: ") + testString);
+ delete anyLatin;
+}
+
+