]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
83273ef07a6f541ceb928036de86943fb866f3fc
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
50 # if wxUSE_UNICODE // temporary - preserve binary compatibility
51 typedef _TCHAR wxChar
;
52 typedef _TSCHAR wxSChar
;
53 typedef _TUCHAR wxUChar
;
56 # define wxSChar signed char
57 # define wxUChar unsigned char
59 // wchar_t is available
61 # define wxUSE_WCHAR_T 1
64 # define wxIsalnum _istalnum
65 # define wxIsalpha _istalpha
66 # define wxIsctrl _istctrl
67 # define wxIsdigit _istdigit
68 # define wxIsgraph _istgraph
69 # define wxIslower _istlower
70 # define wxIsprint _istprint
71 # define wxIspunct _istpunct
72 # define wxIsspace _istspace
73 # define wxIsupper _istupper
74 # define wxIsxdigit _istxdigit
75 # define wxTolower _totlower
76 # define wxToupper _totupper
79 # define wxSetlocale _tsetlocale
82 # define wxStrcat _tcscat
83 # define wxStrchr _tcschr
84 # define wxStrcmp _tcscmp
85 # define wxStrcoll _tcscoll
86 # define wxStrcpy _tcscpy
87 # define wxStrcspn _tcscspn
88 # define wxStrftime _tcsftime
89 # define wxStricmp _tcsicmp
90 # define wxStrlen_ _tcslen // used in wxStrlen inline function
91 # define wxStrncat _tcsncat
92 # define wxStrncmp _tcsncmp
93 # define wxStrncpy _tcsncpy
94 # define wxStrpbrk _tcspbrk
95 # define wxStrrchr _tcsrchr
96 # define wxStrspn _tcsspn
97 # define wxStrstr _tcsstr
98 # define wxStrtod _tcstod
99 // is there a _tcstok[_r] ?
100 # define wxStrtol _tcstol
101 # define wxStrtoul _tcstoul
102 # define wxStrxfrm _tcsxfrm
105 # define wxFgetc _fgettc
106 # define wxFgetchar _fgettchar
107 # define wxFgets _fgetts
108 # define wxFopen _tfopen
109 # define wxFputc _fputtc
110 # define wxFputchar _fputtchar
111 # define wxFprintf _ftprintf
112 # define wxFreopen _tfreopen
113 # define wxFscanf _ftscanf
114 # define wxGetc _gettc
115 # define wxGetchar _gettchar
116 # define wxGets _getts
117 # define wxPerror _tperror
118 # define wxPrintf _tprintf
119 # define wxPutc _puttc
120 # define wxPutchar _puttchar
121 # define wxPuts _putts
122 # define wxRemove _tremove
123 # define wxRename _trename
124 # define wxScanf _tscanf
125 # define wxSprintf _stprintf
126 # define wxSscanf _stscanf
127 # define wxTmpnam _ttmpnam
128 # define wxUngetc _tungetc
129 # define wxVfprint _vftprintf
130 # define wxVprintf _vtprintf
131 # define wxVsscanf _vstscanf
132 # define wxVsprintf _vstprintf
134 // stdlib.h functions
138 # define wxAtoi _ttoi
139 # define wxAtol _ttol
140 # define wxGetenv _tgetenv
141 # define wxSystem _tsystem
144 # define wxAsctime _tasctime
145 # define wxCtime _tctime
147 // #elif defined(XXX)
148 // #include XXX-specific files here
149 // typeddef YYY wxChar;
151 // translate wxZZZ names
153 #elif defined(__BORLANDC__) && defined(__WIN32__)
155 // Borland C++ 4.52 doesn't have much tchar support
156 // maybe Borland C++ 5.02 has, can't check right now
157 // but I'll use the Win32 API instead here
160 # if wxUSE_UNICODE // temporary - preserve binary compatibility
161 typedef _TCHAR wxChar
;
162 typedef _TSCHAR wxSChar
;
163 typedef _TUCHAR wxUChar
;
166 # define wxSChar signed char
167 # define wxUChar unsigned char
169 // wchar_t is available
170 # undef wxUSE_WCHAR_T
171 # define wxUSE_WCHAR_T 1
173 # define wxNEED_WX_CTYPE_H
174 // #define wxStrtok strtok_r // Borland C++ 4.52 doesn't have strtok_r
175 # define wxNEED_WX_STRING_H
176 # define wxNEED_WX_STDIO_H
177 # define wxNEED_WX_STDLIB_H
178 # define wxNEED_WX_TIME_H
179 # define wxNEED_WCSLEN
181 #else//!TCHAR-aware compilers
183 // check whether we should include wchar.h or equivalent
185 # undef wxUSE_WCHAR_T
186 # define wxUSE_WCHAR_T 1 // wchar_t *must* be available in Unicode mode
187 # elif !defined(wxUSE_WCHAR_T)
188 # if defined(__VISUALC__) && (__VISUALC__ < 900)
189 # define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
190 # elif defined(__UNIX__)
191 # if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__)
192 # define wxUSE_WCHAR_T 1
194 # define wxUSE_WCHAR_T 0
196 # elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
197 # define wxUSE_WCHAR_T 0
198 # elif defined(__BORLANDC__) // WIN16 BC++
199 # define wxUSE_WCHAR_T 0
200 # elif defined(__WATCOMC__)
201 # define wxUSE_WCHAR_T 0
203 // add additional compiler checks if this fails
204 # define wxUSE_WCHAR_T 1
206 # endif//wxUSE_UNICODE
216 # define wxNEED_WCSLEN
221 // check whether we are doing Unicode
226 // this is probably glibc-specific
227 # if defined(__WCHAR_TYPE__)
229 typedef __WCHAR_TYPE__ wxChar
;
230 typedef signed __WCHAR_TYPE__ wxSChar
;
231 typedef unsigned __WCHAR_TYPE__ wxUChar
;
235 // ctype.h functions (wctype.h)
236 # define wxIsalnum iswalnum
237 # define wxIsalpha iswalpha
238 # define wxIsctrl iswcntrl
239 # define wxIsdigit iswdigit
240 # define wxIsgraph iswgraph
241 # define wxIslower iswlower
242 # define wxIsprint iswprint
243 # define wxIspunct iswpunct
244 # define wxIsspace iswspace
245 # define wxIsupper iswupper
246 # define wxIsxdigit iswxdigit
248 # if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
249 // /usr/include/wctype.h incorrectly declares translations tables which
250 // provokes tons of compile-time warnings - try to correct this
251 # define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
252 # define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
254 # define wxTolower towlower
255 # define wxToupper towupper
258 // string.h functions (wchar.h)
259 # define wxStrcat wcscat
260 # define wxStrchr wcschr
261 # define wxStrcmp wcscmp
262 # define wxStrcoll wcscoll
263 # define wxStrcpy wcscpy
264 # define wxStrcspn wcscspn
265 # define wxStrlen_ wcslen // used in wxStrlen inline function
266 # define wxStrncat wcsncat
267 # define wxStrncmp wcsncmp
268 # define wxStrncpy wcsncpy
269 # define wxStrpbrk wcspbrk
270 # define wxStrrchr wcsrchr
271 # define wxStrspn wcsspn
272 # define wxStrstr wcsstr
273 # define wxStrtod wcstod
274 # define wxStrtok wcstok
275 # define wxStrtol wcstol
276 # define wxStrtoul wcstoul
277 # define wxStrxfrm wcsxfrm
279 // glibc doesn't have wc equivalents of the other stuff
280 # define wxNEED_WX_STDIO_H
281 # define wxNEED_WX_STDLIB_H
282 # define wxNEED_WX_TIME_H
285 # error "Please define your compiler's Unicode conventions in wxChar.h"
292 # if 0 // temporary - preserve binary compatibilty
294 typedef signed char wxSChar
;
295 typedef unsigned char wxUChar
;
298 # define wxSChar signed char
299 # define wxUChar unsigned char
308 # define wxIsalnum isalnum
309 # define wxIsalpha isalpha
310 # define wxIsctrl isctrl
311 # define wxIsdigit isdigit
312 # define wxIsgraph isgraph
313 # define wxIslower islower
314 # define wxIsprint isprint
315 # define wxIspunct ispunct
316 # define wxIsspace isspace
317 # define wxIsupper isupper
318 # define wxIsxdigit isxdigit
319 # define wxTolower tolower
320 # define wxToupper toupper
323 # define wxSetlocale setlocale
325 // string.h functions
326 // #define wxStricmp strcasecmp
327 // wxStricmp is defined below!!
330 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
332 #define wxStrtok(str, sep, last) strtok(str, sep)
335 // leave the rest to defaults below
336 # define wxNEED_WX_STRING_H
337 # define wxNEED_WX_STDIO_H
338 # define wxNEED_WX_STDLIB_H
339 # define wxNEED_WX_TIME_H
342 #endif//TCHAR-aware compilers
344 // define wxStricmp for various compilers without Unicode possibilities
345 #if !defined(wxStricmp) && !wxUSE_UNICODE
346 # if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__) || defined(__VISAGECPP__) || defined(__EMX__)
347 # define wxStricmp stricmp
348 # elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS__) && defined(__INTEL__))
349 # define wxStricmp _stricmp
350 # elif defined(__UNIX__) || defined(__GNUWIN32__)
351 # define wxStricmp strcasecmp
352 # elif defined(__MWERKS__) && !defined(__INTEL__)
353 // use wxWindows' implementation
355 // if you leave wxStricmp undefined, wxWindows' implementation will be used
356 # error "Please define string case-insensitive compare for your OS/compiler"
360 // if we need to define for standard headers, and we're not using Unicode,
361 // just define to standard C library routines
363 # ifdef wxNEED_WX_STRING_H
364 # define wxStrcat strcat
365 # define wxStrchr strchr
366 # define wxStrcmp strcmp
367 # define wxStrcoll strcoll
368 # define wxStrcpy strcpy
369 # define wxStrcspn strcspn
370 # define wxStrdup strdup
371 # define wxStrlen_ strlen // used in wxStrlen inline function
372 # define wxStrncat strncat
373 # define wxStrncmp strncmp
374 # define wxStrncpy strncpy
375 # define wxStrpbrk strpbrk
376 # define wxStrrchr strrchr
377 # define wxStrspn strspn
378 # define wxStrstr strstr
379 # define wxStrtod strtod
380 # define wxStrtol strtol
381 # define wxStrtoul strtoul
382 # define wxStrxfrm strxfrm
383 # undef wxNEED_WX_STRING_H
386 # ifdef wxNEED_WX_STDIO_H
387 # define wxFgetc fgetc
388 # define wxFgetchar fgetchar
389 # define wxFgets fgets
390 # define wxFopen fopen
391 # define wxFputc fputc
392 # define wxFputchar fputchar
393 # define wxFprintf fprintf
394 # define wxFreopen freopen
395 # define wxFscanf fscanf
397 # define wxGetchar getchar
399 # define wxPerror perror
400 # define wxPrintf printf
402 # define wxPutchar putchar
404 # define wxRemove remove
405 # define wxRename rename
406 # define wxScanf scanf
407 # define wxSprintf sprintf
408 # define wxSscanf sscanf
409 # define wxTmpnam tmpnam
410 # define wxUngetc ungetc
411 # define wxVfprint vfprintf
412 # define wxVprintf vprintf
413 # define wxVsscanf vsscanf
414 # define wxVsprintf vsprintf
415 # undef wxNEED_WX_STDIO_H
418 # ifdef wxNEED_WX_STDLIB_H
422 # define wxGetenv getenv
423 # define wxSystem system
424 # undef wxNEED_WX_STDLIB_H
427 # ifdef wxNEED_WX_TIME_H
428 # define wxAsctime asctime
429 # define wxCtime ctime
430 # define wxStrftime strftime
431 # undef wxNEED_WX_TIME_H
435 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
436 # define wcslen wxStrlen
437 # undef wxNEED_WCSLEN
440 /// checks whether the passed in pointer is NULL and if the string is empty
441 WXDLLEXPORT
inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
443 #ifndef wxNEED_WX_STRING_H
444 /// safe version of strlen() (returns 0 if passed NULL pointer)
445 WXDLLEXPORT
inline size_t wxStrlen(const wxChar
*psz
)
446 { return psz
? wxStrlen_(psz
) : 0; }
450 // multibyte<->widechar conversion
451 WXDLLEXPORT
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
452 WXDLLEXPORT
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
454 # define wxMB2WX wxMB2WC
455 # define wxWX2MB wxWC2MB
456 # define wxWC2WX wxStrncpy
457 # define wxWX2WC wxStrncpy
459 # define wxMB2WX wxStrncpy
460 # define wxWX2MB wxStrncpy
461 # define wxWC2WX wxWC2MB
462 # define wxWX2WC wxMB2WC
465 // No wxUSE_WCHAR_T: we have to do something (JACS)
466 # define wxMB2WC wxStrncpy
467 # define wxWC2MB wxStrncpy
468 # define wxMB2WX wxStrncpy
469 # define wxWX2MB wxStrncpy
470 # define wxWC2WX wxWC2MB
471 # define wxWX2WC wxMB2WC
474 WXDLLEXPORT
bool wxOKlibc(); // for internal use
476 // if libc versions are not available, use replacements defined in wxchar.cpp
478 WXDLLEXPORT wxChar
* wxStrdup(const wxChar
*psz
);
482 WXDLLEXPORT
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
486 WXDLLEXPORT wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
490 WXDLLEXPORT wxChar
* wxSetlocale(int category
, const wxChar
*locale
);
493 #ifdef wxNEED_WCSLEN // for use in buffer.h
494 WXDLLEXPORT
size_t wcslen(const wchar_t *s
);
497 #ifdef wxNEED_WX_CTYPE_H
498 WXDLLEXPORT
int wxIsalnum(wxChar ch
);
499 WXDLLEXPORT
int wxIsalpha(wxChar ch
);
500 WXDLLEXPORT
int wxIsctrl(wxChar ch
);
501 WXDLLEXPORT
int wxIsdigit(wxChar ch
);
502 WXDLLEXPORT
int wxIsgraph(wxChar ch
);
503 WXDLLEXPORT
int wxIslower(wxChar ch
);
504 WXDLLEXPORT
int wxIsprint(wxChar ch
);
505 WXDLLEXPORT
int wxIspunct(wxChar ch
);
506 WXDLLEXPORT
int wxIsspace(wxChar ch
);
507 WXDLLEXPORT
int wxIsupper(wxChar ch
);
508 WXDLLEXPORT
int wxIsxdigit(wxChar ch
);
509 WXDLLEXPORT
int wxTolower(wxChar ch
);
510 WXDLLEXPORT
int wxToupper(wxChar ch
);
513 #ifdef wxNEED_WX_STRING_H
514 WXDLLEXPORT wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
515 WXDLLEXPORT wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
516 WXDLLEXPORT
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
517 WXDLLEXPORT
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
518 WXDLLEXPORT wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
519 WXDLLEXPORT
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
520 WXDLLEXPORT
size_t wxStrlen(const wxChar
*s
);
521 WXDLLEXPORT wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
522 WXDLLEXPORT
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
523 WXDLLEXPORT wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
524 WXDLLEXPORT wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
525 WXDLLEXPORT wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
526 WXDLLEXPORT
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
527 WXDLLEXPORT wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
528 WXDLLEXPORT
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
529 WXDLLEXPORT
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
530 WXDLLEXPORT
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
531 WXDLLEXPORT
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
534 #ifdef wxNEED_WX_STDIO_H
537 WXDLLEXPORT
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
538 WXDLLEXPORT
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
539 WXDLLEXPORT
int wxPrintf(const wxChar
*fmt
, ...);
540 WXDLLEXPORT
int wxVprintf(const wxChar
*fmt
, va_list argptr
);
541 WXDLLEXPORT
int wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
542 WXDLLEXPORT
int wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
543 WXDLLEXPORT
int wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
544 WXDLLEXPORT
int wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
545 WXDLLEXPORT
int wxSscanf(const wxChar
*buf
, const wxChar
*fmt
, ...);
546 WXDLLEXPORT
int wxVsscanf(const wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
550 WXDLLEXPORT
double wxAtof(const wxChar
*psz
);
553 #ifdef wxNEED_WX_STDLIB_H
554 WXDLLEXPORT
int wxAtoi(const wxChar
*psz
);
555 WXDLLEXPORT
long wxAtol(const wxChar
*psz
);
556 WXDLLEXPORT wxChar
* wxGetenv(const wxChar
*name
);
557 WXDLLEXPORT
int wxSystem(const wxChar
*psz
);
560 #ifdef wxNEED_WX_TIME_H
561 WXDLLEXPORT
size_t wxStrftime(wxChar
*s
, size_t max
, const wxChar
*fmt
, const struct tm
*tm
);
564 // a Unicode-friendly __FILE__ analog
566 #define __XFILE__(x) T(x)
567 #define __TFILE__ __XFILE__(__FILE__)