X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8fd7108e7cfd6d3564a71ab5f49c391613e27798..fc32630a5e03e60a67d4ef53fc59985ea087b451:/src/common/wxcrt.cpp diff --git a/src/common/wxcrt.cpp b/src/common/wxcrt.cpp index 4b3096aee5..9bd6305307 100644 --- a/src/common/wxcrt.cpp +++ b/src/common/wxcrt.cpp @@ -21,6 +21,7 @@ #endif #include "wx/crt.h" +#include "wx/strconv.h" // wxMBConv::cWC2MB() #define _ISOC9X_SOURCE 1 // to get vsscanf() #define _BSD_SOURCE 1 // to still get strdup() @@ -29,12 +30,14 @@ #include #include +#ifndef __WXPALMOS5__ #ifndef __WXWINCE__ #include #include #else #include "wx/msw/wince/time.h" #endif +#endif // !__WXPALMOS5__ #ifndef WX_PRECOMP #include "wx/string.h" @@ -43,6 +46,10 @@ #include "wx/log.h" #endif +#ifdef HAVE_LANGINFO_H + #include +#endif + #ifdef __WXWINCE__ // there is no errno.h under CE apparently #define wxSET_ERRNO(value) @@ -57,6 +64,13 @@ namespace std {} using namespace std ; #endif +#if defined(__DARWIN__) + #include "wx/mac/corefoundation/cfref.h" + #include + #include "wx/mac/corefoundation/cfstring.h" + #include +#endif + #if wxUSE_WCHAR_T WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n) { @@ -119,27 +133,6 @@ WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *pwz, size_t n) } #endif // wxUSE_WCHAR_T -WXDLLIMPEXP_BASE bool wxOKlibc() -{ -#if wxUSE_WCHAR_T && defined(__UNIX__) && defined(__GLIBC__) && !defined(__WINE__) - // glibc 2.0 uses UTF-8 even when it shouldn't - wchar_t res = 0; - if ((MB_CUR_MAX == 2) && - (wxMB2WC(&res, "\xdd\xa5", 1) == 1) && - (res==0x765)) { - // this is UTF-8 allright, check whether that's what we want - char *cur_locale = setlocale(LC_CTYPE, NULL); - if ((strlen(cur_locale) < 4) || - (strcasecmp(cur_locale + strlen(cur_locale) - 4, "utf8")) || - (strcasecmp(cur_locale + strlen(cur_locale) - 5, "utf-8"))) { - // nope, don't use libc conversion - return false; - } - } -#endif - return true; -} - char* wxSetlocale(int category, const char *locale) { #ifdef __WXWINCE__ @@ -149,7 +142,27 @@ char* wxSetlocale(int category, const char *locale) return NULL; #else // !__WXWINCE__ +#ifdef __WXMAC__ + char *rv = NULL ; + if ( locale != NULL && locale[0] == 0 ) + { + // the attempt to use newlocale(LC_ALL_MASK, "", NULL); + // here in order to deduce the language along the environment vars rules + // lead to strange crashes later... + + // we have to emulate the behaviour under OS X + wxCFRef userLocaleRef(CFLocaleCopyCurrent()); + wxCFStringRef str(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleLanguageCode))); + wxString langFull = str.AsString()+"_"; + str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode))); + langFull += str.AsString(); + rv = setlocale(category, langFull.c_str()); + } + else + rv = setlocale(category, locale); +#else char *rv = setlocale(category, locale); +#endif if ( locale != NULL /* setting locale, not querying */ && rv /* call was successful */ ) { @@ -247,21 +260,6 @@ static int vwscanf(const wchar_t *format, va_list argptr) return -1; } -static int vswscanf(const wchar_t *ws, const wchar_t *format, va_list argptr) -{ - // The best we can do without proper Unicode support in glibc is to - // convert the strings into MB representation and run ANSI version - // of the function. This doesn't work with %c and %s because of difference - // in size of char and wchar_t, though. - - wxCHECK_MSG( wxStrstr(format, _T("%s")) == NULL, -1, - _T("incomplete vswscanf implementation doesn't allow %s") ); - wxCHECK_MSG( wxStrstr(format, _T("%c")) == NULL, -1, - _T("incomplete vswscanf implementation doesn't allow %c") ); - - return vsscanf(wxConvLibc.cWX2MB(ws), wxConvLibc.cWX2MB(format), argptr); -} - static int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr) { wxFAIL_MSG( _T("TODO") ); @@ -293,6 +291,24 @@ static int vwprintf(const wchar_t *format, va_list argptr) #endif // wxNEED_WPRINTF +#ifdef wxNEED_VSWSCANF +static int vswscanf(const wchar_t *ws, const wchar_t *format, va_list argptr) +{ + // The best we can do without proper Unicode support in glibc is to + // convert the strings into MB representation and run ANSI version + // of the function. This doesn't work with %c and %s because of difference + // in size of char and wchar_t, though. + + wxCHECK_MSG( wxStrstr(format, _T("%s")) == NULL, -1, + _T("incomplete vswscanf implementation doesn't allow %s") ); + wxCHECK_MSG( wxStrstr(format, _T("%c")) == NULL, -1, + _T("incomplete vswscanf implementation doesn't allow %c") ); + + return vsscanf(wx_static_cast(const char*, wxConvLibc.cWX2MB(ws)), + wxConvLibc.cWX2MB(format), argptr); +} +#endif + // ---------------------------------------------------------------------------- // wxPrintf(), wxScanf() and relatives // ---------------------------------------------------------------------------- @@ -625,7 +641,20 @@ int wxVsprintf(char *str, const wxString& format, va_list argptr) int wxVsprintf(wchar_t *str, const wxString& format, va_list argptr) { #if wxUSE_UNICODE_WCHAR +#ifdef __DMC__ +/* +This fails with a bug similar to +http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=c++.beta&artnum=680 +in DMC 8.49 and 8.50 +I don't see it being used in the wxWidgets sources at present (oct 2007) CE +*/ +#pragma message ( "warning ::::: wxVsprintf(wchar_t *str, const wxString& format, va_list argptr) not yet implemented" ) + wxFAIL_MSG( _T("TODO") ); + + return -1; +#else return wxCRT_VsprintfW(str, format.wc_str(), argptr); +#endif //DMC #else // wxUSE_UNICODE_UTF8 #if !wxUSE_UTF8_LOCALE_ONLY if ( !wxLocaleIsUtf8 ) @@ -936,9 +965,9 @@ wxCRT_StrtoullBase(const T* nptr, T** endptr, int base, T* sign) unsigned int n; T c = *i; - if ( c >= wxT('0') ) + if ( c >= '0' ) { - if ( c <= wxT('9') ) + if ( c <= '9' ) n = c - wxT('0'); else n = wxTolower(c) - wxT('a') + 10; @@ -992,12 +1021,9 @@ static wxLongLong_t wxCRT_DoStrtoll(const T* nptr, T** endptr, int base) if ( sign == wxT('-') ) { - if ( uval <= wxULL(wxINT64_MAX+1) ) + if (uval <= (wxULongLong_t)wxINT64_MAX + 1) { - if ( uval == wxULL(wxINT64_MAX+1)) - val = -((wxLongLong_t)wxINT64_MAX) - 1; - else - val = -((wxLongLong_t)uval); + val = -(wxLongLong_t)uval; } else { @@ -1139,7 +1165,7 @@ static bool wxIsLocaleUtf8() return true; } } -#endif +#endif // HAVE_LANGINFO_H // 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: @@ -1243,21 +1269,21 @@ wchar_t *wxFgets(wchar_t *s, int size, FILE *stream) // wxScanf() and friends // ---------------------------------------------------------------------------- -#ifndef __VISUALC__ +#ifdef HAVE_VSSCANF // __VISUALC__ and __DMC__ see wx/crt.h int wxVsscanf(const char *str, const char *format, va_list ap) { return wxCRT_VsscanfA(str, format, ap); } int wxVsscanf(const wchar_t *str, const wchar_t *format, va_list ap) { return wxCRT_VsscanfW(str, format, ap); } int wxVsscanf(const wxCharBuffer& str, const char *format, va_list ap) - { return wxCRT_VsscanfA(str, format, ap); } + { return wxCRT_VsscanfA(wx_static_cast(const char*, str), format, ap); } int wxVsscanf(const wxWCharBuffer& str, const wchar_t *format, va_list ap) { return wxCRT_VsscanfW(str, format, ap); } int wxVsscanf(const wxString& str, const char *format, va_list ap) - { return wxCRT_VsscanfA(str.mb_str(), format, ap); } + { return wxCRT_VsscanfA(wx_static_cast(const char*, str.mb_str()), format, ap); } int wxVsscanf(const wxString& str, const wchar_t *format, va_list ap) { return wxCRT_VsscanfW(str.wc_str(), format, ap); } int wxVsscanf(const wxCStrData& str, const char *format, va_list ap) - { return wxCRT_VsscanfA(str.AsCharBuf(), format, ap); } + { return wxCRT_VsscanfA(wx_static_cast(const char*, str.AsCharBuf()), format, ap); } int wxVsscanf(const wxCStrData& str, const wchar_t *format, va_list ap) { return wxCRT_VsscanfW(str.AsWCharBuf(), format, ap); } -#endif // !__VISUALC__ +#endif // HAVE_NO_VSSCANF