// 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 license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "wxchar.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <locale.h>
+
+#ifndef __WXWINCE__
#include <time.h>
+#include <locale.h>
+#else
+#include "wx/msw/wince/time.h"
+#endif
#ifndef WX_PRECOMP
#include "wx/defs.h"
#include <winnt.h>
#endif
+#if defined(__MWERKS__) && __MSL__ >= 0x6000
+using namespace std ;
+#endif
+
+#ifdef __WXMAC__
+ #include "wx/mac/private.h"
+#endif
+
#if wxUSE_WCHAR_T
size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n)
{
bool WXDLLEXPORT wxOKlibc()
{
-#if wxUSE_WCHAR_T && defined(__UNIX__) && defined(__GLIBC__)
+#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) &&
}
#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
// ----------------------------------------------------------------------------
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;
}
// precision?
if ( *format == _T('.') )
{
- SkipDigits(&format);
+ CopyFmtChar(*format++);
+ if ( *format == _T('*') )
+ CopyFmtChar(*format++);
+ else
+ SkipDigits(&format);
}
// next we can have a size modifier
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++);
}
}
#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
// ----------------------------------------------------------------------------
{
va_list argptr;
va_start(argptr, format);
-
int ret = vfwscanf(stream, wxFormatConverter(format), argptr);
va_end(argptr);
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, ... )
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
+#if wxUSE_WCHAR_T
+
// ----------------------------------------------------------------------------
// ctype.h stuff (currently unused)
// ----------------------------------------------------------------------------
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); }
WXDLLEXPORT int wxToupper(wxChar ch) { return (wxChar)CharUpper((LPTSTR)(ch)); }
#endif
-#ifndef wxStrdup
-WXDLLEXPORT wxChar * wxStrdup(const wxChar *psz)
+#ifndef wxStrdupA
+
+WXDLLEXPORT char *wxStrdupA(const char *s)
+{
+ return strcpy((char *)malloc(strlen(s) + 1), s);
+}
+
+#endif // wxStrdupA
+
+#ifndef wxStrdupW
+
+WXDLLEXPORT wchar_t * wxStrdupW(const wchar_t *pwz)
{
- size_t size = (wxStrlen(psz) + 1) * sizeof(wxChar);
- wxChar *ret = (wxChar *) malloc(size);
- memcpy(ret, psz, size);
+ size_t size = (wxWcslen(pwz) + 1) * sizeof(wchar_t);
+ wchar_t *ret = (wchar_t *) malloc(size);
+ memcpy(ret, pwz, size);
return ret;
}
-#endif
+
+#endif // wxStrdupW
#ifndef wxStricmp
int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2)
#ifndef wxStricmp
int WXDLLEXPORT wxStrnicmp(const wxChar *s1, const wxChar *s2, size_t n)
{
- register wxChar c1, c2;
+ // initialize the variables just to suppress stupid gcc warning
+ register wxChar c1 = 0, c2 = 0;
while (n && ((c1 = wxTolower(*s1)) == (c2 = wxTolower(*s2)) ) && c1) n--, s1++, s2++;
if (n) {
if (c1 < c2) return -1;
}
#endif
-#ifndef wxStrtok
-WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr)
-{
- if (!psz)
- {
- psz = *save_ptr;
- if ( !psz )
- return NULL;
- }
-
- psz += wxStrspn(psz, delim);
- if (!*psz)
- {
- *save_ptr = (wxChar *)NULL;
- return (wxChar *)NULL;
- }
-
- wxChar *ret = psz;
- psz = wxStrpbrk(psz, delim);
- if (!psz)
- {
- *save_ptr = (wxChar*)NULL;
- }
- else
- {
- *psz = wxT('\0');
- *save_ptr = psz + 1;
- }
-
- return ret;
-}
-#endif // wxStrtok
-
#ifndef wxSetlocale
WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale)
{
#ifndef wxAtof
double WXDLLEXPORT wxAtof(const wxChar *psz)
{
- return atof(wxConvLocal.cWX2MB(psz));
+#ifdef __WXWINCE__
+ double d;
+ wxString str(psz);
+ if (str.ToDouble(& d))
+ return d;
+ else
+ return 0.0;
+#else
+ return atof(wxConvLocal.cWX2MB(psz));
+#endif
}
#endif
// 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);
return system(wxConvLocal.cWX2MB(psz));
}
-#endif
+#endif // wxNEED_WX_STDLIB_H
#ifdef wxNEED_WX_TIME_H
WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max, const wxChar *fmt, const struct tm *tm)
return 0;
}
}
+#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
+
+// ----------------------------------------------------------------------------
+// functions which we may need even if !wxUSE_WCHAR_T
+// ----------------------------------------------------------------------------
+
+#ifndef wxStrtok
+
+WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr)
+{
+ if (!psz)
+ {
+ psz = *save_ptr;
+ if ( !psz )
+ return NULL;
+ }
+
+ psz += wxStrspn(psz, delim);
+ if (!*psz)
+ {
+ *save_ptr = (wxChar *)NULL;
+ return (wxChar *)NULL;
+ }
+
+ wxChar *ret = psz;
+ psz = wxStrpbrk(psz, delim);
+ if (!psz)
+ {
+ *save_ptr = (wxChar*)NULL;
+ }
+ else
+ {
+ *psz = wxT('\0');
+ *save_ptr = psz + 1;
+ }
+
+ return ret;
+}
+
+#endif // wxStrtok
+
+// ----------------------------------------------------------------------------
+// missing C RTL functions
+// ----------------------------------------------------------------------------
+
+#if (defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)) || \
+ defined(__WXWINCE__)
+char *strdup(const char *s)
+{
+ char *dest = (char*) malloc( strlen( s ) + 1 ) ;
+ if ( dest )
+ strcpy( dest , s ) ;
+ return dest ;
+}
#endif
+
+#if (defined(__MWERKS__) && !defined(__MACH__)) || (defined(__WXWINCE__) && _WIN32_WCE <= 211)
+
+int isascii( int c )
+{
+ 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 == ' ');
+}
+
+#endif
+