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
29 # ifndef wxUSE_UNICODE
30 # define wxUSE_UNICODE 0
34 // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
44 // ----------------------------------------------------------------------------
45 // define wxHAVE_TCHAR_FUNCTIONS for the compilers which support the
46 // wide-character functions
47 // ----------------------------------------------------------------------------
50 // VC++ and BC++ starting with 5.2 have TCHAR support
52 #define wxHAVE_TCHAR_FUNCTIONS
53 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
54 #define wxHAVE_TCHAR_FUNCTIONS
56 #elif defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
57 // VisualAge 4.0+ supports TCHAR
58 #define wxHAVE_TCHAR_FUNCTIONS
60 // but not stdio.h nor time nor conversion functions
61 #define wxNO_TCHAR_STDIO
62 #define wxNO_TCHAR_STDLIB
63 #define wxNO_TCHAR_TIME
64 #define wxNO_TCHAR_LOCALE
66 // supplemental VA V4 defs so at least we know what these are
67 // just define to standard defs
73 // locale.h functons -- not defined in tchar.h
74 #define wxSetlocale setlocale
75 // some stdio functions are defined others are not
77 #define wxFgetchar fgetchar
79 #define wxFputchar fputchar
80 #define wxFreopen freopen
82 #define wxPerror perror
84 #define wxRemove remove
85 #define wxRename rename
86 #define wxTmpnam tmpnam
87 #define wxUngetc ungetc
88 #define wxVsscanf vsscanf
89 // stdlib not defined in VA V4
95 #define wxGetenv getenv
96 #define wxSystem system
97 // time.h functions -- none defined in tchar.h
98 #define wxAsctime asctime
104 #ifdef wxHAVE_TCHAR_FUNCTIONS
105 # define HAVE_WCSLEN 1
109 # if wxUSE_UNICODE // temporary - preserve binary compatibility
110 typedef _TCHAR wxChar
;
111 typedef _TSCHAR wxSChar
;
112 typedef _TUCHAR wxUChar
;
115 # define wxSChar signed char
116 # define wxUChar unsigned char
118 // wchar_t is available
119 # undef wxUSE_WCHAR_T
120 # define wxUSE_WCHAR_T 1
123 #ifndef wxNO_TCHAR_CTYPE
127 # define wxIsalnum _istalnum
128 # define wxIsalpha _istalpha
129 # define wxIsctrl _istctrl
130 # define wxIsdigit _istdigit
131 # define wxIsgraph _istgraph
132 # define wxIslower _istlower
133 # define wxIsprint _istprint
134 # define wxIspunct _istpunct
135 # define wxIsspace _istspace
136 # define wxIsupper _istupper
137 # define wxIsxdigit _istxdigit
138 # define wxTolower _totlower
139 # define wxToupper _totupper
140 #endif // wxNO_TCHAR_CTYPE
143 #ifndef wxNO_TCHAR_LOCALE
144 # define wxSetlocale _tsetlocale
145 #endif // wxNO_TCHAR_LOCALE
147 // string.h functions
148 #ifndef wxNO_TCHAR_STRING
149 # define wxStrcat _tcscat
150 # define wxStrchr _tcschr
151 # define wxStrcmp _tcscmp
152 # define wxStrcoll _tcscoll
153 # define wxStrcpy _tcscpy
154 # define wxStrcspn _tcscspn
155 # define wxStrftime _tcsftime
156 # define wxStricmp _tcsicmp
157 # define wxStrlen_ _tcslen // used in wxStrlen inline function
158 # define wxStrncat _tcsncat
159 # define wxStrncmp _tcsncmp
160 # define wxStrncpy _tcsncpy
161 # define wxStrpbrk _tcspbrk
162 # define wxStrrchr _tcsrchr
163 # define wxStrspn _tcsspn
164 # define wxStrstr _tcsstr
165 # define wxStrtod _tcstod
166 # define wxStrtol _tcstol
167 # define wxStrtoul _tcstoul
168 # define wxStrxfrm _tcsxfrm
169 #endif // wxNO_TCHAR_STRING
172 #ifndef wxNO_TCHAR_STDIO
173 # define wxFgetc _fgettc
174 # define wxFgetchar _fgettchar
175 # define wxFgets _fgetts
176 # define wxFopen _tfopen
177 # define wxFputc _fputtc
178 # define wxFputchar _fputtchar
179 # define wxFprintf _ftprintf
180 # define wxFreopen _tfreopen
181 # define wxFscanf _ftscanf
182 # define wxGetc _gettc
183 # define wxGetchar _gettchar
184 # define wxGets _getts
185 # define wxPerror _tperror
186 # define wxPrintf _tprintf
187 # define wxPutc _puttc
188 # define wxPutchar _puttchar
189 # define wxPuts _putts
190 # define wxRemove _tremove
191 # define wxRename _trename
192 # define wxScanf _tscanf
193 # define wxSprintf _stprintf
194 # define wxSscanf _stscanf
195 # define wxTmpnam _ttmpnam
196 # define wxUngetc _tungetc
197 # define wxVfprint _vftprintf
198 # define wxVprintf _vtprintf
199 # define wxVsscanf _vstscanf
200 # define wxVsprintf _vstprintf
201 #elif defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
202 // it has some stdio.h functions, apparently
203 # define wxFgetc _fgettc
204 # define wxFgets _fgetts
205 # define wxFputc _fputtc
206 # define wxFprintf _ftprintf
207 # define wxFscanf _ftscanf
208 # define wxGetc _gettc
209 # define wxGetchar _gettchar
210 # define wxPrintf _tprintf
211 # define wxPutc _puttc
212 # define wxPutchar _puttchar
213 # define wxScanf _tscanf
214 # define wxSprintf _stprintf
215 # define wxSscanf _stscanf
216 # define wxVfprint _vftprintf
217 # define wxVprintf _vtprintf
218 # define wxVsprintf _vstprintf
219 #endif // wxNO_TCHAR_STDIO
221 // stdlib.h functions
222 #ifndef wxNO_TCHAR_STDLIB
226 # define wxAtoi _ttoi
227 # define wxAtol _ttol
228 # define wxGetenv _tgetenv
229 # define wxSystem _tsystem
230 #endif // wxNO_TCHAR_STDLIB
233 #ifndef wxNO_TCHAR_TIME
234 # define wxAsctime _tasctime
235 # define wxCtime _tctime
236 #endif // wxNO_TCHAR_TIME
238 #else // !TCHAR-aware compilers
240 // check whether we should include wchar.h or equivalent
242 # undef wxUSE_WCHAR_T
243 # define wxUSE_WCHAR_T 1 // wchar_t *must* be available in Unicode mode
244 # elif !defined(wxUSE_WCHAR_T)
245 # if defined(__VISUALC__) && (__VISUALC__ < 900)
246 # define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
247 # elif defined(__UNIX__)
248 # if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__)
249 # define wxUSE_WCHAR_T 1
251 # define wxUSE_WCHAR_T 0
253 # elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
254 # define wxUSE_WCHAR_T 0
255 # elif defined(__BORLANDC__) // WIN16 BC++
256 # define wxUSE_WCHAR_T 0
257 # elif defined(__WATCOMC__)
258 # define wxUSE_WCHAR_T 0
259 # elif defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
260 # define wxUSE_WCHAR_T 1
262 // add additional compiler checks if this fails
263 # define wxUSE_WCHAR_T 1
265 # endif//wxUSE_UNICODE
275 # define wxNEED_WCSLEN
280 // check whether we are doing Unicode
285 // this is probably glibc-specific
286 # if defined(__WCHAR_TYPE__)
288 typedef __WCHAR_TYPE__ wxChar
;
289 typedef signed __WCHAR_TYPE__ wxSChar
;
290 typedef unsigned __WCHAR_TYPE__ wxUChar
;
294 // ctype.h functions (wctype.h)
295 # define wxIsalnum iswalnum
296 # define wxIsalpha iswalpha
297 # define wxIsctrl iswcntrl
298 # define wxIsdigit iswdigit
299 # define wxIsgraph iswgraph
300 # define wxIslower iswlower
301 # define wxIsprint iswprint
302 # define wxIspunct iswpunct
303 # define wxIsspace iswspace
304 # define wxIsupper iswupper
305 # define wxIsxdigit iswxdigit
307 # if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
308 // /usr/include/wctype.h incorrectly declares translations tables which
309 // provokes tons of compile-time warnings - try to correct this
310 # define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
311 # define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
313 # define wxTolower towlower
314 # define wxToupper towupper
317 // string.h functions (wchar.h)
318 # define wxStrcat wcscat
319 # define wxStrchr wcschr
320 # define wxStrcmp wcscmp
321 # define wxStrcoll wcscoll
322 # define wxStrcpy wcscpy
323 # define wxStrcspn wcscspn
324 # define wxStrlen_ wcslen // used in wxStrlen inline function
325 # define wxStrncat wcsncat
326 # define wxStrncmp wcsncmp
327 # define wxStrncpy wcsncpy
328 # define wxStrpbrk wcspbrk
329 # define wxStrrchr wcsrchr
330 # define wxStrspn wcsspn
331 # define wxStrstr wcsstr
332 # define wxStrtod wcstod
333 # define wxStrtok wcstok
334 # define wxStrtol wcstol
335 # define wxStrtoul wcstoul
336 # define wxStrxfrm wcsxfrm
338 // glibc doesn't have wc equivalents of the other stuff
339 # define wxNEED_WX_STDIO_H
340 # define wxNEED_WX_STDLIB_H
341 # define wxNEED_WX_TIME_H
344 # error "Please define your compiler's Unicode conventions in wxChar.h"
351 # if 0 // temporary - preserve binary compatibilty
353 typedef signed char wxSChar
;
354 typedef unsigned char wxUChar
;
357 # define wxSChar signed char
358 # define wxUChar unsigned char
365 # if !defined(__MINGW32__) || !defined(_T)
370 # define wxIsalnum isalnum
371 # define wxIsalpha isalpha
372 # define wxIsctrl isctrl
373 # define wxIsdigit isdigit
374 # define wxIsgraph isgraph
375 # define wxIslower islower
376 # define wxIsprint isprint
377 # define wxIspunct ispunct
378 # define wxIsspace isspace
379 # define wxIsupper isupper
380 # define wxIsxdigit isxdigit
381 # define wxTolower tolower
382 # define wxToupper toupper
385 # define wxSetlocale setlocale
387 // string.h functions
388 // #define wxStricmp strcasecmp
389 // wxStricmp is defined below!!
392 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
394 #define wxStrtok(str, sep, last) strtok(str, sep)
397 // leave the rest to defaults below
398 # define wxNEED_WX_STRING_H
399 # define wxNEED_WX_STDIO_H
400 # define wxNEED_WX_STDLIB_H
401 # define wxNEED_WX_TIME_H
404 #endif//TCHAR-aware compilers
406 // define wxStricmp for various compilers without Unicode possibilities
407 #if !defined(wxStricmp) && !wxUSE_UNICODE
408 # if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__) || defined(__VISAGECPP__) || defined(__EMX__)
409 # define wxStricmp stricmp
410 # define wxStrnicmp strnicmp
411 # elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS__) && defined(__INTEL__))
412 # define wxStricmp _stricmp
413 # define wxStrnicmp _strnicmp
414 # elif defined(__UNIX__) || defined(__GNUWIN32__)
415 # define wxStricmp strcasecmp
416 # define wxStrnicmp strncasecmp
417 # elif defined(__MWERKS__) && !defined(__INTEL__)
418 // use wxWindows' implementation
420 // if you leave wxStricmp undefined, wxWindows' implementation will be used
421 # error "Please define string case-insensitive compare for your OS/compiler"
425 // if we need to define for standard headers, and we're not using Unicode,
426 // just define to standard C library routines
428 # ifdef wxNEED_WX_STRING_H
429 # define wxStrcat strcat
430 # define wxStrchr strchr
431 # define wxStrcmp strcmp
432 # define wxStrcoll strcoll
433 # define wxStrcpy strcpy
434 # define wxStrcspn strcspn
435 # define wxStrdup strdup
436 # define wxStrlen_ strlen // used in wxStrlen inline function
437 # define wxStrncat strncat
438 # define wxStrncmp strncmp
439 # define wxStrncpy strncpy
440 # define wxStrpbrk strpbrk
441 # define wxStrrchr strrchr
442 # define wxStrspn strspn
443 # define wxStrstr strstr
444 # define wxStrtod strtod
445 # define wxStrtol strtol
446 # define wxStrtoul strtoul
447 # define wxStrxfrm strxfrm
448 # undef wxNEED_WX_STRING_H
451 # ifdef wxNEED_WX_STDIO_H
452 # define wxFgetc fgetc
453 # define wxFgetchar fgetchar
454 # define wxFgets fgets
455 # define wxFopen fopen
456 # define wxFputc fputc
457 # define wxFputchar fputchar
458 # define wxFprintf fprintf
459 # define wxFreopen freopen
460 # define wxFscanf fscanf
462 # define wxGetchar getchar
464 # define wxPerror perror
465 # define wxPrintf printf
467 # define wxPutchar putchar
469 # define wxRemove remove
470 # define wxRename rename
471 # define wxScanf scanf
472 # define wxSprintf sprintf
473 # define wxSscanf sscanf
474 # define wxTmpnam tmpnam
475 # define wxUngetc ungetc
476 # define wxVfprint vfprintf
477 # define wxVprintf vprintf
478 # define wxVsscanf vsscanf
479 # define wxVsprintf vsprintf
480 # undef wxNEED_WX_STDIO_H
483 # ifdef wxNEED_WX_STDLIB_H
487 # define wxGetenv getenv
488 # define wxSystem system
489 # undef wxNEED_WX_STDLIB_H
492 # ifdef wxNEED_WX_TIME_H
493 # define wxAsctime asctime
494 # define wxCtime ctime
495 # define wxStrftime strftime
496 # undef wxNEED_WX_TIME_H
500 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
501 # define wcslen wxStrlen
502 # undef wxNEED_WCSLEN
505 // checks whether the passed in pointer is NULL and if the string is empty
506 WXDLLEXPORT
inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
508 #ifndef wxNEED_WX_STRING_H
509 // safe version of strlen() (returns 0 if passed NULL pointer)
510 WXDLLEXPORT
inline size_t wxStrlen(const wxChar
*psz
)
511 { return psz
? wxStrlen_(psz
) : 0; }
515 // multibyte<->widechar conversion
516 WXDLLEXPORT
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
517 WXDLLEXPORT
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
519 # define wxMB2WX wxMB2WC
520 # define wxWX2MB wxWC2MB
521 # define wxWC2WX wxStrncpy
522 # define wxWX2WC wxStrncpy
524 # define wxMB2WX wxStrncpy
525 # define wxWX2MB wxStrncpy
526 # define wxWC2WX wxWC2MB
527 # define wxWX2WC wxMB2WC
530 // No wxUSE_WCHAR_T: we have to do something (JACS)
531 # define wxMB2WC wxStrncpy
532 # define wxWC2MB wxStrncpy
533 # define wxMB2WX wxStrncpy
534 # define wxWX2MB wxStrncpy
535 # define wxWC2WX wxWC2MB
536 # define wxWX2WC wxMB2WC
539 WXDLLEXPORT
bool wxOKlibc(); // for internal use
541 // if libc versions are not available, use replacements defined in wxchar.cpp
543 WXDLLEXPORT wxChar
* wxStrdup(const wxChar
*psz
);
547 WXDLLEXPORT
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
551 WXDLLEXPORT wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
556 WXDLLEXPORT wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
559 #ifdef wxNEED_WCSLEN // for use in buffer.h
560 WXDLLEXPORT
size_t wcslen(const wchar_t *s
);
563 #ifdef wxNEED_WX_CTYPE_H
564 WXDLLEXPORT
int wxIsalnum(wxChar ch
);
565 WXDLLEXPORT
int wxIsalpha(wxChar ch
);
566 WXDLLEXPORT
int wxIsctrl(wxChar ch
);
567 WXDLLEXPORT
int wxIsdigit(wxChar ch
);
568 WXDLLEXPORT
int wxIsgraph(wxChar ch
);
569 WXDLLEXPORT
int wxIslower(wxChar ch
);
570 WXDLLEXPORT
int wxIsprint(wxChar ch
);
571 WXDLLEXPORT
int wxIspunct(wxChar ch
);
572 WXDLLEXPORT
int wxIsspace(wxChar ch
);
573 WXDLLEXPORT
int wxIsupper(wxChar ch
);
574 WXDLLEXPORT
int wxIsxdigit(wxChar ch
);
575 WXDLLEXPORT
int wxTolower(wxChar ch
);
576 WXDLLEXPORT
int wxToupper(wxChar ch
);
579 #ifdef wxNEED_WX_STRING_H
580 WXDLLEXPORT wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
581 WXDLLEXPORT wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
582 WXDLLEXPORT
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
583 WXDLLEXPORT
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
584 WXDLLEXPORT wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
585 WXDLLEXPORT
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
586 WXDLLEXPORT
size_t wxStrlen(const wxChar
*s
);
587 WXDLLEXPORT wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
588 WXDLLEXPORT
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
589 WXDLLEXPORT wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
590 WXDLLEXPORT wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
591 WXDLLEXPORT wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
592 WXDLLEXPORT
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
593 WXDLLEXPORT wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
594 WXDLLEXPORT
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
595 WXDLLEXPORT
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
596 WXDLLEXPORT
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
597 WXDLLEXPORT
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
600 #ifdef wxNEED_WX_STDIO_H
603 WXDLLEXPORT
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
604 WXDLLEXPORT
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
605 WXDLLEXPORT
int wxPrintf(const wxChar
*fmt
, ...);
606 WXDLLEXPORT
int wxVprintf(const wxChar
*fmt
, va_list argptr
);
607 WXDLLEXPORT
int wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
608 WXDLLEXPORT
int wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
609 WXDLLEXPORT
int wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
610 WXDLLEXPORT
int wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
611 WXDLLEXPORT
int wxSscanf(const wxChar
*buf
, const wxChar
*fmt
, ...);
612 WXDLLEXPORT
int wxVsscanf(const wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
616 WXDLLEXPORT
double wxAtof(const wxChar
*psz
);
619 #ifdef wxNEED_WX_STDLIB_H
620 WXDLLEXPORT
int wxAtoi(const wxChar
*psz
);
621 WXDLLEXPORT
long wxAtol(const wxChar
*psz
);
622 WXDLLEXPORT wxChar
* wxGetenv(const wxChar
*name
);
623 WXDLLEXPORT
int wxSystem(const wxChar
*psz
);
626 #ifdef wxNEED_WX_TIME_H
627 WXDLLEXPORT
size_t wxStrftime(wxChar
*s
, size_t max
, const wxChar
*fmt
, const struct tm
*tm
);
630 // although global macros with such names are really bad, we want to have
631 // another name for _T() which should be used to avoid confusion between _T()
632 // and _() in wxWindows sources
635 // a Unicode-friendly __FILE__ analog
637 #define __XFILE__(x) wxT(x)
638 #define __TFILE__ __XFILE__(__FILE__)