summaryrefslogtreecommitdiff
path: root/thirdparty/icu4c/common/ucurr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/icu4c/common/ucurr.cpp')
-rw-r--r--thirdparty/icu4c/common/ucurr.cpp91
1 files changed, 58 insertions, 33 deletions
diff --git a/thirdparty/icu4c/common/ucurr.cpp b/thirdparty/icu4c/common/ucurr.cpp
index 6e489e0563..928d049fb5 100644
--- a/thirdparty/icu4c/common/ucurr.cpp
+++ b/thirdparty/icu4c/common/ucurr.cpp
@@ -97,11 +97,11 @@ static const char CURRENCYPLURALS[] = "CurrencyPlurals";
// ISO codes mapping table
static const UHashtable* gIsoCodes = NULL;
-static icu::UInitOnce gIsoCodesInitOnce = U_INITONCE_INITIALIZER;
+static icu::UInitOnce gIsoCodesInitOnce {};
// Currency symbol equivalances
static const icu::Hashtable* gCurrSymbolsEquiv = NULL;
-static icu::UInitOnce gCurrSymbolsEquivInitOnce = U_INITONCE_INITIALIZER;
+static icu::UInitOnce gCurrSymbolsEquivInitOnce {};
U_NAMESPACE_BEGIN
@@ -238,7 +238,7 @@ isoCodes_cleanup(void)
gIsoCodes = NULL;
}
gIsoCodesInitOnce.reset();
- return TRUE;
+ return true;
}
/**
@@ -250,7 +250,7 @@ currSymbolsEquiv_cleanup(void)
delete const_cast<icu::Hashtable *>(gCurrSymbolsEquiv);
gCurrSymbolsEquiv = NULL;
gCurrSymbolsEquivInitOnce.reset();
- return TRUE;
+ return true;
}
/**
@@ -349,7 +349,7 @@ _findMetaData(const UChar* currency, UErrorCode& ec) {
static void
idForLocale(const char* locale, char* countryAndVariant, int capacity, UErrorCode* ec)
{
- ulocimp_getRegionForSupplementalData(locale, FALSE, countryAndVariant, capacity, ec);
+ ulocimp_getRegionForSupplementalData(locale, false, countryAndVariant, capacity, ec);
}
// ------------------------------------------
@@ -409,7 +409,7 @@ struct CReg : public icu::UMemory {
}
static UBool unreg(UCurrRegistryKey key) {
- UBool found = FALSE;
+ UBool found = false;
umtx_lock(&gCRegLock);
CReg** p = &gCRegHead;
@@ -417,7 +417,7 @@ struct CReg : public icu::UMemory {
if (*p == key) {
*p = ((CReg*)key)->next;
delete (CReg*)key;
- found = TRUE;
+ found = true;
break;
}
p = &((*p)->next);
@@ -476,7 +476,7 @@ ucurr_unregister(UCurrRegistryKey key, UErrorCode* status)
if (status && U_SUCCESS(*status)) {
return CReg::unreg(key);
}
- return FALSE;
+ return false;
}
#endif /* UCONFIG_NO_SERVICE */
@@ -503,7 +503,7 @@ static UBool U_CALLCONV currency_cleanup(void) {
isoCodes_cleanup();
currSymbolsEquiv_cleanup();
- return TRUE;
+ return true;
}
U_CDECL_END
@@ -566,9 +566,32 @@ ucurr_forLocale(const char* locale,
UResourceBundle *rb = ures_openDirect(U_ICUDATA_CURR, CURRENCY_DATA, &localStatus);
UResourceBundle *cm = ures_getByKey(rb, CURRENCY_MAP, rb, &localStatus);
UResourceBundle *countryArray = ures_getByKey(rb, id, cm, &localStatus);
- UResourceBundle *currencyReq = ures_getByIndex(countryArray, 0, NULL, &localStatus);
- s = ures_getStringByKey(currencyReq, "id", &resLen, &localStatus);
- ures_close(currencyReq);
+ // https://unicode-org.atlassian.net/browse/ICU-21997
+ // Prefer to use currencies that are legal tender.
+ if (U_SUCCESS(localStatus)) {
+ int32_t arrayLength = ures_getSize(countryArray);
+ for (int32_t i = 0; i < arrayLength; ++i) {
+ LocalUResourceBundlePointer currencyReq(
+ ures_getByIndex(countryArray, i, nullptr, &localStatus));
+ // The currency is legal tender if it is *not* marked with tender{"false"}.
+ UErrorCode tenderStatus = localStatus;
+ const UChar *tender =
+ ures_getStringByKey(currencyReq.getAlias(), "tender", nullptr, &tenderStatus);
+ bool isTender = U_FAILURE(tenderStatus) || u_strcmp(tender, u"false") != 0;
+ if (!isTender && s != nullptr) {
+ // We already have a non-tender currency. Ignore all following non-tender ones.
+ continue;
+ }
+ // Fetch the currency code.
+ s = ures_getStringByKey(currencyReq.getAlias(), "id", &resLen, &localStatus);
+ if (isTender) {
+ break;
+ }
+ }
+ if (U_SUCCESS(localStatus) && s == nullptr) {
+ localStatus = U_MISSING_RESOURCE_ERROR;
+ }
+ }
ures_close(countryArray);
}
@@ -598,12 +621,12 @@ ucurr_forLocale(const char* locale,
* Modify the given locale name by removing the rightmost _-delimited
* element. If there is none, empty the string ("" == root).
* NOTE: The string "root" is not recognized; do not use it.
- * @return TRUE if the fallback happened; FALSE if locale is already
+ * @return true if the fallback happened; false if locale is already
* root ("").
*/
static UBool fallback(char *loc) {
if (!*loc) {
- return FALSE;
+ return false;
}
UErrorCode status = U_ZERO_ERROR;
if (uprv_strcmp(loc, "en_GB") == 0) {
@@ -623,7 +646,7 @@ static UBool fallback(char *loc) {
}
*i = 0;
*/
- return TRUE;
+ return true;
}
@@ -729,7 +752,7 @@ ucurr_getName(const UChar* currency,
// We no longer support choice format data in names. Data should not contain
// choice patterns.
if (isChoiceFormat != NULL) {
- *isChoiceFormat = FALSE;
+ *isChoiceFormat = false;
}
if (U_SUCCESS(ec2)) {
U_ASSERT(s != NULL);
@@ -896,7 +919,7 @@ getCurrencyNameCount(const char* loc, int32_t* total_currency_name_count, int32_
s = ures_getStringByIndex(names, UCURR_SYMBOL_NAME, &len, &ec2);
++(*total_currency_symbol_count); // currency symbol
if (currencySymbolsEquiv != NULL) {
- *total_currency_symbol_count += countEquivalent(*currencySymbolsEquiv, UnicodeString(TRUE, s, len));
+ *total_currency_symbol_count += countEquivalent(*currencySymbolsEquiv, UnicodeString(true, s, len));
}
++(*total_currency_symbol_count); // iso code
++(*total_currency_name_count); // long name
@@ -1017,7 +1040,7 @@ collectCurrencyNames(const char* locale,
(*currencySymbols)[(*total_currency_symbol_count)++].currencyNameLen = len;
// Add equivalent symbols
if (currencySymbolsEquiv != NULL) {
- UnicodeString str(TRUE, s, len);
+ UnicodeString str(true, s, len);
icu::EquivIterator iter(*currencySymbolsEquiv, str);
const UnicodeString *symbol;
while ((symbol = iter.next()) != NULL) {
@@ -1401,7 +1424,7 @@ currency_cache_cleanup(void) {
currCache[i] = 0;
}
}
- return TRUE;
+ return true;
}
@@ -1928,6 +1951,7 @@ static const struct CurrencyList {
{"SHP", UCURR_COMMON|UCURR_NON_DEPRECATED},
{"SIT", UCURR_COMMON|UCURR_DEPRECATED},
{"SKK", UCURR_COMMON|UCURR_DEPRECATED},
+ {"SLE", UCURR_COMMON|UCURR_NON_DEPRECATED},
{"SLL", UCURR_COMMON|UCURR_NON_DEPRECATED},
{"SOS", UCURR_COMMON|UCURR_NON_DEPRECATED},
{"SRD", UCURR_COMMON|UCURR_NON_DEPRECATED},
@@ -1965,6 +1989,7 @@ static const struct CurrencyList {
{"UYW", UCURR_UNCOMMON|UCURR_NON_DEPRECATED},
{"UZS", UCURR_COMMON|UCURR_NON_DEPRECATED},
{"VEB", UCURR_COMMON|UCURR_DEPRECATED},
+ {"VED", UCURR_UNCOMMON|UCURR_NON_DEPRECATED},
{"VEF", UCURR_COMMON|UCURR_NON_DEPRECATED},
{"VES", UCURR_COMMON|UCURR_NON_DEPRECATED},
{"VND", UCURR_COMMON|UCURR_NON_DEPRECATED},
@@ -2220,19 +2245,19 @@ U_CAPI UBool U_EXPORT2
ucurr_isAvailable(const UChar* isoCode, UDate from, UDate to, UErrorCode* eErrorCode) {
umtx_initOnce(gIsoCodesInitOnce, &initIsoCodes, *eErrorCode);
if (U_FAILURE(*eErrorCode)) {
- return FALSE;
+ return false;
}
IsoCodeEntry* result = (IsoCodeEntry *) uhash_get(gIsoCodes, isoCode);
if (result == NULL) {
- return FALSE;
+ return false;
} else if (from > to) {
*eErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
- return FALSE;
+ return false;
} else if ((from > result->to) || (to < result->from)) {
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
static const icu::Hashtable* getCurrSymbolsEquiv() {
@@ -2537,7 +2562,7 @@ static const UEnumeration defaultKeywordValues = {
U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key, const char *locale, UBool commonlyUsed, UErrorCode* status) {
// Resolve region
char prefRegion[ULOC_COUNTRY_CAPACITY];
- ulocimp_getRegionForSupplementalData(locale, TRUE, prefRegion, sizeof(prefRegion), status);
+ ulocimp_getRegionForSupplementalData(locale, true, prefRegion, sizeof(prefRegion), status);
// Read value from supplementalData
UList *values = ulist_createEmptyList(status);
@@ -2570,7 +2595,7 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
break;
}
const char *region = ures_getKey(&bundlekey);
- UBool isPrefRegion = uprv_strcmp(region, prefRegion) == 0 ? TRUE : FALSE;
+ UBool isPrefRegion = uprv_strcmp(region, prefRegion) == 0 ? true : false;
if (!isPrefRegion && commonlyUsed) {
// With commonlyUsed=true, we do not put
// currencies for other regions in the
@@ -2595,7 +2620,7 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
}
#if U_CHARSET_FAMILY==U_ASCII_FAMILY
- ures_getUTF8StringByKey(&curbndl, "id", curID, &curIDLength, TRUE, status);
+ ures_getUTF8StringByKey(&curbndl, "id", curID, &curIDLength, true, status);
/* optimize - use the utf-8 string */
#else
{
@@ -2613,19 +2638,19 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
if (U_FAILURE(*status)) {
break;
}
- UBool hasTo = FALSE;
+ UBool hasTo = false;
ures_getByKey(&curbndl, "to", &to, status);
if (U_FAILURE(*status)) {
// Do nothing here...
*status = U_ZERO_ERROR;
} else {
- hasTo = TRUE;
+ hasTo = true;
}
if (isPrefRegion && !hasTo && !ulist_containsString(values, curID, (int32_t)uprv_strlen(curID))) {
// Currently active currency for the target country
- ulist_addItemEndList(values, curID, TRUE, status);
+ ulist_addItemEndList(values, curID, true, status);
} else if (!ulist_containsString(otherValues, curID, (int32_t)uprv_strlen(curID)) && !commonlyUsed) {
- ulist_addItemEndList(otherValues, curID, TRUE, status);
+ ulist_addItemEndList(otherValues, curID, true, status);
} else {
uprv_free(curID);
}
@@ -2638,7 +2663,7 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
// This could happen if no valid region is supplied in the input
// locale. In this case, we use the CLDR's default.
uenum_close(en);
- en = ucurr_getKeywordValuesForLocale(key, "und", TRUE, status);
+ en = ucurr_getKeywordValuesForLocale(key, "und", true, status);
}
} else {
// Consolidate the list
@@ -2648,7 +2673,7 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
if (!ulist_containsString(values, value, (int32_t)uprv_strlen(value))) {
char *tmpValue = (char *)uprv_malloc(sizeof(char) * ULOC_KEYWORDS_CAPACITY);
uprv_memcpy(tmpValue, value, uprv_strlen(value) + 1);
- ulist_addItemEndList(values, tmpValue, TRUE, status);
+ ulist_addItemEndList(values, tmpValue, true, status);
if (U_FAILURE(*status)) {
break;
}