diff options
author | mcheshkov <mcheshkov@yandex-team.ru> | 2022-02-10 16:46:16 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:16 +0300 |
commit | 1312621288956f199a5bd5342b0133d4395fa725 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/libs/icu/common/ucurr.cpp | |
parent | e9d19cec64684c9c1e6b0c98297e5b895cf904fe (diff) | |
download | ydb-1312621288956f199a5bd5342b0133d4395fa725.tar.gz |
Restoring authorship annotation for <mcheshkov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/icu/common/ucurr.cpp')
-rw-r--r-- | contrib/libs/icu/common/ucurr.cpp | 512 |
1 files changed, 256 insertions, 256 deletions
diff --git a/contrib/libs/icu/common/ucurr.cpp b/contrib/libs/icu/common/ucurr.cpp index 665424a0f2..5eacc4a99b 100644 --- a/contrib/libs/icu/common/ucurr.cpp +++ b/contrib/libs/icu/common/ucurr.cpp @@ -1,4 +1,4 @@ -// © 2016 and later: Unicode, Inc. and others. +// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ********************************************************************** @@ -16,29 +16,29 @@ #include "unicode/ures.h" #include "unicode/ustring.h" #include "unicode/parsepos.h" -#include "unicode/uniset.h" -#include "unicode/usetiter.h" -#include "unicode/utf16.h" +#include "unicode/uniset.h" +#include "unicode/usetiter.h" +#include "unicode/utf16.h" #include "ustr_imp.h" -#include "charstr.h" +#include "charstr.h" #include "cmemory.h" #include "cstring.h" -#include "static_unicode_sets.h" +#include "static_unicode_sets.h" #include "uassert.h" #include "umutex.h" #include "ucln_cmn.h" #include "uenumimp.h" #include "uhash.h" #include "hash.h" -#include "uinvchar.h" +#include "uinvchar.h" #include "uresimp.h" #include "ulist.h" -#include "uresimp.h" +#include "uresimp.h" #include "ureslocs.h" #include "ulocimp.h" -using namespace icu; - +using namespace icu; + //#define UCURR_DEBUG_EQUIV 1 #ifdef UCURR_DEBUG_EQUIV #include "stdio.h" @@ -90,7 +90,7 @@ static const char VAR_DELIM = '_'; // Tag for localized display names (symbols) of currencies static const char CURRENCIES[] = "Currencies"; -static const char CURRENCIES_NARROW[] = "Currencies%narrow"; +static const char CURRENCIES_NARROW[] = "Currencies%narrow"; static const char CURRENCYPLURALS[] = "CurrencyPlurals"; // ISO codes mapping table @@ -344,7 +344,7 @@ _findMetaData(const UChar* currency, UErrorCode& ec) { // ------------------------------------- -static void +static void idForLocale(const char* locale, char* countryAndVariant, int capacity, UErrorCode* ec) { ulocimp_getRegionForSupplementalData(locale, FALSE, countryAndVariant, capacity, ec); @@ -365,7 +365,7 @@ U_CDECL_END #if !UCONFIG_NO_SERVICE struct CReg; -static UMutex gCRegLock; +static UMutex gCRegLock; static CReg* gCRegHead = 0; struct CReg : public icu::UMemory { @@ -511,83 +511,83 @@ U_CAPI int32_t U_EXPORT2 ucurr_forLocale(const char* locale, UChar* buff, int32_t buffCapacity, - UErrorCode* ec) { - if (U_FAILURE(*ec)) { return 0; } - if (buffCapacity < 0 || (buff == nullptr && buffCapacity > 0)) { - *ec = U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } + UErrorCode* ec) { + if (U_FAILURE(*ec)) { return 0; } + if (buffCapacity < 0 || (buff == nullptr && buffCapacity > 0)) { + *ec = U_ILLEGAL_ARGUMENT_ERROR; + return 0; + } - char currency[4]; // ISO currency codes are alpha3 codes. - UErrorCode localStatus = U_ZERO_ERROR; - int32_t resLen = uloc_getKeywordValue(locale, "currency", - currency, UPRV_LENGTHOF(currency), &localStatus); - if (U_SUCCESS(localStatus) && resLen == 3 && uprv_isInvariantString(currency, resLen)) { - if (resLen < buffCapacity) { - T_CString_toUpperCase(currency); - u_charsToUChars(currency, buff, resLen); - } - return u_terminateUChars(buff, buffCapacity, resLen, ec); - } + char currency[4]; // ISO currency codes are alpha3 codes. + UErrorCode localStatus = U_ZERO_ERROR; + int32_t resLen = uloc_getKeywordValue(locale, "currency", + currency, UPRV_LENGTHOF(currency), &localStatus); + if (U_SUCCESS(localStatus) && resLen == 3 && uprv_isInvariantString(currency, resLen)) { + if (resLen < buffCapacity) { + T_CString_toUpperCase(currency); + u_charsToUChars(currency, buff, resLen); + } + return u_terminateUChars(buff, buffCapacity, resLen, ec); + } + + // get country or country_variant in `id' + char id[ULOC_FULLNAME_CAPACITY]; + idForLocale(locale, id, UPRV_LENGTHOF(id), ec); + if (U_FAILURE(*ec)) { + return 0; + } - // get country or country_variant in `id' - char id[ULOC_FULLNAME_CAPACITY]; - idForLocale(locale, id, UPRV_LENGTHOF(id), ec); - if (U_FAILURE(*ec)) { - return 0; - } - #if !UCONFIG_NO_SERVICE - const UChar* result = CReg::get(id); - if (result) { - if(buffCapacity > u_strlen(result)) { - u_strcpy(buff, result); - } - resLen = u_strlen(result); - return u_terminateUChars(buff, buffCapacity, resLen, ec); - } + const UChar* result = CReg::get(id); + if (result) { + if(buffCapacity > u_strlen(result)) { + u_strcpy(buff, result); + } + resLen = u_strlen(result); + return u_terminateUChars(buff, buffCapacity, resLen, ec); + } #endif - // Remove variants, which is only needed for registration. - char *idDelim = uprv_strchr(id, VAR_DELIM); - if (idDelim) { - idDelim[0] = 0; - } + // Remove variants, which is only needed for registration. + char *idDelim = uprv_strchr(id, VAR_DELIM); + if (idDelim) { + idDelim[0] = 0; + } - const UChar* s = NULL; // Currency code from data file. - if (id[0] == 0) { - // No point looking in the data for an empty string. - // This is what we would get. - localStatus = U_MISSING_RESOURCE_ERROR; - } else { - // Look up the CurrencyMap element in the root bundle. - localStatus = U_ZERO_ERROR; - 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); - ures_close(countryArray); - } + const UChar* s = NULL; // Currency code from data file. + if (id[0] == 0) { + // No point looking in the data for an empty string. + // This is what we would get. + localStatus = U_MISSING_RESOURCE_ERROR; + } else { + // Look up the CurrencyMap element in the root bundle. + localStatus = U_ZERO_ERROR; + 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); + ures_close(countryArray); + } - if ((U_FAILURE(localStatus)) && strchr(id, '_') != 0) { - // We don't know about it. Check to see if we support the variant. - uloc_getParent(locale, id, UPRV_LENGTHOF(id), ec); - *ec = U_USING_FALLBACK_WARNING; - // TODO: Loop over the shortened id rather than recursing and - // looking again for a currency keyword. - return ucurr_forLocale(id, buff, buffCapacity, ec); - } - if (*ec == U_ZERO_ERROR || localStatus != U_ZERO_ERROR) { - // There is nothing to fallback to. Report the failure/warning if possible. - *ec = localStatus; - } - if (U_SUCCESS(*ec)) { - if(buffCapacity > resLen) { - u_strcpy(buff, s); + if ((U_FAILURE(localStatus)) && strchr(id, '_') != 0) { + // We don't know about it. Check to see if we support the variant. + uloc_getParent(locale, id, UPRV_LENGTHOF(id), ec); + *ec = U_USING_FALLBACK_WARNING; + // TODO: Loop over the shortened id rather than recursing and + // looking again for a currency keyword. + return ucurr_forLocale(id, buff, buffCapacity, ec); + } + if (*ec == U_ZERO_ERROR || localStatus != U_ZERO_ERROR) { + // There is nothing to fallback to. Report the failure/warning if possible. + *ec = localStatus; + } + if (U_SUCCESS(*ec)) { + if(buffCapacity > resLen) { + u_strcpy(buff, s); } } - return u_terminateUChars(buff, buffCapacity, resLen, ec); + return u_terminateUChars(buff, buffCapacity, resLen, ec); } // end registration @@ -604,16 +604,16 @@ static UBool fallback(char *loc) { return FALSE; } UErrorCode status = U_ZERO_ERROR; - if (uprv_strcmp(loc, "en_GB") == 0) { - // HACK: See #13368. We need "en_GB" to fall back to "en_001" instead of "en" - // in order to consume the correct data strings. This hack will be removed - // when proper data sink loading is implemented here. - // NOTE: "001" adds 1 char over "GB". However, both call sites allocate - // arrays with length ULOC_FULLNAME_CAPACITY (plenty of room for en_001). - uprv_strcpy(loc + 3, "001"); - } else { - uloc_getParent(loc, loc, (int32_t)uprv_strlen(loc), &status); - } + if (uprv_strcmp(loc, "en_GB") == 0) { + // HACK: See #13368. We need "en_GB" to fall back to "en_001" instead of "en" + // in order to consume the correct data strings. This hack will be removed + // when proper data sink loading is implemented here. + // NOTE: "001" adds 1 char over "GB". However, both call sites allocate + // arrays with length ULOC_FULLNAME_CAPACITY (plenty of room for en_001). + uprv_strcpy(loc + 3, "001"); + } else { + uloc_getParent(loc, loc, (int32_t)uprv_strlen(loc), &status); + } /* char *i = uprv_strrchr(loc, '_'); if (i == NULL) { @@ -649,7 +649,7 @@ ucurr_getName(const UChar* currency, } int32_t choice = (int32_t) nameStyle; - if (choice < 0 || choice > 2) { + if (choice < 0 || choice > 2) { *ec = U_ILLEGAL_ARGUMENT_ERROR; return 0; } @@ -682,25 +682,25 @@ ucurr_getName(const UChar* currency, const UChar* s = NULL; ec2 = U_ZERO_ERROR; - LocalUResourceBundlePointer rb(ures_open(U_ICUDATA_CURR, loc, &ec2)); - - if (nameStyle == UCURR_NARROW_SYMBOL_NAME) { - CharString key; - key.append(CURRENCIES_NARROW, ec2); - key.append("/", ec2); - key.append(buf, ec2); - s = ures_getStringByKeyWithFallback(rb.getAlias(), key.data(), len, &ec2); - if (ec2 == U_MISSING_RESOURCE_ERROR) { - *ec = U_USING_FALLBACK_WARNING; - ec2 = U_ZERO_ERROR; - choice = UCURR_SYMBOL_NAME; - } - } - if (s == NULL) { - ures_getByKey(rb.getAlias(), CURRENCIES, rb.getAlias(), &ec2); - ures_getByKeyWithFallback(rb.getAlias(), buf, rb.getAlias(), &ec2); - s = ures_getStringByIndex(rb.getAlias(), choice, len, &ec2); - } + LocalUResourceBundlePointer rb(ures_open(U_ICUDATA_CURR, loc, &ec2)); + + if (nameStyle == UCURR_NARROW_SYMBOL_NAME) { + CharString key; + key.append(CURRENCIES_NARROW, ec2); + key.append("/", ec2); + key.append(buf, ec2); + s = ures_getStringByKeyWithFallback(rb.getAlias(), key.data(), len, &ec2); + if (ec2 == U_MISSING_RESOURCE_ERROR) { + *ec = U_USING_FALLBACK_WARNING; + ec2 = U_ZERO_ERROR; + choice = UCURR_SYMBOL_NAME; + } + } + if (s == NULL) { + ures_getByKey(rb.getAlias(), CURRENCIES, rb.getAlias(), &ec2); + ures_getByKeyWithFallback(rb.getAlias(), buf, rb.getAlias(), &ec2); + s = ures_getStringByIndex(rb.getAlias(), choice, len, &ec2); + } // If we've succeeded we're done. Otherwise, try to fallback. // If that fails (because we are already at root) then exit. @@ -713,9 +713,9 @@ 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; - } + if (isChoiceFormat != NULL) { + *isChoiceFormat = FALSE; + } if (U_SUCCESS(ec2)) { U_ASSERT(s != NULL); return s; @@ -866,7 +866,7 @@ getCurrencyNameCount(const char* loc, int32_t* total_currency_name_count, int32_ *total_currency_name_count = 0; *total_currency_symbol_count = 0; const UChar* s = NULL; - char locale[ULOC_FULLNAME_CAPACITY] = ""; + char locale[ULOC_FULLNAME_CAPACITY] = ""; uprv_strcpy(locale, loc); const icu::Hashtable *currencySymbolsEquiv = getCurrSymbolsEquiv(); for (;;) { @@ -941,7 +941,7 @@ collectCurrencyNames(const char* locale, // Look up the Currencies resource for the given locale. UErrorCode ec2 = U_ZERO_ERROR; - char loc[ULOC_FULLNAME_CAPACITY] = ""; + char loc[ULOC_FULLNAME_CAPACITY] = ""; uloc_getName(locale, loc, sizeof(loc), &ec2); if (U_FAILURE(ec2) || ec2 == U_STRING_NOT_TERMINATED_WARNING) { ec = U_ILLEGAL_ARGUMENT_ERROR; @@ -1007,8 +1007,8 @@ collectCurrencyNames(const char* locale, const UnicodeString *symbol; while ((symbol = iter.next()) != NULL) { (*currencySymbols)[*total_currency_symbol_count].IsoCode = iso; - (*currencySymbols)[*total_currency_symbol_count].currencyName = - const_cast<UChar*>(symbol->getBuffer()); + (*currencySymbols)[*total_currency_symbol_count].currencyName = + const_cast<UChar*>(symbol->getBuffer()); (*currencySymbols)[*total_currency_symbol_count].flag = 0; (*currencySymbols)[(*total_currency_symbol_count)++].currencyNameLen = symbol->length(); } @@ -1035,11 +1035,11 @@ collectCurrencyNames(const char* locale, } // currency plurals - UErrorCode ec5 = U_ZERO_ERROR; - UResourceBundle* curr_p = ures_getByKey(rb, CURRENCYPLURALS, NULL, &ec5); + UErrorCode ec5 = U_ZERO_ERROR; + UResourceBundle* curr_p = ures_getByKey(rb, CURRENCYPLURALS, NULL, &ec5); n = ures_getSize(curr_p); for (int32_t i=0; i<n; ++i) { - UResourceBundle* names = ures_getByIndex(curr_p, i, NULL, &ec5); + UResourceBundle* names = ures_getByIndex(curr_p, i, NULL, &ec5); iso = (char*)ures_getKey(names); // Using hash to remove duplicated ISO codes in fallback chain. if (localeLevel == 0) { @@ -1057,7 +1057,7 @@ collectCurrencyNames(const char* locale, for (int32_t j = 0; j < num; ++j) { // TODO: remove duplicates between singular name and // currency long name? - s = ures_getStringByIndex(names, j, &len, &ec5); + s = ures_getStringByIndex(names, j, &len, &ec5); (*currencyNames)[*total_currency_name_count].IsoCode = iso; UChar* upperName = toUpperCase(s, len, locale); (*currencyNames)[*total_currency_name_count].currencyName = upperName; @@ -1241,28 +1241,28 @@ static void linearSearch(const CurrencyNameStruct* currencyNames, int32_t begin, int32_t end, const UChar* text, int32_t textLen, - int32_t *partialMatchLen, + int32_t *partialMatchLen, int32_t *maxMatchLen, int32_t* maxMatchIndex) { - int32_t initialPartialMatchLen = *partialMatchLen; + int32_t initialPartialMatchLen = *partialMatchLen; for (int32_t index = begin; index <= end; ++index) { int32_t len = currencyNames[index].currencyNameLen; if (len > *maxMatchLen && len <= textLen && uprv_memcmp(currencyNames[index].currencyName, text, len * sizeof(UChar)) == 0) { - *partialMatchLen = MAX(*partialMatchLen, len); + *partialMatchLen = MAX(*partialMatchLen, len); *maxMatchIndex = index; *maxMatchLen = len; #ifdef UCURR_DEBUG printf("maxMatchIndex = %d, maxMatchLen = %d\n", *maxMatchIndex, *maxMatchLen); #endif - } else { - // Check for partial matches. - for (int32_t i=initialPartialMatchLen; i<MIN(len, textLen); i++) { - if (currencyNames[index].currencyName[i] != text[i]) { - break; - } - *partialMatchLen = MAX(*partialMatchLen, i + 1); - } + } else { + // Check for partial matches. + for (int32_t i=initialPartialMatchLen; i<MIN(len, textLen); i++) { + if (currencyNames[index].currencyName[i] != text[i]) { + break; + } + *partialMatchLen = MAX(*partialMatchLen, i + 1); + } } } } @@ -1279,8 +1279,8 @@ linearSearch(const CurrencyNameStruct* currencyNames, static void searchCurrencyName(const CurrencyNameStruct* currencyNames, int32_t total_currency_count, - const UChar* text, int32_t textLen, - int32_t *partialMatchLen, + const UChar* text, int32_t textLen, + int32_t *partialMatchLen, int32_t* maxMatchLen, int32_t* maxMatchIndex) { *maxMatchIndex = -1; *maxMatchLen = 0; @@ -1310,7 +1310,7 @@ searchCurrencyName(const CurrencyNameStruct* currencyNames, if (binarySearchBegin == -1) { // did not find the range break; } - *partialMatchLen = MAX(*partialMatchLen, index + 1); + *partialMatchLen = MAX(*partialMatchLen, index + 1); if (matchIndex != -1) { // find an exact match for text from text[0] to text[index] // in currencyNames array. @@ -1321,7 +1321,7 @@ searchCurrencyName(const CurrencyNameStruct* currencyNames, // linear search if within threshold. linearSearch(currencyNames, binarySearchBegin, binarySearchEnd, text, textLen, - partialMatchLen, + partialMatchLen, maxMatchLen, maxMatchIndex); break; } @@ -1355,7 +1355,7 @@ static CurrencyNameCacheEntry* currCache[CURRENCY_NAME_CACHE_NUM] = {NULL}; // It is a simple round-robin replacement strategy. static int8_t currentCacheEntryIndex = 0; -static UMutex gCurrencyCacheMutex; +static UMutex gCurrencyCacheMutex; // Cache deletion static void @@ -1390,13 +1390,13 @@ currency_cache_cleanup(void) { } -/** - * Loads the currency name data from the cache, or from resource bundles if necessary. - * The refCount is automatically incremented. It is the caller's responsibility - * to decrement it when done! - */ -static CurrencyNameCacheEntry* -getCacheEntry(const char* locale, UErrorCode& ec) { +/** + * Loads the currency name data from the cache, or from resource bundles if necessary. + * The refCount is automatically incremented. It is the caller's responsibility + * to decrement it when done! + */ +static CurrencyNameCacheEntry* +getCacheEntry(const char* locale, UErrorCode& ec) { int32_t total_currency_name_count = 0; CurrencyNameStruct* currencyNames = NULL; @@ -1407,7 +1407,7 @@ getCacheEntry(const char* locale, UErrorCode& ec) { umtx_lock(&gCurrencyCacheMutex); // in order to handle racing correctly, // not putting 'search' in a separate function. - int8_t found = -1; + int8_t found = -1; for (int8_t i = 0; i < CURRENCY_NAME_CACHE_NUM; ++i) { if (currCache[i]!= NULL && uprv_strcmp(locale, currCache[i]->locale) == 0) { @@ -1423,7 +1423,7 @@ getCacheEntry(const char* locale, UErrorCode& ec) { if (found == -1) { collectCurrencyNames(locale, ¤cyNames, &total_currency_name_count, ¤cySymbols, &total_currency_symbol_count, ec); if (U_FAILURE(ec)) { - return NULL; + return NULL; } umtx_lock(&gCurrencyCacheMutex); // check again. @@ -1457,7 +1457,7 @@ getCacheEntry(const char* locale, UErrorCode& ec) { cacheEntry->totalCurrencySymbolCount = total_currency_symbol_count; cacheEntry->refCount = 2; // one for cache, one for reference currentCacheEntryIndex = (currentCacheEntryIndex + 1) % CURRENCY_NAME_CACHE_NUM; - ucln_common_registerCleanup(UCLN_COMMON_CURRENCY, currency_cleanup); + ucln_common_registerCleanup(UCLN_COMMON_CURRENCY, currency_cleanup); } else { deleteCurrencyNames(currencyNames, total_currency_name_count); deleteCurrencyNames(currencySymbols, total_currency_symbol_count); @@ -1467,40 +1467,40 @@ getCacheEntry(const char* locale, UErrorCode& ec) { umtx_unlock(&gCurrencyCacheMutex); } - return cacheEntry; -} - -static void releaseCacheEntry(CurrencyNameCacheEntry* cacheEntry) { - umtx_lock(&gCurrencyCacheMutex); - --(cacheEntry->refCount); - if (cacheEntry->refCount == 0) { // remove - deleteCacheEntry(cacheEntry); - } - umtx_unlock(&gCurrencyCacheMutex); -} - -U_CAPI void -uprv_parseCurrency(const char* locale, - const icu::UnicodeString& text, - icu::ParsePosition& pos, - int8_t type, - int32_t* partialMatchLen, - UChar* result, - UErrorCode& ec) { - U_NAMESPACE_USE - if (U_FAILURE(ec)) { - return; - } - CurrencyNameCacheEntry* cacheEntry = getCacheEntry(locale, ec); - if (U_FAILURE(ec)) { - return; - } - - int32_t total_currency_name_count = cacheEntry->totalCurrencyNameCount; - CurrencyNameStruct* currencyNames = cacheEntry->currencyNames; - int32_t total_currency_symbol_count = cacheEntry->totalCurrencySymbolCount; - CurrencyNameStruct* currencySymbols = cacheEntry->currencySymbols; - + return cacheEntry; +} + +static void releaseCacheEntry(CurrencyNameCacheEntry* cacheEntry) { + umtx_lock(&gCurrencyCacheMutex); + --(cacheEntry->refCount); + if (cacheEntry->refCount == 0) { // remove + deleteCacheEntry(cacheEntry); + } + umtx_unlock(&gCurrencyCacheMutex); +} + +U_CAPI void +uprv_parseCurrency(const char* locale, + const icu::UnicodeString& text, + icu::ParsePosition& pos, + int8_t type, + int32_t* partialMatchLen, + UChar* result, + UErrorCode& ec) { + U_NAMESPACE_USE + if (U_FAILURE(ec)) { + return; + } + CurrencyNameCacheEntry* cacheEntry = getCacheEntry(locale, ec); + if (U_FAILURE(ec)) { + return; + } + + int32_t total_currency_name_count = cacheEntry->totalCurrencyNameCount; + CurrencyNameStruct* currencyNames = cacheEntry->currencyNames; + int32_t total_currency_symbol_count = cacheEntry->totalCurrencySymbolCount; + CurrencyNameStruct* currencySymbols = cacheEntry->currencySymbols; + int32_t start = pos.getIndex(); UChar inputText[MAX_CURRENCY_NAME_LEN]; @@ -1510,14 +1510,14 @@ uprv_parseCurrency(const char* locale, UErrorCode ec1 = U_ZERO_ERROR; textLen = u_strToUpper(upperText, MAX_CURRENCY_NAME_LEN, inputText, textLen, locale, &ec1); - // Make sure partialMatchLen is initialized - *partialMatchLen = 0; - + // Make sure partialMatchLen is initialized + *partialMatchLen = 0; + int32_t max = 0; int32_t matchIndex = -1; // case in-sensitive comparision against currency names searchCurrencyName(currencyNames, total_currency_name_count, - upperText, textLen, partialMatchLen, &max, &matchIndex); + upperText, textLen, partialMatchLen, &max, &matchIndex); #ifdef UCURR_DEBUG printf("search in names, max = %d, matchIndex = %d\n", max, matchIndex); @@ -1528,8 +1528,8 @@ uprv_parseCurrency(const char* locale, if (type != UCURR_LONG_NAME) { // not name only // case sensitive comparison against currency symbols and ISO code. searchCurrencyName(currencySymbols, total_currency_symbol_count, - inputText, textLen, - partialMatchLen, + inputText, textLen, + partialMatchLen, &maxInSymbol, &matchIndexInSymbol); } @@ -1546,38 +1546,38 @@ uprv_parseCurrency(const char* locale, } else if (maxInSymbol >= max && matchIndexInSymbol != -1) { u_charsToUChars(currencySymbols[matchIndexInSymbol].IsoCode, result, 4); pos.setIndex(start + maxInSymbol); - } + } // decrease reference count - releaseCacheEntry(cacheEntry); -} - -void uprv_currencyLeads(const char* locale, icu::UnicodeSet& result, UErrorCode& ec) { - U_NAMESPACE_USE - if (U_FAILURE(ec)) { - return; - } - CurrencyNameCacheEntry* cacheEntry = getCacheEntry(locale, ec); - if (U_FAILURE(ec)) { - return; - } - - for (int32_t i=0; i<cacheEntry->totalCurrencySymbolCount; i++) { - const CurrencyNameStruct& info = cacheEntry->currencySymbols[i]; - UChar32 cp; - U16_GET(info.currencyName, 0, 0, info.currencyNameLen, cp); - result.add(cp); - } - - for (int32_t i=0; i<cacheEntry->totalCurrencyNameCount; i++) { - const CurrencyNameStruct& info = cacheEntry->currencyNames[i]; - UChar32 cp; - U16_GET(info.currencyName, 0, 0, info.currencyNameLen, cp); - result.add(cp); - } - - // decrease reference count - releaseCacheEntry(cacheEntry); + releaseCacheEntry(cacheEntry); +} + +void uprv_currencyLeads(const char* locale, icu::UnicodeSet& result, UErrorCode& ec) { + U_NAMESPACE_USE + if (U_FAILURE(ec)) { + return; + } + CurrencyNameCacheEntry* cacheEntry = getCacheEntry(locale, ec); + if (U_FAILURE(ec)) { + return; + } + + for (int32_t i=0; i<cacheEntry->totalCurrencySymbolCount; i++) { + const CurrencyNameStruct& info = cacheEntry->currencySymbols[i]; + UChar32 cp; + U16_GET(info.currencyName, 0, 0, info.currencyNameLen, cp); + result.add(cp); + } + + for (int32_t i=0; i<cacheEntry->totalCurrencyNameCount; i++) { + const CurrencyNameStruct& info = cacheEntry->currencyNames[i]; + UChar32 cp; + U16_GET(info.currencyName, 0, 0, info.currencyNameLen, cp); + result.add(cp); + } + + // decrease reference count + releaseCacheEntry(cacheEntry); } @@ -1599,7 +1599,7 @@ uprv_getStaticCurrencyName(const UChar* iso, const char* loc, int32_t len; const UChar* currname = ucurr_getName(iso, loc, UCURR_SYMBOL_NAME, - nullptr /* isChoiceFormat */, &len, &ec); + nullptr /* isChoiceFormat */, &len, &ec); if (U_SUCCESS(ec)) { result.setTo(currname, len); } @@ -1742,8 +1742,8 @@ static const struct CurrencyList { {"BUK", UCURR_COMMON|UCURR_DEPRECATED}, {"BWP", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"BYB", UCURR_COMMON|UCURR_DEPRECATED}, - {"BYN", UCURR_COMMON|UCURR_NON_DEPRECATED}, - {"BYR", UCURR_COMMON|UCURR_DEPRECATED}, + {"BYN", UCURR_COMMON|UCURR_NON_DEPRECATED}, + {"BYR", UCURR_COMMON|UCURR_DEPRECATED}, {"BZD", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"CAD", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"CDF", UCURR_COMMON|UCURR_NON_DEPRECATED}, @@ -1753,7 +1753,7 @@ static const struct CurrencyList { {"CLE", UCURR_COMMON|UCURR_DEPRECATED}, {"CLF", UCURR_UNCOMMON|UCURR_NON_DEPRECATED}, {"CLP", UCURR_COMMON|UCURR_NON_DEPRECATED}, - {"CNH", UCURR_UNCOMMON|UCURR_NON_DEPRECATED}, + {"CNH", UCURR_UNCOMMON|UCURR_NON_DEPRECATED}, {"CNX", UCURR_UNCOMMON|UCURR_DEPRECATED}, {"CNY", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"COP", UCURR_COMMON|UCURR_NON_DEPRECATED}, @@ -1776,7 +1776,7 @@ static const struct CurrencyList { {"ECV", UCURR_UNCOMMON|UCURR_DEPRECATED}, {"EEK", UCURR_COMMON|UCURR_DEPRECATED}, {"EGP", UCURR_COMMON|UCURR_NON_DEPRECATED}, - {"EQE", UCURR_COMMON|UCURR_DEPRECATED}, // questionable, remove? + {"EQE", UCURR_COMMON|UCURR_DEPRECATED}, // questionable, remove? {"ERN", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"ESA", UCURR_UNCOMMON|UCURR_DEPRECATED}, {"ESB", UCURR_UNCOMMON|UCURR_DEPRECATED}, @@ -1800,7 +1800,7 @@ static const struct CurrencyList { {"GRD", UCURR_COMMON|UCURR_DEPRECATED}, {"GTQ", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"GWE", UCURR_COMMON|UCURR_DEPRECATED}, - {"GWP", UCURR_COMMON|UCURR_DEPRECATED}, + {"GWP", UCURR_COMMON|UCURR_DEPRECATED}, {"GYD", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"HKD", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"HNL", UCURR_COMMON|UCURR_NON_DEPRECATED}, @@ -1838,13 +1838,13 @@ static const struct CurrencyList { {"LKR", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"LRD", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"LSL", UCURR_COMMON|UCURR_NON_DEPRECATED}, - {"LSM", UCURR_COMMON|UCURR_DEPRECATED}, // questionable, remove? - {"LTL", UCURR_COMMON|UCURR_DEPRECATED}, + {"LSM", UCURR_COMMON|UCURR_DEPRECATED}, // questionable, remove? + {"LTL", UCURR_COMMON|UCURR_DEPRECATED}, {"LTT", UCURR_COMMON|UCURR_DEPRECATED}, {"LUC", UCURR_UNCOMMON|UCURR_DEPRECATED}, {"LUF", UCURR_COMMON|UCURR_DEPRECATED}, {"LUL", UCURR_UNCOMMON|UCURR_DEPRECATED}, - {"LVL", UCURR_COMMON|UCURR_DEPRECATED}, + {"LVL", UCURR_COMMON|UCURR_DEPRECATED}, {"LVR", UCURR_COMMON|UCURR_DEPRECATED}, {"LYD", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"MAD", UCURR_COMMON|UCURR_NON_DEPRECATED}, @@ -1860,19 +1860,19 @@ static const struct CurrencyList { {"MMK", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"MNT", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"MOP", UCURR_COMMON|UCURR_NON_DEPRECATED}, - {"MRO", UCURR_COMMON|UCURR_DEPRECATED}, - {"MRU", UCURR_COMMON|UCURR_NON_DEPRECATED}, + {"MRO", UCURR_COMMON|UCURR_DEPRECATED}, + {"MRU", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"MTL", UCURR_COMMON|UCURR_DEPRECATED}, {"MTP", UCURR_COMMON|UCURR_DEPRECATED}, {"MUR", UCURR_COMMON|UCURR_NON_DEPRECATED}, - {"MVP", UCURR_COMMON|UCURR_DEPRECATED}, // questionable, remove? + {"MVP", UCURR_COMMON|UCURR_DEPRECATED}, // questionable, remove? {"MVR", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"MWK", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"MXN", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"MXP", UCURR_COMMON|UCURR_DEPRECATED}, {"MXV", UCURR_UNCOMMON|UCURR_NON_DEPRECATED}, {"MYR", UCURR_COMMON|UCURR_NON_DEPRECATED}, - {"MZE", UCURR_COMMON|UCURR_DEPRECATED}, + {"MZE", UCURR_COMMON|UCURR_DEPRECATED}, {"MZM", UCURR_COMMON|UCURR_DEPRECATED}, {"MZN", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"NAD", UCURR_COMMON|UCURR_NON_DEPRECATED}, @@ -1913,16 +1913,16 @@ static const struct CurrencyList { {"SGD", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"SHP", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"SIT", UCURR_COMMON|UCURR_DEPRECATED}, - {"SKK", UCURR_COMMON|UCURR_DEPRECATED}, + {"SKK", UCURR_COMMON|UCURR_DEPRECATED}, {"SLL", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"SOS", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"SRD", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"SRG", UCURR_COMMON|UCURR_DEPRECATED}, {"SSP", UCURR_COMMON|UCURR_NON_DEPRECATED}, - {"STD", UCURR_COMMON|UCURR_DEPRECATED}, - {"STN", UCURR_COMMON|UCURR_NON_DEPRECATED}, + {"STD", UCURR_COMMON|UCURR_DEPRECATED}, + {"STN", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"SUR", UCURR_COMMON|UCURR_DEPRECATED}, - {"SVC", UCURR_COMMON|UCURR_DEPRECATED}, + {"SVC", UCURR_COMMON|UCURR_DEPRECATED}, {"SYP", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"SZL", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"THB", UCURR_COMMON|UCURR_NON_DEPRECATED}, @@ -1971,7 +1971,7 @@ static const struct CurrencyList { {"XPD", UCURR_UNCOMMON|UCURR_NON_DEPRECATED}, {"XPF", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"XPT", UCURR_UNCOMMON|UCURR_NON_DEPRECATED}, - {"XRE", UCURR_UNCOMMON|UCURR_DEPRECATED}, + {"XRE", UCURR_UNCOMMON|UCURR_DEPRECATED}, {"XSU", UCURR_UNCOMMON|UCURR_NON_DEPRECATED}, {"XTS", UCURR_UNCOMMON|UCURR_NON_DEPRECATED}, {"XUA", UCURR_UNCOMMON|UCURR_NON_DEPRECATED}, @@ -1982,13 +1982,13 @@ static const struct CurrencyList { {"YUM", UCURR_COMMON|UCURR_DEPRECATED}, {"YUN", UCURR_COMMON|UCURR_DEPRECATED}, {"YUR", UCURR_COMMON|UCURR_DEPRECATED}, - {"ZAL", UCURR_UNCOMMON|UCURR_DEPRECATED}, + {"ZAL", UCURR_UNCOMMON|UCURR_DEPRECATED}, {"ZAR", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"ZMK", UCURR_COMMON|UCURR_DEPRECATED}, {"ZMW", UCURR_COMMON|UCURR_NON_DEPRECATED}, {"ZRN", UCURR_COMMON|UCURR_DEPRECATED}, {"ZRZ", UCURR_COMMON|UCURR_DEPRECATED}, - {"ZWD", UCURR_COMMON|UCURR_DEPRECATED}, + {"ZWD", UCURR_COMMON|UCURR_DEPRECATED}, {"ZWL", UCURR_COMMON|UCURR_DEPRECATED}, {"ZWR", UCURR_COMMON|UCURR_DEPRECATED}, { NULL, 0 } // Leave here to denote the end of the list. @@ -2161,20 +2161,20 @@ static void U_CALLCONV initIsoCodes(UErrorCode &status) { } static void populateCurrSymbolsEquiv(icu::Hashtable *hash, UErrorCode &status) { - if (U_FAILURE(status)) { return; } - for (auto& entry : unisets::kCurrencyEntries) { - UnicodeString exemplar(entry.exemplar); - const UnicodeSet* set = unisets::get(entry.key); - if (set == nullptr) { return; } - UnicodeSetIterator it(*set); - while (it.next()) { - UnicodeString value = it.getString(); - if (value == exemplar) { - // No need to mark the exemplar character as an equivalent - continue; - } - makeEquivalent(exemplar, value, hash, status); - if (U_FAILURE(status)) { return; } + if (U_FAILURE(status)) { return; } + for (auto& entry : unisets::kCurrencyEntries) { + UnicodeString exemplar(entry.exemplar); + const UnicodeSet* set = unisets::get(entry.key); + if (set == nullptr) { return; } + UnicodeSetIterator it(*set); + while (it.next()) { + UnicodeString value = it.getString(); + if (value == exemplar) { + // No need to mark the exemplar character as an equivalent + continue; + } + makeEquivalent(exemplar, value, hash, status); + if (U_FAILURE(status)) { return; } } } } @@ -2260,9 +2260,9 @@ ucurr_countCurrencies(const char* locale, UErrorCode localStatus = U_ZERO_ERROR; char id[ULOC_FULLNAME_CAPACITY]; uloc_getKeywordValue(locale, "currency", id, ULOC_FULLNAME_CAPACITY, &localStatus); - + // get country or country_variant in `id' - idForLocale(locale, id, sizeof(id), ec); + idForLocale(locale, id, sizeof(id), ec); if (U_FAILURE(*ec)) { @@ -2378,7 +2378,7 @@ ucurr_forLocaleAndDate(const char* locale, resLen = uloc_getKeywordValue(locale, "currency", id, ULOC_FULLNAME_CAPACITY, &localStatus); // get country or country_variant in `id' - idForLocale(locale, id, sizeof(id), ec); + idForLocale(locale, id, sizeof(id), ec); if (U_FAILURE(*ec)) { return 0; |