annotate modules/javafx.web/src/main/native/Source/ThirdParty/icu/source/i18n/number_currencysymbols.cpp @ 11038:20a8447c71c6

8207159: Update ICU to version 62.1 Reviewed-by: mbilla, kcr, ghb
author arajkumar
date Fri, 24 Aug 2018 15:06:40 +0530
parents
children
rev   line source
arajkumar@11038 1 // © 2018 and later: Unicode, Inc. and others.
arajkumar@11038 2 // License & terms of use: http://www.unicode.org/copyright.html
arajkumar@11038 3
arajkumar@11038 4 #include "unicode/utypes.h"
arajkumar@11038 5
arajkumar@11038 6 #if !UCONFIG_NO_FORMATTING
arajkumar@11038 7
arajkumar@11038 8 // Allow implicit conversion from char16_t* to UnicodeString for this file:
arajkumar@11038 9 // Helpful in toString methods and elsewhere.
arajkumar@11038 10 #define UNISTR_FROM_STRING_EXPLICIT
arajkumar@11038 11
arajkumar@11038 12 #include "numparse_types.h"
arajkumar@11038 13 #include "number_currencysymbols.h"
arajkumar@11038 14
arajkumar@11038 15 using namespace icu;
arajkumar@11038 16 using namespace icu::number;
arajkumar@11038 17 using namespace icu::number::impl;
arajkumar@11038 18
arajkumar@11038 19
arajkumar@11038 20 CurrencySymbols::CurrencySymbols(CurrencyUnit currency, const Locale& locale, UErrorCode& status)
arajkumar@11038 21 : fCurrency(currency), fLocaleName(locale.getName(), status) {
arajkumar@11038 22 fCurrencySymbol.setToBogus();
arajkumar@11038 23 fIntlCurrencySymbol.setToBogus();
arajkumar@11038 24 }
arajkumar@11038 25
arajkumar@11038 26 CurrencySymbols::CurrencySymbols(CurrencyUnit currency, const Locale& locale,
arajkumar@11038 27 const DecimalFormatSymbols& symbols, UErrorCode& status)
arajkumar@11038 28 : CurrencySymbols(currency, locale, status) {
arajkumar@11038 29 // If either of the overrides is present, save it in the local UnicodeString.
arajkumar@11038 30 if (symbols.isCustomCurrencySymbol()) {
arajkumar@11038 31 fCurrencySymbol = symbols.getConstSymbol(DecimalFormatSymbols::kCurrencySymbol);
arajkumar@11038 32 }
arajkumar@11038 33 if (symbols.isCustomIntlCurrencySymbol()) {
arajkumar@11038 34 fIntlCurrencySymbol = symbols.getConstSymbol(DecimalFormatSymbols::kIntlCurrencySymbol);
arajkumar@11038 35 }
arajkumar@11038 36 }
arajkumar@11038 37
arajkumar@11038 38 const char16_t* CurrencySymbols::getIsoCode() const {
arajkumar@11038 39 return fCurrency.getISOCurrency();
arajkumar@11038 40 }
arajkumar@11038 41
arajkumar@11038 42 UnicodeString CurrencySymbols::getNarrowCurrencySymbol(UErrorCode& status) const {
arajkumar@11038 43 // Note: currently no override is available for narrow currency symbol
arajkumar@11038 44 return loadSymbol(UCURR_NARROW_SYMBOL_NAME, status);
arajkumar@11038 45 }
arajkumar@11038 46
arajkumar@11038 47 UnicodeString CurrencySymbols::getCurrencySymbol(UErrorCode& status) const {
arajkumar@11038 48 if (!fCurrencySymbol.isBogus()) {
arajkumar@11038 49 return fCurrencySymbol;
arajkumar@11038 50 }
arajkumar@11038 51 return loadSymbol(UCURR_SYMBOL_NAME, status);
arajkumar@11038 52 }
arajkumar@11038 53
arajkumar@11038 54 UnicodeString CurrencySymbols::loadSymbol(UCurrNameStyle selector, UErrorCode& status) const {
arajkumar@11038 55 const char16_t* isoCode = fCurrency.getISOCurrency();
arajkumar@11038 56 UBool ignoredIsChoiceFormatFillIn = FALSE;
arajkumar@11038 57 int32_t symbolLen = 0;
arajkumar@11038 58 const char16_t* symbol = ucurr_getName(
arajkumar@11038 59 isoCode,
arajkumar@11038 60 fLocaleName.data(),
arajkumar@11038 61 selector,
arajkumar@11038 62 &ignoredIsChoiceFormatFillIn,
arajkumar@11038 63 &symbolLen,
arajkumar@11038 64 &status);
arajkumar@11038 65 // If given an unknown currency, ucurr_getName returns the input string, which we can't alias safely!
arajkumar@11038 66 // Otherwise, symbol points to a resource bundle, and we can use readonly-aliasing constructor.
arajkumar@11038 67 if (symbol == isoCode) {
arajkumar@11038 68 return UnicodeString(isoCode, 3);
arajkumar@11038 69 } else {
arajkumar@11038 70 return UnicodeString(TRUE, symbol, symbolLen);
arajkumar@11038 71 }
arajkumar@11038 72 }
arajkumar@11038 73
arajkumar@11038 74 UnicodeString CurrencySymbols::getIntlCurrencySymbol(UErrorCode&) const {
arajkumar@11038 75 if (!fIntlCurrencySymbol.isBogus()) {
arajkumar@11038 76 return fIntlCurrencySymbol;
arajkumar@11038 77 }
arajkumar@11038 78 // Note: Not safe to use readonly-aliasing constructor here because the buffer belongs to this object,
arajkumar@11038 79 // which could be destructed or moved during the lifetime of the return value.
arajkumar@11038 80 return UnicodeString(fCurrency.getISOCurrency(), 3);
arajkumar@11038 81 }
arajkumar@11038 82
arajkumar@11038 83 UnicodeString CurrencySymbols::getPluralName(StandardPlural::Form plural, UErrorCode& status) const {
arajkumar@11038 84 const char16_t* isoCode = fCurrency.getISOCurrency();
arajkumar@11038 85 UBool isChoiceFormat = FALSE;
arajkumar@11038 86 int32_t symbolLen = 0;
arajkumar@11038 87 const char16_t* symbol = ucurr_getPluralName(
arajkumar@11038 88 isoCode,
arajkumar@11038 89 fLocaleName.data(),
arajkumar@11038 90 &isChoiceFormat,
arajkumar@11038 91 StandardPlural::getKeyword(plural),
arajkumar@11038 92 &symbolLen,
arajkumar@11038 93 &status);
arajkumar@11038 94 // If given an unknown currency, ucurr_getName returns the input string, which we can't alias safely!
arajkumar@11038 95 // Otherwise, symbol points to a resource bundle, and we can use readonly-aliasing constructor.
arajkumar@11038 96 if (symbol == isoCode) {
arajkumar@11038 97 return UnicodeString(isoCode, 3);
arajkumar@11038 98 } else {
arajkumar@11038 99 return UnicodeString(TRUE, symbol, symbolLen);
arajkumar@11038 100 }
arajkumar@11038 101 }
arajkumar@11038 102
arajkumar@11038 103
arajkumar@11038 104 CurrencyUnit
arajkumar@11038 105 icu::number::impl::resolveCurrency(const DecimalFormatProperties& properties, const Locale& locale,
arajkumar@11038 106 UErrorCode& status) {
arajkumar@11038 107 if (!properties.currency.isNull()) {
arajkumar@11038 108 return properties.currency.getNoError();
arajkumar@11038 109 } else {
arajkumar@11038 110 UErrorCode localStatus = U_ZERO_ERROR;
arajkumar@11038 111 char16_t buf[4] = {};
arajkumar@11038 112 ucurr_forLocale(locale.getName(), buf, 4, &localStatus);
arajkumar@11038 113 if (U_SUCCESS(localStatus)) {
arajkumar@11038 114 return CurrencyUnit(buf, status);
arajkumar@11038 115 } else {
arajkumar@11038 116 // Default currency (XXX)
arajkumar@11038 117 return CurrencyUnit();
arajkumar@11038 118 }
arajkumar@11038 119 }
arajkumar@11038 120 }
arajkumar@11038 121
arajkumar@11038 122
arajkumar@11038 123 #endif /* #if !UCONFIG_NO_FORMATTING */