Forgot an additional prototype.
[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
58 // ctype.h functions
59 #define wxIsalnum _istalnum
60 #define wxIsalpha _istalpha
61 #define wxIsctrl _istctrl
62 #define wxIsdigit _istdigit
63 #define wxIsgraph _istgraph
64 #define wxIslower _istlower
65 #define wxIsprint _istprint
66 #define wxIspunct _istpunct
67 #define wxIsspace _istspace
68 #define wxIsupper _istupper
69 #define wxIsxdigit _istxdigit
70 #define wxTolower _totlower
71 #define wxToupper _totupper
72
73 // locale.h functons
74 #define wxSetlocale _tsetlocale
75
76 // string.h functions
77 #define wxStrcat _tcscat
78 #define wxStrchr _tcschr
79 #define wxStrcmp _tcscmp
80 #define wxStrcoll _tcscoll
81 #define wxStrcpy _tcscpy
82 #define wxStrcspn _tcscspn
83 #define wxStrftime _tcsftime
84 #define wxStricmp _tcsicmp
85 #define wxStrlen_ _tcslen // used in wxStrlen inline function
86 #define wxStrncat _tcsncat
87 #define wxStrncmp _tcsncmp
88 #define wxStrncpy _tcsncpy
89 #define wxStrpbrk _tcspbrk
90 #define wxStrrchr _tcsrchr
91 #define wxStrspn _tcsspn
92 #define wxStrstr _tcsstr
93 #define wxStrtod _tcstod
94 // is there a _tcstok[_r] ?
95 #define wxStrtol _tcstol
96 #define wxStrtoul _tcstoul
97 #define wxStrxfrm _tcsxfrm
98
99 // stdio.h functions
100 #define wxFgetc _fgettc
101 #define wxFgetchar _fgettchar
102 #define wxFgets _fgetts
103 #define wxFopen _tfopen
104 #define wxFputc _fputtc
105 #define wxFputchar _fputtchar
106 #define wxFprintf _ftprintf
107 #define wxFreopen _tfreopen
108 #define wxFscanf _ftscanf
109 #define wxGetc _gettc
110 #define wxGetchar _gettchar
111 #define wxGets _getts
112 #define wxPerror _tperror
113 #define wxPrintf _tprintf
114 #define wxPutc _puttc
115 #define wxPutchar _puttchar
116 #define wxPuts _putts
117 #define wxRemove _tremove
118 #define wxRename _trename
119 #define wxScanf _tscanf
120 #define wxSprintf _stprintf
121 #define wxSscanf _stscanf
122 #define wxTmpnam _ttmpnam
123 #define wxUngetc _tungetc
124 #define wxVfprint _vftprintf
125 #define wxVprintf _vtprintf
126 #define wxVsscanf _vstscanf
127 #define wxVsprintf _vstprintf
128
129 // stdlib.h functions
130 #if !wxUSE_UNICODE
131 #define wxAtof atof
132 #endif
133 #define wxAtoi _ttoi
134 #define wxAtol _ttol
135 #define wxGetenv _tgetenv
136 #define wxSystem _tsystem
137
138 // time.h functions
139 #define wxAsctime _tasctime
140 #define wxCtime _tctime
141
142 // #elif defined(XXX)
143 // #include XXX-specific files here
144 // typeddef YYY wxChar;
145
146 // translate wxZZZ names
147
148 #elif defined(__BORLANDC__) && defined(__WIN32__)
149
150 // Borland C++ 4.52 doesn't have much tchar support
151 // maybe Borland C++ 5.02 has, can't check right now
152 // but I'll use the Win32 API instead here
153
154 #include <tchar.h>
155 #if wxUSE_UNICODE // temporary - preserve binary compatibility
156 typedef _TCHAR wxChar;
157 typedef _TSCHAR wxSChar;
158 typedef _TUCHAR wxUChar;
159 #else
160 #define wxChar char
161 #define wxSChar signed char
162 #define wxUChar unsigned char
163 #endif
164
165 #include <windef.h>
166 #include <winbase.h>
167 #include <winnls.h>
168 #include <winnt.h>
169
170 // ctype.h functions
171 inline WORD __wxMSW_ctype(wxChar ch)
172 {
173 WORD ret;
174 GetStringTypeEx(LOCALE_USER_DEFAULT, CT_CTYPE1, &ch, 1, &ret);
175 return ret;
176 }
177 #define wxIsalnum(x) IsCharAlphaNumeric
178 #define wxIsalpha IsCharAlpha
179 #define wxIsctrl(x) (__wxMSW_ctype(x) & C1_CNTRL)
180 #define wxIsdigit(x) (__wxMSW_ctype(x) & C1_DIGIT)
181 #define wxIsgraph(x) (__wxMSW_ctype(x) & (C1_DIGIT|C1_PUNCT|C1_ALPHA))
182 #define wxIslower(x) IsCharLower
183 #define wxIsprint(x) (__wxMSW_ctype(x) & (C1_DIGIT|C1_SPACE|C1_PUNCT|C1_ALPHA))
184 #define wxIspunct(x) (__wxMSW_ctype(x) & C1_PUNCT)
185 #define wxIsspace(x) (__wxMSW_ctype(x) & C1_SPACE)
186 #define wxIsupper(x) IsCharUpper
187 #define wxIsxdigit(x) (__wxMSW_ctype(x) & C1_XDIGIT)
188 #define wxTolower(x) (wxChar)CharLower((LPTSTR)(x))
189 #define wxToupper(x) (wxChar)CharUpper((LPTSTR)(x))
190
191 // #define wxStrtok strtok_r // Borland C++ 4.52 doesn't have strtok_r
192 #define wxNEED_WX_STRING_H
193 #define wxNEED_WX_STDIO_H
194 #define wxNEED_WX_STDLIB_H
195 #define wxNEED_WX_TIME_H
196 #define wxNEED_WCSLEN
197
198 #else//!Windows
199
200 // check whether we are doing Unicode
201 #if wxUSE_UNICODE
202
203 #include <wchar.h>
204 #include <wctype.h>
205
206 // this is probably glibc-specific
207 #if defined(__WCHAR_TYPE__)
208
209 typedef __WCHAR_TYPE__ wxChar;
210 typedef signed __WCHAR_TYPE__ wxSChar;
211 typedef unsigned __WCHAR_TYPE__ wxUChar;
212
213 #define _T(x) L##x
214
215 // ctype.h functions (wctype.h)
216 #define wxIsalnum iswalnum
217 #define wxIsalpha iswalpha
218 #define wxIsctrl iswcntrl
219 #define wxIsdigit iswdigit
220 #define wxIsgraph iswgraph
221 #define wxIslower iswlower
222 #define wxIsprint iswprint
223 #define wxIspunct iswpunct
224 #define wxIsspace iswspace
225 #define wxIsupper iswupper
226 #define wxIsxdigit iswxdigit
227
228 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
229 // /usr/include/wctype.h incorrectly declares translations tables which
230 // provokes tons of compile-time warnings - try to correct this
231 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
232 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
233 #else
234 #define wxTolower towlower
235 #define wxToupper towupper
236 #endif // gcc/!gcc
237
238 // string.h functions (wchar.h)
239 #define wxStrcat wcscat
240 #define wxStrchr wcschr
241 #define wxStrcmp wcscmp
242 #define wxStrcoll wcscoll
243 #define wxStrcpy wcscpy
244 #define wxStrcspn wcscspn
245 #define wxStrlen_ wcslen // used in wxStrlen inline function
246 #define wxStrncat wcsncat
247 #define wxStrncmp wcsncmp
248 #define wxStrncpy wcsncpy
249 #define wxStrpbrk wcspbrk
250 #define wxStrrchr wcsrchr
251 #define wxStrspn wcsspn
252 #define wxStrstr wcsstr
253 #define wxStrtod wcstod
254 #define wxStrtok wcstok
255 #define wxStrtol wcstol
256 #define wxStrtoul wcstoul
257 #define wxStrxfrm wcsxfrm
258
259 // glibc doesn't have wc equivalents of the other stuff
260 #define wxNEED_WX_STDIO_H
261 #define wxNEED_WX_STDLIB_H
262 #define wxNEED_WX_TIME_H
263
264 #else//!glibc
265 #error "Please define your compiler's Unicode conventions in wxChar.h"
266 #endif
267 #else//!Unicode
268
269 #include <ctype.h>
270 #include <string.h>
271
272 #if 0 // temporary - preserve binary compatibilty
273 typedef char wxChar;
274 typedef signed char wxSChar;
275 typedef unsigned char wxUChar;
276 #else
277 #define wxChar char
278 #define wxSChar signed char
279 #define wxUChar unsigned char
280 #endif
281
282 #define _T(x) x
283
284 // ctype.h functions
285 #define wxIsalnum isalnum
286 #define wxIsalpha isalpha
287 #define wxIsctrl isctrl
288 #define wxIsdigit isdigit
289 #define wxIsgraph isgraph
290 #define wxIslower islower
291 #define wxIsprint isprint
292 #define wxIspunct ispunct
293 #define wxIsspace isspace
294 #define wxIsupper isupper
295 #define wxIsxdigit isxdigit
296 #define wxTolower tolower
297 #define wxToupper toupper
298
299 // locale.h functons
300 #define wxSetlocale setlocale
301
302 // string.h functions
303 #define wxStricmp strcasecmp
304 // #define wxStrtok strtok_r // this needs a configure check
305
306 // leave the rest to defaults below
307 #define wxNEED_WX_STRING_H
308 #define wxNEED_WX_STDIO_H
309 #define wxNEED_WX_STDLIB_H
310 #define wxNEED_WX_TIME_H
311
312 #endif//Unicode
313 #endif//TCHAR-aware compilers
314
315 // define wxStricmp for various compilers without Unicode possibilities
316 #if !defined(wxStricmp) && !wxUSE_UNICODE
317 #if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__)
318 #define wxStricmp stricmp
319 #elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS) && defined(__INTEL__))
320 #define wxStricmp _stricmp
321 #elif defined(__UNIX__) || defined(__GNUWIN32__)
322 #define wxStricmp strcasecmp
323 #elif defined(__MWERKS__) && !defined(__INTEL__)
324 // use wxWindows' implementation
325 #else
326 // if you leave wxStricmp undefined, wxWindows' implementation will be used
327 #error "Please define string case-insensitive compare for your OS/compiler"
328 #endif
329 #endif
330
331 // if we need to define for standard headers, and we're not using Unicode,
332 // just define to standard C library routines
333 #if !wxUSE_UNICODE
334 #ifdef wxNEED_WX_STRING_H
335 #define wxStrcat strcat
336 #define wxStrchr strchr
337 #define wxStrcmp strcmp
338 #define wxStrcoll strcoll
339 #define wxStrcpy strcpy
340 #define wxStrcspn strcspn
341 #define wxStrdup strdup
342 #define wxStrlen_ strlen // used in wxStrlen inline function
343 #define wxStrncat strncat
344 #define wxStrncmp strncmp
345 #define wxStrncpy strncpy
346 #define wxStrpbrk strpbrk
347 #define wxStrrchr strrchr
348 #define wxStrspn strspn
349 #define wxStrstr strstr
350 #define wxStrtod strtod
351 #define wxStrtol strtol
352 #define wxStrtoul strtoul
353 #define wxStrxfrm strxfrm
354 #undef wxNEED_WX_STRING_H
355 #endif
356
357 #ifdef wxNEED_WX_STDIO_H
358 #define wxFgetc fgetc
359 #define wxFgetchar fgetchar
360 #define wxFgets fgets
361 #define wxFopen fopen
362 #define wxFputc fputc
363 #define wxFputchar fputchar
364 #define wxFprintf fprintf
365 #define wxFreopen freopen
366 #define wxFscanf fscanf
367 #define wxGetc getc
368 #define wxGetchar getchar
369 #define wxGets gets
370 #define wxPerror perror
371 #define wxPrintf printf
372 #define wxPutc putc
373 #define wxPutchar putchar
374 #define wxPuts puts
375 #define wxRemove remove
376 #define wxRename rename
377 #define wxScanf scanf
378 #define wxSprintf sprintf
379 #define wxSscanf sscanf
380 #define wxTmpnam tmpnam
381 #define wxUngetc ungetc
382 #define wxVfprint vfprintf
383 #define wxVprintf vprintf
384 #define wxVsscanf vsscanf
385 #define wxVsprintf vsprintf
386 #undef wxNEED_WX_STDIO_H
387 #endif
388
389 #ifdef wxNEED_WX_STDLIB_H
390 #define wxAtof atof
391 #define wxAtoi atoi
392 #define wxAtol atol
393 #define wxGetenv getenv
394 #define wxSystem system
395 #undef wxNEED_WX_STDLIB_H
396 #endif
397
398 #ifdef wxNEED_WX_TIME_H
399 #define wxAsctime asctime
400 #define wxCtime ctime
401 #define wxStrftime strftime
402 #undef wxNEED_WX_TIME_H
403 #endif
404 #endif //!Unicode
405
406 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
407 #define wcslen wxStrlen
408 #undef wxNEED_WCSLEN
409 #endif
410
411 /// checks whether the passed in pointer is NULL and if the string is empty
412 inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; }
413
414 #ifndef wxNEED_WX_STRING_H
415 /// safe version of strlen() (returns 0 if passed NULL pointer)
416 inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz)
417 { return psz ? wxStrlen_(psz) : 0; }
418 #endif
419
420 // multibyte<->widechar conversion
421 size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n);
422 size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *psz, size_t n);
423 #if wxUSE_UNICODE
424 #define wxMB2WX wxMB2WC
425 #define wxWX2MB wxWC2MB
426 #define wxWC2WX wxStrncpy
427 #define wxWX2WC wxStrncpy
428 #else
429 #define wxMB2WX wxStrncpy
430 #define wxWX2MB wxStrncpy
431 #define wxWC2WX wxWC2MB
432 #define wxWX2WC wxMB2WC
433 #endif
434
435 // if libc versions are not available, use replacements defined in wxchar.cpp
436 #ifndef wxStrdup
437 wxChar * WXDLLEXPORT wxStrdup(const wxChar *psz);
438 #endif
439
440 #ifndef wxStricmp
441 int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2);
442 #endif
443
444 #ifndef wxStrtok
445 wxChar * WXDLLEXPORT wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
446 #endif
447
448 #ifndef wxSetlocale
449 wxChar * WXDLLEXPORT wxSetlocale(int category, const wxChar *locale);
450 #endif
451
452 #ifdef wxNEED_WCSLEN // for use in buffer.h
453 size_t WXDLLEXPORT wcslen(const wchar_t *s);
454 #endif
455
456 #ifdef wxNEED_WX_STRING_H
457 size_t WXDLLEXPORT wxStrlen(const wxChar *s);
458 #endif
459
460 #ifdef wxNEED_WX_STDIO_H
461 #include <stdio.h>
462 #include <stdarg.h>
463 int WXDLLEXPORT wxPrintf(const wxChar *fmt, ...);
464 int WXDLLEXPORT wxVprintf(const wxChar *fmt, va_list argptr);
465 int WXDLLEXPORT wxFprintf(FILE *stream, const wxChar *fmt, ...);
466 int WXDLLEXPORT wxVfprintf(FILE *stream, const wxChar *fmt, va_list argptr);
467 int WXDLLEXPORT wxSprintf(wxChar *buf, const wxChar *fmt, ...);
468 int WXDLLEXPORT wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr);
469 int WXDLLEXPORT wxSscanf(const wxChar *buf, const wxChar *fmt, ...);
470 int WXDLLEXPORT wxVsscanf(const wxChar *buf, const wxChar *fmt, va_list argptr);
471 #endif
472
473 #ifndef wxAtof
474 double WXDLLEXPORT wxAtof(const wxChar *psz);
475 #endif
476
477 #ifdef wxNEED_WX_STDLIB_H
478 int WXDLLEXPORT wxAtoi(const wxChar *psz);
479 long WXDLLEXPORT wxAtol(const wxChar *psz);
480 wxChar * WXDLLEXPORT wxGetenv(const wxChar *name);
481 int WXDLLEXPORT wxSystem(const wxChar *psz);
482 #endif
483
484 #endif
485 //_WX_WXCHAR_H_