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
124 # define wxIsalnum _istalnum
125 # define wxIsalpha _istalpha
126 # define wxIsctrl _istctrl
127 # define wxIsdigit _istdigit
128 # define wxIsgraph _istgraph
129 # define wxIslower _istlower
130 # define wxIsprint _istprint
131 # define wxIspunct _istpunct
132 # define wxIsspace _istspace
133 # define wxIsupper _istupper
134 # define wxIsxdigit _istxdigit
135 # define wxTolower _totlower
136 # define wxToupper _totupper
137 #endif // wxNO_TCHAR_CTYPE
140 #ifndef wxNO_TCHAR_LOCALE
141 # define wxSetlocale _tsetlocale
142 #endif // wxNO_TCHAR_LOCALE
144 // string.h functions
145 #ifndef wxNO_TCHAR_STRING
146 # define wxStrcat _tcscat
147 # define wxStrchr _tcschr
148 # define wxStrcmp _tcscmp
149 # define wxStrcoll _tcscoll
150 # define wxStrcpy _tcscpy
151 # define wxStrcspn _tcscspn
152 # define wxStrftime _tcsftime
153 # define wxStricmp _tcsicmp
154 # define wxStrlen_ _tcslen // used in wxStrlen inline function
155 # define wxStrncat _tcsncat
156 # define wxStrncmp _tcsncmp
157 # define wxStrncpy _tcsncpy
158 # define wxStrpbrk _tcspbrk
159 # define wxStrrchr _tcsrchr
160 # define wxStrspn _tcsspn
161 # define wxStrstr _tcsstr
162 # define wxStrtod _tcstod
163 # define wxStrtol _tcstol
164 # define wxStrtoul _tcstoul
165 # define wxStrxfrm _tcsxfrm
166 #endif // wxNO_TCHAR_STRING
169 #ifndef wxNO_TCHAR_STDIO
170 # define wxFgetc _fgettc
171 # define wxFgetchar _fgettchar
172 # define wxFgets _fgetts
173 # define wxFopen _tfopen
174 # define wxFputc _fputtc
175 # define wxFputchar _fputtchar
176 # define wxFprintf _ftprintf
177 # define wxFreopen _tfreopen
178 # define wxFscanf _ftscanf
179 # define wxGetc _gettc
180 # define wxGetchar _gettchar
181 # define wxGets _getts
182 # define wxPerror _tperror
183 # define wxPrintf _tprintf
184 # define wxPutc _puttc
185 # define wxPutchar _puttchar
186 # define wxPuts _putts
187 # define wxRemove _tremove
188 # define wxRename _trename
189 # define wxScanf _tscanf
190 # define wxSprintf _stprintf
191 # define wxSscanf _stscanf
192 # define wxTmpnam _ttmpnam
193 # define wxUngetc _tungetc
194 # define wxVfprint _vftprintf
195 # define wxVprintf _vtprintf
196 # define wxVsscanf _vstscanf
197 # define wxVsprintf _vstprintf
198 #elif defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
199 // it has some stdio.h functions, apparently
200 # define wxFgetc _fgettc
201 # define wxFgets _fgetts
202 # define wxFputc _fputtc
203 # define wxFprintf _ftprintf
204 # define wxFscanf _ftscanf
205 # define wxGetc _gettc
206 # define wxGetchar _gettchar
207 # define wxPrintf _tprintf
208 # define wxPutc _puttc
209 # define wxPutchar _puttchar
210 # define wxScanf _tscanf
211 # define wxSprintf _stprintf
212 # define wxSscanf _stscanf
213 # define wxVfprint _vftprintf
214 # define wxVprintf _vtprintf
215 # define wxVsprintf _vstprintf
216 #endif // wxNO_TCHAR_STDIO
218 // stdlib.h functions
219 #ifndef wxNO_TCHAR_STDLIB
223 # define wxAtoi _ttoi
224 # define wxAtol _ttol
225 # define wxGetenv _tgetenv
226 # define wxSystem _tsystem
227 #endif // wxNO_TCHAR_STDLIB
230 #ifndef wxNO_TCHAR_TIME
231 # define wxAsctime _tasctime
232 # define wxCtime _tctime
233 #endif // wxNO_TCHAR_TIME
235 #else // !TCHAR-aware compilers
237 // check whether we should include wchar.h or equivalent
239 # undef wxUSE_WCHAR_T
240 # define wxUSE_WCHAR_T 1 // wchar_t *must* be available in Unicode mode
241 # elif !defined(wxUSE_WCHAR_T)
242 # if defined(__VISUALC__) && (__VISUALC__ < 900)
243 # define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
244 # elif defined(__UNIX__)
245 # if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__)
246 # define wxUSE_WCHAR_T 1
248 # define wxUSE_WCHAR_T 0
250 # elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
251 # define wxUSE_WCHAR_T 0
252 # elif defined(__BORLANDC__) // WIN16 BC++
253 # define wxUSE_WCHAR_T 0
254 # elif defined(__WATCOMC__)
255 # define wxUSE_WCHAR_T 0
256 # elif defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
257 # define wxUSE_WCHAR_T 1
259 // add additional compiler checks if this fails
260 # define wxUSE_WCHAR_T 1
262 # endif//wxUSE_UNICODE
272 # define wxNEED_WCSLEN
277 // check whether we are doing Unicode
282 // this is probably glibc-specific
283 # if defined(__WCHAR_TYPE__)
285 typedef __WCHAR_TYPE__ wxChar
;
286 typedef signed __WCHAR_TYPE__ wxSChar
;
287 typedef unsigned __WCHAR_TYPE__ wxUChar
;
291 // ctype.h functions (wctype.h)
292 # define wxIsalnum iswalnum
293 # define wxIsalpha iswalpha
294 # define wxIsctrl iswcntrl
295 # define wxIsdigit iswdigit
296 # define wxIsgraph iswgraph
297 # define wxIslower iswlower
298 # define wxIsprint iswprint
299 # define wxIspunct iswpunct
300 # define wxIsspace iswspace
301 # define wxIsupper iswupper
302 # define wxIsxdigit iswxdigit
304 # if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
305 // /usr/include/wctype.h incorrectly declares translations tables which
306 // provokes tons of compile-time warnings - try to correct this
307 # define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
308 # define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
310 # define wxTolower towlower
311 # define wxToupper towupper
314 // string.h functions (wchar.h)
315 # define wxStrcat wcscat
316 # define wxStrchr wcschr
317 # define wxStrcmp wcscmp
318 # define wxStrcoll wcscoll
319 # define wxStrcpy wcscpy
320 # define wxStrcspn wcscspn
321 # define wxStrlen_ wcslen // used in wxStrlen inline function
322 # define wxStrncat wcsncat
323 # define wxStrncmp wcsncmp
324 # define wxStrncpy wcsncpy
325 # define wxStrpbrk wcspbrk
326 # define wxStrrchr wcsrchr
327 # define wxStrspn wcsspn
328 # define wxStrstr wcsstr
329 # define wxStrtod wcstod
330 # define wxStrtok wcstok
331 # define wxStrtol wcstol
332 # define wxStrtoul wcstoul
333 # define wxStrxfrm wcsxfrm
335 // glibc doesn't have wc equivalents of the other stuff
336 # define wxNEED_WX_STDIO_H
337 # define wxNEED_WX_STDLIB_H
338 # define wxNEED_WX_TIME_H
341 # error "Please define your compiler's Unicode conventions in wxChar.h"
348 # if 0 // temporary - preserve binary compatibilty
350 typedef signed char wxSChar
;
351 typedef unsigned char wxUChar
;
354 # define wxSChar signed char
355 # define wxUChar unsigned char
362 # if !defined(__MINGW32__) || !defined(_T)
367 # define wxIsalnum isalnum
368 # define wxIsalpha isalpha
369 # define wxIsctrl isctrl
370 # define wxIsdigit isdigit
371 # define wxIsgraph isgraph
372 # define wxIslower islower
373 # define wxIsprint isprint
374 # define wxIspunct ispunct
375 # define wxIsspace isspace
376 # define wxIsupper isupper
377 # define wxIsxdigit isxdigit
378 # define wxTolower tolower
379 # define wxToupper toupper
382 # define wxSetlocale setlocale
384 // string.h functions
385 // #define wxStricmp strcasecmp
386 // wxStricmp is defined below!!
389 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
391 #define wxStrtok(str, sep, last) strtok(str, sep)
394 // leave the rest to defaults below
395 # define wxNEED_WX_STRING_H
396 # define wxNEED_WX_STDIO_H
397 # define wxNEED_WX_STDLIB_H
398 # define wxNEED_WX_TIME_H
401 #endif//TCHAR-aware compilers
403 // define wxStricmp for various compilers without Unicode possibilities
404 #if !defined(wxStricmp) && !wxUSE_UNICODE
405 # if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__) || defined(__VISAGECPP__) || defined(__EMX__)
406 # define wxStricmp stricmp
407 # define wxStrnicmp strnicmp
408 # elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS__) && defined(__INTEL__))
409 # define wxStricmp _stricmp
410 # define wxStrnicmp _strnicmp
411 # elif defined(__UNIX__) || defined(__GNUWIN32__)
412 # define wxStricmp strcasecmp
413 # define wxStrnicmp strncasecmp
414 # elif defined(__MWERKS__) && !defined(__INTEL__)
415 // use wxWindows' implementation
417 // if you leave wxStricmp undefined, wxWindows' implementation will be used
418 # error "Please define string case-insensitive compare for your OS/compiler"
422 // if we need to define for standard headers, and we're not using Unicode,
423 // just define to standard C library routines
425 # ifdef wxNEED_WX_STRING_H
426 # define wxStrcat strcat
427 # define wxStrchr strchr
428 # define wxStrcmp strcmp
429 # define wxStrcoll strcoll
430 # define wxStrcpy strcpy
431 # define wxStrcspn strcspn
432 # define wxStrdup strdup
433 # define wxStrlen_ strlen // used in wxStrlen inline function
434 # define wxStrncat strncat
435 # define wxStrncmp strncmp
436 # define wxStrncpy strncpy
437 # define wxStrpbrk strpbrk
438 # define wxStrrchr strrchr
439 # define wxStrspn strspn
440 # define wxStrstr strstr
441 # define wxStrtod strtod
442 # define wxStrtol strtol
443 # define wxStrtoul strtoul
444 # define wxStrxfrm strxfrm
445 # undef wxNEED_WX_STRING_H
448 # ifdef wxNEED_WX_STDIO_H
449 # define wxFgetc fgetc
450 # define wxFgetchar fgetchar
451 # define wxFgets fgets
452 # define wxFopen fopen
453 # define wxFputc fputc
454 # define wxFputchar fputchar
455 # define wxFprintf fprintf
456 # define wxFreopen freopen
457 # define wxFscanf fscanf
459 # define wxGetchar getchar
461 # define wxPerror perror
462 # define wxPrintf printf
464 # define wxPutchar putchar
466 # define wxRemove remove
467 # define wxRename rename
468 # define wxScanf scanf
469 # define wxSprintf sprintf
470 # define wxSscanf sscanf
471 # define wxTmpnam tmpnam
472 # define wxUngetc ungetc
473 # define wxVfprint vfprintf
474 # define wxVprintf vprintf
475 # define wxVsscanf vsscanf
476 # define wxVsprintf vsprintf
477 # undef wxNEED_WX_STDIO_H
480 # ifdef wxNEED_WX_STDLIB_H
484 # define wxGetenv getenv
485 # define wxSystem system
486 # undef wxNEED_WX_STDLIB_H
489 # ifdef wxNEED_WX_TIME_H
490 # define wxAsctime asctime
491 # define wxCtime ctime
492 # define wxStrftime strftime
493 # undef wxNEED_WX_TIME_H
497 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
498 # define wcslen wxStrlen
499 # undef wxNEED_WCSLEN
502 // checks whether the passed in pointer is NULL and if the string is empty
503 WXDLLEXPORT
inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
505 #ifndef wxNEED_WX_STRING_H
506 // safe version of strlen() (returns 0 if passed NULL pointer)
507 WXDLLEXPORT
inline size_t wxStrlen(const wxChar
*psz
)
508 { return psz
? wxStrlen_(psz
) : 0; }
512 // multibyte<->widechar conversion
513 WXDLLEXPORT
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
514 WXDLLEXPORT
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
516 # define wxMB2WX wxMB2WC
517 # define wxWX2MB wxWC2MB
518 # define wxWC2WX wxStrncpy
519 # define wxWX2WC wxStrncpy
521 # define wxMB2WX wxStrncpy
522 # define wxWX2MB wxStrncpy
523 # define wxWC2WX wxWC2MB
524 # define wxWX2WC wxMB2WC
527 // No wxUSE_WCHAR_T: we have to do something (JACS)
528 # define wxMB2WC wxStrncpy
529 # define wxWC2MB wxStrncpy
530 # define wxMB2WX wxStrncpy
531 # define wxWX2MB wxStrncpy
532 # define wxWC2WX wxWC2MB
533 # define wxWX2WC wxMB2WC
536 WXDLLEXPORT
bool wxOKlibc(); // for internal use
538 // if libc versions are not available, use replacements defined in wxchar.cpp
540 WXDLLEXPORT wxChar
* wxStrdup(const wxChar
*psz
);
544 WXDLLEXPORT
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
548 WXDLLEXPORT wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
552 WXDLLEXPORT wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
555 #ifdef wxNEED_WCSLEN // for use in buffer.h
556 WXDLLEXPORT
size_t wcslen(const wchar_t *s
);
559 #ifdef wxNEED_WX_CTYPE_H
560 WXDLLEXPORT
int wxIsalnum(wxChar ch
);
561 WXDLLEXPORT
int wxIsalpha(wxChar ch
);
562 WXDLLEXPORT
int wxIsctrl(wxChar ch
);
563 WXDLLEXPORT
int wxIsdigit(wxChar ch
);
564 WXDLLEXPORT
int wxIsgraph(wxChar ch
);
565 WXDLLEXPORT
int wxIslower(wxChar ch
);
566 WXDLLEXPORT
int wxIsprint(wxChar ch
);
567 WXDLLEXPORT
int wxIspunct(wxChar ch
);
568 WXDLLEXPORT
int wxIsspace(wxChar ch
);
569 WXDLLEXPORT
int wxIsupper(wxChar ch
);
570 WXDLLEXPORT
int wxIsxdigit(wxChar ch
);
571 WXDLLEXPORT
int wxTolower(wxChar ch
);
572 WXDLLEXPORT
int wxToupper(wxChar ch
);
575 #ifdef wxNEED_WX_STRING_H
576 WXDLLEXPORT wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
577 WXDLLEXPORT wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
578 WXDLLEXPORT
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
579 WXDLLEXPORT
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
580 WXDLLEXPORT wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
581 WXDLLEXPORT
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
582 WXDLLEXPORT
size_t wxStrlen(const wxChar
*s
);
583 WXDLLEXPORT wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
584 WXDLLEXPORT
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
585 WXDLLEXPORT wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
586 WXDLLEXPORT wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
587 WXDLLEXPORT wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
588 WXDLLEXPORT
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
589 WXDLLEXPORT wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
590 WXDLLEXPORT
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
591 WXDLLEXPORT
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
592 WXDLLEXPORT
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
593 WXDLLEXPORT
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
596 #ifdef wxNEED_WX_STDIO_H
599 WXDLLEXPORT
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
600 WXDLLEXPORT
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
601 WXDLLEXPORT
int wxPrintf(const wxChar
*fmt
, ...);
602 WXDLLEXPORT
int wxVprintf(const wxChar
*fmt
, va_list argptr
);
603 WXDLLEXPORT
int wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
604 WXDLLEXPORT
int wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
605 WXDLLEXPORT
int wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
606 WXDLLEXPORT
int wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
607 WXDLLEXPORT
int wxSscanf(const wxChar
*buf
, const wxChar
*fmt
, ...);
608 WXDLLEXPORT
int wxVsscanf(const wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
612 WXDLLEXPORT
double wxAtof(const wxChar
*psz
);
615 #ifdef wxNEED_WX_STDLIB_H
616 WXDLLEXPORT
int wxAtoi(const wxChar
*psz
);
617 WXDLLEXPORT
long wxAtol(const wxChar
*psz
);
618 WXDLLEXPORT wxChar
* wxGetenv(const wxChar
*name
);
619 WXDLLEXPORT
int wxSystem(const wxChar
*psz
);
622 #ifdef wxNEED_WX_TIME_H
623 WXDLLEXPORT
size_t wxStrftime(wxChar
*s
, size_t max
, const wxChar
*fmt
, const struct tm
*tm
);
626 // although global macros with such names are really bad, we want to have
627 // another name for _T() which should be used to avoid confusion between _T()
628 // and _() in wxWindows sources
631 // a Unicode-friendly __FILE__ analog
633 #define __XFILE__(x) wxT(x)
634 #define __TFILE__ __XFILE__(__FILE__)