]> git.saurik.com Git - wxWidgets.git/blame - include/wx/wxchar.h
auto buffer class(es)
[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
34f9227c 24// Windows (VC++) has broad TCHAR support
3f4a0c5b 25#if defined(__VISUALC__) && defined(__WIN32__)
e35d0039
JS
26
27#include <tchar.h>
1cfecdda 28#if wxUSE_UNICODE // temporary - preserve binary compatibility
e35d0039 29typedef _TCHAR wxChar;
3f4a0c5b 30typedef _TSCHAR wxSChar;
e35d0039 31typedef _TUCHAR wxUChar;
1cfecdda
OK
32#else
33#define wxChar char
34#define wxSChar signed char
35#define wxUChar unsigned char
36#endif
e35d0039
JS
37
38 // ctype.h functions
39#define wxIsalnum _istalnum
40#define wxIsalpha _istalpha
41#define wxIsctrl _istctrl
42#define wxIsdigit _istdigit
43#define wxIsgraph _istgraph
44#define wxIslower _istlower
45#define wxIsprint _istprint
46#define wxIspunct _istpunct
47#define wxIsspace _istspace
48#define wxIsupper _istupper
49#define wxIsxdigit _istxdigit
50#define wxTolower _totlower
51#define wxToupper _totupper
52
53 // locale.h functons
54#define wxSetlocale _tsetlocale
55
56 // string.h functions
57#define wxStrcat _tcscat
58#define wxStrchr _tcschr
59#define wxStrcmp _tcscmp
60#define wxStrcoll _tcscoll
61#define wxStrcpy _tcscpy
62#define wxStrcspn _tcscspn
63#define wxStrftime _tcsftime
64#define wxStrncat _tcsncat
65#define wxStrncmp _tcsncmp
66#define wxStrncpy _tcsncpy
67#define wxStrpbrk _tcspbrk
68#define wxStrrchr _tcsrchr
69#define wxStrspn _tcsspn
70#define wxStrstr _tcsstr
71#define wxStrtod _tcstod
72#define wxStrtok _tcstok
73#define wxStrtol _tcstol
74#define wxStrtoul _tcstoul
75#define wxStrxfrm _tcsxfrm
76
77 // stdio.h functions
78#define wxFgetc _fgettc
79#define wxFgetchar _fgettchar
80#define wxFgets _fgetts
81#define wxFopen _tfopen
82#define wxFputc _fputtc
83#define wxFputchar _fputtchar
84#define wxFprintf _ftprintf
85#define wxFreopen _tfreopen
86#define wxFscanf _ftscanf
87#define wxGetc _gettc
88#define wxGetchar _gettchar
89#define wxGets _getts
90#define wxPerror _tperror
91#define wxPrintf _tprintf
92#define wxPutc _puttc
93#define wxPutchar _puttchar
94#define wxPuts _putts
95#define wxRemove _tremove
96#define wxRename _trename
97#define wxScanf _tscanf
98#define wxSprintf _stprintf
99#define wxSscanf _stscanf
100#define wxTmpnam _ttmpnam
101#define wxUngetc _tungetc
102#define wxVfprint _vftprintf
103#define wxVprintf _vtprintf
104#define wxVsprintf _vstprintf
105
106 // stdlib.h functions
107#define wxAtoi _ttoi
108#define wxAtol _ttol
109#define wxGetenv _tgetenv
110#define wxSystem _tsystem
111
112 // time.h functions
113#define wxAsctime _tasctime
114#define wxCtime _tctime
115
116// #elif defined(XXX)
117 // #include XXX-specific files here
118 // typeddef YYY wxChar;
119
120 // translate wxZZZ names
121
34f9227c
OK
122#else//!Windows (VC++)
123
124// check whether we are doing Unicode
125#if wxUSE_UNICODE
126
127#include <wchar.h>
128#include <wctype.h>
129
130// this is probably glibc-specific
131#if defined(__WCHAR_TYPE__)
132
133typedef __WCHAR_TYPE__ wxChar;
134typedef signed __WCHAR_TYPE__ wxSChar;
135typedef unsigned __WCHAR_TYPE__ wxUChar;
136
137#define _T(x) L##x
138
139 // ctype.h functions (wctype.h)
140#define wxIsalnum iswalnum
141#define wxIsalpha iswalpha
142#define wxIsctrl iswcntrl
143#define wxIsdigit iswdigit
144#define wxIsgraph iswgraph
145#define wxIslower iswlower
146#define wxIsprint iswprint
147#define wxIspunct iswpunct
148#define wxIsspace iswspace
149#define wxIsupper iswupper
150#define wxIsxdigit iswxdigit
151#define wxTolower towlower
152#define wxToupper towupper
153
154 // string.h functions (wchar.h)
155#define wxStrcat wcscat
156#define wxStrchr wcschr
157#define wxStrcmp wcscmp
158#define wxStrcoll wcscoll
159#define wxStrcpy wcscpy
160#define wxStrcspn wcscspn
161#define wxStrncat wcsncat
162#define wxStrncmp wcsncmp
163#define wxStrncpy wcsncpy
164#define wxStrpbrk wcspbrk
165#define wxStrrchr wcsrchr
166#define wxStrspn wcsspn
167#define wxStrstr wcsstr
168#define wxStrtod wcstod
169#define wxStrtok wcstok
170#define wxStrtol wcstol
171#define wxStrtoul wcstoul
172#define wxStrxfrm wcsxfrm
e35d0039 173
34f9227c
OK
174// glibc doesn't have wc equivalents of the other stuff
175// do we need to write wrappers for them?
176
177#else
e35d0039
JS
178#error "Please define your compiler's Unicode conventions in wxChar.h"
179#endif
34f9227c 180#else//!Unicode
e35d0039 181
1cfecdda 182#if 0 // temporary - preserve binary compatibilty
3f4a0c5b
VZ
183typedef char wxChar;
184typedef signed char wxSChar;
185typedef unsigned char wxUChar;
1cfecdda
OK
186#else
187#define wxChar char
188#define wxSChar signed char
189#define wxUChar unsigned char
190#endif
e35d0039 191
3f4a0c5b 192#define _T(x) x
e35d0039
JS
193
194 // ctype.h functions
195#define wxIsalnum isalnum
196#define wxIsalpha isalpha
197#define wxIsctrl isctrl
198#define wxIsdigit isdigit
199#define wxIsgraph isgraph
200#define wxIslower islower
201#define wxIsprint isprint
202#define wxIspunct ispunct
203#define wxIsspace isspace
204#define wxIsupper isupper
205#define wxIsxdigit isxdigit
206#define wxTolower tolower
207#define wxToupper toupper
208
209 // locale.h functons
210#define wxSetlocale setlocale
211
212 // string.h functions
213#define wxStrcat strcat
214#define wxStrchr strchr
215#define wxStrcmp strcmp
216#define wxStrcoll strcoll
217#define wxStrcpy strcpy
218#define wxStrcspn strcspn
e35d0039
JS
219#define wxStrncat strncat
220#define wxStrncmp strncmp
221#define wxStrncpy strncpy
222#define wxStrpbrk strpbrk
223#define wxStrrchr strrchr
224#define wxStrspn strspn
225#define wxStrstr strstr
226#define wxStrtod strtod
227#define wxStrtok strtok
228#define wxStrtol strtol
229#define wxStrtoul strtoul
230#define wxStrxfrm strxfrm
231
232 // stdio.h functions
233#define wxFgetc fgetc
234#define wxFgetchar fgetchar
235#define wxFgets fgets
236#define wxFopen fopen
237#define wxFputc fputc
238#define wxFputchar fputchar
239#define wxFprintf fprintf
240#define wxFreopen freopen
241#define wxFscanf fscanf
242#define wxGetc getc
243#define wxGetchar getchar
244#define wxGets gets
245#define wxPerror perror
246#define wxPrintf printf
247#define wxPutc putc
248#define wxPutchar putchar
249#define wxPuts puts
250#define wxRemove remove
251#define wxRename rename
252#define wxScanf scanf
253#define wxSprintf sprintf
254#define wxSscanf sscanf
255#define wxTmpnam tmpnam
256#define wxUngetc ungetc
257#define wxVfprint vfprintf
258#define wxVprintf vprintf
259#define wxVsprintf vsprintf
260
261 // stdlib.h functions
262#define wxAtoi atoi
263#define wxAtol atol
264#define wxGetenv getenv
265#define wxSystem system
266
267 // time.h functions
268#define wxAsctime asctime
269#define wxCtime ctime
34f9227c 270#define wxStrftime strftime
e35d0039
JS
271
272#endif//Unicode
34f9227c 273#endif
e35d0039
JS
274
275
276/// checks whether the passed in pointer is NULL and if the string is empty
277inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; }
278
279/// safe version of strlen() (returns 0 if passed NULL pointer)
639a9fb5 280inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz)
3f4a0c5b 281#if defined(__VISUALC__)
e35d0039 282 { return psz ? _tcslen(psz) : 0; }
34f9227c
OK
283#elif wxUSE_UNICODE
284 { return psz ? wcslen(psz) : 0; }
e35d0039
JS
285#else
286 { return psz ? strlen(psz) : 0; }
287#endif
288
289/// portable strcasecmp/_stricmp
34f9227c 290inline int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2)
3f4a0c5b 291#if defined(__VISUALC__)
e35d0039 292 { return _tcsicmp(psz1, psz2); }
34f9227c 293#elif defined(__BORLANDC__) && !wxUSE_UNICODE
e35d0039 294 { return stricmp(psz1, psz2); }
34f9227c
OK
295#elif defined(__UNIX__) || defined(__GNUWIN32__)
296#if !wxUSE_UNICODE
e35d0039 297 { return strcasecmp(psz1, psz2); }
34f9227c
OK
298#else // glibc doesn't seem to have wide char equivalent
299 {
300 register wxChar c1, c2;
301 do {
302 c1 = wxTolower(*psz1++);
303 c2 = wxTolower(*psz2++);
304 } while ( c1 && (c1 == c2) );
305
306 return c1 - c2;
307 }
308#endif
e35d0039
JS
309#else
310 // almost all compilers/libraries provide this function (unfortunately under
311 // different names), that's why we don't implement our own which will surely
312 // be more efficient than this code (uncomment to use):
313 /*
34f9227c 314 register wxChar c1, c2;
e35d0039 315 do {
34f9227c
OK
316 c1 = wxTolower(*psz1++);
317 c2 = wxTolower(*psz2++);
e35d0039
JS
318 } while ( c1 && (c1 == c2) );
319
320 return c1 - c2;
321 */
3f4a0c5b 322
e35d0039
JS
323 #error "Please define string case-insensitive compare for your OS/compiler"
324#endif // OS/compiler
325
639a9fb5
OK
326/// portable strdup
327inline wxChar * WXDLLEXPORT wxStrdup(const wxChar *psz)
328#if !wxUSE_UNICODE
329 { return strdup(psz); }
330#else
331 {
332 size_t size = (wxStrlen(psz) + 1) * sizeof(wxChar);
333 wxChar *ret = (wxChar *) malloc(size);
334 memcpy(ret, psz, size);
335 return ret;
336 }
337#endif
338
e35d0039
JS
339#endif
340 //_WX_WXCHAR_H_