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