]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
46c0f1cddce926f3eddffd2011da5bef28a8e2ac
[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 #include <tchar.h>
48 #if wxUSE_UNICODE // temporary - preserve binary compatibility
49 typedef _TCHAR wxChar;
50 typedef _TSCHAR wxSChar;
51 typedef _TUCHAR wxUChar;
52 #else
53 #define wxChar char
54 #define wxSChar signed char
55 #define wxUChar unsigned char
56 #endif
57 // wchar_t is available
58 #undef wxUSE_WCHAR_T
59 #define wxUSE_WCHAR_T 1
60
61 // ctype.h functions
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
75
76 // locale.h functons
77 #define wxSetlocale _tsetlocale
78
79 // string.h functions
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
101
102 // stdio.h functions
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
131
132 // stdlib.h functions
133 #if !wxUSE_UNICODE
134 #define wxAtof atof
135 #endif
136 #define wxAtoi _ttoi
137 #define wxAtol _ttol
138 #define wxGetenv _tgetenv
139 #define wxSystem _tsystem
140
141 // time.h functions
142 #define wxAsctime _tasctime
143 #define wxCtime _tctime
144
145 // #elif defined(XXX)
146 // #include XXX-specific files here
147 // typeddef YYY wxChar;
148
149 // translate wxZZZ names
150
151 #elif defined(__BORLANDC__) && defined(__WIN32__)
152
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
156
157 #include <tchar.h>
158 #if wxUSE_UNICODE // temporary - preserve binary compatibility
159 typedef _TCHAR wxChar;
160 typedef _TSCHAR wxSChar;
161 typedef _TUCHAR wxUChar;
162 #else
163 #define wxChar char
164 #define wxSChar signed char
165 #define wxUChar unsigned char
166 #endif
167 // wchar_t is available
168 #undef wxUSE_WCHAR_T
169 #define wxUSE_WCHAR_T 1
170
171 #include <windef.h>
172 #include <winbase.h>
173 #include <winnls.h>
174 #include <winnt.h>
175
176 // ctype.h functions
177 inline WORD __wxMSW_ctype(wxChar ch)
178 {
179 WORD ret;
180 GetStringTypeEx(LOCALE_USER_DEFAULT, CT_CTYPE1, &ch, 1, &ret);
181 return ret;
182 }
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))
196
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
203
204 #else//!TCHAR-aware compilers
205
206 // check whether we should include wchar.h or equivalent
207 #if wxUSE_UNICODE
208 #undef wxUSE_WCHAR_T
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
213 #elif defined(__UNIX__)
214 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H)
215 #define wxUSE_WCHAR_T 1
216 #else
217 #define wxUSE_WCHAR_T 0
218 #endif
219 #elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
220 #define wxUSE_WCHAR_T 0
221 #else
222 // add additional compiler checks if this fails
223 #define wxUSE_WCHAR_T 1
224 #endif
225 #endif//wxUSE_UNICODE
226
227 #if wxUSE_WCHAR_T
228 #ifdef HAVE_WCSTR_H
229 #include <wcstr.h>
230 #else
231 #include <wchar.h>
232 #endif
233 #endif
234
235 // check whether we are doing Unicode
236 #if wxUSE_UNICODE
237
238 #include <wctype.h>
239
240 // this is probably glibc-specific
241 #if defined(__WCHAR_TYPE__)
242
243 typedef __WCHAR_TYPE__ wxChar;
244 typedef signed __WCHAR_TYPE__ wxSChar;
245 typedef unsigned __WCHAR_TYPE__ wxUChar;
246
247 #define _T(x) L##x
248
249 // ctype.h functions (wctype.h)
250 #define wxIsalnum iswalnum
251 #define wxIsalpha iswalpha
252 #define wxIsctrl iswcntrl
253 #define wxIsdigit iswdigit
254 #define wxIsgraph iswgraph
255 #define wxIslower iswlower
256 #define wxIsprint iswprint
257 #define wxIspunct iswpunct
258 #define wxIsspace iswspace
259 #define wxIsupper iswupper
260 #define wxIsxdigit iswxdigit
261
262 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
263 // /usr/include/wctype.h incorrectly declares translations tables which
264 // provokes tons of compile-time warnings - try to correct this
265 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
266 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
267 #else
268 #define wxTolower towlower
269 #define wxToupper towupper
270 #endif // gcc/!gcc
271
272 // string.h functions (wchar.h)
273 #define wxStrcat wcscat
274 #define wxStrchr wcschr
275 #define wxStrcmp wcscmp
276 #define wxStrcoll wcscoll
277 #define wxStrcpy wcscpy
278 #define wxStrcspn wcscspn
279 #define wxStrlen_ wcslen // used in wxStrlen inline function
280 #define wxStrncat wcsncat
281 #define wxStrncmp wcsncmp
282 #define wxStrncpy wcsncpy
283 #define wxStrpbrk wcspbrk
284 #define wxStrrchr wcsrchr
285 #define wxStrspn wcsspn
286 #define wxStrstr wcsstr
287 #define wxStrtod wcstod
288 #define wxStrtok wcstok
289 #define wxStrtol wcstol
290 #define wxStrtoul wcstoul
291 #define wxStrxfrm wcsxfrm
292
293 // glibc doesn't have wc equivalents of the other stuff
294 #define wxNEED_WX_STDIO_H
295 #define wxNEED_WX_STDLIB_H
296 #define wxNEED_WX_TIME_H
297
298 #else//!glibc
299 #error "Please define your compiler's Unicode conventions in wxChar.h"
300 #endif
301 #else//!Unicode
302
303 #include <ctype.h>
304 #include <string.h>
305
306 #if 0 // temporary - preserve binary compatibilty
307 typedef char wxChar;
308 typedef signed char wxSChar;
309 typedef unsigned char wxUChar;
310 #else
311 #define wxChar char
312 #define wxSChar signed char
313 #define wxUChar unsigned char
314 #endif
315
316 #define _T(x) x
317
318 // ctype.h functions
319 #define wxIsalnum isalnum
320 #define wxIsalpha isalpha
321 #define wxIsctrl isctrl
322 #define wxIsdigit isdigit
323 #define wxIsgraph isgraph
324 #define wxIslower islower
325 #define wxIsprint isprint
326 #define wxIspunct ispunct
327 #define wxIsspace isspace
328 #define wxIsupper isupper
329 #define wxIsxdigit isxdigit
330 #define wxTolower tolower
331 #define wxToupper toupper
332
333 // locale.h functons
334 #define wxSetlocale setlocale
335
336 // string.h functions
337 #define wxStricmp strcasecmp
338 // #define wxStrtok strtok_r // this needs a configure check
339
340 // leave the rest to defaults below
341 #define wxNEED_WX_STRING_H
342 #define wxNEED_WX_STDIO_H
343 #define wxNEED_WX_STDLIB_H
344 #define wxNEED_WX_TIME_H
345
346 #endif//Unicode
347 #endif//TCHAR-aware compilers
348
349 // define wxStricmp for various compilers without Unicode possibilities
350 #if !defined(wxStricmp) && !wxUSE_UNICODE
351 #if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__)
352 #define wxStricmp stricmp
353 #elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS) && defined(__INTEL__))
354 #define wxStricmp _stricmp
355 #elif defined(__UNIX__) || defined(__GNUWIN32__)
356 #define wxStricmp strcasecmp
357 #elif defined(__MWERKS__) && !defined(__INTEL__)
358 // use wxWindows' implementation
359 #else
360 // if you leave wxStricmp undefined, wxWindows' implementation will be used
361 #error "Please define string case-insensitive compare for your OS/compiler"
362 #endif
363 #endif
364
365 // if we need to define for standard headers, and we're not using Unicode,
366 // just define to standard C library routines
367 #if !wxUSE_UNICODE
368 #ifdef wxNEED_WX_STRING_H
369 #define wxStrcat strcat
370 #define wxStrchr strchr
371 #define wxStrcmp strcmp
372 #define wxStrcoll strcoll
373 #define wxStrcpy strcpy
374 #define wxStrcspn strcspn
375 #define wxStrdup strdup
376 #define wxStrlen_ strlen // used in wxStrlen inline function
377 #define wxStrncat strncat
378 #define wxStrncmp strncmp
379 #define wxStrncpy strncpy
380 #define wxStrpbrk strpbrk
381 #define wxStrrchr strrchr
382 #define wxStrspn strspn
383 #define wxStrstr strstr
384 #define wxStrtod strtod
385 #define wxStrtol strtol
386 #define wxStrtoul strtoul
387 #define wxStrxfrm strxfrm
388 #undef wxNEED_WX_STRING_H
389 #endif
390
391 #ifdef wxNEED_WX_STDIO_H
392 #define wxFgetc fgetc
393 #define wxFgetchar fgetchar
394 #define wxFgets fgets
395 #define wxFopen fopen
396 #define wxFputc fputc
397 #define wxFputchar fputchar
398 #define wxFprintf fprintf
399 #define wxFreopen freopen
400 #define wxFscanf fscanf
401 #define wxGetc getc
402 #define wxGetchar getchar
403 #define wxGets gets
404 #define wxPerror perror
405 #define wxPrintf printf
406 #define wxPutc putc
407 #define wxPutchar putchar
408 #define wxPuts puts
409 #define wxRemove remove
410 #define wxRename rename
411 #define wxScanf scanf
412 #define wxSprintf sprintf
413 #define wxSscanf sscanf
414 #define wxTmpnam tmpnam
415 #define wxUngetc ungetc
416 #define wxVfprint vfprintf
417 #define wxVprintf vprintf
418 #define wxVsscanf vsscanf
419 #define wxVsprintf vsprintf
420 #undef wxNEED_WX_STDIO_H
421 #endif
422
423 #ifdef wxNEED_WX_STDLIB_H
424 #define wxAtof atof
425 #define wxAtoi atoi
426 #define wxAtol atol
427 #define wxGetenv getenv
428 #define wxSystem system
429 #undef wxNEED_WX_STDLIB_H
430 #endif
431
432 #ifdef wxNEED_WX_TIME_H
433 #define wxAsctime asctime
434 #define wxCtime ctime
435 #define wxStrftime strftime
436 #undef wxNEED_WX_TIME_H
437 #endif
438 #endif //!Unicode
439
440 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
441 #define wcslen wxStrlen
442 #undef wxNEED_WCSLEN
443 #endif
444
445 /// checks whether the passed in pointer is NULL and if the string is empty
446 inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; }
447
448 #ifndef wxNEED_WX_STRING_H
449 /// safe version of strlen() (returns 0 if passed NULL pointer)
450 inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz)
451 { return psz ? wxStrlen_(psz) : 0; }
452 #endif
453
454 #if wxUSE_WCHAR_T
455 // multibyte<->widechar conversion
456 size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n);
457 size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *psz, size_t n);
458 #if wxUSE_UNICODE
459 #define wxMB2WX wxMB2WC
460 #define wxWX2MB wxWC2MB
461 #define wxWC2WX wxStrncpy
462 #define wxWX2WC wxStrncpy
463 #else
464 #define wxMB2WX wxStrncpy
465 #define wxWX2MB wxStrncpy
466 #define wxWC2WX wxWC2MB
467 #define wxWX2WC wxMB2WC
468 #endif
469 #endif
470 bool WXDLLEXPORT wxOKlibc(); // for internal use
471
472 // if libc versions are not available, use replacements defined in wxchar.cpp
473 #ifndef wxStrdup
474 wxChar * WXDLLEXPORT wxStrdup(const wxChar *psz);
475 #endif
476
477 #ifndef wxStricmp
478 int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2);
479 #endif
480
481 #ifndef wxStrtok
482 wxChar * WXDLLEXPORT wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
483 #endif
484
485 #ifndef wxSetlocale
486 wxChar * WXDLLEXPORT wxSetlocale(int category, const wxChar *locale);
487 #endif
488
489 #ifdef wxNEED_WCSLEN // for use in buffer.h
490 size_t WXDLLEXPORT wcslen(const wchar_t *s);
491 #endif
492
493 #ifdef wxNEED_WX_STRING_H
494 wxChar * WXDLLEXPORT wxStrcat(wxChar *dest, const wxChar *src);
495 wxChar * WXDLLEXPORT wxStrchr(const wxChar *s, wxChar c);
496 int WXDLLEXPORT wxStrcmp(const wxChar *s1, const wxChar *s2);
497 int WXDLLEXPORT wxStrcoll(const wxChar *s1, const wxChar *s2);
498 wxChar * WXDLLEXPORT wxStrcpy(wxChar *dest, const wxChar *src);
499 size_t WXDLLEXPORT wxStrcspn(const wxChar *s, const wxChar *reject);
500 size_t WXDLLEXPORT wxStrlen(const wxChar *s);
501 wxChar * WXDLLEXPORT wxStrncat(wxChar *dest, const wxChar *src, size_t n);
502 int WXDLLEXPORT wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
503 wxChar * WXDLLEXPORT wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
504 wxChar * WXDLLEXPORT wxStrpbrk(const wxChar *s, const wxChar *accept);
505 wxChar * WXDLLEXPORT wxStrrchr(const wxChar *s, wxChar c);
506 size_t WXDLLEXPORT wxStrspn(const wxChar *s, const wxChar *accept);
507 wxChar * WXDLLEXPORT wxStrstr(const wxChar *haystack, const wxChar *needle);
508 double WXDLLEXPORT wxStrtod(const wxChar *nptr, wxChar **endptr);
509 long int WXDLLEXPORT wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
510 unsigned long int WXDLLEXPORT wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
511 size_t WXDLLEXPORT wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
512 #endif
513
514 #ifdef wxNEED_WX_STDIO_H
515 #include <stdio.h>
516 #include <stdarg.h>
517 int WXDLLEXPORT wxPrintf(const wxChar *fmt, ...);
518 int WXDLLEXPORT wxVprintf(const wxChar *fmt, va_list argptr);
519 int WXDLLEXPORT wxFprintf(FILE *stream, const wxChar *fmt, ...);
520 int WXDLLEXPORT wxVfprintf(FILE *stream, const wxChar *fmt, va_list argptr);
521 int WXDLLEXPORT wxSprintf(wxChar *buf, const wxChar *fmt, ...);
522 int WXDLLEXPORT wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr);
523 int WXDLLEXPORT wxSscanf(const wxChar *buf, const wxChar *fmt, ...);
524 int WXDLLEXPORT wxVsscanf(const wxChar *buf, const wxChar *fmt, va_list argptr);
525 #endif
526
527 #ifndef wxAtof
528 double WXDLLEXPORT wxAtof(const wxChar *psz);
529 #endif
530
531 #ifdef wxNEED_WX_STDLIB_H
532 int WXDLLEXPORT wxAtoi(const wxChar *psz);
533 long WXDLLEXPORT wxAtol(const wxChar *psz);
534 wxChar * WXDLLEXPORT wxGetenv(const wxChar *name);
535 int WXDLLEXPORT wxSystem(const wxChar *psz);
536 #endif
537
538 #endif
539 //_WX_WXCHAR_H_