mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 09:21:03 +00:00
ICU-12086 ICU-12165 Currency.getName() param isChoiceFormat can be null, make it so, document, use null in library code
This commit is contained in:
parent
6ff43608d2
commit
7237fc58b4
9 changed files with 58 additions and 40 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<StandardPlural::Form>(i)),
|
||||
&longNameLen,
|
||||
&status);
|
||||
|
|
|
@ -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"},
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue