summaryrefslogtreecommitdiff
path: root/src/corefx
diff options
context:
space:
mode:
authorSteve Harter <sharter@microsoft.com>2015-10-08 17:03:53 -0500
committerSteve Harter <sharter@microsoft.com>2015-10-09 14:17:53 -0500
commite3562c04b5e8a28b7d852ccbca627947b72a947d (patch)
tree57600f5c73ddef62437b147eceec2aed0319192a /src/corefx
parenta717bb49a6e45f162367dcb303eb94eafb7491e5 (diff)
downloadcoreclr-e3562c04b5e8a28b7d852ccbca627947b72a947d.tar.gz
coreclr-e3562c04b5e8a28b7d852ccbca627947b72a947d.tar.bz2
coreclr-e3562c04b5e8a28b7d852ccbca627947b72a947d.zip
Add support for obtaining default locale in Linux and fix issue with @collation= not being passed to ICU
Diffstat (limited to 'src/corefx')
-rw-r--r--src/corefx/System.Globalization.Native/locale.cpp44
-rw-r--r--src/corefx/System.Globalization.Native/locale.hpp5
2 files changed, 42 insertions, 7 deletions
diff --git a/src/corefx/System.Globalization.Native/locale.cpp b/src/corefx/System.Globalization.Native/locale.cpp
index e02c32d680..ca4569f9c9 100644
--- a/src/corefx/System.Globalization.Native/locale.cpp
+++ b/src/corefx/System.Globalization.Native/locale.cpp
@@ -36,8 +36,9 @@ Locale GetLocale(const UChar* localeName, bool canonize)
if (localeName != NULL)
{
- int32_t len = u_strlen(localeName);
- u_UCharsToChars(localeName, localeNameTemp, len + 1);
+ // use UnicodeString.extract instead of u_UCharsToChars; u_UCharsToChars considers '@' a variant and stops
+ UnicodeString str(localeName, -1, ULOC_FULLNAME_CAPACITY);
+ str.extract(0, str.length(), localeNameTemp);
}
Locale loc;
@@ -64,9 +65,10 @@ UErrorCode u_charsToUChars_safe(const char *str, UChar* value, int32_t valueLeng
return U_ZERO_ERROR;
}
-void FixupLocaleName(UChar* value, int32_t valueLength)
+int FixupLocaleName(UChar* value, int32_t valueLength)
{
- for (int i = 0; i < valueLength; i++)
+ int i = 0;
+ for (; i < valueLength; i++)
{
if (value[i] == (UChar)'\0')
{
@@ -77,8 +79,9 @@ void FixupLocaleName(UChar* value, int32_t valueLength)
value[i] = (UChar)'-';
}
}
-}
+ return i;
+}
extern "C" int32_t GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength)
{
@@ -100,3 +103,34 @@ extern "C" int32_t GetLocaleName(const UChar* localeName, UChar* value, int32_t
return UErrorCodeToBool(status);
}
+
+extern "C" int32_t GetDefaultLocaleName(UChar* value, int32_t valueLength)
+{
+ Locale locale = GetLocale(NULL);
+ if (locale.isBogus())
+ {
+ // ICU should be able to get default locale
+ return UErrorCodeToBool(U_INTERNAL_PROGRAM_ERROR);
+ }
+
+ UErrorCode status = u_charsToUChars_safe(locale.getBaseName(), value, valueLength);
+ if (U_SUCCESS(status))
+ {
+ int localeNameLen = FixupLocaleName(value, valueLength);
+
+ // if collation is present, return that to managed side
+ char collationValueTemp[ULOC_KEYWORDS_CAPACITY];
+ if (locale.getKeywordValue("collation", collationValueTemp, ULOC_KEYWORDS_CAPACITY, status) > 0)
+ {
+ // copy the collation; managed uses a "_" to represent collation (not "@collation=")
+ status = u_charsToUChars_safe("_", &value[localeNameLen], valueLength - localeNameLen);
+ if (U_SUCCESS(status))
+ {
+ status = u_charsToUChars_safe(collationValueTemp, &value[localeNameLen + 1], valueLength - localeNameLen - 1);
+ }
+ }
+ }
+
+ return UErrorCodeToBool(status);
+}
+
diff --git a/src/corefx/System.Globalization.Native/locale.hpp b/src/corefx/System.Globalization.Native/locale.hpp
index 894ea90936..0c100dae3c 100644
--- a/src/corefx/System.Globalization.Native/locale.hpp
+++ b/src/corefx/System.Globalization.Native/locale.hpp
@@ -43,6 +43,7 @@ UErrorCode u_charsToUChars_safe(const char *str, UChar* value, int32_t valueLeng
Function:
FixupLocaleName
-Replace underscores with hyphens to interop with existing .NET code
+Replace underscores with hyphens to interop with existing .NET code.
+Returns the length of the string.
*/
-void FixupLocaleName(UChar* value, int32_t valueLength);
+int FixupLocaleName(UChar* value, int32_t valueLength);