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
30 #define wxUSE_UNICODE 0
34 // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
44 // Windows (VC++) has broad TCHAR support
45 #if defined(__VISUALC__) && defined(__WIN32__)
48 #if wxUSE_UNICODE // temporary - preserve binary compatibility
49 typedef _TCHAR wxChar
;
50 typedef _TSCHAR wxSChar
;
51 typedef _TUCHAR wxUChar
;
54 #define wxSChar signed char
55 #define wxUChar unsigned char
57 // wchar_t is available
59 #define wxUSE_WCHAR_T 1
62 #define wxIsalnum _istalnum
63 #define wxIsalpha _istalpha
64 #define wxIsctrl _istctrl
65 #define wxIsdigit _istdigit
66 #define wxIsgraph _istgraph
67 #define wxIslower _istlower
68 #define wxIsprint _istprint
69 #define wxIspunct _istpunct
70 #define wxIsspace _istspace
71 #define wxIsupper _istupper
72 #define wxIsxdigit _istxdigit
73 #define wxTolower _totlower
74 #define wxToupper _totupper
77 #define wxSetlocale _tsetlocale
80 #define wxStrcat _tcscat
81 #define wxStrchr _tcschr
82 #define wxStrcmp _tcscmp
83 #define wxStrcoll _tcscoll
84 #define wxStrcpy _tcscpy
85 #define wxStrcspn _tcscspn
86 #define wxStrftime _tcsftime
87 #define wxStricmp _tcsicmp
88 #define wxStrlen_ _tcslen // used in wxStrlen inline function
89 #define wxStrncat _tcsncat
90 #define wxStrncmp _tcsncmp
91 #define wxStrncpy _tcsncpy
92 #define wxStrpbrk _tcspbrk
93 #define wxStrrchr _tcsrchr
94 #define wxStrspn _tcsspn
95 #define wxStrstr _tcsstr
96 #define wxStrtod _tcstod
97 // is there a _tcstok[_r] ?
98 #define wxStrtol _tcstol
99 #define wxStrtoul _tcstoul
100 #define wxStrxfrm _tcsxfrm
103 #define wxFgetc _fgettc
104 #define wxFgetchar _fgettchar
105 #define wxFgets _fgetts
106 #define wxFopen _tfopen
107 #define wxFputc _fputtc
108 #define wxFputchar _fputtchar
109 #define wxFprintf _ftprintf
110 #define wxFreopen _tfreopen
111 #define wxFscanf _ftscanf
112 #define wxGetc _gettc
113 #define wxGetchar _gettchar
114 #define wxGets _getts
115 #define wxPerror _tperror
116 #define wxPrintf _tprintf
117 #define wxPutc _puttc
118 #define wxPutchar _puttchar
119 #define wxPuts _putts
120 #define wxRemove _tremove
121 #define wxRename _trename
122 #define wxScanf _tscanf
123 #define wxSprintf _stprintf
124 #define wxSscanf _stscanf
125 #define wxTmpnam _ttmpnam
126 #define wxUngetc _tungetc
127 #define wxVfprint _vftprintf
128 #define wxVprintf _vtprintf
129 #define wxVsscanf _vstscanf
130 #define wxVsprintf _vstprintf
132 // stdlib.h functions
138 #define wxGetenv _tgetenv
139 #define wxSystem _tsystem
142 #define wxAsctime _tasctime
143 #define wxCtime _tctime
145 // #elif defined(XXX)
146 // #include XXX-specific files here
147 // typeddef YYY wxChar;
149 // translate wxZZZ names
151 #elif defined(__BORLANDC__) && defined(__WIN32__)
153 // Borland C++ 4.52 doesn't have much tchar support
154 // maybe Borland C++ 5.02 has, can't check right now
155 // but I'll use the Win32 API instead here
158 #if wxUSE_UNICODE // temporary - preserve binary compatibility
159 typedef _TCHAR wxChar
;
160 typedef _TSCHAR wxSChar
;
161 typedef _TUCHAR wxUChar
;
164 #define wxSChar signed char
165 #define wxUChar unsigned char
167 // wchar_t is available
169 #define wxUSE_WCHAR_T 1
177 inline WORD
__wxMSW_ctype(wxChar ch
)
180 GetStringTypeEx(LOCALE_USER_DEFAULT
, CT_CTYPE1
, &ch
, 1, &ret
);
183 #define wxIsalnum(x) IsCharAlphaNumeric
184 #define wxIsalpha IsCharAlpha
185 #define wxIsctrl(x) (__wxMSW_ctype(x) & C1_CNTRL)
186 #define wxIsdigit(x) (__wxMSW_ctype(x) & C1_DIGIT)
187 #define wxIsgraph(x) (__wxMSW_ctype(x) & (C1_DIGIT|C1_PUNCT|C1_ALPHA))
188 #define wxIslower(x) IsCharLower
189 #define wxIsprint(x) (__wxMSW_ctype(x) & (C1_DIGIT|C1_SPACE|C1_PUNCT|C1_ALPHA))
190 #define wxIspunct(x) (__wxMSW_ctype(x) & C1_PUNCT)
191 #define wxIsspace(x) (__wxMSW_ctype(x) & C1_SPACE)
192 #define wxIsupper(x) IsCharUpper
193 #define wxIsxdigit(x) (__wxMSW_ctype(x) & C1_XDIGIT)
194 #define wxTolower(x) (wxChar)CharLower((LPTSTR)(x))
195 #define wxToupper(x) (wxChar)CharUpper((LPTSTR)(x))
197 // #define wxStrtok strtok_r // Borland C++ 4.52 doesn't have strtok_r
198 #define wxNEED_WX_STRING_H
199 #define wxNEED_WX_STDIO_H
200 #define wxNEED_WX_STDLIB_H
201 #define wxNEED_WX_TIME_H
202 #define wxNEED_WCSLEN
204 #else//!TCHAR-aware compilers
206 // check whether we should include wchar.h or equivalent
209 #define wxUSE_WCHAR_T 1 // wchar_t *must* be available in Unicode mode
210 #elif !defined(wxUSE_WCHAR_T)
211 #if defined(__VISUALC__) && (__VISUALC__ < 900)
212 #define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
214 #define wxUSE_WCHAR_T 1
222 // check whether we are doing Unicode
227 // this is probably glibc-specific
228 #if defined(__WCHAR_TYPE__)
230 typedef __WCHAR_TYPE__ wxChar
;
231 typedef signed __WCHAR_TYPE__ wxSChar
;
232 typedef unsigned __WCHAR_TYPE__ wxUChar
;
236 // ctype.h functions (wctype.h)
237 #define wxIsalnum iswalnum
238 #define wxIsalpha iswalpha
239 #define wxIsctrl iswcntrl
240 #define wxIsdigit iswdigit
241 #define wxIsgraph iswgraph
242 #define wxIslower iswlower
243 #define wxIsprint iswprint
244 #define wxIspunct iswpunct
245 #define wxIsspace iswspace
246 #define wxIsupper iswupper
247 #define wxIsxdigit iswxdigit
249 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
250 // /usr/include/wctype.h incorrectly declares translations tables which
251 // provokes tons of compile-time warnings - try to correct this
252 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
253 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
255 #define wxTolower towlower
256 #define wxToupper towupper
259 // string.h functions (wchar.h)
260 #define wxStrcat wcscat
261 #define wxStrchr wcschr
262 #define wxStrcmp wcscmp
263 #define wxStrcoll wcscoll
264 #define wxStrcpy wcscpy
265 #define wxStrcspn wcscspn
266 #define wxStrlen_ wcslen // used in wxStrlen inline function
267 #define wxStrncat wcsncat
268 #define wxStrncmp wcsncmp
269 #define wxStrncpy wcsncpy
270 #define wxStrpbrk wcspbrk
271 #define wxStrrchr wcsrchr
272 #define wxStrspn wcsspn
273 #define wxStrstr wcsstr
274 #define wxStrtod wcstod
275 #define wxStrtok wcstok
276 #define wxStrtol wcstol
277 #define wxStrtoul wcstoul
278 #define wxStrxfrm wcsxfrm
280 // glibc doesn't have wc equivalents of the other stuff
281 #define wxNEED_WX_STDIO_H
282 #define wxNEED_WX_STDLIB_H
283 #define wxNEED_WX_TIME_H
286 #error "Please define your compiler's Unicode conventions in wxChar.h"
293 #if 0 // temporary - preserve binary compatibilty
295 typedef signed char wxSChar
;
296 typedef unsigned char wxUChar
;
299 #define wxSChar signed char
300 #define wxUChar unsigned char
306 #define wxIsalnum isalnum
307 #define wxIsalpha isalpha
308 #define wxIsctrl isctrl
309 #define wxIsdigit isdigit
310 #define wxIsgraph isgraph
311 #define wxIslower islower
312 #define wxIsprint isprint
313 #define wxIspunct ispunct
314 #define wxIsspace isspace
315 #define wxIsupper isupper
316 #define wxIsxdigit isxdigit
317 #define wxTolower tolower
318 #define wxToupper toupper
321 #define wxSetlocale setlocale
323 // string.h functions
324 #define wxStricmp strcasecmp
325 // #define wxStrtok strtok_r // this needs a configure check
327 // leave the rest to defaults below
328 #define wxNEED_WX_STRING_H
329 #define wxNEED_WX_STDIO_H
330 #define wxNEED_WX_STDLIB_H
331 #define wxNEED_WX_TIME_H
334 #endif//TCHAR-aware compilers
336 // define wxStricmp for various compilers without Unicode possibilities
337 #if !defined(wxStricmp) && !wxUSE_UNICODE
338 #if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__)
339 #define wxStricmp stricmp
340 #elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS) && defined(__INTEL__))
341 #define wxStricmp _stricmp
342 #elif defined(__UNIX__) || defined(__GNUWIN32__)
343 #define wxStricmp strcasecmp
344 #elif defined(__MWERKS__) && !defined(__INTEL__)
345 // use wxWindows' implementation
347 // if you leave wxStricmp undefined, wxWindows' implementation will be used
348 #error "Please define string case-insensitive compare for your OS/compiler"
352 // if we need to define for standard headers, and we're not using Unicode,
353 // just define to standard C library routines
355 #ifdef wxNEED_WX_STRING_H
356 #define wxStrcat strcat
357 #define wxStrchr strchr
358 #define wxStrcmp strcmp
359 #define wxStrcoll strcoll
360 #define wxStrcpy strcpy
361 #define wxStrcspn strcspn
362 #define wxStrdup strdup
363 #define wxStrlen_ strlen // used in wxStrlen inline function
364 #define wxStrncat strncat
365 #define wxStrncmp strncmp
366 #define wxStrncpy strncpy
367 #define wxStrpbrk strpbrk
368 #define wxStrrchr strrchr
369 #define wxStrspn strspn
370 #define wxStrstr strstr
371 #define wxStrtod strtod
372 #define wxStrtol strtol
373 #define wxStrtoul strtoul
374 #define wxStrxfrm strxfrm
375 #undef wxNEED_WX_STRING_H
378 #ifdef wxNEED_WX_STDIO_H
379 #define wxFgetc fgetc
380 #define wxFgetchar fgetchar
381 #define wxFgets fgets
382 #define wxFopen fopen
383 #define wxFputc fputc
384 #define wxFputchar fputchar
385 #define wxFprintf fprintf
386 #define wxFreopen freopen
387 #define wxFscanf fscanf
389 #define wxGetchar getchar
391 #define wxPerror perror
392 #define wxPrintf printf
394 #define wxPutchar putchar
396 #define wxRemove remove
397 #define wxRename rename
398 #define wxScanf scanf
399 #define wxSprintf sprintf
400 #define wxSscanf sscanf
401 #define wxTmpnam tmpnam
402 #define wxUngetc ungetc
403 #define wxVfprint vfprintf
404 #define wxVprintf vprintf
405 #define wxVsscanf vsscanf
406 #define wxVsprintf vsprintf
407 #undef wxNEED_WX_STDIO_H
410 #ifdef wxNEED_WX_STDLIB_H
414 #define wxGetenv getenv
415 #define wxSystem system
416 #undef wxNEED_WX_STDLIB_H
419 #ifdef wxNEED_WX_TIME_H
420 #define wxAsctime asctime
421 #define wxCtime ctime
422 #define wxStrftime strftime
423 #undef wxNEED_WX_TIME_H
427 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
428 #define wcslen wxStrlen
432 /// checks whether the passed in pointer is NULL and if the string is empty
433 inline bool WXDLLEXPORT
wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
435 #ifndef wxNEED_WX_STRING_H
436 /// safe version of strlen() (returns 0 if passed NULL pointer)
437 inline size_t WXDLLEXPORT
wxStrlen(const wxChar
*psz
)
438 { return psz ?
wxStrlen_(psz
) : 0; }
442 // multibyte<->widechar conversion
443 size_t WXDLLEXPORT
wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
444 size_t WXDLLEXPORT
wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
446 #define wxMB2WX wxMB2WC
447 #define wxWX2MB wxWC2MB
448 #define wxWC2WX wxStrncpy
449 #define wxWX2WC wxStrncpy
451 #define wxMB2WX wxStrncpy
452 #define wxWX2MB wxStrncpy
453 #define wxWC2WX wxWC2MB
454 #define wxWX2WC wxMB2WC
458 // if libc versions are not available, use replacements defined in wxchar.cpp
460 wxChar
* WXDLLEXPORT
wxStrdup(const wxChar
*psz
);
464 int WXDLLEXPORT
wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
468 wxChar
* WXDLLEXPORT
wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
472 wxChar
* WXDLLEXPORT
wxSetlocale(int category
, const wxChar
*locale
);
475 #ifdef wxNEED_WCSLEN // for use in buffer.h
476 size_t WXDLLEXPORT
wcslen(const wchar_t *s
);
479 #ifdef wxNEED_WX_STRING_H
480 wxChar
* WXDLLEXPORT
wxStrcat(wxChar
*dest
, const wxChar
*src
);
481 wxChar
* WXDLLEXPORT
wxStrchr(const wxChar
*s
, wxChar c
);
482 int WXDLLEXPORT
wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
483 int WXDLLEXPORT
wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
484 wxChar
* WXDLLEXPORT
wxStrcpy(wxChar
*dest
, const wxChar
*src
);
485 size_t WXDLLEXPORT
wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
486 size_t WXDLLEXPORT
wxStrlen(const wxChar
*s
);
487 wxChar
* WXDLLEXPORT
wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
488 int WXDLLEXPORT
wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
489 wxChar
* WXDLLEXPORT
wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
490 wxChar
* WXDLLEXPORT
wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
491 wxChar
* WXDLLEXPORT
wxStrrchr(const wxChar
*s
, wxChar c
);
492 size_t WXDLLEXPORT
wxStrspn(const wxChar
*s
, const wxChar
*accept
);
493 wxChar
* WXDLLEXPORT
wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
494 double WXDLLEXPORT
wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
495 long int WXDLLEXPORT
wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
496 unsigned long int WXDLLEXPORT
wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
497 size_t WXDLLEXPORT
wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
500 #ifdef wxNEED_WX_STDIO_H
503 int WXDLLEXPORT
wxPrintf(const wxChar
*fmt
, ...);
504 int WXDLLEXPORT
wxVprintf(const wxChar
*fmt
, va_list argptr
);
505 int WXDLLEXPORT
wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
506 int WXDLLEXPORT
wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
507 int WXDLLEXPORT
wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
508 int WXDLLEXPORT
wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
509 int WXDLLEXPORT
wxSscanf(const wxChar
*buf
, const wxChar
*fmt
, ...);
510 int WXDLLEXPORT
wxVsscanf(const wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
514 double WXDLLEXPORT
wxAtof(const wxChar
*psz
);
517 #ifdef wxNEED_WX_STDLIB_H
518 int WXDLLEXPORT
wxAtoi(const wxChar
*psz
);
519 long WXDLLEXPORT
wxAtol(const wxChar
*psz
);
520 wxChar
* WXDLLEXPORT
wxGetenv(const wxChar
*name
);
521 int WXDLLEXPORT
wxSystem(const wxChar
*psz
);