summaryrefslogtreecommitdiff
path: root/src/corefx/System.Globalization.Native/locale.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corefx/System.Globalization.Native/locale.cpp')
-rw-r--r--src/corefx/System.Globalization.Native/locale.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/corefx/System.Globalization.Native/locale.cpp b/src/corefx/System.Globalization.Native/locale.cpp
index 1cb564a45a..951179d321 100644
--- a/src/corefx/System.Globalization.Native/locale.cpp
+++ b/src/corefx/System.Globalization.Native/locale.cpp
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <locale.h>
+#include "icushim.h"
#include "locale.hpp"
int32_t UErrorCodeToBool(UErrorCode status)
@@ -147,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;