Update Locale

This commit is contained in:
Joshua Granick
2016-09-07 14:47:37 -07:00
parent fdae1d359a
commit 83ac4fa432
4 changed files with 21 additions and 25 deletions

View File

@@ -1,6 +1,8 @@
#ifndef LIME_SYSTEM_LOCALE_H #ifndef LIME_SYSTEM_LOCALE_H
#define LIME_SYSTEM_LOCALE_H #define LIME_SYSTEM_LOCALE_H
#include <string>
namespace lime { namespace lime {
@@ -10,7 +12,7 @@ namespace lime {
public: public:
static char* GetSystemLocale (); static std::string* GetSystemLocale ();
}; };

View File

@@ -1033,21 +1033,19 @@ namespace lime {
value lime_locale_get_system_locale () { value lime_locale_get_system_locale () {
std::string* locale = Locale::GetSystemLocale ();
if (!locale) {
return alloc_null (); return alloc_null ();
//char* locale = Locale::GetSystemLocale (); } else {
//
//if (!locale) { value result = alloc_string (locale->c_str ());
// delete locale;
//return alloc_null (); return result;
//
//} else { }
//
//value result = alloc_string (locale);
//free (locale);
//return result;
//
//}
} }

View File

@@ -12,14 +12,13 @@
namespace lime { namespace lime {
char* Locale::GetSystemLocale () { std::string* Locale::GetSystemLocale () {
#if defined(HX_WINDOWS) #if defined(HX_WINDOWS)
char locale[8]; char locale[8];
int length = GetLocaleInfo (GetSystemDefaultUILanguage (), LOCALE_SISO639LANGNAME, locale, sizeof (locale)); int length = GetLocaleInfo (GetSystemDefaultUILanguage (), LOCALE_SISO639LANGNAME, locale, sizeof (locale));
char *result = (char*)malloc (length + 1); std::string* result = new std::string (locale);
strcpy (result, locale);
return result; return result;
#elif defined(HX_LINUX) #elif defined(HX_LINUX)
@@ -34,9 +33,7 @@ namespace lime {
if (locale) { if (locale) {
char *result = (char*)malloc (sizeof (locale)); std::string* result = new std::string (locale);
strcpy (result, locale);
return result; return result;
} }

View File

@@ -10,20 +10,19 @@
namespace lime { namespace lime {
char* Locale::GetSystemLocale () { std::string* Locale::GetSystemLocale () {
#ifndef OBJC_ARC #ifndef OBJC_ARC
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
#endif #endif
NSString* locale = [[NSLocale currentLocale] localeIdentifier]; NSString* locale = [[NSLocale currentLocale] localeIdentifier];
char* result = 0; std::string* result = 0;
if (locale) { if (locale) {
const char* ptr = [locale UTF8String]; const char* ptr = [locale UTF8String];
result = (char*)malloc ([locale length] + 1); result = new std::string (ptr);
strncpy (result, ptr, [locale length]);
} }