static int32_t checkItemCount(uint32_t currencyType) { UErrorCode status = U_ZERO_ERROR; int32_t originalCount, count; UEnumeration *en = ucurr_openISOCurrencies(currencyType, &status); int32_t expectedLen = 3, len; if (U_FAILURE(status)) { log_err("Error: ucurr_openISOCurrencies returned %s\n", myErrorName(status)); return -1; } originalCount = uenum_count(en, &status); for (count=0;;count++) { const char *str = uenum_next(en, &len, &status); if (str == NULL || len != expectedLen || strlen(str) != expectedLen) { break; } } if (originalCount != count) { log_err("Error: uenum_count returned the wrong value (type = 0x%X). Got: %d Expected %d\n", currencyType, count, originalCount); } if (U_FAILURE(status)) { log_err("Error: uenum_next got an error: %s\n", u_errorName(status)); } uenum_close(en); return count; }
CFArrayRef CFLocaleCopyCommonISOCurrencyCodes(void) { UErrorCode icuStatus = U_ZERO_ERROR; UEnumeration *enumer = ucurr_openISOCurrencies(UCURR_COMMON|UCURR_NON_DEPRECATED, &icuStatus); CFArrayRef result = __CFLocaleCopyUEnumerationAsArray(enumer, &icuStatus); uenum_close(enumer); return result; }
static jobject ICU_getAvailableCurrencyCodes(JNIEnv* env, jclass) { UErrorCode status = U_ZERO_ERROR; UEnumeration* e(ucurr_openISOCurrencies(UCURR_COMMON|UCURR_NON_DEPRECATED, &status)); EnumerationCounter counter(uenum_count(e, &status)); EnumerationGetter getter(e, &status); jobject result = toStringArray16(env, &counter, &getter); maybeThrowIcuException(env, status); uenum_close(e); return result; }
bool PaymentRequestValidator::validateCurrencyCode(const String& currencyCode) const { if (!currencyCode) { m_window.printErrorMessage("Missing currency code."); return false; } UErrorCode errorCode = U_ZERO_ERROR; auto currencyCodes = std::unique_ptr<UEnumeration, void (*)(UEnumeration*)>(ucurr_openISOCurrencies(UCURR_ALL, &errorCode), uenum_close); int32_t length; while (auto *currencyCodePtr = uenum_next(currencyCodes.get(), &length, &errorCode)) { if (currencyCodePtr == currencyCode) return true; } auto message = makeString("\"" + currencyCode, "\" is not a valid currency code."); m_window.printErrorMessage(message); return false; }
static void TestEnumListReset(void) { UErrorCode status = U_ZERO_ERROR; const char *currency1; const char *currency2; UEnumeration *en = ucurr_openISOCurrencies(UCURR_ALL, &status); if (U_FAILURE(status)) { log_err("Error: ucurr_openISOCurrencies returned %s\n", myErrorName(status)); return; } currency1 = uenum_next(en, NULL, &status); uenum_reset(en, &status); currency2 = uenum_next(en, NULL, &status); if (U_FAILURE(status)) { log_err("Error: uenum_next or uenum_reset returned %s\n", myErrorName(status)); return; } /* The first item's pointer in the list should be the same between resets. */ if (currency1 != currency2) { log_err("Error: reset doesn't work %s != %s\n", currency1, currency2); } uenum_close(en); }
static void expectInList(const char *isoCurrency, uint32_t currencyType, UBool isExpected) { UErrorCode status = U_ZERO_ERROR; const char *foundCurrency = NULL; const char *currentCurrency; UEnumeration *en = ucurr_openISOCurrencies(currencyType, &status); if (U_FAILURE(status)) { log_err("Error: ucurr_openISOCurrencies returned %s\n", myErrorName(status)); return; } while ((currentCurrency = uenum_next(en, NULL, &status)) != NULL) { if (strcmp(isoCurrency, currentCurrency) == 0) { foundCurrency = currentCurrency; break; } } if ((foundCurrency != NULL) != isExpected) { log_err("Error: could not find %s as expected. isExpected = %s type=0x%X\n", isoCurrency, isExpected ? "TRUE" : "FALSE", currencyType); } uenum_close(en); }
static jobject ICU_getAvailableCurrencyCodes(JNIEnv* env, jclass) { UErrorCode status = U_ZERO_ERROR; UStringEnumeration e(ucurr_openISOCurrencies(UCURR_COMMON|UCURR_NON_DEPRECATED, &status)); return fromStringEnumeration(env, status, "ucurr_openISOCurrencies", &e); }