]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
75396ac0b79c2c34f63184a6d2cce903c25f57dd
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 // Windows (VC++) has broad TCHAR support
45 #if defined(__VISUALC__) && defined(__WIN32__)
47 # define HAVE_WCSLEN 1
51 # if wxUSE_UNICODE // temporary - preserve binary compatibility
52 typedef _TCHAR wxChar
;
53 typedef _TSCHAR wxSChar
;
54 typedef _TUCHAR wxUChar
;
57 # define wxSChar signed char
58 # define wxUChar unsigned char
60 // wchar_t is available
62 # define wxUSE_WCHAR_T 1
65 # define wxIsalnum _istalnum
66 # define wxIsalpha _istalpha
67 # define wxIsctrl _istctrl
68 # define wxIsdigit _istdigit
69 # define wxIsgraph _istgraph
70 # define wxIslower _istlower
71 # define wxIsprint _istprint
72 # define wxIspunct _istpunct
73 # define wxIsspace _istspace
74 # define wxIsupper _istupper
75 # define wxIsxdigit _istxdigit
76 # define wxTolower _totlower
77 # define wxToupper _totupper
80 # define wxSetlocale _tsetlocale
83 # define wxStrcat _tcscat
84 # define wxStrchr _tcschr
85 # define wxStrcmp _tcscmp
86 # define wxStrcoll _tcscoll
87 # define wxStrcpy _tcscpy
88 # define wxStrcspn _tcscspn
89 # define wxStrftime _tcsftime
90 # define wxStricmp _tcsicmp
91 # define wxStrlen_ _tcslen // used in wxStrlen inline function
92 # define wxStrncat _tcsncat
93 # define wxStrncmp _tcsncmp
94 # define wxStrncpy _tcsncpy
95 # define wxStrpbrk _tcspbrk
96 # define wxStrrchr _tcsrchr
97 # define wxStrspn _tcsspn
98 # define wxStrstr _tcsstr
99 # define wxStrtod _tcstod
100 // is there a _tcstok[_r] ?
101 # define wxStrtol _tcstol
102 # define wxStrtoul _tcstoul
103 # define wxStrxfrm _tcsxfrm
106 # define wxFgetc _fgettc
107 # define wxFgetchar _fgettchar
108 # define wxFgets _fgetts
109 # define wxFopen _tfopen
110 # define wxFputc _fputtc
111 # define wxFputchar _fputtchar
112 # define wxFprintf _ftprintf
113 # define wxFreopen _tfreopen
114 # define wxFscanf _ftscanf
115 # define wxGetc _gettc
116 # define wxGetchar _gettchar
117 # define wxGets _getts
118 # define wxPerror _tperror
119 # define wxPrintf _tprintf
120 # define wxPutc _puttc
121 # define wxPutchar _puttchar
122 # define wxPuts _putts
123 # define wxRemove _tremove
124 # define wxRename _trename
125 # define wxScanf _tscanf
126 # define wxSprintf _stprintf
127 # define wxSscanf _stscanf
128 # define wxTmpnam _ttmpnam
129 # define wxUngetc _tungetc
130 # define wxVfprint _vftprintf
131 # define wxVprintf _vtprintf
132 # define wxVsscanf _vstscanf
133 # define wxVsprintf _vstprintf
135 // stdlib.h functions
139 # define wxAtoi _ttoi
140 # define wxAtol _ttol
141 # define wxGetenv _tgetenv
142 # define wxSystem _tsystem
145 # define wxAsctime _tasctime
146 # define wxCtime _tctime
148 // #elif defined(XXX)
149 // #include XXX-specific files here
150 // typeddef YYY wxChar;
152 // translate wxZZZ names
154 #elif defined(__BORLANDC__) && defined(__WIN32__)
156 // Borland C++ 4.52 doesn't have much tchar support
157 // maybe Borland C++ 5.02 has, can't check right now
158 // but I'll use the Win32 API instead here
161 # if wxUSE_UNICODE // temporary - preserve binary compatibility
162 typedef _TCHAR wxChar
;
163 typedef _TSCHAR wxSChar
;
164 typedef _TUCHAR wxUChar
;
167 # define wxSChar signed char
168 # define wxUChar unsigned char
170 // wchar_t is available
171 # undef wxUSE_WCHAR_T
172 # define wxUSE_WCHAR_T 1
174 # define wxNEED_WX_CTYPE_H
175 // #define wxStrtok strtok_r // Borland C++ 4.52 doesn't have strtok_r
176 # define wxNEED_WX_STRING_H
177 # define wxNEED_WX_STDIO_H
178 # define wxNEED_WX_STDLIB_H
179 # define wxNEED_WX_TIME_H
180 # define wxNEED_WCSLEN
182 #else//!TCHAR-aware compilers
184 // check whether we should include wchar.h or equivalent
186 # undef wxUSE_WCHAR_T
187 # define wxUSE_WCHAR_T 1 // wchar_t *must* be available in Unicode mode
188 # elif !defined(wxUSE_WCHAR_T)
189 # if defined(__VISUALC__) && (__VISUALC__ < 900)
190 # define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
191 # elif defined(__UNIX__)
192 # if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__)
193 # define wxUSE_WCHAR_T 1
195 # define wxUSE_WCHAR_T 0
197 # elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
198 # define wxUSE_WCHAR_T 0
199 # elif defined(__BORLANDC__) // WIN16 BC++
200 # define wxUSE_WCHAR_T 0
201 # elif defined(__WATCOMC__)
202 # define wxUSE_WCHAR_T 0
204 // add additional compiler checks if this fails
205 # define wxUSE_WCHAR_T 1
207 # endif//wxUSE_UNICODE
217 # define wxNEED_WCSLEN
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
307 # if !defined(__MINGW32__) || !defined(_T)
312 # define wxIsalnum isalnum
313 # define wxIsalpha isalpha
314 # define wxIsctrl isctrl
315 # define wxIsdigit isdigit
316 # define wxIsgraph isgraph
317 # define wxIslower islower
318 # define wxIsprint isprint
319 # define wxIspunct ispunct
320 # define wxIsspace isspace
321 # define wxIsupper isupper
322 # define wxIsxdigit isxdigit
323 # define wxTolower tolower
324 # define wxToupper toupper
327 # define wxSetlocale setlocale
329 // string.h functions
330 // #define wxStricmp strcasecmp
331 // wxStricmp is defined below!!
334 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
336 #define wxStrtok(str, sep, last) strtok(str, sep)
339 // leave the rest to defaults below
340 # define wxNEED_WX_STRING_H
341 # define wxNEED_WX_STDIO_H
342 # define wxNEED_WX_STDLIB_H
343 # define wxNEED_WX_TIME_H
346 #endif//TCHAR-aware compilers
348 // define wxStricmp for various compilers without Unicode possibilities
349 #if !defined(wxStricmp) && !wxUSE_UNICODE
350 # if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__) || defined(__VISAGECPP__) || defined(__EMX__)
351 # define wxStricmp stricmp
352 # define wxStrnicmp strnicmp
353 # elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS__) && defined(__INTEL__))
354 # define wxStricmp _stricmp
355 # define wxStrnicmp _strnicmp
356 # elif defined(__UNIX__) || defined(__GNUWIN32__)
357 # define wxStricmp strcasecmp
358 # define wxStrnicmp strncasecmp
359 # elif defined(__MWERKS__) && !defined(__INTEL__)
360 // use wxWindows' implementation
362 // if you leave wxStricmp undefined, wxWindows' implementation will be used
363 # error "Please define string case-insensitive compare for your OS/compiler"
367 // if we need to define for standard headers, and we're not using Unicode,
368 // just define to standard C library routines
370 # ifdef wxNEED_WX_STRING_H
371 # define wxStrcat strcat
372 # define wxStrchr strchr
373 # define wxStrcmp strcmp
374 # define wxStrcoll strcoll
375 # define wxStrcpy strcpy
376 # define wxStrcspn strcspn
377 # define wxStrdup strdup
378 # define wxStrlen_ strlen // used in wxStrlen inline function
379 # define wxStrncat strncat
380 # define wxStrncmp strncmp
381 # define wxStrncpy strncpy
382 # define wxStrpbrk strpbrk
383 # define wxStrrchr strrchr
384 # define wxStrspn strspn
385 # define wxStrstr strstr
386 # define wxStrtod strtod
387 # define wxStrtol strtol
388 # define wxStrtoul strtoul
389 # define wxStrxfrm strxfrm
390 # undef wxNEED_WX_STRING_H
393 # ifdef wxNEED_WX_STDIO_H
394 # define wxFgetc fgetc
395 # define wxFgetchar fgetchar
396 # define wxFgets fgets
397 # define wxFopen fopen
398 # define wxFputc fputc
399 # define wxFputchar fputchar
400 # define wxFprintf fprintf
401 # define wxFreopen freopen
402 # define wxFscanf fscanf
404 # define wxGetchar getchar
406 # define wxPerror perror
407 # define wxPrintf printf
409 # define wxPutchar putchar
411 # define wxRemove remove
412 # define wxRename rename
413 # define wxScanf scanf
414 # define wxSprintf sprintf
415 # define wxSscanf sscanf
416 # define wxTmpnam tmpnam
417 # define wxUngetc ungetc
418 # define wxVfprint vfprintf
419 # define wxVprintf vprintf
420 # define wxVsscanf vsscanf
421 # define wxVsprintf vsprintf
422 # undef wxNEED_WX_STDIO_H
425 # ifdef wxNEED_WX_STDLIB_H
429 # define wxGetenv getenv
430 # define wxSystem system
431 # undef wxNEED_WX_STDLIB_H
434 # ifdef wxNEED_WX_TIME_H
435 # define wxAsctime asctime
436 # define wxCtime ctime
437 # define wxStrftime strftime
438 # undef wxNEED_WX_TIME_H
442 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
443 # define wcslen wxStrlen
444 # undef wxNEED_WCSLEN
447 /// checks whether the passed in pointer is NULL and if the string is empty
448 WXDLLEXPORT
inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
450 #ifndef wxNEED_WX_STRING_H
451 /// safe version of strlen() (returns 0 if passed NULL pointer)
452 WXDLLEXPORT
inline size_t wxStrlen(const wxChar
*psz
)
453 { return psz
? wxStrlen_(psz
) : 0; }
457 // multibyte<->widechar conversion
458 WXDLLEXPORT
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
459 WXDLLEXPORT
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
461 # define wxMB2WX wxMB2WC
462 # define wxWX2MB wxWC2MB
463 # define wxWC2WX wxStrncpy
464 # define wxWX2WC wxStrncpy
466 # define wxMB2WX wxStrncpy
467 # define wxWX2MB wxStrncpy
468 # define wxWC2WX wxWC2MB
469 # define wxWX2WC wxMB2WC
472 // No wxUSE_WCHAR_T: we have to do something (JACS)
473 # define wxMB2WC wxStrncpy
474 # define wxWC2MB wxStrncpy
475 # define wxMB2WX wxStrncpy
476 # define wxWX2MB wxStrncpy
477 # define wxWC2WX wxWC2MB
478 # define wxWX2WC wxMB2WC
481 WXDLLEXPORT
bool wxOKlibc(); // for internal use
483 // if libc versions are not available, use replacements defined in wxchar.cpp
485 WXDLLEXPORT wxChar
* wxStrdup(const wxChar
*psz
);
489 WXDLLEXPORT
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
493 WXDLLEXPORT wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
497 WXDLLEXPORT wxChar
* wxSetlocale(int category
, const wxChar
*locale
);
500 #ifdef wxNEED_WCSLEN // for use in buffer.h
501 WXDLLEXPORT
size_t wcslen(const wchar_t *s
);
504 #ifdef wxNEED_WX_CTYPE_H
505 WXDLLEXPORT
int wxIsalnum(wxChar ch
);
506 WXDLLEXPORT
int wxIsalpha(wxChar ch
);
507 WXDLLEXPORT
int wxIsctrl(wxChar ch
);
508 WXDLLEXPORT
int wxIsdigit(wxChar ch
);
509 WXDLLEXPORT
int wxIsgraph(wxChar ch
);
510 WXDLLEXPORT
int wxIslower(wxChar ch
);
511 WXDLLEXPORT
int wxIsprint(wxChar ch
);
512 WXDLLEXPORT
int wxIspunct(wxChar ch
);
513 WXDLLEXPORT
int wxIsspace(wxChar ch
);
514 WXDLLEXPORT
int wxIsupper(wxChar ch
);
515 WXDLLEXPORT
int wxIsxdigit(wxChar ch
);
516 WXDLLEXPORT
int wxTolower(wxChar ch
);
517 WXDLLEXPORT
int wxToupper(wxChar ch
);
520 #ifdef wxNEED_WX_STRING_H
521 WXDLLEXPORT wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
522 WXDLLEXPORT wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
523 WXDLLEXPORT
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
524 WXDLLEXPORT
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
525 WXDLLEXPORT wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
526 WXDLLEXPORT
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
527 WXDLLEXPORT
size_t wxStrlen(const wxChar
*s
);
528 WXDLLEXPORT wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
529 WXDLLEXPORT
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
530 WXDLLEXPORT wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
531 WXDLLEXPORT wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
532 WXDLLEXPORT wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
533 WXDLLEXPORT
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
534 WXDLLEXPORT wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
535 WXDLLEXPORT
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
536 WXDLLEXPORT
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
537 WXDLLEXPORT
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
538 WXDLLEXPORT
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
541 #ifdef wxNEED_WX_STDIO_H
544 WXDLLEXPORT
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
545 WXDLLEXPORT
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
546 WXDLLEXPORT
int wxPrintf(const wxChar
*fmt
, ...);
547 WXDLLEXPORT
int wxVprintf(const wxChar
*fmt
, va_list argptr
);
548 WXDLLEXPORT
int wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
549 WXDLLEXPORT
int wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
550 WXDLLEXPORT
int wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
551 WXDLLEXPORT
int wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
552 WXDLLEXPORT
int wxSscanf(const wxChar
*buf
, const wxChar
*fmt
, ...);
553 WXDLLEXPORT
int wxVsscanf(const wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
557 WXDLLEXPORT
double wxAtof(const wxChar
*psz
);
560 #ifdef wxNEED_WX_STDLIB_H
561 WXDLLEXPORT
int wxAtoi(const wxChar
*psz
);
562 WXDLLEXPORT
long wxAtol(const wxChar
*psz
);
563 WXDLLEXPORT wxChar
* wxGetenv(const wxChar
*name
);
564 WXDLLEXPORT
int wxSystem(const wxChar
*psz
);
567 #ifdef wxNEED_WX_TIME_H
568 WXDLLEXPORT
size_t wxStrftime(wxChar
*s
, size_t max
, const wxChar
*fmt
, const struct tm
*tm
);
571 // although global macros with such names are really bad, we want to have
572 // another name for _T() which should be used to avoid confusion between _T()
573 // and _() in wxWindows sources
576 // a Unicode-friendly __FILE__ analog
578 #define __XFILE__(x) wxT(x)
579 #define __TFILE__ __XFILE__(__FILE__)