X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3a12b759c9262ae0c4e2fca5adaf5feab573d716..bba35861478a26f5d8c756a9a7fa2bbd19a69cb1:/src/common/wxcrt.cpp?ds=sidebyside diff --git a/src/common/wxcrt.cpp b/src/common/wxcrt.cpp index d7de48de96..6f3377d6cd 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" @@ -65,6 +68,7 @@ using namespace std ; #include "wx/mac/corefoundation/cfref.h" #include #include "wx/mac/corefoundation/cfstring.h" + #include #endif #if wxUSE_WCHAR_T @@ -163,11 +167,15 @@ char* wxSetlocale(int category, const char *locale) 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()); - wxMacCFStringHolder str(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleLanguageCode))); + wxCFStringRef str(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleLanguageCode))); wxString langFull = str.AsString()+"_"; - str.Assign(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode))); + str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode))); langFull += str.AsString(); rv = setlocale(category, langFull.c_str()); } @@ -273,21 +281,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") ); @@ -319,6 +312,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 // ---------------------------------------------------------------------------- @@ -1031,12 +1042,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 { @@ -1288,15 +1296,15 @@ int wxVsscanf(const char *str, const char *format, va_list 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 // HAVE_NO_VSSCANF