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
66 #ifdef wxHAVE_TCHAR_FUNCTIONS
67 # define HAVE_WCSLEN 1
71 # if wxUSE_UNICODE // temporary - preserve binary compatibility
72 typedef _TCHAR wxChar
;
73 typedef _TSCHAR wxSChar
;
74 typedef _TUCHAR wxUChar
;
77 # define wxSChar signed char
78 # define wxUChar unsigned char
80 // wchar_t is available
82 # define wxUSE_WCHAR_T 1
85 #ifndef wxNO_TCHAR_CTYPE
86 # define wxIsalnum _istalnum
87 # define wxIsalpha _istalpha
88 # define wxIsctrl _istctrl
89 # define wxIsdigit _istdigit
90 # define wxIsgraph _istgraph
91 # define wxIslower _istlower
92 # define wxIsprint _istprint
93 # define wxIspunct _istpunct
94 # define wxIsspace _istspace
95 # define wxIsupper _istupper
96 # define wxIsxdigit _istxdigit
97 # define wxTolower _totlower
98 # define wxToupper _totupper
99 #endif // wxNO_TCHAR_CTYPE
102 #ifndef wxNO_TCHAR_LOCALE
103 # define wxSetlocale _tsetlocale
104 #endif // wxNO_TCHAR_LOCALE
106 // string.h functions
107 #ifndef wxNO_TCHAR_STRING
108 # define wxStrcat _tcscat
109 # define wxStrchr _tcschr
110 # define wxStrcmp _tcscmp
111 # define wxStrcoll _tcscoll
112 # define wxStrcpy _tcscpy
113 # define wxStrcspn _tcscspn
114 # define wxStrftime _tcsftime
115 # define wxStricmp _tcsicmp
116 # define wxStrlen_ _tcslen // used in wxStrlen inline function
117 # define wxStrncat _tcsncat
118 # define wxStrncmp _tcsncmp
119 # define wxStrncpy _tcsncpy
120 # define wxStrpbrk _tcspbrk
121 # define wxStrrchr _tcsrchr
122 # define wxStrspn _tcsspn
123 # define wxStrstr _tcsstr
124 # define wxStrtod _tcstod
125 # define wxStrtol _tcstol
126 # define wxStrtoul _tcstoul
127 # define wxStrxfrm _tcsxfrm
128 #endif // wxNO_TCHAR_STRING
131 #ifndef wxNO_TCHAR_STDIO
132 # define wxFgetc _fgettc
133 # define wxFgetchar _fgettchar
134 # define wxFgets _fgetts
135 # define wxFopen _tfopen
136 # define wxFputc _fputtc
137 # define wxFputchar _fputtchar
138 # define wxFprintf _ftprintf
139 # define wxFreopen _tfreopen
140 # define wxFscanf _ftscanf
141 # define wxGetc _gettc
142 # define wxGetchar _gettchar
143 # define wxGets _getts
144 # define wxPerror _tperror
145 # define wxPrintf _tprintf
146 # define wxPutc _puttc
147 # define wxPutchar _puttchar
148 # define wxPuts _putts
149 # define wxRemove _tremove
150 # define wxRename _trename
151 # define wxScanf _tscanf
152 # define wxSprintf _stprintf
153 # define wxSscanf _stscanf
154 # define wxTmpnam _ttmpnam
155 # define wxUngetc _tungetc
156 # define wxVfprint _vftprintf
157 # define wxVprintf _vtprintf
158 # define wxVsscanf _vstscanf
159 # define wxVsprintf _vstprintf
160 #elif defined(__VISAGECPP__)
161 // it has some stdio.h functions, apparently
162 # define wxFgetc _fgettc
163 # define wxFgets _fgetts
164 # define wxFputc _fputtc
165 # define wxFprintf _ftprintf
166 # define wxFscanf _ftscanf
167 # define wxGetc _gettc
168 # define wxGetchar _gettchar
169 # define wxPrintf _tprintf
170 # define wxPutc _puttc
171 # define wxPutchar _puttchar
172 # define wxScanf _tscanf
173 # define wxSprintf _stprintf
174 # define wxSscanf _stscanf
175 # define wxVfprint _vftprintf
176 # define wxVprintf _vtprintf
177 # define wxVsprintf _vstprintf
178 #endif // wxNO_TCHAR_STDIO
180 // stdlib.h functions
181 #ifndef wxNO_TCHAR_STDLIB
185 # define wxAtoi _ttoi
186 # define wxAtol _ttol
187 # define wxGetenv _tgetenv
188 # define wxSystem _tsystem
189 #endif // wxNO_TCHAR_STDLIB
192 #ifndef wxNO_TCHAR_TIME
193 # define wxAsctime _tasctime
194 # define wxCtime _tctime
195 #endif // wxNO_TCHAR_TIME
197 #else // !TCHAR-aware compilers
199 // check whether we should include wchar.h or equivalent
201 # undef wxUSE_WCHAR_T
202 # define wxUSE_WCHAR_T 1 // wchar_t *must* be available in Unicode mode
203 # elif !defined(wxUSE_WCHAR_T)
204 # if defined(__VISUALC__) && (__VISUALC__ < 900)
205 # define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
206 # elif defined(__UNIX__)
207 # if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__)
208 # define wxUSE_WCHAR_T 1
210 # define wxUSE_WCHAR_T 0
212 # elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
213 # define wxUSE_WCHAR_T 0
214 # elif defined(__BORLANDC__) // WIN16 BC++
215 # define wxUSE_WCHAR_T 0
216 # elif defined(__WATCOMC__)
217 # define wxUSE_WCHAR_T 0
219 // add additional compiler checks if this fails
220 # define wxUSE_WCHAR_T 1
222 # endif//wxUSE_UNICODE
232 # define wxNEED_WCSLEN
237 // check whether we are doing Unicode
242 // this is probably glibc-specific
243 # if defined(__WCHAR_TYPE__)
245 typedef __WCHAR_TYPE__ wxChar
;
246 typedef signed __WCHAR_TYPE__ wxSChar
;
247 typedef unsigned __WCHAR_TYPE__ wxUChar
;
251 // ctype.h functions (wctype.h)
252 # define wxIsalnum iswalnum
253 # define wxIsalpha iswalpha
254 # define wxIsctrl iswcntrl
255 # define wxIsdigit iswdigit
256 # define wxIsgraph iswgraph
257 # define wxIslower iswlower
258 # define wxIsprint iswprint
259 # define wxIspunct iswpunct
260 # define wxIsspace iswspace
261 # define wxIsupper iswupper
262 # define wxIsxdigit iswxdigit
264 # if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
265 // /usr/include/wctype.h incorrectly declares translations tables which
266 // provokes tons of compile-time warnings - try to correct this
267 # define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
268 # define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
270 # define wxTolower towlower
271 # define wxToupper towupper
274 // string.h functions (wchar.h)
275 # define wxStrcat wcscat
276 # define wxStrchr wcschr
277 # define wxStrcmp wcscmp
278 # define wxStrcoll wcscoll
279 # define wxStrcpy wcscpy
280 # define wxStrcspn wcscspn
281 # define wxStrlen_ wcslen // used in wxStrlen inline function
282 # define wxStrncat wcsncat
283 # define wxStrncmp wcsncmp
284 # define wxStrncpy wcsncpy
285 # define wxStrpbrk wcspbrk
286 # define wxStrrchr wcsrchr
287 # define wxStrspn wcsspn
288 # define wxStrstr wcsstr
289 # define wxStrtod wcstod
290 # define wxStrtok wcstok
291 # define wxStrtol wcstol
292 # define wxStrtoul wcstoul
293 # define wxStrxfrm wcsxfrm
295 // glibc doesn't have wc equivalents of the other stuff
296 # define wxNEED_WX_STDIO_H
297 # define wxNEED_WX_STDLIB_H
298 # define wxNEED_WX_TIME_H
301 # error "Please define your compiler's Unicode conventions in wxChar.h"
308 # if 0 // temporary - preserve binary compatibilty
310 typedef signed char wxSChar
;
311 typedef unsigned char wxUChar
;
314 # define wxSChar signed char
315 # define wxUChar unsigned char
322 # if !defined(__MINGW32__) || !defined(_T)
327 # define wxIsalnum isalnum
328 # define wxIsalpha isalpha
329 # define wxIsctrl isctrl
330 # define wxIsdigit isdigit
331 # define wxIsgraph isgraph
332 # define wxIslower islower
333 # define wxIsprint isprint
334 # define wxIspunct ispunct
335 # define wxIsspace isspace
336 # define wxIsupper isupper
337 # define wxIsxdigit isxdigit
338 # define wxTolower tolower
339 # define wxToupper toupper
342 # define wxSetlocale setlocale
344 // string.h functions
345 // #define wxStricmp strcasecmp
346 // wxStricmp is defined below!!
349 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
351 #define wxStrtok(str, sep, last) strtok(str, sep)
354 // leave the rest to defaults below
355 # define wxNEED_WX_STRING_H
356 # define wxNEED_WX_STDIO_H
357 # define wxNEED_WX_STDLIB_H
358 # define wxNEED_WX_TIME_H
361 #endif//TCHAR-aware compilers
363 // define wxStricmp for various compilers without Unicode possibilities
364 #if !defined(wxStricmp) && !wxUSE_UNICODE
365 # if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__) || defined(__VISAGECPP__) || defined(__EMX__)
366 # define wxStricmp stricmp
367 # define wxStrnicmp strnicmp
368 # elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS__) && defined(__INTEL__))
369 # define wxStricmp _stricmp
370 # define wxStrnicmp _strnicmp
371 # elif defined(__UNIX__) || defined(__GNUWIN32__)
372 # define wxStricmp strcasecmp
373 # define wxStrnicmp strncasecmp
374 # elif defined(__MWERKS__) && !defined(__INTEL__)
375 // use wxWindows' implementation
377 // if you leave wxStricmp undefined, wxWindows' implementation will be used
378 # error "Please define string case-insensitive compare for your OS/compiler"
382 // if we need to define for standard headers, and we're not using Unicode,
383 // just define to standard C library routines
385 # ifdef wxNEED_WX_STRING_H
386 # define wxStrcat strcat
387 # define wxStrchr strchr
388 # define wxStrcmp strcmp
389 # define wxStrcoll strcoll
390 # define wxStrcpy strcpy
391 # define wxStrcspn strcspn
392 # define wxStrdup strdup
393 # define wxStrlen_ strlen // used in wxStrlen inline function
394 # define wxStrncat strncat
395 # define wxStrncmp strncmp
396 # define wxStrncpy strncpy
397 # define wxStrpbrk strpbrk
398 # define wxStrrchr strrchr
399 # define wxStrspn strspn
400 # define wxStrstr strstr
401 # define wxStrtod strtod
402 # define wxStrtol strtol
403 # define wxStrtoul strtoul
404 # define wxStrxfrm strxfrm
405 # undef wxNEED_WX_STRING_H
408 # ifdef wxNEED_WX_STDIO_H
409 # define wxFgetc fgetc
410 # define wxFgetchar fgetchar
411 # define wxFgets fgets
412 # define wxFopen fopen
413 # define wxFputc fputc
414 # define wxFputchar fputchar
415 # define wxFprintf fprintf
416 # define wxFreopen freopen
417 # define wxFscanf fscanf
419 # define wxGetchar getchar
421 # define wxPerror perror
422 # define wxPrintf printf
424 # define wxPutchar putchar
426 # define wxRemove remove
427 # define wxRename rename
428 # define wxScanf scanf
429 # define wxSprintf sprintf
430 # define wxSscanf sscanf
431 # define wxTmpnam tmpnam
432 # define wxUngetc ungetc
433 # define wxVfprint vfprintf
434 # define wxVprintf vprintf
435 # define wxVsscanf vsscanf
436 # define wxVsprintf vsprintf
437 # undef wxNEED_WX_STDIO_H
440 # ifdef wxNEED_WX_STDLIB_H
444 # define wxGetenv getenv
445 # define wxSystem system
446 # undef wxNEED_WX_STDLIB_H
449 # ifdef wxNEED_WX_TIME_H
450 # define wxAsctime asctime
451 # define wxCtime ctime
452 # define wxStrftime strftime
453 # undef wxNEED_WX_TIME_H
457 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
458 # define wcslen wxStrlen
459 # undef wxNEED_WCSLEN
462 // checks whether the passed in pointer is NULL and if the string is empty
463 WXDLLEXPORT
inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
465 #ifndef wxNEED_WX_STRING_H
466 // safe version of strlen() (returns 0 if passed NULL pointer)
467 WXDLLEXPORT
inline size_t wxStrlen(const wxChar
*psz
)
468 { return psz
? wxStrlen_(psz
) : 0; }
472 // multibyte<->widechar conversion
473 WXDLLEXPORT
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
474 WXDLLEXPORT
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
476 # define wxMB2WX wxMB2WC
477 # define wxWX2MB wxWC2MB
478 # define wxWC2WX wxStrncpy
479 # define wxWX2WC wxStrncpy
481 # define wxMB2WX wxStrncpy
482 # define wxWX2MB wxStrncpy
483 # define wxWC2WX wxWC2MB
484 # define wxWX2WC wxMB2WC
487 // No wxUSE_WCHAR_T: we have to do something (JACS)
488 # define wxMB2WC wxStrncpy
489 # define wxWC2MB wxStrncpy
490 # define wxMB2WX wxStrncpy
491 # define wxWX2MB wxStrncpy
492 # define wxWC2WX wxWC2MB
493 # define wxWX2WC wxMB2WC
496 WXDLLEXPORT
bool wxOKlibc(); // for internal use
498 // if libc versions are not available, use replacements defined in wxchar.cpp
500 WXDLLEXPORT wxChar
* wxStrdup(const wxChar
*psz
);
504 WXDLLEXPORT
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
508 WXDLLEXPORT wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
512 WXDLLEXPORT wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
515 #ifdef wxNEED_WCSLEN // for use in buffer.h
516 WXDLLEXPORT
size_t wcslen(const wchar_t *s
);
519 #ifdef wxNEED_WX_CTYPE_H
520 WXDLLEXPORT
int wxIsalnum(wxChar ch
);
521 WXDLLEXPORT
int wxIsalpha(wxChar ch
);
522 WXDLLEXPORT
int wxIsctrl(wxChar ch
);
523 WXDLLEXPORT
int wxIsdigit(wxChar ch
);
524 WXDLLEXPORT
int wxIsgraph(wxChar ch
);
525 WXDLLEXPORT
int wxIslower(wxChar ch
);
526 WXDLLEXPORT
int wxIsprint(wxChar ch
);
527 WXDLLEXPORT
int wxIspunct(wxChar ch
);
528 WXDLLEXPORT
int wxIsspace(wxChar ch
);
529 WXDLLEXPORT
int wxIsupper(wxChar ch
);
530 WXDLLEXPORT
int wxIsxdigit(wxChar ch
);
531 WXDLLEXPORT
int wxTolower(wxChar ch
);
532 WXDLLEXPORT
int wxToupper(wxChar ch
);
535 #ifdef wxNEED_WX_STRING_H
536 WXDLLEXPORT wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
537 WXDLLEXPORT wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
538 WXDLLEXPORT
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
539 WXDLLEXPORT
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
540 WXDLLEXPORT wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
541 WXDLLEXPORT
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
542 WXDLLEXPORT
size_t wxStrlen(const wxChar
*s
);
543 WXDLLEXPORT wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
544 WXDLLEXPORT
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
545 WXDLLEXPORT wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
546 WXDLLEXPORT wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
547 WXDLLEXPORT wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
548 WXDLLEXPORT
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
549 WXDLLEXPORT wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
550 WXDLLEXPORT
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
551 WXDLLEXPORT
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
552 WXDLLEXPORT
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
553 WXDLLEXPORT
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
556 #ifdef wxNEED_WX_STDIO_H
559 WXDLLEXPORT
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
560 WXDLLEXPORT
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
561 WXDLLEXPORT
int wxPrintf(const wxChar
*fmt
, ...);
562 WXDLLEXPORT
int wxVprintf(const wxChar
*fmt
, va_list argptr
);
563 WXDLLEXPORT
int wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
564 WXDLLEXPORT
int wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
565 WXDLLEXPORT
int wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
566 WXDLLEXPORT
int wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
567 WXDLLEXPORT
int wxSscanf(const wxChar
*buf
, const wxChar
*fmt
, ...);
568 WXDLLEXPORT
int wxVsscanf(const wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
572 WXDLLEXPORT
double wxAtof(const wxChar
*psz
);
575 #ifdef wxNEED_WX_STDLIB_H
576 WXDLLEXPORT
int wxAtoi(const wxChar
*psz
);
577 WXDLLEXPORT
long wxAtol(const wxChar
*psz
);
578 WXDLLEXPORT wxChar
* wxGetenv(const wxChar
*name
);
579 WXDLLEXPORT
int wxSystem(const wxChar
*psz
);
582 #ifdef wxNEED_WX_TIME_H
583 WXDLLEXPORT
size_t wxStrftime(wxChar
*s
, size_t max
, const wxChar
*fmt
, const struct tm
*tm
);
586 // although global macros with such names are really bad, we want to have
587 // another name for _T() which should be used to avoid confusion between _T()
588 // and _() in wxWindows sources
591 // a Unicode-friendly __FILE__ analog
593 #define __XFILE__(x) wxT(x)
594 #define __TFILE__ __XFILE__(__FILE__)