diff options
author | Tarek Mahmoud Sayed <tarekms@microsoft.com> | 2016-10-26 08:37:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-26 08:37:53 -0700 |
commit | e5b7e4450a087240fc55a5174314605cee07b991 (patch) | |
tree | add0e1e5033cf79ef3dd80aee0e2161ae7f5b0be /src/corefx | |
parent | cf0c28faec35090781799df0a2360cf2440d05ce (diff) | |
download | coreclr-e5b7e4450a087240fc55a5174314605cee07b991.tar.gz coreclr-e5b7e4450a087240fc55a5174314605cee07b991.tar.bz2 coreclr-e5b7e4450a087240fc55a5174314605cee07b991.zip |
Enable CultureInfo netstandard 1.7 APIs on Linux (#7811)
* Enable CultureInfo netstandard 1.7 APIs on Linux
* fix spaces
* Use Array.Empty<CultureInfo> instead of CultureInfo[0]
Diffstat (limited to 'src/corefx')
-rw-r--r-- | src/corefx/System.Globalization.Native/locale.cpp | 50 | ||||
-rw-r--r-- | src/corefx/System.Globalization.Native/localeStringData.cpp | 31 |
2 files changed, 76 insertions, 5 deletions
diff --git a/src/corefx/System.Globalization.Native/locale.cpp b/src/corefx/System.Globalization.Native/locale.cpp index 0a85ae1873..951179d321 100644 --- a/src/corefx/System.Globalization.Native/locale.cpp +++ b/src/corefx/System.Globalization.Native/locale.cpp @@ -148,6 +148,56 @@ const char* DetectDefaultLocaleName() return uloc_getDefault(); } +// GlobalizationNative_GetLocales gets all locale names and store it in the value buffer +// in case of success, it returns the count of the characters stored in value buffer +// in case of failure, it returns negative number. +// if the input value buffer is null, it returns the length needed to store the +// locale names list. +// if the value is not null, it fills the value with locale names separated by the length +// of each name. +extern "C" int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLength) +{ + int32_t totalLength = 0; + int32_t index = 0; + int32_t localeCount = uloc_countAvailable(); + + if (localeCount <= 0) + return -1; // failed + + for (int32_t i = 0; i < localeCount; i++) + { + const char *pLocaleName = uloc_getAvailable(i); + if (pLocaleName[0] == 0) // unexpected empty name + return -2; + + int32_t localeNameLength = strlen(pLocaleName); + + totalLength += localeNameLength + 1; // add 1 for the name length + + if (value != nullptr) + { + if (totalLength > valueLength) + return -3; + + value[index++] = (UChar) localeNameLength; + + for (int j=0; j<localeNameLength; j++) + { + if (pLocaleName[j] == '_') // fix the locale name + { + value[index++] = (UChar) '-'; + } + else + { + value[index++] = (UChar) pLocaleName[j]; + } + } + } + } + + return totalLength; +} + extern "C" int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength) { UErrorCode status = U_ZERO_ERROR; diff --git a/src/corefx/System.Globalization.Native/localeStringData.cpp b/src/corefx/System.Globalization.Native/localeStringData.cpp index 54ef8f02f1..b8eaa307c7 100644 --- a/src/corefx/System.Globalization.Native/localeStringData.cpp +++ b/src/corefx/System.Globalization.Native/localeStringData.cpp @@ -37,7 +37,8 @@ enum LocaleStringData : int32_t PMDesignator = 0x00000029, PositiveSign = 0x00000050, NegativeSign = 0x00000051, - Iso639LanguageName = 0x00000059, + Iso639LanguageTwoLetterName = 0x00000059, + Iso639LanguageThreeLetterName = 0x00000067, Iso3166CountryName = 0x0000005A, Iso3166CountryName2= 0x00000068, NaNSymbol = 0x00000069, @@ -115,11 +116,11 @@ UErrorCode GetLocaleInfoAmPm(const char* locale, bool am, UChar* value, int32_t /* Function: -GetLocaleIso639LanguageName +GetLocaleIso639LanguageTwoLetterName Gets the language name for a locale (via uloc_getLanguage) and converts the result to UChars */ -UErrorCode GetLocaleIso639LanguageName(const char* locale, UChar* value, int32_t valueLength) +UErrorCode GetLocaleIso639LanguageTwoLetterName(const char* locale, UChar* value, int32_t valueLength) { UErrorCode status = U_ZERO_ERROR; int32_t length = uloc_getLanguage(locale, nullptr, 0, &status); @@ -139,6 +140,23 @@ UErrorCode GetLocaleIso639LanguageName(const char* locale, UChar* value, int32_t /* Function: +GetLocaleIso639LanguageThreeLetterName + +Gets the language name for a locale (via uloc_getISO3Language) and converts the result to UChars +*/ +UErrorCode GetLocaleIso639LanguageThreeLetterName(const char* locale, UChar* value, int32_t valueLength) +{ + const char *isoLanguage = uloc_getISO3Language(locale); + if (isoLanguage[0] == 0) + { + return U_ILLEGAL_ARGUMENT_ERROR; + } + + return u_charsToUChars_safe(isoLanguage, value, valueLength); +} + +/* +Function: GetLocaleIso3166CountryName Gets the country name for a locale (via uloc_getCountry) and converts the result to UChars @@ -315,8 +333,11 @@ extern "C" int32_t GlobalizationNative_GetLocaleInfoString( case NegativeSign: status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MINUS_SIGN_SYMBOL, value, valueLength); break; - case Iso639LanguageName: - status = GetLocaleIso639LanguageName(locale, value, valueLength); + case Iso639LanguageTwoLetterName: + status = GetLocaleIso639LanguageTwoLetterName(locale, value, valueLength); + break; + case Iso639LanguageThreeLetterName: + status = GetLocaleIso639LanguageThreeLetterName(locale, value, valueLength); break; case Iso3166CountryName: status = GetLocaleIso3166CountryName(locale, value, valueLength); |