1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Declarations common to wx char/wchar_t usage (wide chars)
8 // Copyright: (c) wxWindows copyright
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "wxchar.h"
19 // only do SBCS or _UNICODE
21 #error "MBCS is not supported by wxChar"
24 // set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
25 #if defined(_UNICODE) || defined(UNICODE)
27 #define wxUSE_UNICODE 1
30 #define wxUSE_UNICODE 0
34 // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
44 // Windows (VC++) has broad TCHAR support
45 #if defined(__VISUALC__) && defined(__WIN32__)
48 #if wxUSE_UNICODE // temporary - preserve binary compatibility
49 typedef _TCHAR wxChar
;
50 typedef _TSCHAR wxSChar
;
51 typedef _TUCHAR wxUChar
;
54 #define wxSChar signed char
55 #define wxUChar unsigned char
59 #define wxIsalnum _istalnum
60 #define wxIsalpha _istalpha
61 #define wxIsctrl _istctrl
62 #define wxIsdigit _istdigit
63 #define wxIsgraph _istgraph
64 #define wxIslower _istlower
65 #define wxIsprint _istprint
66 #define wxIspunct _istpunct
67 #define wxIsspace _istspace
68 #define wxIsupper _istupper
69 #define wxIsxdigit _istxdigit
70 #define wxTolower _totlower
71 #define wxToupper _totupper
74 #define wxSetlocale _tsetlocale
77 #define wxStrcat _tcscat
78 #define wxStrchr _tcschr
79 #define wxStrcmp _tcscmp
80 #define wxStrcoll _tcscoll
81 #define wxStrcpy _tcscpy
82 #define wxStrcspn _tcscspn
83 #define wxStrftime _tcsftime
84 #define wxStricmp _tcsicmp
85 #define wxStrlen_ _tcslen // used in wxStrlen inline function
86 #define wxStrncat _tcsncat
87 #define wxStrncmp _tcsncmp
88 #define wxStrncpy _tcsncpy
89 #define wxStrpbrk _tcspbrk
90 #define wxStrrchr _tcsrchr
91 #define wxStrspn _tcsspn
92 #define wxStrstr _tcsstr
93 #define wxStrtod _tcstod
94 // is there a _tcstok[_r] ?
95 #define wxStrtol _tcstol
96 #define wxStrtoul _tcstoul
97 #define wxStrxfrm _tcsxfrm
100 #define wxFgetc _fgettc
101 #define wxFgetchar _fgettchar
102 #define wxFgets _fgetts
103 #define wxFopen _tfopen
104 #define wxFputc _fputtc
105 #define wxFputchar _fputtchar
106 #define wxFprintf _ftprintf
107 #define wxFreopen _tfreopen
108 #define wxFscanf _ftscanf
109 #define wxGetc _gettc
110 #define wxGetchar _gettchar
111 #define wxGets _getts
112 #define wxPerror _tperror
113 #define wxPrintf _tprintf
114 #define wxPutc _puttc
115 #define wxPutchar _puttchar
116 #define wxPuts _putts
117 #define wxRemove _tremove
118 #define wxRename _trename
119 #define wxScanf _tscanf
120 #define wxSprintf _stprintf
121 #define wxSscanf _stscanf
122 #define wxTmpnam _ttmpnam
123 #define wxUngetc _tungetc
124 #define wxVfprint _vftprintf
125 #define wxVprintf _vtprintf
126 #define wxVsscanf _vstscanf
127 #define wxVsprintf _vstprintf
129 // stdlib.h functions
135 #define wxGetenv _tgetenv
136 #define wxSystem _tsystem
139 #define wxAsctime _tasctime
140 #define wxCtime _tctime
142 // #elif defined(XXX)
143 // #include XXX-specific files here
144 // typeddef YYY wxChar;
146 // translate wxZZZ names
148 #elif defined(__BORLANDC__) && defined(__WIN32__)
150 // Borland C++ 4.52 doesn't have much tchar support
151 // maybe Borland C++ 5.02 has, can't check right now
152 // but I'll use the Win32 API instead here
155 #if wxUSE_UNICODE // temporary - preserve binary compatibility
156 typedef _TCHAR wxChar
;
157 typedef _TSCHAR wxSChar
;
158 typedef _TUCHAR wxUChar
;
161 #define wxSChar signed char
162 #define wxUChar unsigned char
171 inline WORD
__wxMSW_ctype(wxChar ch
)
174 GetStringTypeEx(LOCALE_USER_DEFAULT
, CT_CTYPE1
, &ch
, 1, &ret
);
177 #define wxIsalnum(x) IsCharAlphaNumeric
178 #define wxIsalpha IsCharAlpha
179 #define wxIsctrl(x) (__wxMSW_ctype(x) & C1_CNTRL)
180 #define wxIsdigit(x) (__wxMSW_ctype(x) & C1_DIGIT)
181 #define wxIsgraph(x) (__wxMSW_ctype(x) & (C1_DIGIT|C1_PUNCT|C1_ALPHA))
182 #define wxIslower(x) IsCharLower
183 #define wxIsprint(x) (__wxMSW_ctype(x) & (C1_DIGIT|C1_SPACE|C1_PUNCT|C1_ALPHA))
184 #define wxIspunct(x) (__wxMSW_ctype(x) & C1_PUNCT)
185 #define wxIsspace(x) (__wxMSW_ctype(x) & C1_SPACE)
186 #define wxIsupper(x) IsCharUpper
187 #define wxIsxdigit(x) (__wxMSW_ctype(x) & C1_XDIGIT)
188 #define wxTolower(x) (wxChar)CharLower((LPTSTR)(x))
189 #define wxToupper(x) (wxChar)CharUpper((LPTSTR)(x))
191 // #define wxStrtok strtok_r // Borland C++ 4.52 doesn't have strtok_r
192 #define wxNEED_WX_STRING_H
193 #define wxNEED_WX_STDIO_H
194 #define wxNEED_WX_STDLIB_H
195 #define wxNEED_WX_TIME_H
196 #define wxNEED_WCSLEN
200 // wchar_t will be used in buffer.h, so include it rather unconditionally
203 // check whether we are doing Unicode
208 // this is probably glibc-specific
209 #if defined(__WCHAR_TYPE__)
211 typedef __WCHAR_TYPE__ wxChar
;
212 typedef signed __WCHAR_TYPE__ wxSChar
;
213 typedef unsigned __WCHAR_TYPE__ wxUChar
;
217 // ctype.h functions (wctype.h)
218 #define wxIsalnum iswalnum
219 #define wxIsalpha iswalpha
220 #define wxIsctrl iswcntrl
221 #define wxIsdigit iswdigit
222 #define wxIsgraph iswgraph
223 #define wxIslower iswlower
224 #define wxIsprint iswprint
225 #define wxIspunct iswpunct
226 #define wxIsspace iswspace
227 #define wxIsupper iswupper
228 #define wxIsxdigit iswxdigit
230 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
231 // /usr/include/wctype.h incorrectly declares translations tables which
232 // provokes tons of compile-time warnings - try to correct this
233 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
234 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
236 #define wxTolower towlower
237 #define wxToupper towupper
240 // string.h functions (wchar.h)
241 #define wxStrcat wcscat
242 #define wxStrchr wcschr
243 #define wxStrcmp wcscmp
244 #define wxStrcoll wcscoll
245 #define wxStrcpy wcscpy
246 #define wxStrcspn wcscspn
247 #define wxStrlen_ wcslen // used in wxStrlen inline function
248 #define wxStrncat wcsncat
249 #define wxStrncmp wcsncmp
250 #define wxStrncpy wcsncpy
251 #define wxStrpbrk wcspbrk
252 #define wxStrrchr wcsrchr
253 #define wxStrspn wcsspn
254 #define wxStrstr wcsstr
255 #define wxStrtod wcstod
256 #define wxStrtok wcstok
257 #define wxStrtol wcstol
258 #define wxStrtoul wcstoul
259 #define wxStrxfrm wcsxfrm
261 // glibc doesn't have wc equivalents of the other stuff
262 #define wxNEED_WX_STDIO_H
263 #define wxNEED_WX_STDLIB_H
264 #define wxNEED_WX_TIME_H
267 #error "Please define your compiler's Unicode conventions in wxChar.h"
274 #if 0 // temporary - preserve binary compatibilty
276 typedef signed char wxSChar
;
277 typedef unsigned char wxUChar
;
280 #define wxSChar signed char
281 #define wxUChar unsigned char
287 #define wxIsalnum isalnum
288 #define wxIsalpha isalpha
289 #define wxIsctrl isctrl
290 #define wxIsdigit isdigit
291 #define wxIsgraph isgraph
292 #define wxIslower islower
293 #define wxIsprint isprint
294 #define wxIspunct ispunct
295 #define wxIsspace isspace
296 #define wxIsupper isupper
297 #define wxIsxdigit isxdigit
298 #define wxTolower tolower
299 #define wxToupper toupper
302 #define wxSetlocale setlocale
304 // string.h functions
305 #define wxStricmp strcasecmp
306 // #define wxStrtok strtok_r // this needs a configure check
308 // leave the rest to defaults below
309 #define wxNEED_WX_STRING_H
310 #define wxNEED_WX_STDIO_H
311 #define wxNEED_WX_STDLIB_H
312 #define wxNEED_WX_TIME_H
315 #endif//TCHAR-aware compilers
317 // define wxStricmp for various compilers without Unicode possibilities
318 #if !defined(wxStricmp) && !wxUSE_UNICODE
319 #if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__)
320 #define wxStricmp stricmp
321 #elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS) && defined(__INTEL__))
322 #define wxStricmp _stricmp
323 #elif defined(__UNIX__) || defined(__GNUWIN32__)
324 #define wxStricmp strcasecmp
325 #elif defined(__MWERKS__) && !defined(__INTEL__)
326 // use wxWindows' implementation
328 // if you leave wxStricmp undefined, wxWindows' implementation will be used
329 #error "Please define string case-insensitive compare for your OS/compiler"
333 // if we need to define for standard headers, and we're not using Unicode,
334 // just define to standard C library routines
336 #ifdef wxNEED_WX_STRING_H
337 #define wxStrcat strcat
338 #define wxStrchr strchr
339 #define wxStrcmp strcmp
340 #define wxStrcoll strcoll
341 #define wxStrcpy strcpy
342 #define wxStrcspn strcspn
343 #define wxStrdup strdup
344 #define wxStrlen_ strlen // used in wxStrlen inline function
345 #define wxStrncat strncat
346 #define wxStrncmp strncmp
347 #define wxStrncpy strncpy
348 #define wxStrpbrk strpbrk
349 #define wxStrrchr strrchr
350 #define wxStrspn strspn
351 #define wxStrstr strstr
352 #define wxStrtod strtod
353 #define wxStrtol strtol
354 #define wxStrtoul strtoul
355 #define wxStrxfrm strxfrm
356 #undef wxNEED_WX_STRING_H
359 #ifdef wxNEED_WX_STDIO_H
360 #define wxFgetc fgetc
361 #define wxFgetchar fgetchar
362 #define wxFgets fgets
363 #define wxFopen fopen
364 #define wxFputc fputc
365 #define wxFputchar fputchar
366 #define wxFprintf fprintf
367 #define wxFreopen freopen
368 #define wxFscanf fscanf
370 #define wxGetchar getchar
372 #define wxPerror perror
373 #define wxPrintf printf
375 #define wxPutchar putchar
377 #define wxRemove remove
378 #define wxRename rename
379 #define wxScanf scanf
380 #define wxSprintf sprintf
381 #define wxSscanf sscanf
382 #define wxTmpnam tmpnam
383 #define wxUngetc ungetc
384 #define wxVfprint vfprintf
385 #define wxVprintf vprintf
386 #define wxVsscanf vsscanf
387 #define wxVsprintf vsprintf
388 #undef wxNEED_WX_STDIO_H
391 #ifdef wxNEED_WX_STDLIB_H
395 #define wxGetenv getenv
396 #define wxSystem system
397 #undef wxNEED_WX_STDLIB_H
400 #ifdef wxNEED_WX_TIME_H
401 #define wxAsctime asctime
402 #define wxCtime ctime
403 #define wxStrftime strftime
404 #undef wxNEED_WX_TIME_H
408 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
409 #define wcslen wxStrlen
413 /// checks whether the passed in pointer is NULL and if the string is empty
414 inline bool WXDLLEXPORT
wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
416 #ifndef wxNEED_WX_STRING_H
417 /// safe version of strlen() (returns 0 if passed NULL pointer)
418 inline size_t WXDLLEXPORT
wxStrlen(const wxChar
*psz
)
419 { return psz ?
wxStrlen_(psz
) : 0; }
422 // multibyte<->widechar conversion
423 size_t WXDLLEXPORT
wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
424 size_t WXDLLEXPORT
wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
426 #define wxMB2WX wxMB2WC
427 #define wxWX2MB wxWC2MB
428 #define wxWC2WX wxStrncpy
429 #define wxWX2WC wxStrncpy
431 #define wxMB2WX wxStrncpy
432 #define wxWX2MB wxStrncpy
433 #define wxWC2WX wxWC2MB
434 #define wxWX2WC wxMB2WC
437 // if libc versions are not available, use replacements defined in wxchar.cpp
439 wxChar
* WXDLLEXPORT
wxStrdup(const wxChar
*psz
);
443 int WXDLLEXPORT
wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
447 wxChar
* WXDLLEXPORT
wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
451 wxChar
* WXDLLEXPORT
wxSetlocale(int category
, const wxChar
*locale
);
454 #ifdef wxNEED_WCSLEN // for use in buffer.h
455 size_t WXDLLEXPORT
wcslen(const wchar_t *s
);
458 #ifdef wxNEED_WX_STRING_H
459 int WXDLLEXPORT
wxStrcmp(const wxChar
*psz1
, const wxChar
*psz2
);
460 size_t WXDLLEXPORT
wxStrlen(const wxChar
*s
);
463 #ifdef wxNEED_WX_STDIO_H
466 int WXDLLEXPORT
wxPrintf(const wxChar
*fmt
, ...);
467 int WXDLLEXPORT
wxVprintf(const wxChar
*fmt
, va_list argptr
);
468 int WXDLLEXPORT
wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
469 int WXDLLEXPORT
wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
470 int WXDLLEXPORT
wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
471 int WXDLLEXPORT
wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
472 int WXDLLEXPORT
wxSscanf(const wxChar
*buf
, const wxChar
*fmt
, ...);
473 int WXDLLEXPORT
wxVsscanf(const wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
477 double WXDLLEXPORT
wxAtof(const wxChar
*psz
);
480 #ifdef wxNEED_WX_STDLIB_H
481 int WXDLLEXPORT
wxAtoi(const wxChar
*psz
);
482 long WXDLLEXPORT
wxAtol(const wxChar
*psz
);
483 wxChar
* WXDLLEXPORT
wxGetenv(const wxChar
*name
);
484 int WXDLLEXPORT
wxSystem(const wxChar
*psz
);