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