]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
Committing in .
[wxWidgets.git] / include / wx / wxchar.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wxchar.h
3 // Purpose: Declarations common to wx char/wchar_t usage (wide chars)
4 // Author: Joel Farley
5 // Modified by:
6 // Created: 1998/06/12
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows copyright
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WXCHAR_H_
13 #define _WX_WXCHAR_H_
14
15 //#ifdef __GNUG__
16 //#pragma interface "wxchar.h"
17 //#endif
18
19 // only do SBCS or _UNICODE
20 #if defined (_MBCS )
21 # error "MBCS is not supported by wxChar"
22 #endif
23
24 // set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
25 #if defined(_UNICODE) || defined(UNICODE)
26 # undef wxUSE_UNICODE
27 # define wxUSE_UNICODE 1
28 #else
29 # ifndef wxUSE_UNICODE
30 # define wxUSE_UNICODE 0
31 # endif
32 #endif
33
34 // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
35 #if wxUSE_UNICODE
36 # ifndef _UNICODE
37 # define _UNICODE
38 # endif
39 # ifndef UNICODE
40 # define UNICODE
41 # endif
42 #endif
43
44 // Windows (VC++) has broad TCHAR support
45 #if defined(__VISUALC__) && defined(__WIN32__)
46
47 # define HAVE_WCSLEN 1
48
49 # include <tchar.h>
50
51 # if wxUSE_UNICODE // temporary - preserve binary compatibility
52 typedef _TCHAR wxChar;
53 typedef _TSCHAR wxSChar;
54 typedef _TUCHAR wxUChar;
55 # else
56 # define wxChar char
57 # define wxSChar signed char
58 # define wxUChar unsigned char
59 # endif
60 // wchar_t is available
61 # undef wxUSE_WCHAR_T
62 # define wxUSE_WCHAR_T 1
63
64 // ctype.h functions
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
78
79 // locale.h functons
80 # define wxSetlocale _tsetlocale
81
82 // string.h functions
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
104
105 // stdio.h functions
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
134
135 // stdlib.h functions
136 # if !wxUSE_UNICODE
137 # define wxAtof atof
138 # endif
139 # define wxAtoi _ttoi
140 # define wxAtol _ttol
141 # define wxGetenv _tgetenv
142 # define wxSystem _tsystem
143
144 // time.h functions
145 # define wxAsctime _tasctime
146 # define wxCtime _tctime
147
148 // #elif defined(XXX)
149 // #include XXX-specific files here
150 // typeddef YYY wxChar;
151
152 // translate wxZZZ names
153
154 #elif defined(__BORLANDC__) && defined(__WIN32__)
155
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
159
160 # include <tchar.h>
161 # if wxUSE_UNICODE // temporary - preserve binary compatibility
162 typedef _TCHAR wxChar;
163 typedef _TSCHAR wxSChar;
164 typedef _TUCHAR wxUChar;
165 # else
166 # define wxChar char
167 # define wxSChar signed char
168 # define wxUChar unsigned char
169 # endif
170 // wchar_t is available
171 # undef wxUSE_WCHAR_T
172 // This test is for C++Builder
173 #if __BORLANDC__ == 0x530
174 # define wxUSE_WCHAR_T 0
175 #elif
176 # define wxUSE_WCHAR_T 1
177 # define wxNEED_WCSLEN
178 #endif
179 # define wxNEED_WX_CTYPE_H
180 // #define wxStrtok strtok_r // Borland C++ 4.52 doesn't have strtok_r
181 # define wxNEED_WX_STRING_H
182 # define wxNEED_WX_STDIO_H
183 # define wxNEED_WX_STDLIB_H
184 # define wxNEED_WX_TIME_H
185
186 #else//!TCHAR-aware compilers
187
188 // check whether we should include wchar.h or equivalent
189 # if wxUSE_UNICODE
190 # undef wxUSE_WCHAR_T
191 # define wxUSE_WCHAR_T 1 // wchar_t *must* be available in Unicode mode
192 # elif !defined(wxUSE_WCHAR_T)
193 # if defined(__VISUALC__) && (__VISUALC__ < 900)
194 # define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
195 # elif defined(__UNIX__)
196 # if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__)
197 # define wxUSE_WCHAR_T 1
198 # else
199 # define wxUSE_WCHAR_T 0
200 # endif
201 # elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
202 # define wxUSE_WCHAR_T 0
203 # elif defined(__BORLANDC__) // WIN16 BC++
204 # define wxUSE_WCHAR_T 0
205 # elif defined(__WATCOMC__)
206 # define wxUSE_WCHAR_T 0
207 # else
208 // add additional compiler checks if this fails
209 # define wxUSE_WCHAR_T 1
210 # endif
211 # endif//wxUSE_UNICODE
212
213 # if wxUSE_WCHAR_T
214 # ifdef HAVE_WCSTR_H
215 # include <wcstr.h>
216 # else
217 # ifndef __FreeBSD__
218 # include <wchar.h>
219 # else
220 # include <stdlib.h>
221 # define wxNEED_WCSLEN
222 # endif
223 # endif
224 # endif
225
226 // check whether we are doing Unicode
227 # if wxUSE_UNICODE
228
229 # include <wctype.h>
230
231 // this is probably glibc-specific
232 # if defined(__WCHAR_TYPE__)
233
234 typedef __WCHAR_TYPE__ wxChar;
235 typedef signed __WCHAR_TYPE__ wxSChar;
236 typedef unsigned __WCHAR_TYPE__ wxUChar;
237
238 # define _T(x) L##x
239
240 // ctype.h functions (wctype.h)
241 # define wxIsalnum iswalnum
242 # define wxIsalpha iswalpha
243 # define wxIsctrl iswcntrl
244 # define wxIsdigit iswdigit
245 # define wxIsgraph iswgraph
246 # define wxIslower iswlower
247 # define wxIsprint iswprint
248 # define wxIspunct iswpunct
249 # define wxIsspace iswspace
250 # define wxIsupper iswupper
251 # define wxIsxdigit iswxdigit
252
253 # if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
254 // /usr/include/wctype.h incorrectly declares translations tables which
255 // provokes tons of compile-time warnings - try to correct this
256 # define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
257 # define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
258 # else
259 # define wxTolower towlower
260 # define wxToupper towupper
261 # endif // gcc/!gcc
262
263 // string.h functions (wchar.h)
264 # define wxStrcat wcscat
265 # define wxStrchr wcschr
266 # define wxStrcmp wcscmp
267 # define wxStrcoll wcscoll
268 # define wxStrcpy wcscpy
269 # define wxStrcspn wcscspn
270 # define wxStrlen_ wcslen // used in wxStrlen inline function
271 # define wxStrncat wcsncat
272 # define wxStrncmp wcsncmp
273 # define wxStrncpy wcsncpy
274 # define wxStrpbrk wcspbrk
275 # define wxStrrchr wcsrchr
276 # define wxStrspn wcsspn
277 # define wxStrstr wcsstr
278 # define wxStrtod wcstod
279 # define wxStrtok wcstok
280 # define wxStrtol wcstol
281 # define wxStrtoul wcstoul
282 # define wxStrxfrm wcsxfrm
283
284 // glibc doesn't have wc equivalents of the other stuff
285 # define wxNEED_WX_STDIO_H
286 # define wxNEED_WX_STDLIB_H
287 # define wxNEED_WX_TIME_H
288
289 # else//!glibc
290 # error "Please define your compiler's Unicode conventions in wxChar.h"
291 # endif
292 # else//!Unicode
293
294 # include <ctype.h>
295 # include <string.h>
296
297 # if 0 // temporary - preserve binary compatibilty
298 typedef char wxChar;
299 typedef signed char wxSChar;
300 typedef unsigned char wxUChar;
301 # else
302 # define wxChar char
303 # define wxSChar signed char
304 # define wxUChar unsigned char
305 # endif
306
307 # ifdef __FreeBSD__
308 # undef _T
309 # endif
310
311 # if !defined(__MINGW32__) || !defined(_T)
312 # define _T(x) x
313 # endif
314
315 // ctype.h functions
316 # define wxIsalnum isalnum
317 # define wxIsalpha isalpha
318 # define wxIsctrl isctrl
319 # define wxIsdigit isdigit
320 # define wxIsgraph isgraph
321 # define wxIslower islower
322 # define wxIsprint isprint
323 # define wxIspunct ispunct
324 # define wxIsspace isspace
325 # define wxIsupper isupper
326 # define wxIsxdigit isxdigit
327 # define wxTolower tolower
328 # define wxToupper toupper
329
330 // locale.h functons
331 # define wxSetlocale setlocale
332
333 // string.h functions
334 // #define wxStricmp strcasecmp
335 // wxStricmp is defined below!!
336
337 #ifdef HAVE_STRTOK_R
338 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
339 #else
340 #define wxStrtok(str, sep, last) strtok(str, sep)
341 #endif
342
343 // leave the rest to defaults below
344 # define wxNEED_WX_STRING_H
345 # define wxNEED_WX_STDIO_H
346 # define wxNEED_WX_STDLIB_H
347 # define wxNEED_WX_TIME_H
348
349 # endif//Unicode
350 #endif//TCHAR-aware compilers
351
352 // define wxStricmp for various compilers without Unicode possibilities
353 #if !defined(wxStricmp) && !wxUSE_UNICODE
354 # if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__) || defined(__VISAGECPP__) || defined(__EMX__)
355 # define wxStricmp stricmp
356 # define wxStrnicmp strnicmp
357 # elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS__) && defined(__INTEL__))
358 # define wxStricmp _stricmp
359 # define wxStrnicmp _strnicmp
360 # elif defined(__UNIX__) || defined(__GNUWIN32__)
361 # define wxStricmp strcasecmp
362 # define wxStrnicmp strncasecmp
363 # elif defined(__MWERKS__) && !defined(__INTEL__)
364 // use wxWindows' implementation
365 # else
366 // if you leave wxStricmp undefined, wxWindows' implementation will be used
367 # error "Please define string case-insensitive compare for your OS/compiler"
368 # endif
369 #endif
370
371 // if we need to define for standard headers, and we're not using Unicode,
372 // just define to standard C library routines
373 #if !wxUSE_UNICODE
374 # ifdef wxNEED_WX_STRING_H
375 # define wxStrcat strcat
376 # define wxStrchr strchr
377 # define wxStrcmp strcmp
378 # define wxStrcoll strcoll
379 # define wxStrcpy strcpy
380 # define wxStrcspn strcspn
381 # define wxStrdup strdup
382 # define wxStrlen_ strlen // used in wxStrlen inline function
383 # define wxStrncat strncat
384 # define wxStrncmp strncmp
385 # define wxStrncpy strncpy
386 # define wxStrpbrk strpbrk
387 # define wxStrrchr strrchr
388 # define wxStrspn strspn
389 # define wxStrstr strstr
390 # define wxStrtod strtod
391 # define wxStrtol strtol
392 # define wxStrtoul strtoul
393 # define wxStrxfrm strxfrm
394 # undef wxNEED_WX_STRING_H
395 # endif
396
397 # ifdef wxNEED_WX_STDIO_H
398 # define wxFgetc fgetc
399 # define wxFgetchar fgetchar
400 # define wxFgets fgets
401 # define wxFopen fopen
402 # define wxFputc fputc
403 # define wxFputchar fputchar
404 # define wxFprintf fprintf
405 # define wxFreopen freopen
406 # define wxFscanf fscanf
407 # define wxGetc getc
408 # define wxGetchar getchar
409 # define wxGets gets
410 # define wxPerror perror
411 # define wxPrintf printf
412 # define wxPutc putc
413 # define wxPutchar putchar
414 # define wxPuts puts
415 # define wxRemove remove
416 # define wxRename rename
417 # define wxScanf scanf
418 # define wxSprintf sprintf
419 # define wxSscanf sscanf
420 # define wxTmpnam tmpnam
421 # define wxUngetc ungetc
422 # define wxVfprint vfprintf
423 # define wxVprintf vprintf
424 # define wxVsscanf vsscanf
425 # define wxVsprintf vsprintf
426 # undef wxNEED_WX_STDIO_H
427 # endif
428
429 # ifdef wxNEED_WX_STDLIB_H
430 # define wxAtof atof
431 # define wxAtoi atoi
432 # define wxAtol atol
433 # define wxGetenv getenv
434 # define wxSystem system
435 # undef wxNEED_WX_STDLIB_H
436 # endif
437
438 # ifdef wxNEED_WX_TIME_H
439 # define wxAsctime asctime
440 # define wxCtime ctime
441 # define wxStrftime strftime
442 # undef wxNEED_WX_TIME_H
443 # endif
444 #endif //!Unicode
445
446 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
447 # define wcslen wxStrlen
448 # undef wxNEED_WCSLEN
449 #endif
450
451 /// checks whether the passed in pointer is NULL and if the string is empty
452 WXDLLEXPORT inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
453
454 #ifndef wxNEED_WX_STRING_H
455 /// safe version of strlen() (returns 0 if passed NULL pointer)
456 WXDLLEXPORT inline size_t wxStrlen(const wxChar *psz)
457 { return psz ? wxStrlen_(psz) : 0; }
458 #endif
459
460 #if wxUSE_WCHAR_T
461 // multibyte<->widechar conversion
462 WXDLLEXPORT size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
463 WXDLLEXPORT size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
464 # if wxUSE_UNICODE
465 # define wxMB2WX wxMB2WC
466 # define wxWX2MB wxWC2MB
467 # define wxWC2WX wxStrncpy
468 # define wxWX2WC wxStrncpy
469 # else
470 # define wxMB2WX wxStrncpy
471 # define wxWX2MB wxStrncpy
472 # define wxWC2WX wxWC2MB
473 # define wxWX2WC wxMB2WC
474 # endif
475 #else
476 // No wxUSE_WCHAR_T: we have to do something (JACS)
477 # define wxMB2WC wxStrncpy
478 # define wxWC2MB wxStrncpy
479 # define wxMB2WX wxStrncpy
480 # define wxWX2MB wxStrncpy
481 # define wxWC2WX wxWC2MB
482 # define wxWX2WC wxMB2WC
483 #endif
484
485 WXDLLEXPORT bool wxOKlibc(); // for internal use
486
487 // if libc versions are not available, use replacements defined in wxchar.cpp
488 #ifndef wxStrdup
489 WXDLLEXPORT wxChar * wxStrdup(const wxChar *psz);
490 #endif
491
492 #ifndef wxStricmp
493 WXDLLEXPORT int wxStricmp(const wxChar *psz1, const wxChar *psz2);
494 #endif
495
496 #ifndef wxStrtok
497 WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
498 #endif
499
500 #ifndef wxSetlocale
501 WXDLLEXPORT wxChar * wxSetlocale(int category, const wxChar *locale);
502 #endif
503
504 #ifdef wxNEED_WCSLEN // for use in buffer.h
505 WXDLLEXPORT size_t wcslen(const wchar_t *s);
506 #endif
507
508 #ifdef wxNEED_WX_CTYPE_H
509 WXDLLEXPORT int wxIsalnum(wxChar ch);
510 WXDLLEXPORT int wxIsalpha(wxChar ch);
511 WXDLLEXPORT int wxIsctrl(wxChar ch);
512 WXDLLEXPORT int wxIsdigit(wxChar ch);
513 WXDLLEXPORT int wxIsgraph(wxChar ch);
514 WXDLLEXPORT int wxIslower(wxChar ch);
515 WXDLLEXPORT int wxIsprint(wxChar ch);
516 WXDLLEXPORT int wxIspunct(wxChar ch);
517 WXDLLEXPORT int wxIsspace(wxChar ch);
518 WXDLLEXPORT int wxIsupper(wxChar ch);
519 WXDLLEXPORT int wxIsxdigit(wxChar ch);
520 WXDLLEXPORT int wxTolower(wxChar ch);
521 WXDLLEXPORT int wxToupper(wxChar ch);
522 #endif
523
524 #ifdef wxNEED_WX_STRING_H
525 WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src);
526 WXDLLEXPORT wxChar * wxStrchr(const wxChar *s, wxChar c);
527 WXDLLEXPORT int wxStrcmp(const wxChar *s1, const wxChar *s2);
528 WXDLLEXPORT int wxStrcoll(const wxChar *s1, const wxChar *s2);
529 WXDLLEXPORT wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
530 WXDLLEXPORT size_t wxStrcspn(const wxChar *s, const wxChar *reject);
531 WXDLLEXPORT size_t wxStrlen(const wxChar *s);
532 WXDLLEXPORT wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
533 WXDLLEXPORT int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
534 WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
535 WXDLLEXPORT wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
536 WXDLLEXPORT wxChar * wxStrrchr(const wxChar *s, wxChar c);
537 WXDLLEXPORT size_t wxStrspn(const wxChar *s, const wxChar *accept);
538 WXDLLEXPORT wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
539 WXDLLEXPORT double wxStrtod(const wxChar *nptr, wxChar **endptr);
540 WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
541 WXDLLEXPORT unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
542 WXDLLEXPORT size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
543 #endif
544
545 #ifdef wxNEED_WX_STDIO_H
546 # include <stdio.h>
547 # include <stdarg.h>
548 WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode);
549 WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
550 WXDLLEXPORT int wxPrintf(const wxChar *fmt, ...);
551 WXDLLEXPORT int wxVprintf(const wxChar *fmt, va_list argptr);
552 WXDLLEXPORT int wxFprintf(FILE *stream, const wxChar *fmt, ...);
553 WXDLLEXPORT int wxVfprintf(FILE *stream, const wxChar *fmt, va_list argptr);
554 WXDLLEXPORT int wxSprintf(wxChar *buf, const wxChar *fmt, ...);
555 WXDLLEXPORT int wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr);
556 WXDLLEXPORT int wxSscanf(const wxChar *buf, const wxChar *fmt, ...);
557 WXDLLEXPORT int wxVsscanf(const wxChar *buf, const wxChar *fmt, va_list argptr);
558 #endif
559
560 #ifndef wxAtof
561 WXDLLEXPORT double wxAtof(const wxChar *psz);
562 #endif
563
564 #ifdef wxNEED_WX_STDLIB_H
565 WXDLLEXPORT int wxAtoi(const wxChar *psz);
566 WXDLLEXPORT long wxAtol(const wxChar *psz);
567 WXDLLEXPORT wxChar * wxGetenv(const wxChar *name);
568 WXDLLEXPORT int wxSystem(const wxChar *psz);
569 #endif
570
571 #ifdef wxNEED_WX_TIME_H
572 WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max, const wxChar *fmt, const struct tm *tm);
573 #endif
574
575 // although global macros with such names are really bad, we want to have
576 // another name for _T() which should be used to avoid confusion between _T()
577 // and _() in wxWindows sources
578 #define wxT(x) _T(x)
579
580 // a Unicode-friendly __FILE__ analog
581 #ifndef __TFILE__
582 #define __XFILE__(x) wxT(x)
583 #define __TFILE__ __XFILE__(__FILE__)
584 #endif
585
586 #endif
587 //_WX_WXCHAR_H_
588