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