X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3f4a0c5be34be837210768501c13dbcff81e533c..d4ffe273ca70deb8e2cff7be9a07b0640e24bee0:/include/wx/wxchar.h?ds=sidebyside diff --git a/include/wx/wxchar.h b/include/wx/wxchar.h index b2e27e2796..5832ca016c 100644 --- a/include/wx/wxchar.h +++ b/include/wx/wxchar.h @@ -21,13 +21,19 @@ #error "MBCS is not supported by wxChar" #endif -// only do Unicode for Windows (VC++), for now +// Windows (VC++) has broad TCHAR support #if defined(__VISUALC__) && defined(__WIN32__) #include +#if wxUSE_UNICODE // temporary - preserve binary compatibility typedef _TCHAR wxChar; typedef _TSCHAR wxSChar; typedef _TUCHAR wxUChar; +#else +#define wxChar char +#define wxSChar signed char +#define wxUChar unsigned char +#endif // ctype.h functions #define wxIsalnum _istalnum @@ -63,7 +69,7 @@ typedef _TUCHAR wxUChar; #define wxStrspn _tcsspn #define wxStrstr _tcsstr #define wxStrtod _tcstod -#define wxStrtok _tcstok +// is there a _tcstok[_r] ? #define wxStrtol _tcstol #define wxStrtoul _tcstoul #define wxStrxfrm _tcsxfrm @@ -95,9 +101,13 @@ typedef _TUCHAR wxUChar; #define wxUngetc _tungetc #define wxVfprint _vftprintf #define wxVprintf _vtprintf +#define wxVsscanf _vstscanf #define wxVsprintf _vstprintf // stdlib.h functions +#if !wxUSE_UNICODE +#define wxAtof atof +#endif #define wxAtoi _ttoi #define wxAtol _ttol #define wxGetenv _tgetenv @@ -113,16 +123,88 @@ typedef _TUCHAR wxUChar; // translate wxZZZ names -#else//!Unicode +#else//!Windows (VC++) + +// check whether we are doing Unicode +#if wxUSE_UNICODE + +#include +#include + +// this is probably glibc-specific +#if defined(__WCHAR_TYPE__) + +typedef __WCHAR_TYPE__ wxChar; +typedef signed __WCHAR_TYPE__ wxSChar; +typedef unsigned __WCHAR_TYPE__ wxUChar; + +#define _T(x) L##x + + // ctype.h functions (wctype.h) +#define wxIsalnum iswalnum +#define wxIsalpha iswalpha +#define wxIsctrl iswcntrl +#define wxIsdigit iswdigit +#define wxIsgraph iswgraph +#define wxIslower iswlower +#define wxIsprint iswprint +#define wxIspunct iswpunct +#define wxIsspace iswspace +#define wxIsupper iswupper +#define wxIsxdigit iswxdigit -// make sure we aren't doing Unicode -#if defined ( __WXUNICODE__ ) || defined ( _UNICODE ) +#if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0) + // /usr/include/wctype.h incorrectly declares translations tables which + // provokes tons of compile-time warnings - try to correct this + #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower) + #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper) +#else + #define wxTolower towlower + #define wxToupper towupper +#endif // gcc/!gcc + + // string.h functions (wchar.h) +#define wxStrcat wcscat +#define wxStrchr wcschr +#define wxStrcmp wcscmp +#define wxStrcoll wcscoll +#define wxStrcpy wcscpy +#define wxStrcspn wcscspn +#define wxStrncat wcsncat +#define wxStrncmp wcsncmp +#define wxStrncpy wcsncpy +#define wxStrpbrk wcspbrk +#define wxStrrchr wcsrchr +#define wxStrspn wcsspn +#define wxStrstr wcsstr +#define wxStrtod wcstod +#define wxStrtok wcstok +#define wxStrtol wcstol +#define wxStrtoul wcstoul +#define wxStrxfrm wcsxfrm + +// glibc doesn't have wc equivalents of the other stuff +#define wxNEED_WX_STDIO_H +#define wxNEED_WX_STDLIB_H +#define wxNEED_WX_TIME_H + +#else #error "Please define your compiler's Unicode conventions in wxChar.h" #endif +#else//!Unicode + +#include +#include +#if 0 // temporary - preserve binary compatibilty typedef char wxChar; typedef signed char wxSChar; typedef unsigned char wxUChar; +#else +#define wxChar char +#define wxSChar signed char +#define wxUChar unsigned char +#endif #define _T(x) x @@ -151,7 +233,7 @@ typedef unsigned char wxUChar; #define wxStrcoll strcoll #define wxStrcpy strcpy #define wxStrcspn strcspn -#define wxStrftime strftime +#define wxStrdup strdup #define wxStrncat strncat #define wxStrncmp strncmp #define wxStrncpy strncpy @@ -160,7 +242,7 @@ typedef unsigned char wxUChar; #define wxStrspn strspn #define wxStrstr strstr #define wxStrtod strtod -#define wxStrtok strtok +// #define wxStrtok strtok_r // this needs a configure check #define wxStrtol strtol #define wxStrtoul strtoul #define wxStrxfrm strxfrm @@ -192,9 +274,11 @@ typedef unsigned char wxUChar; #define wxUngetc ungetc #define wxVfprint vfprintf #define wxVprintf vprintf +#define wxVsscanf vsscanf #define wxVsprintf vsprintf // stdlib.h functions +#define wxAtof atof #define wxAtoi atoi #define wxAtol atol #define wxGetenv getenv @@ -203,38 +287,54 @@ typedef unsigned char wxUChar; // time.h functions #define wxAsctime asctime #define wxCtime ctime +#define wxStrftime strftime #endif//Unicode +#endif /// checks whether the passed in pointer is NULL and if the string is empty inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; } /// safe version of strlen() (returns 0 if passed NULL pointer) -inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz) +inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz) #if defined(__VISUALC__) { return psz ? _tcslen(psz) : 0; } +#elif wxUSE_UNICODE + { return psz ? wcslen(psz) : 0; } #else { return psz ? strlen(psz) : 0; } #endif /// portable strcasecmp/_stricmp -inline int WXDLLEXPORT wxStricmp(const wxChar *, const wxChar *) +inline int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2) #if defined(__VISUALC__) { return _tcsicmp(psz1, psz2); } -#elif defined(__BORLANDC__) +#elif defined(__BORLANDC__) && !wxUSE_UNICODE { return stricmp(psz1, psz2); } -#elif defined(__UNIX__) || defined(__GNUWIN32__) +#elif defined(__UNIX__) || defined(__GNUWIN32__) +#if !wxUSE_UNICODE { return strcasecmp(psz1, psz2); } +#else // glibc doesn't seem to have wide char equivalent + { + register wxChar c1, c2; + do { + c1 = wxTolower(*psz1++); + c2 = wxTolower(*psz2++); + } while ( c1 && (c1 == c2) ); + + return c1 - c2; + } +#endif #else // almost all compilers/libraries provide this function (unfortunately under // different names), that's why we don't implement our own which will surely // be more efficient than this code (uncomment to use): /* - register char c1, c2; + register wxChar c1, c2; do { - c1 = tolower(*psz1++); - c2 = tolower(*psz2++); + c1 = wxTolower(*psz1++); + c2 = wxTolower(*psz2++); } while ( c1 && (c1 == c2) ); return c1 - c2; @@ -243,5 +343,57 @@ inline int WXDLLEXPORT wxStricmp(const wxChar *, const wxChar *) #error "Please define string case-insensitive compare for your OS/compiler" #endif // OS/compiler +// multibyte<->widechar conversion +size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n); +size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *psz, size_t n); +#if wxUSE_UNICODE +#define wxMB2WX wxMB2WC +#define wxWX2MB wxWC2MB +#define wxWC2WX wxStrncpy +#define wxWX2WC wxStrncpy +#else +#define wxMB2WX wxStrncpy +#define wxWX2MB wxStrncpy +#define wxWC2WX wxWC2MB +#define wxWX2WC wxMB2WC +#endif + +// if libc versions are not available, use replacements defined in wxchar.cpp +#ifndef wxStrdup +wxChar * WXDLLEXPORT wxStrdup(const wxChar *psz); +#endif + +#ifndef wxStrtok +wxChar * WXDLLEXPORT wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr); +#endif + +#ifndef wxSetlocale +wxChar * WXDLLEXPORT wxSetlocale(int category, const wxChar *locale); +#endif + +#ifdef wxNEED_WX_STDIO_H +#include +#include +int WXDLLEXPORT wxPrintf(const wxChar *fmt, ...); +int WXDLLEXPORT wxVprintf(const wxChar *fmt, va_list argptr); +int WXDLLEXPORT wxFprintf(FILE *stream, const wxChar *fmt, ...); +int WXDLLEXPORT wxVfprintf(FILE *stream, const wxChar *fmt, va_list argptr); +int WXDLLEXPORT wxSprintf(wxChar *buf, const wxChar *fmt, ...); +int WXDLLEXPORT wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr); +int WXDLLEXPORT wxSscanf(const wxChar *buf, const wxChar *fmt, ...); +int WXDLLEXPORT wxVsscanf(const wxChar *buf, const wxChar *fmt, va_list argptr); +#endif + +#ifndef wxAtof +double WXDLLEXPORT wxAtof(const wxChar *psz); +#endif + +#ifdef wxNEED_WX_STDLIB_H +int WXDLLEXPORT wxAtoi(const wxChar *psz); +long WXDLLEXPORT wxAtol(const wxChar *psz); +wxChar * WXDLLEXPORT wxGetenv(const wxChar *name); +int WXDLLEXPORT wxSystem(const wxChar *psz); +#endif + #endif //_WX_WXCHAR_H_