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
66 #elif defined(__GNUWIN32__) && wxCHECK_W32API_VERSION( 0, 6 )
67 #define wxHAVE_TCHAR_FUNCTIONS
72 #elif defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
73 // VisualAge 4.0+ supports TCHAR
74 #define wxHAVE_TCHAR_FUNCTIONS
76 // but not stdio.h nor time nor conversion functions
77 #define wxNO_TCHAR_STDIO
78 #define wxNO_TCHAR_STDLIB
79 #define wxNO_TCHAR_TIME
80 #define wxNO_TCHAR_LOCALE
82 // supplemental VA V4 defs so at least we know what these are
83 // just define to standard defs
89 // locale.h functons -- not defined in tchar.h
90 #define wxSetlocale setlocale
91 // some stdio functions are defined others are not
93 #define wxFgetchar fgetchar
95 #define wxFputchar fputchar
96 #define wxFreopen freopen
98 #define wxPerror perror
100 #define wxRemove remove
101 #define wxRename rename
102 #define wxTmpnam tmpnam
103 #define wxUngetc ungetc
104 #define wxVsscanf vsscanf
105 // stdlib not defined in VA V4
111 #define wxGetenv getenv
112 #define wxSystem system
113 // time.h functions -- none defined in tchar.h
114 #define wxAsctime asctime
115 #define wxCtime ctime
116 #endif // compilers with (good) TCHAR support
118 #ifdef wxHAVE_TCHAR_FUNCTIONS
119 # define HAVE_WCSLEN 1
123 # if wxUSE_UNICODE // temporary - preserve binary compatibility
124 #if defined(__GNUWIN32__)
126 #define _TSCHAR TCHAR
127 #define _TUCHAR TCHAR
130 typedef _TCHAR wxChar
;
131 typedef _TSCHAR wxSChar
;
132 typedef _TUCHAR wxUChar
;
135 # define wxSChar signed char
136 # define wxUChar unsigned char
139 // wchar_t is available
140 #ifndef wxUSE_WCHAR_T
141 #define wxUSE_WCHAR_T 1
142 #endif // !defined(wxUSE_WCHAR_T)
145 #ifndef wxNO_TCHAR_CTYPE
149 # define wxIsalnum _istalnum
150 # define wxIsalpha _istalpha
151 # define wxIsctrl _istctrl
152 # define wxIsdigit _istdigit
153 # define wxIsgraph _istgraph
154 # define wxIslower _istlower
155 # define wxIsprint _istprint
156 # define wxIspunct _istpunct
157 # define wxIsspace _istspace
158 # define wxIsupper _istupper
159 # define wxIsxdigit _istxdigit
160 # define wxTolower _totlower
161 # define wxToupper _totupper
162 #endif // wxNO_TCHAR_CTYPE
165 #ifndef wxNO_TCHAR_LOCALE
166 # define wxSetlocale _tsetlocale
167 #endif // wxNO_TCHAR_LOCALE
169 // string.h functions
170 #ifndef wxNO_TCHAR_STRING
171 # define wxStrcat _tcscat
172 # define wxStrchr _tcschr
173 # define wxStrcmp _tcscmp
174 # define wxStrcoll _tcscoll
175 # define wxStrcpy _tcscpy
176 # define wxStrcspn _tcscspn
177 # define wxStrftime _tcsftime
178 # define wxStricmp _tcsicmp
179 # define wxStrlen_ _tcslen // used in wxStrlen inline function
180 # define wxStrncat _tcsncat
181 # define wxStrncmp _tcsncmp
182 # define wxStrncpy _tcsncpy
183 # define wxStrpbrk _tcspbrk
184 # define wxStrrchr _tcsrchr
185 # define wxStrspn _tcsspn
186 # define wxStrstr _tcsstr
187 # define wxStrtod _tcstod
188 # define wxStrtol _tcstol
189 # define wxStrtoul _tcstoul
190 # define wxStrxfrm _tcsxfrm
191 #endif // wxNO_TCHAR_STRING
194 #ifndef wxNO_TCHAR_STDIO
195 # define wxFgetc _fgettc
196 # define wxFgetchar _fgettchar
197 # define wxFgets _fgetts
198 # define wxFopen _tfopen
199 # define wxFputc _fputtc
200 # define wxFputchar _fputtchar
201 # define wxFprintf _ftprintf
202 # define wxFreopen _tfreopen
203 # define wxFscanf _ftscanf
204 # define wxGetc _gettc
205 # define wxGetchar _gettchar
206 # define wxGets _getts
207 # define wxPerror _tperror
208 # define wxPrintf _tprintf
209 # define wxPutc _puttc
210 # define wxPutchar _puttchar
211 # define wxPuts _putts
212 # define wxRemove _tremove
213 # define wxRename _trename
214 # define wxScanf _tscanf
215 # define wxSprintf _stprintf
216 # define wxSscanf _stscanf
217 # define wxTmpnam _ttmpnam
218 # define wxUngetc _tungetc
219 # define wxVfprint _vftprintf
220 # define wxVprintf _vtprintf
221 # define wxVsscanf _vstscanf
222 # define wxVsprintf _vstprintf
223 #elif defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
224 // it has some stdio.h functions, apparently
225 # define wxFgetc _fgettc
226 # define wxFgets _fgetts
227 # define wxFputc _fputtc
228 # define wxFprintf _ftprintf
229 # define wxFscanf _ftscanf
230 # define wxGetc _gettc
231 # define wxGetchar _gettchar
232 # define wxPrintf _tprintf
233 # define wxPutc _puttc
234 # define wxPutchar _puttchar
235 # define wxScanf _tscanf
236 # define wxSprintf _stprintf
237 # define wxSscanf _stscanf
238 # define wxVfprint _vftprintf
239 # define wxVprintf _vtprintf
240 # define wxVsprintf _vstprintf
241 #endif // wxNO_TCHAR_STDIO
243 // stdlib.h functions
244 #ifndef wxNO_TCHAR_STDLIB
248 # define wxAtoi _ttoi
249 # define wxAtol _ttol
250 # define wxGetenv _tgetenv
251 # define wxSystem _tsystem
252 #endif // wxNO_TCHAR_STDLIB
255 #ifndef wxNO_TCHAR_TIME
256 # define wxAsctime _tasctime
257 # define wxCtime _tctime
258 #endif // wxNO_TCHAR_TIME
260 #else // !TCHAR-aware compilers
262 // check whether we should include wchar.h or equivalent
263 # if !defined(wxUSE_WCHAR_T)
264 # if defined(__VISUALC__) && (__VISUALC__ < 900)
265 # define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
266 # elif defined(__UNIX__)
267 # if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__)
268 # define wxUSE_WCHAR_T 1
270 # define wxUSE_WCHAR_T 0
272 # elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
273 # define wxUSE_WCHAR_T 0
274 # elif defined(__BORLANDC__) // WIN16 BC++
275 # define wxUSE_WCHAR_T 0
276 # elif defined(__WATCOMC__)
277 # define wxUSE_WCHAR_T 0
278 # elif defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
279 # define wxUSE_WCHAR_T 1
281 // add additional compiler checks if this fails
282 # define wxUSE_WCHAR_T 1
284 # endif // !defined(wxUSE_WCHAR_T)
294 # define wxNEED_WCSLEN
299 // check whether we are doing Unicode
304 // this is probably glibc-specific
305 # if defined(__WCHAR_TYPE__)
307 typedef __WCHAR_TYPE__ wxChar
;
308 typedef signed __WCHAR_TYPE__ wxSChar
;
309 typedef unsigned __WCHAR_TYPE__ wxUChar
;
313 // ctype.h functions (wctype.h)
314 # define wxIsalnum iswalnum
315 # define wxIsalpha iswalpha
316 # define wxIsctrl iswcntrl
317 # define wxIsdigit iswdigit
318 # define wxIsgraph iswgraph
319 # define wxIslower iswlower
320 # define wxIsprint iswprint
321 # define wxIspunct iswpunct
322 # define wxIsspace iswspace
323 # define wxIsupper iswupper
324 # define wxIsxdigit iswxdigit
326 # if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
327 // /usr/include/wctype.h incorrectly declares translations tables which
328 // provokes tons of compile-time warnings - try to correct this
329 # define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
330 # define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
332 # define wxTolower towlower
333 # define wxToupper towupper
336 // string.h functions (wchar.h)
337 # define wxStrcat wcscat
338 # define wxStrchr wcschr
339 # define wxStrcmp wcscmp
340 # define wxStrcoll wcscoll
341 # define wxStrcpy wcscpy
342 # define wxStrcspn wcscspn
343 # define wxStrlen_ wcslen // used in wxStrlen inline function
344 # define wxStrncat wcsncat
345 # define wxStrncmp wcsncmp
346 # define wxStrncpy wcsncpy
347 # define wxStrpbrk wcspbrk
348 # define wxStrrchr wcsrchr
349 # define wxStrspn wcsspn
350 # define wxStrstr wcsstr
351 # define wxStrtod wcstod
352 # define wxStrtok wcstok
353 # define wxStrtol wcstol
354 # define wxStrtoul wcstoul
355 # define wxStrxfrm wcsxfrm
357 // glibc doesn't have wc equivalents of the other stuff
358 # define wxNEED_WX_STDIO_H
359 # define wxNEED_WX_STDLIB_H
360 # define wxNEED_WX_TIME_H
363 # error "Please define your compiler's Unicode conventions in wxChar.h"
370 # if 0 // temporary - preserve binary compatibilty
372 typedef signed char wxSChar
;
373 typedef unsigned char wxUChar
;
376 # define wxSChar signed char
377 # define wxUChar unsigned char
380 # if defined(__FreeBSD__) || (defined(__APPLE__) && defined(__UNIX__))
384 # if !defined(__MINGW32__) || !defined(_T)
389 # define wxIsalnum isalnum
390 # define wxIsalpha isalpha
391 # define wxIsctrl isctrl
392 # define wxIsdigit isdigit
393 # define wxIsgraph isgraph
394 # define wxIslower islower
395 # define wxIsprint isprint
396 # define wxIspunct ispunct
397 # define wxIsspace isspace
398 # define wxIsupper isupper
399 # define wxIsxdigit isxdigit
400 # define wxTolower tolower
401 # define wxToupper toupper
404 # define wxSetlocale setlocale
406 // string.h functions
407 // #define wxStricmp strcasecmp
408 // wxStricmp is defined below!!
411 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
413 #define wxStrtok(str, sep, last) strtok(str, sep)
416 // leave the rest to defaults below
417 # define wxNEED_WX_STRING_H
418 # define wxNEED_WX_STDIO_H
419 # define wxNEED_WX_STDLIB_H
420 # define wxNEED_WX_TIME_H
423 #endif//TCHAR-aware compilers
425 // define wxStricmp for various compilers without Unicode possibilities
426 #if !defined(wxStricmp) && !wxUSE_UNICODE
427 # if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__) || defined(__VISAGECPP__) || defined(__EMX__)
428 # define wxStricmp stricmp
429 # define wxStrnicmp strnicmp
430 # elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS__) && defined(__INTEL__))
431 # define wxStricmp _stricmp
432 # define wxStrnicmp _strnicmp
433 # elif defined(__UNIX__) || defined(__GNUWIN32__)
434 # define wxStricmp strcasecmp
435 # define wxStrnicmp strncasecmp
436 # elif defined(__MWERKS__) && !defined(__INTEL__)
437 // use wxWindows' implementation
439 // if you leave wxStricmp undefined, wxWindows' implementation will be used
440 # error "Please define string case-insensitive compare for your OS/compiler"
444 // if we need to define for standard headers, and we're not using Unicode,
445 // just define to standard C library routines
447 # ifdef wxNEED_WX_STRING_H
448 # define wxStrcat strcat
449 # define wxStrchr strchr
450 # define wxStrcmp strcmp
451 # define wxStrcoll strcoll
452 # define wxStrcpy strcpy
453 # define wxStrcspn strcspn
454 # define wxStrdup strdup
455 # define wxStrlen_ strlen // used in wxStrlen inline function
456 # define wxStrncat strncat
457 # define wxStrncmp strncmp
458 # define wxStrncpy strncpy
459 # define wxStrpbrk strpbrk
460 # define wxStrrchr strrchr
461 # define wxStrspn strspn
462 # define wxStrstr strstr
463 # define wxStrtod strtod
464 # define wxStrtol strtol
465 # define wxStrtoul strtoul
466 # define wxStrxfrm strxfrm
467 # undef wxNEED_WX_STRING_H
470 # ifdef wxNEED_WX_STDIO_H
471 # define wxFgetc fgetc
472 # define wxFgetchar fgetchar
473 # define wxFgets fgets
474 # define wxFopen fopen
475 # define wxFputc fputc
476 # define wxFputchar fputchar
477 # define wxFprintf fprintf
478 # define wxFreopen freopen
479 # define wxFscanf fscanf
481 # define wxGetchar getchar
483 # define wxPerror perror
484 # define wxPrintf printf
486 # define wxPutchar putchar
488 # define wxRemove remove
489 # define wxRename rename
490 # define wxScanf scanf
491 # define wxSprintf sprintf
492 # define wxSscanf sscanf
493 # define wxTmpnam tmpnam
494 # define wxUngetc ungetc
495 # define wxVfprint vfprintf
496 # define wxVprintf vprintf
497 # define wxVsscanf vsscanf
498 # define wxVsprintf vsprintf
499 # undef wxNEED_WX_STDIO_H
502 # ifdef wxNEED_WX_STDLIB_H
506 # define wxGetenv getenv
507 # define wxSystem system
508 # undef wxNEED_WX_STDLIB_H
511 # ifdef wxNEED_WX_TIME_H
512 # define wxAsctime asctime
513 # define wxCtime ctime
514 # define wxStrftime strftime
515 # undef wxNEED_WX_TIME_H
519 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
520 # define wcslen wxStrlen
521 # undef wxNEED_WCSLEN
524 // checks whether the passed in pointer is NULL and if the string is empty
525 inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
527 #ifndef wxNEED_WX_STRING_H
528 // safe version of strlen() (returns 0 if passed NULL pointer)
529 inline size_t wxStrlen(const wxChar
*psz
)
530 { return psz
? wxStrlen_(psz
) : 0; }
534 // multibyte<->widechar conversion
535 WXDLLEXPORT
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
536 WXDLLEXPORT
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
538 # define wxMB2WX wxMB2WC
539 # define wxWX2MB wxWC2MB
540 # define wxWC2WX wxStrncpy
541 # define wxWX2WC wxStrncpy
543 # define wxMB2WX wxStrncpy
544 # define wxWX2MB wxStrncpy
545 # define wxWC2WX wxWC2MB
546 # define wxWX2WC wxMB2WC
549 // No wxUSE_WCHAR_T: we have to do something (JACS)
550 # define wxMB2WC wxStrncpy
551 # define wxWC2MB wxStrncpy
552 # define wxMB2WX wxStrncpy
553 # define wxWX2MB wxStrncpy
554 # define wxWC2WX wxWC2MB
555 # define wxWX2WC wxMB2WC
558 WXDLLEXPORT
bool wxOKlibc(); // for internal use
560 // if libc versions are not available, use replacements defined in wxchar.cpp
562 WXDLLEXPORT wxChar
* wxStrdup(const wxChar
*psz
);
566 WXDLLEXPORT
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
570 WXDLLEXPORT wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
575 WXDLLEXPORT wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
578 #ifdef wxNEED_WCSLEN // for use in buffer.h
579 WXDLLEXPORT
size_t wcslen(const wchar_t *s
);
582 #ifdef wxNEED_WX_CTYPE_H
583 WXDLLEXPORT
int wxIsalnum(wxChar ch
);
584 WXDLLEXPORT
int wxIsalpha(wxChar ch
);
585 WXDLLEXPORT
int wxIsctrl(wxChar ch
);
586 WXDLLEXPORT
int wxIsdigit(wxChar ch
);
587 WXDLLEXPORT
int wxIsgraph(wxChar ch
);
588 WXDLLEXPORT
int wxIslower(wxChar ch
);
589 WXDLLEXPORT
int wxIsprint(wxChar ch
);
590 WXDLLEXPORT
int wxIspunct(wxChar ch
);
591 WXDLLEXPORT
int wxIsspace(wxChar ch
);
592 WXDLLEXPORT
int wxIsupper(wxChar ch
);
593 WXDLLEXPORT
int wxIsxdigit(wxChar ch
);
594 WXDLLEXPORT
int wxTolower(wxChar ch
);
595 WXDLLEXPORT
int wxToupper(wxChar ch
);
598 #ifdef wxNEED_WX_STRING_H
599 WXDLLEXPORT wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
600 WXDLLEXPORT wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
601 WXDLLEXPORT
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
602 WXDLLEXPORT
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
603 WXDLLEXPORT wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
604 WXDLLEXPORT
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
605 WXDLLEXPORT
size_t wxStrlen(const wxChar
*s
);
606 WXDLLEXPORT wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
607 WXDLLEXPORT
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
608 WXDLLEXPORT wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
609 WXDLLEXPORT wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
610 WXDLLEXPORT wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
611 WXDLLEXPORT
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
612 WXDLLEXPORT wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
613 WXDLLEXPORT
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
614 WXDLLEXPORT
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
615 WXDLLEXPORT
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
616 WXDLLEXPORT
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
619 #ifdef wxNEED_WX_STDIO_H
622 WXDLLEXPORT
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
623 WXDLLEXPORT
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
624 WXDLLEXPORT
int wxRemove(const wxChar
*path
);
625 WXDLLEXPORT
int wxRename(const wxChar
*oldpath
, const wxChar
*newpath
);
626 WXDLLEXPORT
int wxPrintf(const wxChar
*fmt
, ...);
627 WXDLLEXPORT
int wxVprintf(const wxChar
*fmt
, va_list argptr
);
628 WXDLLEXPORT
int wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
629 WXDLLEXPORT
int wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
630 WXDLLEXPORT
int wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
631 WXDLLEXPORT
int wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
632 WXDLLEXPORT
int wxSscanf(const wxChar
*buf
, const wxChar
*fmt
, ...);
633 WXDLLEXPORT
int wxVsscanf(const wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
637 WXDLLEXPORT
double wxAtof(const wxChar
*psz
);
640 #ifdef wxNEED_WX_STDLIB_H
641 WXDLLEXPORT
int wxAtoi(const wxChar
*psz
);
642 WXDLLEXPORT
long wxAtol(const wxChar
*psz
);
643 WXDLLEXPORT wxChar
* wxGetenv(const wxChar
*name
);
644 WXDLLEXPORT
int wxSystem(const wxChar
*psz
);
647 #ifdef wxNEED_WX_TIME_H
648 WXDLLEXPORT
size_t wxStrftime(wxChar
*s
, size_t max
, const wxChar
*fmt
, const struct tm
*tm
);
651 // under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks
652 // the file parsing - this may be true for 5.0 as well, update #ifdef then
653 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
655 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
658 // ----------------------------------------------------------------------------
659 // common macros which are always defined
660 // ----------------------------------------------------------------------------
662 // although global macros with such names are really bad, we want to have
663 // another name for _T() which should be used to avoid confusion between _T()
664 // and _() in wxWindows sources
667 // a Unicode-friendly __FILE__ analog
669 #define __XFILE__(x) wxT(x)
670 #define __TFILE__ __XFILE__(__FILE__)