fixing strange bug under OS X (null strings from within CoreFoundation)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50833 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2007-12-19 17:05:57 +00:00
parent 1bf629bd9a
commit 93254327a1

View File

@@ -167,26 +167,17 @@ char* wxSetlocale(int category, const char *locale)
char *rv = NULL ; char *rv = NULL ;
if ( locale != NULL && locale[0] == 0 ) if ( locale != NULL && locale[0] == 0 )
{ {
locale_t lt = newlocale(LC_ALL_MASK, "", NULL); // the attempt to use newlocale(LC_ALL_MASK, "", NULL);
if ( lt ) // here in order to deduce the language along the environment vars rules
{ // lead to strange crashes later...
rv = (char*) querylocale( LC_ALL_MASK, lt );
freelocale(lt); // we have to emulate the behaviour under OS X
} wxCFRef<CFLocaleRef> userLocaleRef(CFLocaleCopyCurrent());
if ( rv == NULL || rv[0] == 0 || strcmp( rv , "C" ) == 0 || strcmp( rv, "POSIX" ) == 0 ) wxCFStringRef str(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleLanguageCode)));
{ wxString langFull = str.AsString()+"_";
// we have to emulate the behaviour under OS X str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode)));
wxCFRef<CFLocaleRef> userLocaleRef(CFLocaleCopyCurrent()); langFull += str.AsString();
wxCFStringRef str(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleLanguageCode))); rv = setlocale(category, langFull.c_str());
wxString langFull = str.AsString()+"_";
str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode)));
langFull += str.AsString();
rv = setlocale(category, langFull.c_str());
}
else
{
rv = setlocale(category, rv);
}
} }
else else
rv = setlocale(category, locale); rv = setlocale(category, locale);