From: Markus Scherer Date: Fri, 30 Aug 2019 19:17:02 +0000 (-0700) Subject: ICU-12086 ICU-12165 Currency.getName() param isChoiceFormat can be null, make it... X-Git-Tag: release-65-rc~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7237fc58b440c0a77c5efc1fd69c500c999a0c02;p=icu ICU-12086 ICU-12165 Currency.getName() param isChoiceFormat can be null, make it so, document, use null in library code --- diff --git a/icu4c/source/common/locdspnm.cpp b/icu4c/source/common/locdspnm.cpp index d590a8860af..43334f51964 100644 --- a/icu4c/source/common/locdspnm.cpp +++ b/icu4c/source/common/locdspnm.cpp @@ -853,9 +853,8 @@ LocaleDisplayNamesImpl::keyValueDisplayName(const char* key, UErrorCode sts = U_ZERO_ERROR; UnicodeString ustrValue(value, -1, US_INV); int32_t len; - UBool isChoice = FALSE; const UChar *currencyName = ucurr_getName(ustrValue.getTerminatedBuffer(), - locale.getBaseName(), UCURR_LONG_NAME, &isChoice, &len, &sts); + locale.getBaseName(), UCURR_LONG_NAME, nullptr /* isChoiceFormat */, &len, &sts); if (U_FAILURE(sts)) { // Return the value as is on failure result = ustrValue; diff --git a/icu4c/source/common/ucurr.cpp b/icu4c/source/common/ucurr.cpp index 811764593ab..dfee3bd3000 100644 --- a/icu4c/source/common/ucurr.cpp +++ b/icu4c/source/common/ucurr.cpp @@ -713,7 +713,9 @@ ucurr_getName(const UChar* currency, // We no longer support choice format data in names. Data should not contain // choice patterns. - *isChoiceFormat = FALSE; + if (isChoiceFormat != NULL) { + *isChoiceFormat = FALSE; + } if (U_SUCCESS(ec2)) { U_ASSERT(s != NULL); return s; @@ -1595,10 +1597,9 @@ uprv_getStaticCurrencyName(const UChar* iso, const char* loc, { U_NAMESPACE_USE - UBool isChoiceFormat; int32_t len; const UChar* currname = ucurr_getName(iso, loc, UCURR_SYMBOL_NAME, - &isChoiceFormat, &len, &ec); + nullptr /* isChoiceFormat */, &len, &ec); if (U_SUCCESS(ec)) { result.setTo(currname, len); } diff --git a/icu4c/source/common/unicode/ucurr.h b/icu4c/source/common/unicode/ucurr.h index a6a94769cd8..f91cc0df7c6 100644 --- a/icu4c/source/common/unicode/ucurr.h +++ b/icu4c/source/common/unicode/ucurr.h @@ -159,14 +159,14 @@ ucurr_unregister(UCurrRegistryKey key, UErrorCode* status); * @param currency null-terminated 3-letter ISO 4217 code * @param locale locale in which to display currency * @param nameStyle selector for which kind of name to return - * @param isChoiceFormat fill-in set to TRUE if the returned value - * is a ChoiceFormat pattern; otherwise it is a static string + * @param isChoiceFormat always set to FALSE, or can be NULL; + * display names are static strings; + * since ICU 4.4, ChoiceFormat patterns are no longer supported * @param len fill-in parameter to receive length of result * @param ec error code * @return pointer to display string of 'len' UChars. If the resource * data contains no entry for 'currency', then 'currency' itself is - * returned. If *isChoiceFormat is TRUE, then the result is a - * ChoiceFormat pattern. Otherwise it is a static string. + * returned. * @stable ICU 2.6 */ U_STABLE const UChar* U_EXPORT2 @@ -183,14 +183,15 @@ ucurr_getName(const UChar* currency, * currency object in the en_US locale is "US dollar" or "US dollars". * @param currency null-terminated 3-letter ISO 4217 code * @param locale locale in which to display currency - * @param isChoiceFormat fill-in set to TRUE if the returned value - * is a ChoiceFormat pattern; otherwise it is a static string + * @param isChoiceFormat always set to FALSE, or can be NULL; + * display names are static strings; + * since ICU 4.4, ChoiceFormat patterns are no longer supported * @param pluralCount plural count * @param len fill-in parameter to receive length of result * @param ec error code * @return pointer to display string of 'len' UChars. If the resource * data contains no entry for 'currency', then 'currency' itself is - * returned. + * returned. * @stable ICU 4.2 */ U_STABLE const UChar* U_EXPORT2 diff --git a/icu4c/source/i18n/number_currencysymbols.cpp b/icu4c/source/i18n/number_currencysymbols.cpp index 0b79d6596f1..4d6fb2cb1d8 100644 --- a/icu4c/source/i18n/number_currencysymbols.cpp +++ b/icu4c/source/i18n/number_currencysymbols.cpp @@ -53,13 +53,12 @@ UnicodeString CurrencySymbols::getCurrencySymbol(UErrorCode& status) const { UnicodeString CurrencySymbols::loadSymbol(UCurrNameStyle selector, UErrorCode& status) const { const char16_t* isoCode = fCurrency.getISOCurrency(); - UBool ignoredIsChoiceFormatFillIn = FALSE; int32_t symbolLen = 0; const char16_t* symbol = ucurr_getName( isoCode, fLocaleName.data(), selector, - &ignoredIsChoiceFormatFillIn, + nullptr /* isChoiceFormat */, &symbolLen, &status); // If given an unknown currency, ucurr_getName returns the input string, which we can't alias safely! @@ -82,12 +81,11 @@ UnicodeString CurrencySymbols::getIntlCurrencySymbol(UErrorCode&) const { UnicodeString CurrencySymbols::getPluralName(StandardPlural::Form plural, UErrorCode& status) const { const char16_t* isoCode = fCurrency.getISOCurrency(); - UBool isChoiceFormat = FALSE; int32_t symbolLen = 0; const char16_t* symbol = ucurr_getPluralName( isoCode, fLocaleName.data(), - &isChoiceFormat, + nullptr /* isChoiceFormat */, StandardPlural::getKeyword(plural), &symbolLen, &status); diff --git a/icu4c/source/i18n/number_longnames.cpp b/icu4c/source/i18n/number_longnames.cpp index bd416992909..b790ffb67e8 100644 --- a/icu4c/source/i18n/number_longnames.cpp +++ b/icu4c/source/i18n/number_longnames.cpp @@ -148,12 +148,11 @@ void getCurrencyLongNameData(const Locale &locale, const CurrencyUnit ¤cy, if (pattern.isBogus()) { continue; } - UBool isChoiceFormat = FALSE; int32_t longNameLen = 0; const char16_t *longName = ucurr_getPluralName( currency.getISOCurrency(), locale.getName(), - &isChoiceFormat, + nullptr /* isChoiceFormat */, StandardPlural::getKeyword(static_cast(i)), &longNameLen, &status); diff --git a/icu4j/main/classes/collate/src/com/ibm/icu/util/GlobalizationPreferences.java b/icu4j/main/classes/collate/src/com/ibm/icu/util/GlobalizationPreferences.java index cab3bdfba89..13c9e081bdf 100644 --- a/icu4j/main/classes/collate/src/com/ibm/icu/util/GlobalizationPreferences.java +++ b/icu4j/main/classes/collate/src/com/ibm/icu/util/GlobalizationPreferences.java @@ -187,7 +187,7 @@ public class GlobalizationPreferences implements Freezable(); + result = new ArrayList<>(); result.addAll(locales); } return result; @@ -598,7 +598,7 @@ public class GlobalizationPreferences implements Freezable processLocales(List inputLocales) { - List result = new ArrayList(); + List result = new ArrayList<>(); /* * Step 1: Relocate later occurrence of more specific locale * before earlier occurrence of less specific locale. @@ -1053,7 +1053,7 @@ public class GlobalizationPreferences implements Freezable guessLocales() { if (implicitLocales == null) { - List result = new ArrayList(1); + List result = new ArrayList<>(1); result.add(ULocale.getDefault()); implicitLocales = processLocales(result); } @@ -1205,7 +1205,7 @@ public class GlobalizationPreferences implements Freezable available_locales = new HashMap(); + private static final HashMap available_locales = new HashMap<>(); private static final int TYPE_GENERIC = 0, TYPE_CALENDAR = 1, @@ -1274,7 +1274,7 @@ public class GlobalizationPreferences implements Freezable language_territory_hack_map = new HashMap(); + private static final Map language_territory_hack_map = new HashMap<>(); private static final String[][] language_territory_hack = { {"af", "ZA"}, {"am", "ET"}, @@ -1436,7 +1436,7 @@ public class GlobalizationPreferences implements Freezable territory_tzid_hack_map = new HashMap(); + static final Map territory_tzid_hack_map = new HashMap<>(); static final String[][] territory_tzid_hack = { {"AQ", "Antarctica/McMurdo"}, {"AR", "America/Buenos_Aires"}, diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/number/CustomSymbolCurrency.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/number/CustomSymbolCurrency.java index bf43ccfff4b..5e73c86e56f 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/number/CustomSymbolCurrency.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/number/CustomSymbolCurrency.java @@ -42,6 +42,9 @@ public class CustomSymbolCurrency extends Currency { @Override public String getName(ULocale locale, int nameStyle, boolean[] isChoiceFormat) { if (nameStyle == SYMBOL_NAME) { + if (isChoiceFormat != null) { + isChoiceFormat[0] = false; + } return symbol1; } return super.getName(locale, nameStyle, isChoiceFormat); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java b/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java index af0089f231e..95e363457d0 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java @@ -519,6 +519,17 @@ public class Currency extends MeasureUnit { * given locale. * This is a convenient method for * getName(ULocale, int, boolean[]); + * + * @param locale locale in which to display currency + * @param nameStyle selector for which kind of name to return. + * The nameStyle should be SYMBOL_NAME, NARROW_SYMBOL_NAME, + * or LONG_NAME. Otherwise, throw IllegalArgumentException. + * @param isChoiceFormat isChoiceFormat[0] is always set to false, or isChoiceFormat can be null; + * display names are static strings; + * since ICU 4.4, ChoiceFormat patterns are no longer supported + * @return display string for this currency. If the resource data + * contains no entry for this currency, then the ISO 4217 code is + * returned. * @stable ICU 3.2 */ public String getName(Locale locale, @@ -531,19 +542,17 @@ public class Currency extends MeasureUnit { * Returns the display name for the given currency in the * given locale. For example, the display name for the USD * currency object in the en_US locale is "$". + * * @param locale locale in which to display currency * @param nameStyle selector for which kind of name to return. * The nameStyle should be SYMBOL_NAME, NARROW_SYMBOL_NAME, * or LONG_NAME. Otherwise, throw IllegalArgumentException. - * @param isChoiceFormat fill-in; isChoiceFormat[0] is set to true - * if the returned value is a ChoiceFormat pattern; otherwise it - * is set to false + * @param isChoiceFormat isChoiceFormat[0] is always set to false, or isChoiceFormat can be null; + * display names are static strings; + * since ICU 4.4, ChoiceFormat patterns are no longer supported * @return display string for this currency. If the resource data * contains no entry for this currency, then the ISO 4217 code is - * returned. If isChoiceFormat[0] is true, then the result is a - * ChoiceFormat pattern. Otherwise it is a static string. Note: - * as of ICU 4.4, choice formats are not used, and the value returned - * in isChoiceFormat is always false. + * returned. *

* @throws IllegalArgumentException if the nameStyle is not SYMBOL_NAME * or LONG_NAME. @@ -573,6 +582,16 @@ public class Currency extends MeasureUnit { /** * Returns the display name for the given currency in the given locale. * This is a convenience overload of getName(ULocale, int, String, boolean[]); + * + * @param locale locale in which to display currency + * @param nameStyle selector for which kind of name to return + * @param pluralCount plural count string for this locale + * @param isChoiceFormat isChoiceFormat[0] is always set to false, or isChoiceFormat can be null; + * display names are static strings; + * since ICU 4.4, ChoiceFormat patterns are no longer supported + * @return display string for this currency. If the resource data + * contains no entry for this currency, then the ISO 4217 code is + * returned. * @stable ICU 4.2 */ public String getName(Locale locale, int nameStyle, String pluralCount, @@ -588,18 +607,16 @@ public class Currency extends MeasureUnit { * amount is plural is "US dollars", such as in "3.00 US dollars"; * while the PLURAL_LONG_NAME for the USD currency object when the currency * amount is singular is "US dollar", such as in "1.00 US dollar". + * * @param locale locale in which to display currency * @param nameStyle selector for which kind of name to return * @param pluralCount plural count string for this locale - * @param isChoiceFormat fill-in; isChoiceFormat[0] is set to true - * if the returned value is a ChoiceFormat pattern; otherwise it - * is set to false + * @param isChoiceFormat isChoiceFormat[0] is always set to false, or isChoiceFormat can be null; + * display names are static strings; + * since ICU 4.4, ChoiceFormat patterns are no longer supported * @return display string for this currency. If the resource data * contains no entry for this currency, then the ISO 4217 code is - * returned. If isChoiceFormat[0] is true, then the result is a - * ChoiceFormat pattern. Otherwise it is a static string. Note: - * as of ICU 4.4, choice formats are not used, and the value returned - * in isChoiceFormat is always false. + * returned. * @throws IllegalArgumentException if the nameStyle is not SYMBOL_NAME, * LONG_NAME, or PLURAL_LONG_NAME. * @stable ICU 4.2 diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/DisplayNameTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/DisplayNameTest.java index cd61579a87d..483875dca92 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/DisplayNameTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/DisplayNameTest.java @@ -126,7 +126,7 @@ public class DisplayNameTest extends TestFmwk { @Override public String get(ULocale loc, String code, Object context) { Currency s = Currency.getInstance(code); - return s.getName(loc, ((Integer)context).intValue(), new boolean[1]); + return s.getName(loc, ((Integer)context).intValue(), null /* isChoiceFormat */); } }); // comment this out, because the zone string information is lost