]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/wxchar.h
Implemented wxArrayString::Shrink() and stuff.
[wxWidgets.git] / include / wx / wxchar.h
index b2e27e27964423bf91544832b9450bbff0104119..5832ca016c70f75b684c8b72e6d9292c101f53a1 100644 (file)
 #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 <tchar.h>
+#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 <wchar.h>
+#include <wctype.h>
+
+// 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 <ctype.h>
+#include <string.h>
 
+#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 <stdio.h>
+#include <stdarg.h>
+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_