From: Václav Slavík Date: Sat, 28 Apr 2007 07:06:18 +0000 (+0000) Subject: allow the UTF8 build to treat C locale as UTF8, too, it's a 7bit subset of it, so... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e40dfb3a3820330084a899279d5ba624a390c96c allow the UTF8 build to treat C locale as UTF8, too, it's a 7bit subset of it, so it should be OK git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45703 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/wxcrt.cpp b/src/common/wxcrt.cpp index 7a1c9363bb..0cbcd5aa24 100644 --- a/src/common/wxcrt.cpp +++ b/src/common/wxcrt.cpp @@ -1544,18 +1544,28 @@ static bool wxIsLocaleUtf8() { // "UTF-8" is used by modern glibc versions, but test other variants // as well, just in case: - return strcmp(charset, "UTF-8") == 0 || - strcmp(charset, "utf-8") == 0 || - strcmp(charset, "UTF8") == 0 || - strcmp(charset, "utf8") == 0; + if ( strcmp(charset, "UTF-8") == 0 || + strcmp(charset, "utf-8") == 0 || + strcmp(charset, "UTF8") == 0 || + strcmp(charset, "utf8") == 0 ) + { + return true; + } } - else // nl_langinfo() failed #endif + + // check if we're running under the "C" locale: it is 7bit subset + // of UTF-8, so it can be safely used with the UTF-8 build: + const char *lc_ctype = setlocale(LC_CTYPE, NULL); + if ( lc_ctype && + (strcmp(lc_ctype, "C") == 0 || strcmp(lc_ctype, "POSIX") == 0) ) { - // we don't know what charset libc is using, so assume the worst - // to be safe: - return false; + return true; } + + // we don't know what charset libc is using, so assume the worst + // to be safe: + return false; } void wxUpdateLocaleIsUtf8()