X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0be9ace27e0a278272cbb1e9daa988b65898eca1..2877659b059c5d20b07b585e26391dfd9ed780a2:/src/common/wxchar.cpp?ds=sidebyside diff --git a/src/common/wxchar.cpp b/src/common/wxchar.cpp index 326c34dbe6..a7a37548aa 100644 --- a/src/common/wxchar.cpp +++ b/src/common/wxchar.cpp @@ -2,14 +2,14 @@ // Name: wxchar.cpp // Purpose: wxChar implementation // Author: Ove Kåven -// Modified by: +// Modified by: Ron Lee // Created: 09/04/99 // RCS-ID: $Id$ // Copyright: (c) wxWindows copyright // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "wxchar.h" #endif @@ -540,6 +540,23 @@ int WXDLLEXPORT wxSnprintf_(wxChar *buf, size_t len, const wxChar *format, ...) } #endif // wxSnprintf_ +#if defined(__DMC__) + /* Digital Mars adds count to _stprintf (C99) so convert */ + #if wxUSE_UNICODE + int wxSprintf (wchar_t * __RESTRICT s, const wchar_t * __RESTRICT format, ... ) + { + va_list arglist; + + va_start( arglist, format ); + int iLen = swprintf ( s, -1, format, arglist ); + va_end( arglist ); + return iLen ; + } + + #endif // wxUSE_UNICODE + +#endif //__DMC__ + // ---------------------------------------------------------------------------- // implement the standard IO functions for wide char if libc doesn't have them // ---------------------------------------------------------------------------- @@ -599,7 +616,7 @@ int vfwprintf(FILE *stream, const wxChar *format, va_list argptr) if ( rc != -1 ) { // we can't do much better without Unicode support in libc... - if ( fprintf(stream, "%s", s.mb_str()) == -1 ) + if ( fprintf(stream, "%s", (const char*)s.mb_str() ) == -1 ) return -1; } @@ -752,7 +769,11 @@ wxFormatConverter::wxFormatConverter(const wxChar *format) // precision? if ( *format == _T('.') ) { - SkipDigits(&format); + CopyFmtChar(*format++); + if ( *format == _T('*') ) + CopyFmtChar(*format++); + else + SkipDigits(&format); } // next we can have a size modifier @@ -799,23 +820,14 @@ wxFormatConverter::wxFormatConverter(const wxChar *format) case _T('c'): case _T('s'): // %c -> %lc but %hc stays %hc and %lc is still %lc - switch ( size ) - { - case Default: - InsertFmtChar(_T('l')); - break; - - case Short: - CopyFmtChar(_T('h')); - break; - - case Long: - ; - } + if ( size == Default) + InsertFmtChar(_T('l')); // fall through default: // nothing special to do + if ( size != Default ) + CopyFmtChar(*(format - 1)); CopyFmtChar(*format++); } } @@ -827,6 +839,14 @@ wxFormatConverter::wxFormatConverter(const wxChar *format) #define wxFormatConverter(x) (x) #endif // wxNEED_PRINTF_CONVERSION/!wxNEED_PRINTF_CONVERSION +#ifdef __WXDEBUG__ +// For testing the format converter +wxString wxConvertFormat(const wxChar *format) +{ + return wxString(wxFormatConverter(format)); +} +#endif + // ---------------------------------------------------------------------------- // wxPrintf(), wxScanf() and relatives // ---------------------------------------------------------------------------- @@ -899,12 +919,14 @@ int wxSprintf( wxChar *str, const wxChar *format, ... ) va_list argptr; va_start(argptr, format); - // callers of wxSprintf() deserve what they get - int ret = vswprintf( str, UINT_MAX, wxFormatConverter(format), argptr ); + // note that wxString::Format() uses wxVsnprintf(), not wxSprintf(), so + // it's safe to implement this one in terms of it + wxString s(wxString::Format(format, argptr)); + wxStrcpy(str, s); va_end(argptr); - return ret; + return s.length(); } int wxFprintf( FILE *stream, const wxChar *format, ... ) @@ -944,7 +966,7 @@ int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list argptr int wxVsprintf( wxChar *str, const wxChar *format, va_list argptr ) { // same as for wxSprintf() - return vswprintf(str, UINT_MAX, wxFormatConverter(format), argptr); + return vswprintf(str, INT_MAX / 4, wxFormatConverter(format), argptr); } #endif // wxNEED_PRINTF_CONVERSION @@ -965,7 +987,7 @@ inline WORD wxMSW_ctype(wxChar ch) WXDLLEXPORT int wxIsalnum(wxChar ch) { return IsCharAlphaNumeric(ch); } WXDLLEXPORT int wxIsalpha(wxChar ch) { return IsCharAlpha(ch); } -WXDLLEXPORT int wxIsctrl(wxChar ch) { return wxMSW_ctype(ch) & C1_CNTRL; } +WXDLLEXPORT int wxIscntrl(wxChar ch) { return wxMSW_ctype(ch) & C1_CNTRL; } WXDLLEXPORT int wxIsdigit(wxChar ch) { return wxMSW_ctype(ch) & C1_DIGIT; } WXDLLEXPORT int wxIsgraph(wxChar ch) { return wxMSW_ctype(ch) & (C1_DIGIT|C1_PUNCT|C1_ALPHA); } WXDLLEXPORT int wxIslower(wxChar ch) { return IsCharLower(ch); } @@ -1205,28 +1227,6 @@ WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base) } #endif // wxNEED_WX_STRING_H -#if defined(__WXMAC__) && !defined(__DARWIN__) -WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode) -{ - return fopen( wxMacStringToCString(path), mode ); -} - -WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream) -{ - return freopen( wxMacStringToCString(path), mode, stream ); -} - -WXDLLEXPORT int wxRemove(const wxChar *path) -{ - return remove( wxMacStringToCString(path) ); -} - -WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath) -{ - return rename( wxMacStringToCString(oldpath), wxMacStringToCString(newpath) ); -} -#endif - #ifdef wxNEED_WX_STDIO_H WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode) { @@ -1305,7 +1305,7 @@ wxChar * WXDLLEXPORT wxGetenv(const wxChar *name) // printf( "home %s\n", val ); // convert it, -#ifdef wxUSE_UNICODE +#if wxUSE_UNICODE data = (wxObject *)new wxString(val, wxConvLocal); #else data = (wxObject *)new wxString(val); @@ -1347,6 +1347,18 @@ WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max, const wxChar *fmt, const } #endif // wxNEED_WX_TIME_H +#ifndef wxCtime +WXDLLEXPORT wxChar *wxCtime(const time_t *timep) +{ + static wxChar buf[128]; + + wxStrncpy( buf, wxConvertMB2WX( ctime( timep ) ), sizeof( buf ) ); + buf[ sizeof( buf ) - 1 ] = _T('\0'); + + return buf; +} +#endif // wxCtime + #endif // wxUSE_WCHAR_T // ---------------------------------------------------------------------------- @@ -1392,8 +1404,8 @@ WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_pt // missing C RTL functions // ---------------------------------------------------------------------------- -#if defined( __MWERKS__ ) && !defined(__MACH__) -#if __MSL__ < 0x00008000 +#if (defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)) || \ + defined(__WXWINCE__) char *strdup(const char *s) { char *dest = (char*) malloc( strlen( s ) + 1 ) ; @@ -1402,37 +1414,29 @@ char *strdup(const char *s) return dest ; } #endif -int isascii( int c ) -{ - return ( c >= 0 && c < 128 ) ; -} -#endif // __MWERKS__ -#ifdef __WXWINCE__ -char* strdup(const char* s) +#if (defined(__MWERKS__) && !defined(__MACH__)) || (defined(__WXWINCE__) && _WIN32_WCE <= 211) + +int isascii( int c ) { - char *dest = (char*) malloc( strlen( s ) + 1 ) ; - if ( dest ) - strcpy( dest , s ) ; - return dest ; + return ( c >= 0 && c < 128 ); } +#endif +#if defined(__WXWINCE__) && (_WIN32_WCE <= 211) +#if (_WIN32_WCE < 300) void *calloc( size_t num, size_t size ) { void** ptr = (void **)malloc(num * size); memset( ptr, 0, num * size); return ptr; } +#endif int isspace(int c) { return (c == ' '); } -int isascii( int c ) -{ - return ( c >= 0 && c < 128 ) ; -} #endif -