const String GetDefaultLocale() { assert(s_defaultLocale); if (s_defaultLocale->empty()) { return String(uloc_getDefault(), CopyString); } return *s_defaultLocale; }
U_CAPI UCalendar* U_EXPORT2 ucal_open( const UChar* zoneID, int32_t len, const char* locale, UCalendarType caltype, UErrorCode* status) { if(U_FAILURE(*status)) return 0; TimeZone* zone = (zoneID==NULL) ? TimeZone::createDefault() : _createTimeZone(zoneID, len, status); if (U_FAILURE(*status)) { return NULL; } if ( caltype == UCAL_GREGORIAN ) { char localeBuf[ULOC_LOCALE_IDENTIFIER_CAPACITY]; if ( locale == NULL ) { locale = uloc_getDefault(); } uprv_strncpy(localeBuf, locale, ULOC_LOCALE_IDENTIFIER_CAPACITY); uloc_setKeywordValue("calendar", "gregorian", localeBuf, ULOC_LOCALE_IDENTIFIER_CAPACITY, status); if (U_FAILURE(*status)) { return NULL; } return (UCalendar*)Calendar::createInstance(zone, Locale(localeBuf), *status); } return (UCalendar*)Calendar::createInstance(zone, Locale(locale), *status); }
const char *intl_locale_get_default( void ) { if( INTL_G(default_locale) == NULL ) { return uloc_getDefault(); } return INTL_G(default_locale); }
/* Version information */ static void version() { UErrorCode status = U_ZERO_ERROR; const char *tzVer; int len = 256; UChar tzName[256]; printf("icudate version %s, created by Stephen F. Booth.\n", DATE_VERSION); puts(U_COPYRIGHT_STRING); tzVer = ucal_getTZDataVersion(&status); if(U_FAILURE(status)) { tzVer = u_errorName(status); } printf("\n"); printf("ICU Version: %s\n", U_ICU_VERSION); printf("ICU Data (major+min): %s\n", U_ICUDATA_NAME); printf("Default Locale: %s\n", uloc_getDefault()); printf("Time Zone Data Version: %s\n", tzVer); printf("Default Time Zone: "); status = U_ZERO_ERROR; u_init(&status); len = ucal_getDefaultTimeZone(tzName, len, &status); if(U_FAILURE(status)) { printf(" ** Error getting default zone: %s\n", u_errorName(status)); } uprint(tzName, stdout, &status); printf("\n\n"); }
const String GetDefaultLocale() { String locale(s_intl_request->getDefaultLocale()); if (locale.empty()) { locale = String(uloc_getDefault(), CopyString); } return locale; }
U_CAPI ULocaleBundle * u_locbund_init(ULocaleBundle *result, const char *loc) { int32_t len; if(result == 0) return 0; if (loc == NULL) { loc = uloc_getDefault(); } uprv_memset(result, 0, sizeof(ULocaleBundle)); len = (int32_t)strlen(loc); result->fLocale = (char*) uprv_malloc(len + 1); if(result->fLocale == 0) { return 0; } uprv_strcpy(result->fLocale, loc); result->isInvariantLocale = uprv_strcmp(result->fLocale, "en_US_POSIX") == 0; return result; }
static void setTempCaseMapLocale(UCaseMap *csm, const char *locale, UErrorCode *pErrorCode) { /* * We could call ucasemap_setLocale(), but here we really only care about * the initial language subtag, we need not return the real string via * ucasemap_getLocale(), and we don't care about only getting "x" from * "x-some-thing" etc. * * We ignore locales with a longer-than-3 initial subtag. * * We also do not fill in the locCache because it is rarely used, * and not worth setting unless we reuse it for many case mapping operations. * (That's why UCaseMap was created.) */ int i; char c; /* the internal functions require locale!=NULL */ if(locale==NULL) { locale=uloc_getDefault(); } for(i=0; i<4 && (c=locale[i])!=0 && c!='-' && c!='_'; ++i) { csm->locale[i]=c; } if(i<=3) { csm->locale[i]=0; /* Up to 3 non-separator characters. */ } else { csm->locale[0]=0; /* Longer-than-3 initial subtag: Ignore. */ } }
static int load(ErlNifEnv *env, void **priv_data, ERL_NIF_TERM load_info) { static int is_loaded = 0; int code; if (is_loaded) return 0; uloc_getDefault(); code = i18n_atom_load(env, priv_data, load_info); if (code) return code; #if I18N_STRING code = i18n_string_load(env, priv_data, load_info); if (code) return code; #endif #if I18N_COLLATION code = i18n_collation_load(env, priv_data, load_info); if (code) return code; #endif #if I18N_COLLATION code = i18n_search_load(env, priv_data, load_info); if (code) return code; #endif #if I18N_MESSAGE code = i18n_message_load(env, priv_data, load_info); if (code) return code; #endif #if I18N_REGEX code = i18n_regex_load(env, priv_data, load_info); if (code) return code; #endif #if I18N_DATE code = i18n_date_load(env, priv_data, load_info); if (code) return code; #endif #if I18N_TRANS code = i18n_trans_load(env, priv_data, load_info); if (code) return code; #endif is_loaded = 1; return 0; }
void TestTwoDigitYearDSTParse() { UDateFormat *fullFmt, *fmt; UErrorCode status = U_ZERO_ERROR; UChar *pattern; UDate d; UChar *s; int32_t pos; ctest_setTimeZone(NULL, &status); pattern=(UChar*)malloc(sizeof(UChar) * (strlen("EEE MMM dd HH:mm:ss.SSS zzz yyyy G")+1 )); u_uastrcpy(pattern, "EEE MMM dd HH:mm:ss.SSS zzz yyyy G"); fullFmt= udat_open(UDAT_IGNORE, UDAT_IGNORE,"en_US",NULL,0,pattern, u_strlen(pattern),&status); if(U_FAILURE(status)) { log_err_status(status, "FAIL: Error in creating a date format using udat_openPattern %s\n", myErrorName(status) ); } else { log_verbose("PASS: creating dateformat using udat_openPattern() succesful\n"); u_uastrcpy(pattern, "dd-MMM-yy h:mm:ss 'o''clock' a z"); fmt= udat_open(UDAT_IGNORE,UDAT_IGNORE,"en_US", NULL, 0,pattern, u_strlen(pattern), &status); s=(UChar*)malloc(sizeof(UChar) * (strlen("03-Apr-04 2:20:47 o'clock AM PST")+1) ); u_uastrcpy(s, "03-Apr-04 2:20:47 o'clock AM PST"); pos=0; d = udat_parse(fmt, s, u_strlen(s), &pos, &status); if (U_FAILURE(status)) { log_err("FAIL: Could not parse \"%s\"\n", austrdup(s)); } else { UCalendar *cal = ucal_open(NULL, 0, uloc_getDefault(), UCAL_TRADITIONAL, &status); if (U_FAILURE(status)) { log_err_status(status, "FAIL: Could not open calendar: %s\n", u_errorName(status)); } else { int32_t h; ucal_setMillis(cal, d, &status); h = ucal_get(cal, UCAL_HOUR_OF_DAY, &status); if (U_FAILURE(status)) { log_err("FAIL: Some calendar operations failed"); } else if (h != 2) { log_err("FAIL: Parse of \"%s\" returned HOUR_OF_DAY %d\n", austrdup(s), h); } ucal_close(cal); } } udat_close(fullFmt); udat_close(fmt); free(s); } free(pattern); ctest_resetTimeZone(); }
U_CFUNC int32_t ustrcase_getCaseLocale(const char *locale) { if (locale == NULL) { locale = uloc_getDefault(); } if (*locale == 0) { return UCASE_LOC_ROOT; } else { return ucase_getCaseLocale(locale); } }
U_CAPI ULocaleDisplayNames * U_EXPORT2 uldn_open(const char * locale, UDialectHandling dialectHandling, UErrorCode *pErrorCode) { if (U_FAILURE(*pErrorCode)) { return 0; } if (locale == NULL) { locale = uloc_getDefault(); } return (ULocaleDisplayNames *)LocaleDisplayNames::createInstance(Locale(locale), dialectHandling); }
U_CAPI ULocaleDisplayNames * U_EXPORT2 uldn_openForContext(const char * locale, UDisplayContext *contexts, int32_t length, UErrorCode *pErrorCode) { if (U_FAILURE(*pErrorCode)) { return 0; } if (locale == NULL) { locale = uloc_getDefault(); } return (ULocaleDisplayNames *)LocaleDisplayNames::createInstance(Locale(locale), contexts, length); }
void LocaleDisplayNamesTest::TestUldnOpen() { UErrorCode status = U_ZERO_ERROR; const int32_t kMaxResultSize = 150; // long enough UChar result[150]; ULocaleDisplayNames *ldn = uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES, &status); int32_t len = uldn_localeDisplayName(ldn, "de_DE", result, kMaxResultSize, &status); uldn_close(ldn); test_assert(U_SUCCESS(status)); UnicodeString str(result, len, kMaxResultSize); test_assert_equal("Deutsch (Deutschland)", str); // make sure that NULL gives us the default locale as usual ldn = uldn_open(NULL, ULDN_STANDARD_NAMES, &status); const char *locale = uldn_getLocale(ldn); if(0 != uprv_strcmp(uloc_getDefault(), locale)) { errln("uldn_getLocale(uldn_open(NULL))=%s != default locale %s\n", locale, uloc_getDefault()); } uldn_close(ldn); test_assert(U_SUCCESS(status)); }
void NumberFormat::getEffectiveCurrency(UChar* result, UErrorCode& ec) const { const UChar* c = getCurrency(); if (*c != 0) { u_strncpy(result, c, 3); result[3] = 0; } else { const char* loc = getLocaleID(ULOC_VALID_LOCALE, ec); if (loc == NULL) { loc = uloc_getDefault(); } ucurr_forLocale(loc, result, 4, &ec); } }
// The behavior of uloc_getDefault() on POSIX systems is to query // setlocale(LC_MESSAGES) and use that value, unless it is C or // POSIX. In that case it tries to read LC_ALL, LC_MESSAGES and LANG // and then falls back to en_US_POSIX if none of them are set. // // en_US_POSIX is a weird locale since the collation rules treat 'a' // and 'A' as different letters even when ignoring case. Furthermore // it's common for LC_ALL, LC_MESSAGES and LANG to be unset when // running under Docker. // // We'd rather default to invariant in this case. If any of these // are set, we'll just call into ICU and let it do whatever // normalization it would do. const char* DetectDefaultLocaleName() { char* loc = setlocale(LC_MESSAGES, nullptr); if (loc != nullptr && (strcmp("C", loc) == 0 || strcmp("POSIX", loc) == 0)) { if (!IsEnvVarSet("LC_ALL") && !IsEnvVarSet("LC_MESSAGES") && !IsEnvVarSet("LANG")) { return ""; } } return uloc_getDefault(); }
static void cal(int32_t month, int32_t year, UBool useLongNames, UErrorCode *status) { UCalendar *c; UChar *days [DAY_COUNT]; UChar *months [MONTH_COUNT]; int32_t fdow; if(U_FAILURE(*status)) return; /* Create a new calendar */ c = ucal_open(0, -1, uloc_getDefault(), UCAL_TRADITIONAL, status); /* Determine if we are printing a calendar for one month or for a year */ /* Print an entire year */ if(month == -1 && year != -1) { /* Set the year */ ucal_set(c, UCAL_YEAR, year); /* Determine the first day of the week */ fdow = ucal_getAttribute(c, UCAL_FIRST_DAY_OF_WEEK); /* Print the calendar for the year */ print_year(c, days, months, useLongNames, fdow, status); } /* Print only one month */ else { /* Set the month and the year, if specified */ if(month != -1) ucal_set(c, UCAL_MONTH, month); if(year != -1) ucal_set(c, UCAL_YEAR, year); /* Determine the first day of the week */ fdow = ucal_getAttribute(c, UCAL_FIRST_DAY_OF_WEEK); /* Print the calendar for the month */ print_month(c, days, useLongNames, fdow, status); } /* Clean up */ ucal_close(c); }
static void *engine_fixed_compile(error_t **error, UString *ustr, uint32_t flags) { UErrorCode status; fixed_pattern_t *p; p = mem_new(*p); p->pattern = ustr; // not needed with usearch ? p->flags = flags; p->ubrk = NULL; p->usearch = NULL; status = U_ZERO_ERROR; if (ustring_empty(ustr)) { if (IS_WORD_BOUNDED(flags)) { p->ubrk = ubrk_open(UBRK_WORD, NULL, NULL, 0, &status); } } else { if (!IS_WHOLE_LINE(flags)) { if (IS_WORD_BOUNDED(flags)) { p->ubrk = ubrk_open(UBRK_WORD, NULL, NULL, 0, &status); } else if (WITH_GRAPHEME()) { p->ubrk = ubrk_open(UBRK_CHARACTER, NULL, NULL, 0, &status); } if (U_FAILURE(status)) { fixed_pattern_destroy(p); icu_error_set(error, FATAL, status, "ubrk_open"); return NULL; } } if (IS_WORD_BOUNDED(flags) || (IS_CASE_INSENSITIVE(flags) && !IS_WHOLE_LINE(flags))) { p->usearch = usearch_open(ustr->ptr, ustr->len, USEARCH_FAKE_USTR, uloc_getDefault(), p->ubrk, &status); if (U_FAILURE(status)) { if (NULL != p->ubrk) { ubrk_close(p->ubrk); } fixed_pattern_destroy(p); icu_error_set(error, FATAL, status, "usearch_open"); return NULL; } if (IS_CASE_INSENSITIVE(flags)) { UCollator *ucol; ucol = usearch_getCollator(p->usearch); ucol_setStrength(ucol, (flags & ~OPT_MASK) > 1 ? UCOL_SECONDARY : UCOL_PRIMARY); } } } return p; }
int main() { UErrorCode status = U_ZERO_ERROR; char theirLocale[ULOC_FULLNAME_CAPACITY]; uloc_forLanguageTag("es-419-u-nu-roman", // IETF BCP 47 theirLocale, ULOC_FULLNAME_CAPACITY, NULL, &status); // theirLocale is now: “es_419@numbers=roman” UChar str[256]; const char *ourLocale = uloc_getDefault(); ULocaleDisplayNames *ldn = uldn_open(ourLocale, ULDN_DIALECT_NAMES, &status); uldn_localeDisplayName(ldn, theirLocale, str, 256, &status); uldn_close(ldn); if(U_FAILURE(status)) { puts(u_errorName(status)); return 1; } u_printf("\n==> %S!\n \n", str); return 0; }
void c_Collator::t___construct(CStrRef locale) { INSTANCE_METHOD_INJECTION_BUILTIN(Collator, Collator::__construct); if (m_ucoll) { ucol_close(m_ucoll); m_ucoll = NULL; } m_errcode.clear(); if (!locale.empty()) { m_locale = locale; m_ucoll = ucol_open(locale.data(), &(m_errcode.code)); if (!U_FAILURE(m_errcode.code)) { // If the specified locale opened successfully, return s_intl_error->m_error.clear(); s_intl_error->m_error.code = m_errcode.code; return; } } // If the empty string was given or if the specified locale did // not open successfully, so fall back to using the default locale m_errcode.code = U_USING_FALLBACK_WARNING; s_intl_error->m_error.clear(); s_intl_error->m_error.code = m_errcode.code; if (m_ucoll) { ucol_close(m_ucoll); m_ucoll = NULL; } UErrorCode errcode = U_ZERO_ERROR; m_locale = String(uloc_getDefault(), CopyString); m_ucoll = ucol_open(m_locale.data(), &errcode); if (U_FAILURE(errcode)) { m_errcode.code = errcode; m_errcode.custom_error_message = "collator_create: unable to open ICU collator"; s_intl_error->m_error.clear(); s_intl_error->m_error.code = m_errcode.code; s_intl_error->m_error.custom_error_message = m_errcode.custom_error_message; if (m_ucoll) { ucol_close(m_ucoll); m_ucoll = NULL; } } }
extern "C" int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLength) { char localeNameBuffer[ULOC_FULLNAME_CAPACITY]; UErrorCode status = U_ZERO_ERROR; const char* defaultLocale = uloc_getDefault(); uloc_getBaseName(defaultLocale, localeNameBuffer, ULOC_FULLNAME_CAPACITY, &status); if (U_SUCCESS(status)) { status = u_charsToUChars_safe(localeNameBuffer, value, valueLength); if (U_SUCCESS(status)) { int localeNameLen = FixupLocaleName(value, valueLength); char collationValueTemp[ULOC_KEYWORDS_CAPACITY]; int32_t collationLen = uloc_getKeywordValue(defaultLocale, "collation", collationValueTemp, ULOC_KEYWORDS_CAPACITY, &status); if (U_SUCCESS(status) && collationLen > 0) { // copy the collation; managed uses a "_" to represent collation (not // "@collation=") status = u_charsToUChars_safe("_", &value[localeNameLen], valueLength - localeNameLen); if (U_SUCCESS(status)) { status = u_charsToUChars_safe( collationValueTemp, &value[localeNameLen + 1], valueLength - localeNameLen - 1); } } } } return UErrorCodeToBool(status); }
/* Format a message and print it's output to fp */ U_CFUNC int u_wmsg(FILE *fp, const char *tag, ... ) { const UChar *msg; int32_t msgLen; UErrorCode err = U_ZERO_ERROR; #if !UCONFIG_NO_FORMATTING va_list ap; #endif UChar result[4096]; int32_t resultLength = LENGTHOF(result); if(gBundle == NULL) { #if 0 fprintf(stderr, "u_wmsg: No path set!!\n"); /* FIXME: codepage?? */ #endif return -1; } msg = ures_getStringByKey(gBundle, tag, &msgLen, &err); if(U_FAILURE(err)) { return -1; } #if UCONFIG_NO_FORMATTING resultLength = sizeof(gNoFormatting) / U_SIZEOF_UCHAR; if((msgLen + resultLength) <= LENGTHOF(result)) { memcpy(result, msg, msgLen * U_SIZEOF_UCHAR); memcpy(result + msgLen, gNoFormatting, resultLength); resultLength += msgLen; uprint(result, resultLength, fp, &err); } else { uprint(msg,msgLen, fp, &err); } #else va_start(ap, tag); resultLength = u_vformatMessage(uloc_getDefault(), msg, msgLen, result, resultLength, ap, &err); va_end(ap); if(U_FAILURE(err)) { #if 0 fprintf(stderr, "u_wmsg: failed to format %s:%s, err %s\n", uloc_getDefault(), tag, u_errorName(err)); #endif err = U_ZERO_ERROR; uprint(msg,msgLen, fp, &err); return -1; } uprint(result, resultLength, fp, &err); #endif if(U_FAILURE(err)) { #if 0 fprintf(stderr, "u_wmsg: failed to print %s: %s, err %s\n", uloc_getDefault(), tag, u_errorName(err)); #endif return -1; } return 0; }
void pkg_sttc_writeReadme(struct UPKGOptions_ *o, const char *libName, UErrorCode *status) { char tmp[1024]; FileStream *out; if(U_FAILURE(*status)) { return; } /* Makefile pathname */ uprv_strcpy(tmp, o->targetDir); uprv_strcat(tmp, U_FILE_SEP_STRING "README_"); uprv_strcat(tmp, o->shortName); uprv_strcat(tmp, ".txt"); out = T_FileStream_open(tmp, "w"); if (!out) { fprintf(stderr, "err: couldn't create README file %s\n", tmp); *status = U_FILE_ACCESS_ERROR; return; } sprintf(tmp, "## README for \"%s\"'s static data (%s)\n" "## created by pkgdata, ICU Version %s\n", o->shortName, libName, U_ICU_VERSION); T_FileStream_writeLine(out, tmp); sprintf(tmp, "\n\nTo use this data in your application:\n\n" "1. At the top of your source file, add the following lines:\n" "\n" " #include \"unicode/utypes.h\"\n" " #include \"unicode/udata.h\"\n" " U_CFUNC char %s_dat[];\n", o->cShortName); T_FileStream_writeLine(out, tmp); sprintf(tmp, "2. *Early* in your application, call the following function:\n" "\n" " UErrorCode myError = U_ZERO_ERROR;\n" " udata_setAppData( \"%s\", (const void*) %s_dat, &myError);\n" " if(U_FAILURE(myError))\n" " {\n" " handle error condition ...\n" " }\n" "\n", o->cShortName, o->cShortName); T_FileStream_writeLine(out, tmp); sprintf(tmp, "3. Link your application against %s\n" "\n\n" "4. Now, you may access this data with a 'path' of \"%s\" as in the following example:\n" "\n" " ... ures_open( \"%s\", \"%s\", &err ); \n", libName, o->shortName, o->shortName, uloc_getDefault()); T_FileStream_writeLine(out, tmp); T_FileStream_close(out); }
/* PAL Function: GetLocaleInfoString Obtains string locale information. Returns 1 for success, 0 otherwise */ extern "C" int32_t GlobalizationNative_GetLocaleInfoString( const UChar* localeName, LocaleStringData localeStringData, UChar* value, int32_t valueLength) { UErrorCode status = U_ZERO_ERROR; char locale[ULOC_FULLNAME_CAPACITY]; GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &status); if (U_FAILURE(status)) { return UErrorCodeToBool(U_ILLEGAL_ARGUMENT_ERROR); } switch (localeStringData) { case LocalizedDisplayName: uloc_getDisplayName(locale, uloc_getDefault(), value, valueLength, &status); break; case EnglishDisplayName: uloc_getDisplayName(locale, ULOC_ENGLISH, value, valueLength, &status); break; case NativeDisplayName: uloc_getDisplayName(locale, locale, value, valueLength, &status); break; case LocalizedLanguageName: uloc_getDisplayLanguage(locale, uloc_getDefault(), value, valueLength, &status); break; case EnglishLanguageName: uloc_getDisplayLanguage(locale, ULOC_ENGLISH, value, valueLength, &status); break; case NativeLanguageName: uloc_getDisplayLanguage(locale, locale, value, valueLength, &status); break; case EnglishCountryName: uloc_getDisplayCountry(locale, ULOC_ENGLISH, value, valueLength, &status); break; case NativeCountryName: uloc_getDisplayCountry(locale, locale, value, valueLength, &status); break; case ListSeparator: // fall through case ThousandSeparator: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_GROUPING_SEPARATOR_SYMBOL, value, valueLength); break; case DecimalSeparator: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_DECIMAL_SEPARATOR_SYMBOL, value, valueLength); break; case Digits: status = GetDigitSymbol(locale, status, UNUM_ZERO_DIGIT_SYMBOL, 0, value, valueLength); // symbols UNUM_ONE_DIGIT to UNUM_NINE_DIGIT are contiguous for (int32_t symbol = UNUM_ONE_DIGIT_SYMBOL; symbol <= UNUM_NINE_DIGIT_SYMBOL; symbol++) { int charIndex = symbol - UNUM_ONE_DIGIT_SYMBOL + 1; status = GetDigitSymbol( locale, status, static_cast<UNumberFormatSymbol>(symbol), charIndex, value, valueLength); } break; case MonetarySymbol: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_CURRENCY_SYMBOL, value, valueLength); break; case Iso4217MonetarySymbol: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_INTL_CURRENCY_SYMBOL, value, valueLength); break; case MonetaryDecimalSeparator: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_SEPARATOR_SYMBOL, value, valueLength); break; case MonetaryThousandSeparator: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL, value, valueLength); break; case AMDesignator: status = GetLocaleInfoAmPm(locale, true, value, valueLength); break; case PMDesignator: status = GetLocaleInfoAmPm(locale, false, value, valueLength); break; case PositiveSign: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PLUS_SIGN_SYMBOL, value, valueLength); break; case NegativeSign: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MINUS_SIGN_SYMBOL, value, valueLength); break; case Iso639LanguageName: status = GetLocaleIso639LanguageName(locale, value, valueLength); break; case Iso3166CountryName: status = GetLocaleIso3166CountryName(locale, value, valueLength); break; case NaNSymbol: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_NAN_SYMBOL, value, valueLength); break; case PositiveInfinitySymbol: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_INFINITY_SYMBOL, value, valueLength); break; case ParentName: { // ICU supports lang[-script][-region][-variant] so up to 4 parents // including invariant locale char localeNameTemp[ULOC_FULLNAME_CAPACITY]; uloc_getParent(locale, localeNameTemp, ULOC_FULLNAME_CAPACITY, &status); if (U_SUCCESS(status)) { status = u_charsToUChars_safe(localeNameTemp, value, valueLength); if (U_SUCCESS(status)) { FixupLocaleName(value, valueLength); } } break; } case PercentSymbol: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PERCENT_SYMBOL, value, valueLength); break; case PerMilleSymbol: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PERMILL_SYMBOL, value, valueLength); break; default: status = U_UNSUPPORTED_ERROR; break; }; return UErrorCodeToBool(status); }
void cmd_version(UBool noLoad) { UVersionInfo icu; char str[200]; printf("<ICUINFO>\n"); printf("International Components for Unicode for C/C++\n"); printf("%s\n", U_COPYRIGHT_STRING); printf("Compiled-Version: %s\n", U_ICU_VERSION); u_getVersion(icu); u_versionToString(icu, str); printf("Runtime-Version: %s\n", str); printf("Compiled-Unicode-Version: %s\n", U_UNICODE_VERSION); u_getUnicodeVersion(icu); u_versionToString(icu, str); printf("Runtime-Unicode-Version: %s\n", U_UNICODE_VERSION); printf("Platform: %s\n", getPlatform()); #if defined(U_BUILD) printf("Build: %s\n", U_BUILD); #if defined(U_HOST) if(strcmp(U_BUILD,U_HOST)) { printf("Host: %s\n", U_HOST); } #endif #endif #if defined(U_CC) printf("C compiler: %s\n", U_CC); #endif #if defined(U_CXX) printf("C++ compiler: %s\n", U_CXX); #endif #if defined(CYGWINMSVC) printf("Cygwin: CYGWINMSVC\n"); #endif printf("ICUDATA: %s\n", U_ICUDATA_NAME); do_init(); printf("Data Directory: %s\n", u_getDataDirectory()); printf("ICU Initialization returned: %s\n", u_errorName(initStatus)); printf( "Default locale: %s\n", uloc_getDefault()); { UErrorCode subStatus = U_ZERO_ERROR; ulocdata_getCLDRVersion(icu, &subStatus); if(U_SUCCESS(subStatus)) { u_versionToString(icu, str); printf("CLDR-Version: %s\n", str); } else { printf("CLDR-Version: %s\n", u_errorName(subStatus)); } } #if !UCONFIG_NO_CONVERSION if(noLoad == FALSE) { printf("Default converter: %s\n", ucnv_getDefaultName()); } #endif #if !UCONFIG_NO_FORMATTING { UChar buf[100]; char buf2[100]; UErrorCode subsubStatus= U_ZERO_ERROR; int32_t len; len = ucal_getDefaultTimeZone(buf, 100, &subsubStatus); if(U_SUCCESS(subsubStatus)&&len>0) { u_UCharsToChars(buf, buf2, len+1); printf("Default TZ: %s\n", buf2); } else { printf("Default TZ: %s\n", u_errorName(subsubStatus)); } } { UErrorCode subStatus = U_ZERO_ERROR; const char *tzVer = ucal_getTZDataVersion(&subStatus); if(U_FAILURE(subStatus)) { tzVer = u_errorName(subStatus); } printf("TZ data version: %s\n", tzVer); } #endif #if U_ENABLE_DYLOAD const char *pluginFile = uplug_getPluginFile(); printf("Plugin file is: %s\n", (pluginFile&&*pluginFile)?pluginFile:"(not set. try setting ICU_PLUGINS to a directory.)"); #else fprintf(stderr, "Dynamic Loading: is disabled. No plugins will be loaded at start-up.\n"); #endif printf("</ICUINFO>\n\n"); }
static int32_t caseMap(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, UBreakIterator *titleIter, const char *locale, uint32_t options, int32_t toWhichCase, UErrorCode *pErrorCode) { UChar buffer[300]; UChar *temp; const UCaseProps *csp; int32_t destLength; UBool ownTitleIter; /* check argument values */ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { return 0; } if( destCapacity<0 || (dest==NULL && destCapacity>0) || src==NULL || srcLength<-1 ) { *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; return 0; } csp=ucase_getSingleton(pErrorCode); if(U_FAILURE(*pErrorCode)) { return 0; } /* get the string length */ if(srcLength==-1) { srcLength=u_strlen(src); } /* check for overlapping source and destination */ if( dest!=NULL && ((src>=dest && src<(dest+destCapacity)) || (dest>=src && dest<(src+srcLength))) ) { /* overlap: provide a temporary destination buffer and later copy the result */ if(destCapacity<=(sizeof(buffer)/U_SIZEOF_UCHAR)) { /* the stack buffer is large enough */ temp=buffer; } else { /* allocate a buffer */ temp=(UChar *)uprv_malloc(destCapacity*U_SIZEOF_UCHAR); if(temp==NULL) { *pErrorCode=U_MEMORY_ALLOCATION_ERROR; return 0; } } } else { temp=dest; } ownTitleIter=FALSE; destLength=0; if(toWhichCase==FOLD_CASE) { destLength=ustr_foldCase(csp, temp, destCapacity, src, srcLength, options, pErrorCode); } else { UCaseContext csc={ NULL }; int32_t locCache; csc.p=(void *)src; csc.limit=srcLength; locCache=0; /* the internal functions require locale!=NULL */ if(locale==NULL) { locale=uloc_getDefault(); } if(toWhichCase==TO_LOWER) { destLength=_caseMap(csp, ucase_toFullLower, temp, destCapacity, src, &csc, 0, srcLength, locale, &locCache, pErrorCode); } else if(toWhichCase==TO_UPPER) { destLength=_caseMap(csp, ucase_toFullUpper, temp, destCapacity, src, &csc, 0, srcLength, locale, &locCache, pErrorCode); } else /* if(toWhichCase==TO_TITLE) */ { #if UCONFIG_NO_BREAK_ITERATION *pErrorCode=U_UNSUPPORTED_ERROR; #else if(titleIter==NULL) { titleIter=ubrk_open(UBRK_WORD, locale, src, srcLength, pErrorCode); ownTitleIter=(UBool)U_SUCCESS(*pErrorCode); } if(U_SUCCESS(*pErrorCode)) { destLength=_toTitle(csp, temp, destCapacity, src, &csc, srcLength, titleIter, locale, &locCache, pErrorCode); } #endif } } if(temp!=dest) { /* copy the result string to the destination buffer */ if(destLength>0) { int32_t copyLength= destLength<=destCapacity ? destLength : destCapacity; if(copyLength>0) { uprv_memmove(dest, temp, copyLength*U_SIZEOF_UCHAR); } } if(temp!=buffer) { uprv_free(temp); } } #if !UCONFIG_NO_BREAK_ITERATION if(ownTitleIter) { ubrk_close(titleIter); } #endif return u_terminateUChars(dest, destCapacity, destLength, pErrorCode); }
U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ u_vsnprintf_u(UChar *buffer, int32_t count, const char *locale, const UChar *patternSpecification, va_list ap) { const UChar *alias = patternSpecification; const UChar *lastAlias; int32_t patCount; int32_t written = 0; uint16_t handlerNum; ufmt_args args; u_localized_string outStr; u_sprintf_spec spec; ufmt_type_info info; u_sprintf_handler handler; if (count < 0) { count = INT32_MAX; } outStr.str = buffer; outStr.len = count; outStr.available = count; /* if locale is 0, use the default */ if(locale == 0) { locale = uloc_getDefault(); } outStr.fBundle = u_loccache_get(locale); if(outStr.fBundle == 0) { return 0; } outStr.fOwnBundle = FALSE; /* iterate through the pattern */ while(outStr.available > 0) { /* find the next '%' */ lastAlias = alias; while(*alias != UP_PERCENT && *alias != 0x0000) { alias++; } /* write any characters before the '%' */ if(alias > lastAlias) { written += u_minstrncpy(&outStr, lastAlias, (int32_t)(alias - lastAlias)); } /* break if at end of string */ if(*alias == 0x0000) { break; } /* parse the specifier */ patCount = u_sprintf_parse_spec(alias, &spec); /* fill in the precision and width, if specified out of line */ /* width specified out of line */ if(spec.fInfo.fWidth == -2) { if(spec.fWidthPos == -1) { /* read the width from the argument list */ spec.fInfo.fWidth = va_arg(ap, int); } else { /* handle positional parameter */ } /* if it's negative, take the absolute value and set left alignment */ if(spec.fInfo.fWidth < 0) { spec.fInfo.fWidth *= -1; spec.fInfo.fLeft = TRUE; } }
static void TestGetKeywordValuesForLocale(void) { #define PREFERRED_SIZE 15 #define MAX_NUMBER_OF_KEYWORDS 4 const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS] = { { "root", "USD", "USN", NULL }, { "und", "USD", "USN", NULL }, /* { "und_ZZ", "USD", NULL, NULL }, -- temporarily remove as this locale now has 15 entries */ { "en_US", "USD", "USN", NULL }, { "en_029", "USD", "USN", NULL }, { "en_TH", "THB", NULL, NULL }, { "de", "EUR", NULL, NULL }, { "de_DE", "EUR", NULL, NULL }, { "ar", "EGP", NULL, NULL }, { "ar_PS", "ILS", "JOD", NULL }, { "en@currency=CAD", "USD", "USN", NULL }, { "fr@currency=zzz", "EUR", NULL, NULL }, { "de_DE@currency=DEM", "EUR", NULL, NULL }, { "en_US@rg=THZZZZ", "THB", NULL, NULL }, { "de@rg=USZZZZ", "USD", "USN", NULL }, { "en_US@currency=CAD;rg=THZZZZ", "THB", NULL, NULL }, }; const int32_t EXPECTED_SIZE[PREFERRED_SIZE] = { 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 1 }; /* ucurr_forLocale results for same locales; "" if no result expected */ const char *FORLOCALE[PREFERRED_SIZE] = { "", "", "USD", "", "THB", "", "EUR", "", "ILS", "CAD", "ZZZ", "DEM", "THB", "USD", "CAD" }; UErrorCode status = U_ZERO_ERROR; int32_t i, j, size; UEnumeration *pref, *all; const char *loc = NULL; UBool matchPref, matchAll; const char *value = NULL; int32_t valueLength = 0; UList *ALLList = NULL; UEnumeration *ALL = ucurr_getKeywordValuesForLocale("currency", uloc_getDefault(), FALSE, &status); if (ALL == NULL) { log_err_status(status, "ERROR getting keyword value for default locale. -> %s\n", u_errorName(status)); return; } for (i = 0; i < PREFERRED_SIZE; i++) { UChar getCurrU[4]; int32_t getCurrLen; status = U_ZERO_ERROR; pref = NULL; all = NULL; loc = PREFERRED[i][0]; pref = ucurr_getKeywordValuesForLocale("currency", loc, TRUE, &status); matchPref = FALSE; matchAll = FALSE; size = uenum_count(pref, &status); if (size == EXPECTED_SIZE[i]) { matchPref = TRUE; for (j = 0; j < size; j++) { if ((value = uenum_next(pref, &valueLength, &status)) != NULL && U_SUCCESS(status)) { if (uprv_strcmp(value, PREFERRED[i][j+1]) != 0) { log_err("ERROR: locale %s got keywords #%d %s expected %s\n", loc, j, value, PREFERRED[i][j+1]); matchPref = FALSE; break; } } else { matchPref = FALSE; log_err("ERROR getting keyword value for locale \"%s\"\n", loc); break; } } } else { log_err("FAIL: size of locale \"%s\" %d does not match expected size %d\n", loc, size, EXPECTED_SIZE[i]); } if (!matchPref) { log_err("FAIL: Preferred values for locale \"%s\" does not match expected.\n", loc); break; } uenum_close(pref); all = ucurr_getKeywordValuesForLocale("currency", loc, FALSE, &status); size = uenum_count(all, &status); if (U_SUCCESS(status) && size == uenum_count(ALL, &status)) { matchAll = TRUE; ALLList = ulist_getListFromEnum(ALL); for (j = 0; j < size; j++) { if ((value = uenum_next(all, &valueLength, &status)) != NULL && U_SUCCESS(status)) { if (!ulist_containsString(ALLList, value, uprv_strlen(value))) { log_err("Locale %s have %s not in ALL\n", loc, value); matchAll = FALSE; break; } } else { matchAll = FALSE; log_err("ERROR getting \"all\" keyword value for locale \"%s\"\n", loc); break; } } if (!matchAll) { log_err("FAIL: All values for locale \"%s\" does not match expected.\n", loc); } } else { if(U_FAILURE(status)) { log_err("ERROR: %s\n", u_errorName(status)); } else if(size!=uenum_count(ALL, &status)) { log_err("ERROR: got size of %d, wanted %d\n", size, uenum_count(ALL, &status)); } } uenum_close(all); status = U_ZERO_ERROR; getCurrLen = ucurr_forLocale(loc, getCurrU, 4, &status); if(U_FAILURE(status)) { if (FORLOCALE[i][0] != 0) { log_err("ERROR: ucurr_forLocale %s, status %s\n", loc, u_errorName(status)); } } else if (getCurrLen != 3) { if (FORLOCALE[i][0] != 0 || getCurrLen != -1) { log_err("ERROR: ucurr_forLocale %s, returned len %d\n", loc, getCurrLen); } } else { char getCurrB[4]; u_UCharsToChars(getCurrU, getCurrB, 4); if ( uprv_strncmp(getCurrB, FORLOCALE[i], 4) != 0 ) { log_err("ERROR: ucurr_forLocale %s, expected %s, got %s\n", loc, FORLOCALE[i], getCurrB); } } } uenum_close(ALL); }
static void TestGetKeywordValuesForLocale(void) { #define PREFERRED_SIZE 13 #define MAX_NUMBER_OF_KEYWORDS 3 const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS] = { { "root", "USD", NULL }, { "und", "USD", NULL }, { "und_ZZ", "USD", NULL }, { "en_US", "USD", NULL }, { "en_029", "USD", NULL }, { "en_TH", "THB", NULL }, { "de", "EUR", NULL }, { "de_DE", "EUR", NULL }, { "ar", "EGP", NULL }, { "ar_PS", "JOD", "ILS" }, { "en@currency=CAD", "USD", NULL }, { "fr@currency=zzz", "EUR", NULL }, { "de_DE@currency=DEM", "EUR", NULL }, }; const int32_t EXPECTED_SIZE[PREFERRED_SIZE] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1 }; UErrorCode status = U_ZERO_ERROR; int32_t i, j, size; UEnumeration *pref, *all; const char *loc = NULL; UBool matchPref, matchAll; const char *value = NULL; int32_t valueLength = 0; UList *ALLList = NULL; UEnumeration *ALL = ucurr_getKeywordValuesForLocale("currency", uloc_getDefault(), FALSE, &status); if (ALL == NULL) { log_err_status(status, "ERROR getting keyword value for default locale. -> %s\n", u_errorName(status)); return; } for (i = 0; i < PREFERRED_SIZE; i++) { pref = NULL; all = NULL; loc = PREFERRED[i][0]; pref = ucurr_getKeywordValuesForLocale("currency", loc, TRUE, &status); matchPref = FALSE; matchAll = FALSE; size = uenum_count(pref, &status); if (size == EXPECTED_SIZE[i]) { matchPref = TRUE; for (j = 0; j < size; j++) { if ((value = uenum_next(pref, &valueLength, &status)) != NULL && U_SUCCESS(status)) { if (uprv_strcmp(value, PREFERRED[i][j+1]) != 0) { log_err("ERROR: locale %s got keywords #%d %s expected %s\n", loc, j, value, PREFERRED[i][j+1]); matchPref = FALSE; break; } } else { matchPref = FALSE; log_err("ERROR getting keyword value for locale \"%s\"\n", loc); break; } } } else { log_err("FAIL: size of locale \"%s\" %d does not match expected size %d\n", loc, size, EXPECTED_SIZE[i]); } if (!matchPref) { log_err("FAIL: Preferred values for locale \"%s\" does not match expected.\n", loc); break; } uenum_close(pref); all = ucurr_getKeywordValuesForLocale("currency", loc, FALSE, &status); size = uenum_count(all, &status); if (U_SUCCESS(status) && size == uenum_count(ALL, &status)) { matchAll = TRUE; ALLList = ulist_getListFromEnum(ALL); for (j = 0; j < size; j++) { if ((value = uenum_next(all, &valueLength, &status)) != NULL && U_SUCCESS(status)) { if (!ulist_containsString(ALLList, value, uprv_strlen(value))) { log_err("Locale %s have %s not in ALL\n", loc, value); matchAll = FALSE; break; } } else { matchAll = FALSE; log_err("ERROR getting \"all\" keyword value for locale \"%s\"\n", loc); break; } } if (!matchAll) { log_err("FAIL: All values for locale \"%s\" does not match expected.\n", loc); } } else { if(U_FAILURE(status)) { log_err("ERROR: %s\n", u_errorName(status)); } else if(size!=uenum_count(ALL, &status)) { log_err("ERROR: got size of %d, wanted %d\n", size, uenum_count(ALL, &status)); } } uenum_close(all); } uenum_close(ALL); }
static void print_icu_xml_locales(const struct config_t *p_config) { int32_t count; int32_t i; UErrorCode status = U_ZERO_ERROR; UChar keyword[64]; int32_t keyword_len = 0; char keyword_str[128]; int32_t keyword_str_len = 0; UChar language[64]; int32_t language_len = 0; char lang_str[128]; int32_t lang_str_len = 0; UChar script[64]; int32_t script_len = 0; char script_str[128]; int32_t script_str_len = 0; UChar location[64]; int32_t location_len = 0; char location_str[128]; int32_t location_str_len = 0; UChar variant[64]; int32_t variant_len = 0; char variant_str[128]; int32_t variant_str_len = 0; UChar name[64]; int32_t name_len = 0; char name_str[128]; int32_t name_str_len = 0; UChar localname[64]; int32_t localname_len = 0; char localname_str[128]; int32_t localname_str_len = 0; count = uloc_countAvailable() ; if (p_config->xmloutput) { fprintf(p_config->outfile, "<locales count=\"%d\" default=\"%s\" collations=\"%d\">\n", count, uloc_getDefault(), ucol_countAvailable()); } else { fprintf(p_config->outfile, "Available ICU locales: %d\n", count); fprintf(p_config->outfile, "Default locale is: %s\n", uloc_getDefault()); } for (i = 0; i < count; i++) { keyword_len = uloc_getDisplayKeyword(uloc_getAvailable(i), "en", keyword, 64, &status); u_strToUTF8(keyword_str, 128, &keyword_str_len, keyword, keyword_len, &status); language_len = uloc_getDisplayLanguage(uloc_getAvailable(i), "en", language, 64, &status); u_strToUTF8(lang_str, 128, &lang_str_len, language, language_len, &status); script_len = uloc_getDisplayScript(uloc_getAvailable(i), "en", script, 64, &status); u_strToUTF8(script_str, 128, &script_str_len, script, script_len, &status); location_len = uloc_getDisplayCountry(uloc_getAvailable(i), "en", location, 64, &status); u_strToUTF8(location_str, 128, &location_str_len, location, location_len, &status); variant_len = uloc_getDisplayVariant(uloc_getAvailable(i), "en", variant, 64, &status); u_strToUTF8(variant_str, 128, &variant_str_len, variant, variant_len, &status); name_len = uloc_getDisplayName(uloc_getAvailable(i), "en", name, 64, &status); u_strToUTF8(name_str, 128, &name_str_len, name, name_len, &status); localname_len = uloc_getDisplayName(uloc_getAvailable(i), uloc_getAvailable(i), localname, 64, &status); u_strToUTF8(localname_str, 128, &localname_str_len, localname, localname_len, &status); if (p_config->xmloutput) { fprintf(p_config->outfile, "<locale id=\"%s\"", uloc_getAvailable(i)); if (strlen(lang_str)) fprintf(p_config->outfile, " language=\"%s\"", lang_str); if (strlen(script_str)) fprintf(p_config->outfile, " script=\"%s\"", script_str); if (strlen(location_str)) fprintf(p_config->outfile, " location=\"%s\"", location_str); if (strlen(variant_str)) fprintf(p_config->outfile, " variant=\"%s\"", variant_str); if (strlen(name_str)) fprintf(p_config->outfile, " name=\"%s\"", name_str); if (strlen(localname_str)) fprintf(p_config->outfile, " localname=\"%s\"", localname_str); fprintf(p_config->outfile, ">"); if (strlen(localname_str)) fprintf(p_config->outfile, "%s", localname_str); fprintf(p_config->outfile, "</locale>\n"); } else if (1 == p_config->xmloutput) { fprintf(p_config->outfile, "%s", uloc_getAvailable(i)); fprintf(p_config->outfile, " | "); if (strlen(name_str)) fprintf(p_config->outfile, "%s", name_str); fprintf(p_config->outfile, " | "); if (strlen(localname_str)) fprintf(p_config->outfile, "%s", localname_str); fprintf(p_config->outfile, "\n"); } else fprintf(p_config->outfile, "%s\n", uloc_getAvailable(i)); } if (p_config->xmloutput) fprintf(p_config->outfile, "</locales>\n"); else fprintf(p_config->outfile, "\n"); if (U_FAILURE(status)) { fprintf(stderr, "ICU Error: %d %s\n", status, u_errorName(status)); exit(2); } }
int main(int argc, const char* const argv[]) { int nerrors = 0; UBool defaultDataFound; TestNode *root; const char *warnOrErr = "Failure"; UDate startTime, endTime; int32_t diffTime; /* initial check for the default converter */ UErrorCode errorCode = U_ZERO_ERROR; UResourceBundle *rb; UConverter *cnv; U_MAIN_INIT_ARGS(argc, argv); startTime = uprv_getRawUTCtime(); gOrigArgc = argc; gOrigArgv = argv; if (!initArgs(argc, argv, NULL, NULL)) { /* Error already displayed. */ return -1; } /* Check whether ICU will initialize without forcing the build data directory into * the ICU_DATA path. Success here means either the data dll contains data, or that * this test program was run with ICU_DATA set externally. Failure of this check * is normal when ICU data is not packaged into a shared library. * * Whether or not this test succeeds, we want to cleanup and reinitialize * with a data path so that data loading from individual files can be tested. */ defaultDataFound = TRUE; u_init(&errorCode); if (U_FAILURE(errorCode)) { fprintf(stderr, "#### Note: ICU Init without build-specific setDataDirectory() failed. %s\n", u_errorName(errorCode)); defaultDataFound = FALSE; } u_cleanup(); #ifdef URES_DEBUG fprintf(stderr, "After initial u_cleanup: RB cache %s empty.\n", ures_dumpCacheContents()?"WAS NOT":"was"); #endif while (getTestOption(REPEAT_TESTS_OPTION) > 0) { /* Loop runs once per complete execution of the tests * used for -r (repeat) test option. */ if (!initArgs(argc, argv, NULL, NULL)) { /* Error already displayed. */ return -1; } errorCode = U_ZERO_ERROR; /* Initialize ICU */ if (!defaultDataFound) { ctest_setICU_DATA(); /* u_setDataDirectory() must happen Before u_init() */ } u_init(&errorCode); if (U_FAILURE(errorCode)) { fprintf(stderr, "#### ERROR! %s: u_init() failed with status = \"%s\".\n" "*** Check the ICU_DATA environment variable and \n" "*** check that the data files are present.\n", argv[0], u_errorName(errorCode)); if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) { fprintf(stderr, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n"); u_cleanup(); return 1; } } /* try more data */ cnv = ucnv_open(TRY_CNV_2, &errorCode); if(cnv != 0) { /* ok */ ucnv_close(cnv); } else { fprintf(stderr, "*** %s! The converter for " TRY_CNV_2 " cannot be opened.\n" "*** Check the ICU_DATA environment variable and \n" "*** check that the data files are present.\n", warnOrErr); if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) { fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n"); u_cleanup(); return 1; } } rb = ures_open(NULL, "en", &errorCode); if(U_SUCCESS(errorCode)) { /* ok */ ures_close(rb); } else { fprintf(stderr, "*** %s! The \"en\" locale resource bundle cannot be opened.\n" "*** Check the ICU_DATA environment variable and \n" "*** check that the data files are present.\n", warnOrErr); if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) { fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n"); u_cleanup(); return 1; } } errorCode = U_ZERO_ERROR; rb = ures_open(NULL, NULL, &errorCode); if(U_SUCCESS(errorCode)) { /* ok */ if (errorCode == U_USING_DEFAULT_WARNING || errorCode == U_USING_FALLBACK_WARNING) { fprintf(stderr, "#### Note: The default locale %s is not available\n", uloc_getDefault()); } ures_close(rb); } else { fprintf(stderr, "*** %s! Can not open a resource bundle for the default locale %s\n", warnOrErr, uloc_getDefault()); if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) { fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n" "*** purposely removed, to continue test anyway.\n"); u_cleanup(); return 1; } } fprintf(stdout, "Default locale for this run is %s\n", uloc_getDefault()); /* Build a tree of all tests. * Subsequently will be used to find / iterate the tests to run */ root = NULL; addAllTests(&root); /* Tests acutally run HERE. TODO: separate command line option parsing & setting from test execution!! */ nerrors = runTestRequest(root, argc, argv); setTestOption(REPEAT_TESTS_OPTION, DECREMENT_OPTION_VALUE); if (getTestOption(REPEAT_TESTS_OPTION) > 0) { printf("Repeating tests %d more time(s)\n", getTestOption(REPEAT_TESTS_OPTION)); } cleanUpTestTree(root); #ifdef CTST_LEAK_CHECK ctst_freeAll(); /* To check for leaks */ u_cleanup(); /* nuke the hashtable.. so that any still-open cnvs are leaked */ if(getTestOption(VERBOSITY_OPTION) && ctst_allocated_total>0) { fprintf(stderr,"ctst_freeAll(): cleaned up after %d allocations (queue of %d)\n", ctst_allocated_total, CTST_MAX_ALLOC); } #ifdef URES_DEBUG if(ures_dumpCacheContents()) { fprintf(stderr, "Error: After final u_cleanup, RB cache was not empty.\n"); nerrors++; } else { fprintf(stderr,"OK: After final u_cleanup, RB cache was empty.\n"); } #endif #endif } /* End of loop that repeats the entire test, if requested. (Normally doesn't loop) */ #ifdef UNISTR_COUNT_FINAL_STRING_LENGTHS unistr_printLengths(); #endif endTime = uprv_getRawUTCtime(); diffTime = (int32_t)(endTime - startTime); printf("Elapsed Time: %02d:%02d:%02d.%03d\n", (int)((diffTime%U_MILLIS_PER_DAY)/U_MILLIS_PER_HOUR), (int)((diffTime%U_MILLIS_PER_HOUR)/U_MILLIS_PER_MINUTE), (int)((diffTime%U_MILLIS_PER_MINUTE)/U_MILLIS_PER_SECOND), (int)(diffTime%U_MILLIS_PER_SECOND)); return nerrors ? 1 : 0; }