From: Vadim Zeitlin Date: Tue, 5 Feb 2013 20:46:26 +0000 (+0000) Subject: Ignore empty LC_XXX variables in locale detection code. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/968b44d37b9fcdc5232fb68312a65e4fc6b5f4ab Ignore empty LC_XXX variables in locale detection code. If LC_ALL or LC_MESSAGES is set but empty, ignore it and use the next environment variable. This is consistent with the standard setlocale() behaviour which only uses LC_ALL if it is set and not empty. Closes #15006. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73466 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 29132e9ad6..5d7cb3e38d 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -570,6 +570,18 @@ bool wxLocale::Init(int language, int flags) #endif // !WX_NO_LOCALE_SUPPORT } +namespace +{ + +// Small helper function: get the value of the given environment variable and +// return true only if the variable was found and has non-empty value. +inline bool wxGetNonEmptyEnvVar(const wxString& name, wxString* value) +{ + return wxGetEnv(name, value) && !value->empty(); +} + +} // anonymous namespace + /*static*/ int wxLocale::GetSystemLanguage() { CreateLanguagesDB(); @@ -592,9 +604,9 @@ bool wxLocale::Init(int language, int flags) str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode))); langFull += str.AsString(); #else - if (!wxGetEnv(wxS("LC_ALL"), &langFull) && - !wxGetEnv(wxS("LC_MESSAGES"), &langFull) && - !wxGetEnv(wxS("LANG"), &langFull)) + if (!wxGetNonEmptyEnvVar(wxS("LC_ALL"), &langFull) && + !wxGetNonEmptyEnvVar(wxS("LC_MESSAGES"), &langFull) && + !wxGetNonEmptyEnvVar(wxS("LANG"), &langFull)) { // no language specified, treat it as English return wxLANGUAGE_ENGLISH_US;