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 // It may be OK anyway.
22 // # error "MBCS is not supported by wxChar"
25 // ----------------------------------------------------------------------------
26 // first deal with Unicode setting
27 // ----------------------------------------------------------------------------
29 // set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
30 #if defined(_UNICODE) || defined(UNICODE)
32 # define wxUSE_UNICODE 1
34 # ifndef wxUSE_UNICODE
35 # define wxUSE_UNICODE 0
39 // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
49 // Unicode support requires wchar_t
52 # define wxUSE_WCHAR_T 1
55 // ----------------------------------------------------------------------------
56 // define wxHAVE_TCHAR_FUNCTIONS for the compilers which support the
57 // wide-character functions
58 // ----------------------------------------------------------------------------
61 // VC++ and BC++ starting with 5.2 have TCHAR support
63 #define wxHAVE_TCHAR_FUNCTIONS
64 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
65 #define wxHAVE_TCHAR_FUNCTIONS
67 #elif defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
68 // VisualAge 4.0+ supports TCHAR
69 #define wxHAVE_TCHAR_FUNCTIONS
71 // but not stdio.h nor time nor conversion functions
72 #define wxNO_TCHAR_STDIO
73 #define wxNO_TCHAR_STDLIB
74 #define wxNO_TCHAR_TIME
75 #define wxNO_TCHAR_LOCALE
77 // supplemental VA V4 defs so at least we know what these are
78 // just define to standard defs
84 // locale.h functons -- not defined in tchar.h
85 #define wxSetlocale setlocale
86 // some stdio functions are defined others are not
88 #define wxFgetchar fgetchar
90 #define wxFputchar fputchar
91 #define wxFreopen freopen
93 #define wxPerror perror
95 #define wxRemove remove
96 #define wxRename rename
97 #define wxTmpnam tmpnam
98 #define wxUngetc ungetc
99 #define wxVsscanf vsscanf
100 // stdlib not defined in VA V4
106 #define wxGetenv getenv
107 #define wxSystem system
108 // time.h functions -- none defined in tchar.h
109 #define wxAsctime asctime
110 #define wxCtime ctime
111 #endif // compilers with (good) TCHAR support
113 #ifdef wxHAVE_TCHAR_FUNCTIONS
114 # define HAVE_WCSLEN 1
118 # if wxUSE_UNICODE // temporary - preserve binary compatibility
119 typedef _TCHAR wxChar
;
120 typedef _TSCHAR wxSChar
;
121 typedef _TUCHAR wxUChar
;
124 # define wxSChar signed char
125 # define wxUChar unsigned char
128 // wchar_t is available
129 #ifndef wxUSE_WCHAR_T
130 #define wxUSE_WCHAR_T 1
131 #endif // !defined(wxUSE_WCHAR_T)
134 #ifndef wxNO_TCHAR_CTYPE
138 # define wxIsalnum _istalnum
139 # define wxIsalpha _istalpha
140 # define wxIsctrl _istctrl
141 # define wxIsdigit _istdigit
142 # define wxIsgraph _istgraph
143 # define wxIslower _istlower
144 # define wxIsprint _istprint
145 # define wxIspunct _istpunct
146 # define wxIsspace _istspace
147 # define wxIsupper _istupper
148 # define wxIsxdigit _istxdigit
149 # define wxTolower _totlower
150 # define wxToupper _totupper
151 #endif // wxNO_TCHAR_CTYPE
154 #ifndef wxNO_TCHAR_LOCALE
155 # define wxSetlocale _tsetlocale
156 #endif // wxNO_TCHAR_LOCALE
158 // string.h functions
159 #ifndef wxNO_TCHAR_STRING
160 # define wxStrcat _tcscat
161 # define wxStrchr _tcschr
162 # define wxStrcmp _tcscmp
163 # define wxStrcoll _tcscoll
164 # define wxStrcpy _tcscpy
165 # define wxStrcspn _tcscspn
166 # define wxStrftime _tcsftime
167 # define wxStricmp _tcsicmp
168 # define wxStrlen_ _tcslen // used in wxStrlen inline function
169 # define wxStrncat _tcsncat
170 # define wxStrncmp _tcsncmp
171 # define wxStrncpy _tcsncpy
172 # define wxStrpbrk _tcspbrk
173 # define wxStrrchr _tcsrchr
174 # define wxStrspn _tcsspn
175 # define wxStrstr _tcsstr
176 # define wxStrtod _tcstod
177 # define wxStrtol _tcstol
178 # define wxStrtoul _tcstoul
179 # define wxStrxfrm _tcsxfrm
180 #endif // wxNO_TCHAR_STRING
183 #ifndef wxNO_TCHAR_STDIO
184 # define wxFgetc _fgettc
185 # define wxFgetchar _fgettchar
186 # define wxFgets _fgetts
187 # define wxFopen _tfopen
188 # define wxFputc _fputtc
189 # define wxFputchar _fputtchar
190 # define wxFprintf _ftprintf
191 # define wxFreopen _tfreopen
192 # define wxFscanf _ftscanf
193 # define wxGetc _gettc
194 # define wxGetchar _gettchar
195 # define wxGets _getts
196 # define wxPerror _tperror
197 # define wxPrintf _tprintf
198 # define wxPutc _puttc
199 # define wxPutchar _puttchar
200 # define wxPuts _putts
201 # define wxRemove _tremove
202 # define wxRename _trename
203 # define wxScanf _tscanf
204 # define wxSprintf _stprintf
205 # define wxSscanf _stscanf
206 # define wxTmpnam _ttmpnam
207 # define wxUngetc _tungetc
208 # define wxVfprint _vftprintf
209 # define wxVprintf _vtprintf
210 # define wxVsscanf _vstscanf
211 # define wxVsprintf _vstprintf
212 #elif defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
213 // it has some stdio.h functions, apparently
214 # define wxFgetc _fgettc
215 # define wxFgets _fgetts
216 # define wxFputc _fputtc
217 # define wxFprintf _ftprintf
218 # define wxFscanf _ftscanf
219 # define wxGetc _gettc
220 # define wxGetchar _gettchar
221 # define wxPrintf _tprintf
222 # define wxPutc _puttc
223 # define wxPutchar _puttchar
224 # define wxScanf _tscanf
225 # define wxSprintf _stprintf
226 # define wxSscanf _stscanf
227 # define wxVfprint _vftprintf
228 # define wxVprintf _vtprintf
229 # define wxVsprintf _vstprintf
230 #endif // wxNO_TCHAR_STDIO
232 // stdlib.h functions
233 #ifndef wxNO_TCHAR_STDLIB
237 # define wxAtoi _ttoi
238 # define wxAtol _ttol
239 # define wxGetenv _tgetenv
240 # define wxSystem _tsystem
241 #endif // wxNO_TCHAR_STDLIB
244 #ifndef wxNO_TCHAR_TIME
245 # define wxAsctime _tasctime
246 # define wxCtime _tctime
247 #endif // wxNO_TCHAR_TIME
249 #else // !TCHAR-aware compilers
251 // check whether we should include wchar.h or equivalent
252 # if !defined(wxUSE_WCHAR_T)
253 # if defined(__VISUALC__) && (__VISUALC__ < 900)
254 # define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
255 # elif defined(__UNIX__)
256 # if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__)
257 # define wxUSE_WCHAR_T 1
259 # define wxUSE_WCHAR_T 0
261 # elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
262 # define wxUSE_WCHAR_T 0
263 # elif defined(__BORLANDC__) // WIN16 BC++
264 # define wxUSE_WCHAR_T 0
265 # elif defined(__WATCOMC__)
266 # define wxUSE_WCHAR_T 0
267 # elif defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
268 # define wxUSE_WCHAR_T 1
270 // add additional compiler checks if this fails
271 # define wxUSE_WCHAR_T 1
273 # endif // !defined(wxUSE_WCHAR_T)
283 # define wxNEED_WCSLEN
288 // check whether we are doing Unicode
293 // this is probably glibc-specific
294 # if defined(__WCHAR_TYPE__)
296 typedef __WCHAR_TYPE__ wxChar
;
297 typedef signed __WCHAR_TYPE__ wxSChar
;
298 typedef unsigned __WCHAR_TYPE__ wxUChar
;
302 // ctype.h functions (wctype.h)
303 # define wxIsalnum iswalnum
304 # define wxIsalpha iswalpha
305 # define wxIsctrl iswcntrl
306 # define wxIsdigit iswdigit
307 # define wxIsgraph iswgraph
308 # define wxIslower iswlower
309 # define wxIsprint iswprint
310 # define wxIspunct iswpunct
311 # define wxIsspace iswspace
312 # define wxIsupper iswupper
313 # define wxIsxdigit iswxdigit
315 # if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
316 // /usr/include/wctype.h incorrectly declares translations tables which
317 // provokes tons of compile-time warnings - try to correct this
318 # define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
319 # define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
321 # define wxTolower towlower
322 # define wxToupper towupper
325 // string.h functions (wchar.h)
326 # define wxStrcat wcscat
327 # define wxStrchr wcschr
328 # define wxStrcmp wcscmp
329 # define wxStrcoll wcscoll
330 # define wxStrcpy wcscpy
331 # define wxStrcspn wcscspn
332 # define wxStrlen_ wcslen // used in wxStrlen inline function
333 # define wxStrncat wcsncat
334 # define wxStrncmp wcsncmp
335 # define wxStrncpy wcsncpy
336 # define wxStrpbrk wcspbrk
337 # define wxStrrchr wcsrchr
338 # define wxStrspn wcsspn
339 # define wxStrstr wcsstr
340 # define wxStrtod wcstod
341 # define wxStrtok wcstok
342 # define wxStrtol wcstol
343 # define wxStrtoul wcstoul
344 # define wxStrxfrm wcsxfrm
346 // glibc doesn't have wc equivalents of the other stuff
347 # define wxNEED_WX_STDIO_H
348 # define wxNEED_WX_STDLIB_H
349 # define wxNEED_WX_TIME_H
352 # error "Please define your compiler's Unicode conventions in wxChar.h"
359 # if 0 // temporary - preserve binary compatibilty
361 typedef signed char wxSChar
;
362 typedef unsigned char wxUChar
;
365 # define wxSChar signed char
366 # define wxUChar unsigned char
369 # if defined(__FreeBSD__) || (defined(__APPLE__) && defined(__UNIX__))
373 # if !defined(__MINGW32__) || !defined(_T)
378 # define wxIsalnum isalnum
379 # define wxIsalpha isalpha
380 # define wxIsctrl isctrl
381 # define wxIsdigit isdigit
382 # define wxIsgraph isgraph
383 # define wxIslower islower
384 # define wxIsprint isprint
385 # define wxIspunct ispunct
386 # define wxIsspace isspace
387 # define wxIsupper isupper
388 # define wxIsxdigit isxdigit
389 # define wxTolower tolower
390 # define wxToupper toupper
393 # define wxSetlocale setlocale
395 // string.h functions
396 // #define wxStricmp strcasecmp
397 // wxStricmp is defined below!!
400 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
402 #define wxStrtok(str, sep, last) strtok(str, sep)
405 // leave the rest to defaults below
406 # define wxNEED_WX_STRING_H
407 # define wxNEED_WX_STDIO_H
408 # define wxNEED_WX_STDLIB_H
409 # define wxNEED_WX_TIME_H
412 #endif//TCHAR-aware compilers
414 // define wxStricmp for various compilers without Unicode possibilities
415 #if !defined(wxStricmp) && !wxUSE_UNICODE
416 # if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__) || defined(__VISAGECPP__) || defined(__EMX__)
417 # define wxStricmp stricmp
418 # define wxStrnicmp strnicmp
419 # elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS__) && defined(__INTEL__))
420 # define wxStricmp _stricmp
421 # define wxStrnicmp _strnicmp
422 # elif defined(__UNIX__) || defined(__GNUWIN32__)
423 # define wxStricmp strcasecmp
424 # define wxStrnicmp strncasecmp
425 # elif defined(__MWERKS__) && !defined(__INTEL__)
426 // use wxWindows' implementation
428 // if you leave wxStricmp undefined, wxWindows' implementation will be used
429 # error "Please define string case-insensitive compare for your OS/compiler"
433 // if we need to define for standard headers, and we're not using Unicode,
434 // just define to standard C library routines
436 # ifdef wxNEED_WX_STRING_H
437 # define wxStrcat strcat
438 # define wxStrchr strchr
439 # define wxStrcmp strcmp
440 # define wxStrcoll strcoll
441 # define wxStrcpy strcpy
442 # define wxStrcspn strcspn
443 # define wxStrdup strdup
444 # define wxStrlen_ strlen // used in wxStrlen inline function
445 # define wxStrncat strncat
446 # define wxStrncmp strncmp
447 # define wxStrncpy strncpy
448 # define wxStrpbrk strpbrk
449 # define wxStrrchr strrchr
450 # define wxStrspn strspn
451 # define wxStrstr strstr
452 # define wxStrtod strtod
453 # define wxStrtol strtol
454 # define wxStrtoul strtoul
455 # define wxStrxfrm strxfrm
456 # undef wxNEED_WX_STRING_H
459 # ifdef wxNEED_WX_STDIO_H
460 # define wxFgetc fgetc
461 # define wxFgetchar fgetchar
462 # define wxFgets fgets
463 # define wxFopen fopen
464 # define wxFputc fputc
465 # define wxFputchar fputchar
466 # define wxFprintf fprintf
467 # define wxFreopen freopen
468 # define wxFscanf fscanf
470 # define wxGetchar getchar
472 # define wxPerror perror
473 # define wxPrintf printf
475 # define wxPutchar putchar
477 # define wxRemove remove
478 # define wxRename rename
479 # define wxScanf scanf
480 # define wxSprintf sprintf
481 # define wxSscanf sscanf
482 # define wxTmpnam tmpnam
483 # define wxUngetc ungetc
484 # define wxVfprint vfprintf
485 # define wxVprintf vprintf
486 # define wxVsscanf vsscanf
487 # define wxVsprintf vsprintf
488 # undef wxNEED_WX_STDIO_H
491 # ifdef wxNEED_WX_STDLIB_H
495 # define wxGetenv getenv
496 # define wxSystem system
497 # undef wxNEED_WX_STDLIB_H
500 # ifdef wxNEED_WX_TIME_H
501 # define wxAsctime asctime
502 # define wxCtime ctime
503 # define wxStrftime strftime
504 # undef wxNEED_WX_TIME_H
508 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
509 # define wcslen wxStrlen
510 # undef wxNEED_WCSLEN
513 // checks whether the passed in pointer is NULL and if the string is empty
514 inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
516 #ifndef wxNEED_WX_STRING_H
517 // safe version of strlen() (returns 0 if passed NULL pointer)
518 inline size_t wxStrlen(const wxChar
*psz
)
519 { return psz
? wxStrlen_(psz
) : 0; }
523 // multibyte<->widechar conversion
524 WXDLLEXPORT
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
525 WXDLLEXPORT
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
527 # define wxMB2WX wxMB2WC
528 # define wxWX2MB wxWC2MB
529 # define wxWC2WX wxStrncpy
530 # define wxWX2WC wxStrncpy
532 # define wxMB2WX wxStrncpy
533 # define wxWX2MB wxStrncpy
534 # define wxWC2WX wxWC2MB
535 # define wxWX2WC wxMB2WC
538 // No wxUSE_WCHAR_T: we have to do something (JACS)
539 # define wxMB2WC wxStrncpy
540 # define wxWC2MB wxStrncpy
541 # define wxMB2WX wxStrncpy
542 # define wxWX2MB wxStrncpy
543 # define wxWC2WX wxWC2MB
544 # define wxWX2WC wxMB2WC
547 WXDLLEXPORT
bool wxOKlibc(); // for internal use
549 // if libc versions are not available, use replacements defined in wxchar.cpp
551 WXDLLEXPORT wxChar
* wxStrdup(const wxChar
*psz
);
555 WXDLLEXPORT
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
559 WXDLLEXPORT wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
564 WXDLLEXPORT wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
567 #ifdef wxNEED_WCSLEN // for use in buffer.h
568 WXDLLEXPORT
size_t wcslen(const wchar_t *s
);
571 #ifdef wxNEED_WX_CTYPE_H
572 WXDLLEXPORT
int wxIsalnum(wxChar ch
);
573 WXDLLEXPORT
int wxIsalpha(wxChar ch
);
574 WXDLLEXPORT
int wxIsctrl(wxChar ch
);
575 WXDLLEXPORT
int wxIsdigit(wxChar ch
);
576 WXDLLEXPORT
int wxIsgraph(wxChar ch
);
577 WXDLLEXPORT
int wxIslower(wxChar ch
);
578 WXDLLEXPORT
int wxIsprint(wxChar ch
);
579 WXDLLEXPORT
int wxIspunct(wxChar ch
);
580 WXDLLEXPORT
int wxIsspace(wxChar ch
);
581 WXDLLEXPORT
int wxIsupper(wxChar ch
);
582 WXDLLEXPORT
int wxIsxdigit(wxChar ch
);
583 WXDLLEXPORT
int wxTolower(wxChar ch
);
584 WXDLLEXPORT
int wxToupper(wxChar ch
);
587 #ifdef wxNEED_WX_STRING_H
588 WXDLLEXPORT wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
589 WXDLLEXPORT wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
590 WXDLLEXPORT
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
591 WXDLLEXPORT
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
592 WXDLLEXPORT wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
593 WXDLLEXPORT
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
594 WXDLLEXPORT
size_t wxStrlen(const wxChar
*s
);
595 WXDLLEXPORT wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
596 WXDLLEXPORT
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
597 WXDLLEXPORT wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
598 WXDLLEXPORT wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
599 WXDLLEXPORT wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
600 WXDLLEXPORT
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
601 WXDLLEXPORT wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
602 WXDLLEXPORT
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
603 WXDLLEXPORT
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
604 WXDLLEXPORT
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
605 WXDLLEXPORT
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
608 #ifdef wxNEED_WX_STDIO_H
611 WXDLLEXPORT
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
612 WXDLLEXPORT
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
613 WXDLLEXPORT
int wxRemove(const wxChar
*path
);
614 WXDLLEXPORT
int wxRename(const wxChar
*oldpath
, const wxChar
*newpath
);
615 WXDLLEXPORT
int wxPrintf(const wxChar
*fmt
, ...);
616 WXDLLEXPORT
int wxVprintf(const wxChar
*fmt
, va_list argptr
);
617 WXDLLEXPORT
int wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
618 WXDLLEXPORT
int wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
619 WXDLLEXPORT
int wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
620 WXDLLEXPORT
int wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
621 WXDLLEXPORT
int wxSscanf(const wxChar
*buf
, const wxChar
*fmt
, ...);
622 WXDLLEXPORT
int wxVsscanf(const wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
626 WXDLLEXPORT
double wxAtof(const wxChar
*psz
);
629 #ifdef wxNEED_WX_STDLIB_H
630 WXDLLEXPORT
int wxAtoi(const wxChar
*psz
);
631 WXDLLEXPORT
long wxAtol(const wxChar
*psz
);
632 WXDLLEXPORT wxChar
* wxGetenv(const wxChar
*name
);
633 WXDLLEXPORT
int wxSystem(const wxChar
*psz
);
636 #ifdef wxNEED_WX_TIME_H
637 WXDLLEXPORT
size_t wxStrftime(wxChar
*s
, size_t max
, const wxChar
*fmt
, const struct tm
*tm
);
640 // under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks
641 // the file parsing - this may be true for 5.0 as well, update #ifdef then
642 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
644 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
647 // ----------------------------------------------------------------------------
648 // common macros which are always defined
649 // ----------------------------------------------------------------------------
651 // although global macros with such names are really bad, we want to have
652 // another name for _T() which should be used to avoid confusion between _T()
653 // and _() in wxWindows sources
656 // a Unicode-friendly __FILE__ analog
658 #define __XFILE__(x) wxT(x)
659 #define __TFILE__ __XFILE__(__FILE__)