static void TestAPI() { enum { BUF_CAP = 128 }; char buf[BUF_CAP], buf2[BUF_CAP]; UErrorCode status = U_ZERO_ERROR; UTransliterator* trans = NULL; int32_t i, n; /* Test getAvailableIDs */ n = utrans_countAvailableIDs(); if (n < 1) { log_err("FAIL: utrans_countAvailableIDs() returned %d\n", n); } else { log_verbose("System ID count: %d\n", n); } for (i=0; i<n; ++i) { utrans_getAvailableID(i, buf, BUF_CAP); if (*buf == 0) { log_err("FAIL: System transliterator %d: \"\"\n", i); } else { log_verbose("System transliterator %d: \"%s\"\n", i, buf); } } /* Test open */ utrans_getAvailableID(0, buf, BUF_CAP); trans = utrans_open(buf, UTRANS_FORWARD,NULL,0,NULL, &status); if (U_FAILURE(status)) { log_err("FAIL: utrans_open(%s) failed, error=%s\n", buf, u_errorName(status)); } else { /* Test getID */ utrans_getID(trans, buf2, BUF_CAP); if (0 != strcmp(buf, buf2)) { log_err("FAIL: utrans_getID(%s) returned %s\n", buf, buf2); } utrans_close(trans); } }
static int printTransliterators(int canon) { #if UCONFIG_NO_TRANSLITERATION printf("no transliterators available because of UCONFIG_NO_TRANSLITERATION, see uconfig.h\n"); return 1; #else int32_t numtrans = utrans_countAvailableIDs(), i; int buflen = 512; char *buf = (char *) uprv_malloc(buflen); char staticbuf[512]; char sepchar = canon ? '\n' : ' '; if (!buf) { buf = staticbuf; buflen = sizeof(staticbuf); } for (i = 0; i < numtrans; ++i) { int32_t len = utrans_getAvailableID(i, buf, buflen); if (len >= buflen - 1) { if (buf != staticbuf) { buflen <<= 1; if (buflen < len) { buflen = len + 64; } buf = (char *) uprv_realloc(buf, buflen); if (!buf) { buf = staticbuf; buflen = sizeof(staticbuf); } } utrans_getAvailableID(i, buf, buflen); if (len >= buflen) { uprv_strcpy(buf + buflen - 4, "..."); /* Truncate the name. */ } } printf("%s", buf); if (i < numtrans - 1) { putchar(sepchar); } } /* Add a terminating newline if needed. */ if (sepchar != '\n') { putchar('\n'); } /* Free temporary data. */ if (buf != staticbuf) { uprv_free(buf); } /* Success. */ return 0; #endif }