]> granicus.if.org Git - icu/commitdiff
ICU-12086 ICU-12165 Currency.getName() param isChoiceFormat can be null, make it...
authorMarkus Scherer <markus.icu@gmail.com>
Fri, 30 Aug 2019 19:17:02 +0000 (12:17 -0700)
committerMarkus Scherer <markus.icu@gmail.com>
Fri, 30 Aug 2019 21:47:19 +0000 (14:47 -0700)
icu4c/source/common/locdspnm.cpp
icu4c/source/common/ucurr.cpp
icu4c/source/common/unicode/ucurr.h
icu4c/source/i18n/number_currencysymbols.cpp
icu4c/source/i18n/number_longnames.cpp
icu4j/main/classes/collate/src/com/ibm/icu/util/GlobalizationPreferences.java
icu4j/main/classes/core/src/com/ibm/icu/impl/number/CustomSymbolCurrency.java
icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/DisplayNameTest.java

index d590a8860afa79a091a455444d8493145fd44856..43334f519646222b6e94cda247c16affe7f6b8f6 100644 (file)
@@ -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;
index 811764593ab718950122a0dfaefeb5592c6ff3dd..dfee3bd300059568c2bc8aebd3d6d1c575447766 100644 (file)
@@ -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);
     }
index a6a94769cd842fb1ac7e3e2beda80d39170a460d..f91cc0df7c61ccd60c49c4a2837518b20fd2e429 100644 (file)
@@ -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
index 0b79d6596f18c0245cffc41a5f657f0fae1ecf5a..4d6fb2cb1d8decc6b856b3b8a890e32302685be9 100644 (file)
@@ -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);
index bd4169929098df363bf568250ba4808e8e3aa284..b790ffb67e8b06b4d623bafccaefc23e660c10bf 100644 (file)
@@ -148,12 +148,11 @@ void getCurrencyLongNameData(const Locale &locale, const CurrencyUnit &currency,
         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<StandardPlural::Form>(i)),
                 &longNameLen,
                 &status);
index cab3bdfba8918be27bc0f5090fcb5b4509a5dedf..13c9e081bdfc02cb273be64be12686a7c3d26b93 100644 (file)
@@ -187,7 +187,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
         if (locales == null) {
             result = guessLocales();
         } else {
-            result = new ArrayList<ULocale>();
+            result = new ArrayList<>();
             result.addAll(locales);
         }
         return result;
@@ -598,7 +598,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
                 Currency temp = new Currency(id);
                 result =temp.getName(locale, type==ID_CURRENCY
                                      ? Currency.LONG_NAME
-                                     : Currency.SYMBOL_NAME, new boolean[1]);
+                                     : Currency.SYMBOL_NAME, null /* isChoiceFormat */);
                 // TODO: have method that doesn't take parameter. Add
                 // function to determine whether string is choice
                 // format.
@@ -815,7 +815,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
      * @provisional This API might change or be removed in a future release.
      */
     protected List<ULocale> processLocales(List<ULocale> inputLocales) {
-        List<ULocale> result = new ArrayList<ULocale>();
+        List<ULocale> 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<GlobalizationPreferen
      */
     protected List<ULocale> guessLocales() {
         if (implicitLocales == null) {
-            List<ULocale> result = new ArrayList<ULocale>(1);
+            List<ULocale> result = new ArrayList<>(1);
             result.add(ULocale.getDefault());
             implicitLocales = processLocales(result);
         }
@@ -1205,7 +1205,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
     /*
      * Available locales for service types
      */
-    private static final HashMap<ULocale, BitSet> available_locales = new HashMap<ULocale, BitSet>();
+    private static final HashMap<ULocale, BitSet> available_locales = new HashMap<>();
     private static final int
         TYPE_GENERIC = 0,
         TYPE_CALENDAR = 1,
@@ -1274,7 +1274,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
     /** WARNING: All of this data is temporary, until we start importing from CLDR!!!
      *
      */
-    private static final Map<String, String> language_territory_hack_map = new HashMap<String, String>();
+    private static final Map<String, String> 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<GlobalizationPreferen
         }
     }
 
-    static final Map<String, String> territory_tzid_hack_map = new HashMap<String, String>();
+    static final Map<String, String> territory_tzid_hack_map = new HashMap<>();
     static final String[][] territory_tzid_hack = {
         {"AQ", "Antarctica/McMurdo"},
         {"AR", "America/Buenos_Aires"},
index bf43ccfff4ba502ef179be21ddb4edd23f11ac0d..5e73c86e56f8617f7968638d956694d40b31bb52 100644 (file)
@@ -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);
index af0089f231e0c9542db26e0c64a1ebb283aedf5b..95e363457d0145beec8cf91a02dc3ee1f46c5910 100644 (file)
@@ -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. <b>Note:</b>
-     * as of ICU 4.4, choice formats are not used, and the value returned
-     * in isChoiceFormat is always false.
+     * returned.
      * <p>
      * @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. <b>Note:</b>
-     * 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
index cd61579a87dcb0e46c8b89bedc7c132012db2e52..483875dca920258ee5018b020059b4a472009025 100644 (file)
@@ -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