]>
Commit | Line | Data |
---|---|---|
e35d0039 JS |
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 | ||
853d7d3d OK |
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 | ||
34f9227c | 44 | // Windows (VC++) has broad TCHAR support |
3f4a0c5b | 45 | #if defined(__VISUALC__) && defined(__WIN32__) |
e35d0039 JS |
46 | |
47 | #include <tchar.h> | |
1cfecdda | 48 | #if wxUSE_UNICODE // temporary - preserve binary compatibility |
e35d0039 | 49 | typedef _TCHAR wxChar; |
3f4a0c5b | 50 | typedef _TSCHAR wxSChar; |
e35d0039 | 51 | typedef _TUCHAR wxUChar; |
1cfecdda OK |
52 | #else |
53 | #define wxChar char | |
54 | #define wxSChar signed char | |
55 | #define wxUChar unsigned char | |
56 | #endif | |
e35d0039 JS |
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 | |
853d7d3d OK |
84 | #define wxStricmp _tcsicmp |
85 | #define wxStrlen_ _tcslen // used in wxStrlen inline function | |
e35d0039 JS |
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 | |
e97a90f0 | 94 | // is there a _tcstok[_r] ? |
e35d0039 JS |
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 | |
ea1395db | 126 | #define wxVsscanf _vstscanf |
e35d0039 JS |
127 | #define wxVsprintf _vstprintf |
128 | ||
129 | // stdlib.h functions | |
a982ddd2 OK |
130 | #if !wxUSE_UNICODE |
131 | #define wxAtof atof | |
132 | #endif | |
e35d0039 JS |
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 | ||
853d7d3d OK |
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 | |
34f9227c OK |
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 | |
0fea8a59 | 227 | |
c1160779 | 228 | #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0) |
0fea8a59 VZ |
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 | |
34f9227c OK |
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 | |
853d7d3d | 245 | #define wxStrlen_ wcslen // used in wxStrlen inline function |
34f9227c OK |
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 | |
e35d0039 | 258 | |
34f9227c | 259 | // glibc doesn't have wc equivalents of the other stuff |
e97a90f0 OK |
260 | #define wxNEED_WX_STDIO_H |
261 | #define wxNEED_WX_STDLIB_H | |
262 | #define wxNEED_WX_TIME_H | |
34f9227c | 263 | |
853d7d3d | 264 | #else//!glibc |
e35d0039 JS |
265 | #error "Please define your compiler's Unicode conventions in wxChar.h" |
266 | #endif | |
34f9227c | 267 | #else//!Unicode |
e35d0039 | 268 | |
e97a90f0 OK |
269 | #include <ctype.h> |
270 | #include <string.h> | |
271 | ||
1cfecdda | 272 | #if 0 // temporary - preserve binary compatibilty |
3f4a0c5b VZ |
273 | typedef char wxChar; |
274 | typedef signed char wxSChar; | |
275 | typedef unsigned char wxUChar; | |
1cfecdda OK |
276 | #else |
277 | #define wxChar char | |
278 | #define wxSChar signed char | |
279 | #define wxUChar unsigned char | |
280 | #endif | |
e35d0039 | 281 | |
3f4a0c5b | 282 | #define _T(x) x |
e35d0039 JS |
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 | |
853d7d3d OK |
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 | |
e35d0039 JS |
335 | #define wxStrcat strcat |
336 | #define wxStrchr strchr | |
337 | #define wxStrcmp strcmp | |
338 | #define wxStrcoll strcoll | |
339 | #define wxStrcpy strcpy | |
340 | #define wxStrcspn strcspn | |
e97a90f0 | 341 | #define wxStrdup strdup |
853d7d3d | 342 | #define wxStrlen_ strlen // used in wxStrlen inline function |
e35d0039 JS |
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 | |
e35d0039 JS |
351 | #define wxStrtol strtol |
352 | #define wxStrtoul strtoul | |
353 | #define wxStrxfrm strxfrm | |
853d7d3d OK |
354 | #undef wxNEED_WX_STRING_H |
355 | #endif | |
e35d0039 | 356 | |
853d7d3d | 357 | #ifdef wxNEED_WX_STDIO_H |
e35d0039 JS |
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 | |
ea1395db | 384 | #define wxVsscanf vsscanf |
e35d0039 | 385 | #define wxVsprintf vsprintf |
853d7d3d OK |
386 | #undef wxNEED_WX_STDIO_H |
387 | #endif | |
e35d0039 | 388 | |
853d7d3d | 389 | #ifdef wxNEED_WX_STDLIB_H |
e97a90f0 | 390 | #define wxAtof atof |
e35d0039 JS |
391 | #define wxAtoi atoi |
392 | #define wxAtol atol | |
393 | #define wxGetenv getenv | |
394 | #define wxSystem system | |
853d7d3d OK |
395 | #undef wxNEED_WX_STDLIB_H |
396 | #endif | |
e35d0039 | 397 | |
853d7d3d | 398 | #ifdef wxNEED_WX_TIME_H |
e35d0039 JS |
399 | #define wxAsctime asctime |
400 | #define wxCtime ctime | |
34f9227c | 401 | #define wxStrftime strftime |
853d7d3d | 402 | #undef wxNEED_WX_TIME_H |
34f9227c | 403 | #endif |
853d7d3d | 404 | #endif //!Unicode |
e35d0039 | 405 | |
853d7d3d OK |
406 | #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE |
407 | #define wcslen wxStrlen | |
408 | #undef wxNEED_WCSLEN | |
409 | #endif | |
e35d0039 JS |
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 | ||
853d7d3d | 414 | #ifndef wxNEED_WX_STRING_H |
e35d0039 | 415 | /// safe version of strlen() (returns 0 if passed NULL pointer) |
639a9fb5 | 416 | inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz) |
853d7d3d | 417 | { return psz ? wxStrlen_(psz) : 0; } |
34f9227c | 418 | #endif |
e35d0039 | 419 | |
e97a90f0 OK |
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 | |
639a9fb5 | 428 | #else |
e97a90f0 OK |
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 | ||
0841bffa OK |
440 | #ifndef wxStricmp |
441 | int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2); | |
442 | #endif | |
443 | ||
e97a90f0 OK |
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 | ||
853d7d3d OK |
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 | |
06c545a7 | 457 | int WXDLLEXPORT wxStrcmp(const wxChar *psz1, const wxChar *psz2); |
853d7d3d OK |
458 | size_t WXDLLEXPORT wxStrlen(const wxChar *s); |
459 | #endif | |
460 | ||
e97a90f0 | 461 | #ifdef wxNEED_WX_STDIO_H |
c1160779 | 462 | #include <stdio.h> |
e97a90f0 | 463 | #include <stdarg.h> |
7c337432 OK |
464 | int WXDLLEXPORT wxPrintf(const wxChar *fmt, ...); |
465 | int WXDLLEXPORT wxVprintf(const wxChar *fmt, va_list argptr); | |
c1160779 OK |
466 | int WXDLLEXPORT wxFprintf(FILE *stream, const wxChar *fmt, ...); |
467 | int WXDLLEXPORT wxVfprintf(FILE *stream, const wxChar *fmt, va_list argptr); | |
e97a90f0 OK |
468 | int WXDLLEXPORT wxSprintf(wxChar *buf, const wxChar *fmt, ...); |
469 | int WXDLLEXPORT wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr); | |
ea1395db OK |
470 | int WXDLLEXPORT wxSscanf(const wxChar *buf, const wxChar *fmt, ...); |
471 | int WXDLLEXPORT wxVsscanf(const wxChar *buf, const wxChar *fmt, va_list argptr); | |
e97a90f0 OK |
472 | #endif |
473 | ||
a982ddd2 | 474 | #ifndef wxAtof |
e97a90f0 | 475 | double WXDLLEXPORT wxAtof(const wxChar *psz); |
a982ddd2 OK |
476 | #endif |
477 | ||
478 | #ifdef wxNEED_WX_STDLIB_H | |
e97a90f0 OK |
479 | int WXDLLEXPORT wxAtoi(const wxChar *psz); |
480 | long WXDLLEXPORT wxAtol(const wxChar *psz); | |
481 | wxChar * WXDLLEXPORT wxGetenv(const wxChar *name); | |
482 | int WXDLLEXPORT wxSystem(const wxChar *psz); | |
639a9fb5 OK |
483 | #endif |
484 | ||
e35d0039 JS |
485 | #endif |
486 | //_WX_WXCHAR_H_ |