diff --git a/project/include/system/Locale.h b/project/include/system/Locale.h index ef0cf3669..926c2312c 100644 --- a/project/include/system/Locale.h +++ b/project/include/system/Locale.h @@ -1,6 +1,8 @@ #ifndef LIME_SYSTEM_LOCALE_H #define LIME_SYSTEM_LOCALE_H +#include + namespace lime { @@ -10,7 +12,7 @@ namespace lime { public: - static char* GetSystemLocale (); + static std::string* GetSystemLocale (); }; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 5f1d50582..e487481c1 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -1033,21 +1033,19 @@ namespace lime { value lime_locale_get_system_locale () { - return alloc_null (); + std::string* locale = Locale::GetSystemLocale (); - //char* locale = Locale::GetSystemLocale (); - // - //if (!locale) { - // - //return alloc_null (); - // - //} else { - // - //value result = alloc_string (locale); - //free (locale); - //return result; - // - //} + if (!locale) { + + return alloc_null (); + + } else { + + value result = alloc_string (locale->c_str ()); + delete locale; + return result; + + } } diff --git a/project/src/system/Locale.cpp b/project/src/system/Locale.cpp index 2db6b1504..85a182594 100644 --- a/project/src/system/Locale.cpp +++ b/project/src/system/Locale.cpp @@ -12,14 +12,13 @@ namespace lime { - char* Locale::GetSystemLocale () { + std::string* Locale::GetSystemLocale () { #if defined(HX_WINDOWS) char locale[8]; int length = GetLocaleInfo (GetSystemDefaultUILanguage (), LOCALE_SISO639LANGNAME, locale, sizeof (locale)); - char *result = (char*)malloc (length + 1); - strcpy (result, locale); + std::string* result = new std::string (locale); return result; #elif defined(HX_LINUX) @@ -34,9 +33,7 @@ namespace lime { if (locale) { - char *result = (char*)malloc (sizeof (locale)); - strcpy (result, locale); - + std::string* result = new std::string (locale); return result; } diff --git a/project/src/system/Locale.mm b/project/src/system/Locale.mm index 2b7798c31..84d9fc796 100644 --- a/project/src/system/Locale.mm +++ b/project/src/system/Locale.mm @@ -10,20 +10,19 @@ namespace lime { - char* Locale::GetSystemLocale () { + std::string* Locale::GetSystemLocale () { #ifndef OBJC_ARC NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; #endif NSString* locale = [[NSLocale currentLocale] localeIdentifier]; - char* result = 0; + std::string* result = 0; if (locale) { const char* ptr = [locale UTF8String]; - result = (char*)malloc ([locale length] + 1); - strncpy (result, ptr, [locale length]); + result = new std::string (ptr); }