diff options
Diffstat (limited to 'src/corefx/System.Globalization.Native/localeStringData.cpp')
-rw-r--r-- | src/corefx/System.Globalization.Native/localeStringData.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/corefx/System.Globalization.Native/localeStringData.cpp b/src/corefx/System.Globalization.Native/localeStringData.cpp index 927da67095..a8dcc519ad 100644 --- a/src/corefx/System.Globalization.Native/localeStringData.cpp +++ b/src/corefx/System.Globalization.Native/localeStringData.cpp @@ -27,6 +27,8 @@ enum LocaleStringData : int32_t ThousandSeparator = 0x0000000F, Digits = 0x00000013, MonetarySymbol = 0x00000014, + CurrencyEnglishName = 0x00001007, + CurrencyNativeName = 0x00001008, Iso4217MonetarySymbol = 0x00000015, MonetaryDecimalSeparator = 0x00000016, MonetaryThousandSeparator = 0x00000017, @@ -36,6 +38,7 @@ enum LocaleStringData : int32_t NegativeSign = 0x00000051, Iso639LanguageName = 0x00000059, Iso3166CountryName = 0x0000005A, + Iso3166CountryName2= 0x00000068, NaNSymbol = 0x00000069, PositiveInfinitySymbol = 0x0000006a, ParentName = 0x0000006d, @@ -158,6 +161,66 @@ UErrorCode GetLocaleIso3166CountryName(const char* locale, UChar* value, int32_t } /* +Function: +GetLocaleIso3166CountryCode + +Gets the 3 letter country code for a locale (via uloc_getISO3Country) and converts the result to UChars +*/ +UErrorCode GetLocaleIso3166CountryCode(const char* locale, UChar* value, int32_t valueLength) +{ + const char *pIsoCountryName = uloc_getISO3Country(locale); + int len = strlen(pIsoCountryName); + + if (len == 0) + { + return U_ILLEGAL_ARGUMENT_ERROR; + } + + return u_charsToUChars_safe(pIsoCountryName, value, valueLength); +} + +/* +Function: +GetLocaleCurrencyName + +Gets the locale currency English or native name and convert the result to UChars +*/ +UErrorCode GetLocaleCurrencyName(const char* locale, bool nativeName, UChar* value, int32_t valueLength) +{ + UErrorCode status = U_ZERO_ERROR; + + UChar currencyThreeLettersName[4]; // 3 letters currency iso name + NULL + ucurr_forLocale(locale, currencyThreeLettersName, 4, &status); + if (!U_SUCCESS(status)) + { + return status; + } + + int32_t len; + UBool formatChoice; + const UChar *pCurrencyLongName = ucurr_getName( + currencyThreeLettersName, + nativeName ? locale : ULOC_US, + UCURR_LONG_NAME, + &formatChoice, + &len, + &status); + if (!U_SUCCESS(status)) + { + return status; + } + + if (len >= valueLength) // we need to have room for NULL too + { + return U_BUFFER_OVERFLOW_ERROR; + } + u_strncpy(value, pCurrencyLongName, len); + value[len] = 0; + + return status; +} + +/* PAL Function: GetLocaleInfoString @@ -226,6 +289,12 @@ extern "C" int32_t GlobalizationNative_GetLocaleInfoString( case Iso4217MonetarySymbol: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_INTL_CURRENCY_SYMBOL, value, valueLength); break; + case CurrencyEnglishName: + status = GetLocaleCurrencyName(locale, false, value, valueLength); + break; + case CurrencyNativeName: + status = GetLocaleCurrencyName(locale, true, value, valueLength); + break; case MonetaryDecimalSeparator: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_SEPARATOR_SYMBOL, value, valueLength); break; @@ -251,6 +320,9 @@ extern "C" int32_t GlobalizationNative_GetLocaleInfoString( case Iso3166CountryName: status = GetLocaleIso3166CountryName(locale, value, valueLength); break; + case Iso3166CountryName2: + status = GetLocaleIso3166CountryCode(locale, value, valueLength); + break; case NaNSymbol: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_NAN_SYMBOL, value, valueLength); break; |