]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
Here it comes:
[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 // Windows (VC++) has broad TCHAR support
25 #if defined(__VISUALC__) && defined(__WIN32__)
26
27 #include <tchar.h>
28 #if wxUSE_UNICODE // temporary - preserve binary compatibility
29 typedef _TCHAR wxChar;
30 typedef _TSCHAR wxSChar;
31 typedef _TUCHAR wxUChar;
32 #else
33 #define wxChar char
34 #define wxSChar signed char
35 #define wxUChar unsigned char
36 #endif
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
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
133 typedef __WCHAR_TYPE__ wxChar;
134 typedef signed __WCHAR_TYPE__ wxSChar;
135 typedef 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
173
174 // glibc doesn't have wc equivalents of the other stuff
175 // do we need to write wrappers for them?
176
177 #else
178 #error "Please define your compiler's Unicode conventions in wxChar.h"
179 #endif
180 #else//!Unicode
181
182 #if 0 // temporary - preserve binary compatibilty
183 typedef char wxChar;
184 typedef signed char wxSChar;
185 typedef unsigned char wxUChar;
186 #else
187 #define wxChar char
188 #define wxSChar signed char
189 #define wxUChar unsigned char
190 #endif
191
192 #define _T(x) x
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
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
270 #define wxStrftime strftime
271
272 #endif//Unicode
273 #endif
274
275
276 /// checks whether the passed in pointer is NULL and if the string is empty
277 inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; }
278
279 /// safe version of strlen() (returns 0 if passed NULL pointer)
280 inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz)
281 #if defined(__VISUALC__)
282 { return psz ? _tcslen(psz) : 0; }
283 #elif wxUSE_UNICODE
284 { return psz ? wcslen(psz) : 0; }
285 #else
286 { return psz ? strlen(psz) : 0; }
287 #endif
288
289 /// portable strcasecmp/_stricmp
290 inline int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2)
291 #if defined(__VISUALC__)
292 { return _tcsicmp(psz1, psz2); }
293 #elif defined(__BORLANDC__) && !wxUSE_UNICODE
294 { return stricmp(psz1, psz2); }
295 #elif defined(__UNIX__) || defined(__GNUWIN32__)
296 #if !wxUSE_UNICODE
297 { return strcasecmp(psz1, psz2); }
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
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 /*
314 register wxChar c1, c2;
315 do {
316 c1 = wxTolower(*psz1++);
317 c2 = wxTolower(*psz2++);
318 } while ( c1 && (c1 == c2) );
319
320 return c1 - c2;
321 */
322
323 #error "Please define string case-insensitive compare for your OS/compiler"
324 #endif // OS/compiler
325
326 #endif
327 //_WX_WXCHAR_H_