]>
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 | ||
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 | 29 | typedef _TCHAR wxChar; |
3f4a0c5b | 30 | typedef _TSCHAR wxSChar; |
e35d0039 | 31 | typedef _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 | |
e97a90f0 | 72 | // is there a _tcstok[_r] ? |
e35d0039 JS |
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 | |
e97a90f0 | 107 | #define wxAtof _ttof /* does this exist? */ |
e35d0039 JS |
108 | #define wxAtoi _ttoi |
109 | #define wxAtol _ttol | |
110 | #define wxGetenv _tgetenv | |
111 | #define wxSystem _tsystem | |
112 | ||
113 | // time.h functions | |
114 | #define wxAsctime _tasctime | |
115 | #define wxCtime _tctime | |
116 | ||
117 | // #elif defined(XXX) | |
118 | // #include XXX-specific files here | |
119 | // typeddef YYY wxChar; | |
120 | ||
121 | // translate wxZZZ names | |
122 | ||
34f9227c OK |
123 | #else//!Windows (VC++) |
124 | ||
125 | // check whether we are doing Unicode | |
126 | #if wxUSE_UNICODE | |
127 | ||
128 | #include <wchar.h> | |
129 | #include <wctype.h> | |
130 | ||
131 | // this is probably glibc-specific | |
132 | #if defined(__WCHAR_TYPE__) | |
133 | ||
134 | typedef __WCHAR_TYPE__ wxChar; | |
135 | typedef signed __WCHAR_TYPE__ wxSChar; | |
136 | typedef unsigned __WCHAR_TYPE__ wxUChar; | |
137 | ||
138 | #define _T(x) L##x | |
139 | ||
140 | // ctype.h functions (wctype.h) | |
141 | #define wxIsalnum iswalnum | |
142 | #define wxIsalpha iswalpha | |
143 | #define wxIsctrl iswcntrl | |
144 | #define wxIsdigit iswdigit | |
145 | #define wxIsgraph iswgraph | |
146 | #define wxIslower iswlower | |
147 | #define wxIsprint iswprint | |
148 | #define wxIspunct iswpunct | |
149 | #define wxIsspace iswspace | |
150 | #define wxIsupper iswupper | |
151 | #define wxIsxdigit iswxdigit | |
152 | #define wxTolower towlower | |
153 | #define wxToupper towupper | |
154 | ||
155 | // string.h functions (wchar.h) | |
156 | #define wxStrcat wcscat | |
157 | #define wxStrchr wcschr | |
158 | #define wxStrcmp wcscmp | |
159 | #define wxStrcoll wcscoll | |
160 | #define wxStrcpy wcscpy | |
161 | #define wxStrcspn wcscspn | |
162 | #define wxStrncat wcsncat | |
163 | #define wxStrncmp wcsncmp | |
164 | #define wxStrncpy wcsncpy | |
165 | #define wxStrpbrk wcspbrk | |
166 | #define wxStrrchr wcsrchr | |
167 | #define wxStrspn wcsspn | |
168 | #define wxStrstr wcsstr | |
169 | #define wxStrtod wcstod | |
170 | #define wxStrtok wcstok | |
171 | #define wxStrtol wcstol | |
172 | #define wxStrtoul wcstoul | |
173 | #define wxStrxfrm wcsxfrm | |
e35d0039 | 174 | |
34f9227c | 175 | // glibc doesn't have wc equivalents of the other stuff |
e97a90f0 OK |
176 | #define wxNEED_WX_STDIO_H |
177 | #define wxNEED_WX_STDLIB_H | |
178 | #define wxNEED_WX_TIME_H | |
34f9227c OK |
179 | |
180 | #else | |
e35d0039 JS |
181 | #error "Please define your compiler's Unicode conventions in wxChar.h" |
182 | #endif | |
34f9227c | 183 | #else//!Unicode |
e35d0039 | 184 | |
e97a90f0 OK |
185 | #include <ctype.h> |
186 | #include <string.h> | |
187 | ||
1cfecdda | 188 | #if 0 // temporary - preserve binary compatibilty |
3f4a0c5b VZ |
189 | typedef char wxChar; |
190 | typedef signed char wxSChar; | |
191 | typedef unsigned char wxUChar; | |
1cfecdda OK |
192 | #else |
193 | #define wxChar char | |
194 | #define wxSChar signed char | |
195 | #define wxUChar unsigned char | |
196 | #endif | |
e35d0039 | 197 | |
3f4a0c5b | 198 | #define _T(x) x |
e35d0039 JS |
199 | |
200 | // ctype.h functions | |
201 | #define wxIsalnum isalnum | |
202 | #define wxIsalpha isalpha | |
203 | #define wxIsctrl isctrl | |
204 | #define wxIsdigit isdigit | |
205 | #define wxIsgraph isgraph | |
206 | #define wxIslower islower | |
207 | #define wxIsprint isprint | |
208 | #define wxIspunct ispunct | |
209 | #define wxIsspace isspace | |
210 | #define wxIsupper isupper | |
211 | #define wxIsxdigit isxdigit | |
212 | #define wxTolower tolower | |
213 | #define wxToupper toupper | |
214 | ||
215 | // locale.h functons | |
216 | #define wxSetlocale setlocale | |
217 | ||
218 | // string.h functions | |
219 | #define wxStrcat strcat | |
220 | #define wxStrchr strchr | |
221 | #define wxStrcmp strcmp | |
222 | #define wxStrcoll strcoll | |
223 | #define wxStrcpy strcpy | |
224 | #define wxStrcspn strcspn | |
e97a90f0 | 225 | #define wxStrdup strdup |
e35d0039 JS |
226 | #define wxStrncat strncat |
227 | #define wxStrncmp strncmp | |
228 | #define wxStrncpy strncpy | |
229 | #define wxStrpbrk strpbrk | |
230 | #define wxStrrchr strrchr | |
231 | #define wxStrspn strspn | |
232 | #define wxStrstr strstr | |
233 | #define wxStrtod strtod | |
e97a90f0 | 234 | // #define wxStrtok strtok_r // this needs a configure check |
e35d0039 JS |
235 | #define wxStrtol strtol |
236 | #define wxStrtoul strtoul | |
237 | #define wxStrxfrm strxfrm | |
238 | ||
239 | // stdio.h functions | |
240 | #define wxFgetc fgetc | |
241 | #define wxFgetchar fgetchar | |
242 | #define wxFgets fgets | |
243 | #define wxFopen fopen | |
244 | #define wxFputc fputc | |
245 | #define wxFputchar fputchar | |
246 | #define wxFprintf fprintf | |
247 | #define wxFreopen freopen | |
248 | #define wxFscanf fscanf | |
249 | #define wxGetc getc | |
250 | #define wxGetchar getchar | |
251 | #define wxGets gets | |
252 | #define wxPerror perror | |
253 | #define wxPrintf printf | |
254 | #define wxPutc putc | |
255 | #define wxPutchar putchar | |
256 | #define wxPuts puts | |
257 | #define wxRemove remove | |
258 | #define wxRename rename | |
259 | #define wxScanf scanf | |
260 | #define wxSprintf sprintf | |
261 | #define wxSscanf sscanf | |
262 | #define wxTmpnam tmpnam | |
263 | #define wxUngetc ungetc | |
264 | #define wxVfprint vfprintf | |
265 | #define wxVprintf vprintf | |
266 | #define wxVsprintf vsprintf | |
267 | ||
268 | // stdlib.h functions | |
e97a90f0 | 269 | #define wxAtof atof |
e35d0039 JS |
270 | #define wxAtoi atoi |
271 | #define wxAtol atol | |
272 | #define wxGetenv getenv | |
273 | #define wxSystem system | |
274 | ||
275 | // time.h functions | |
276 | #define wxAsctime asctime | |
277 | #define wxCtime ctime | |
34f9227c | 278 | #define wxStrftime strftime |
e35d0039 JS |
279 | |
280 | #endif//Unicode | |
34f9227c | 281 | #endif |
e35d0039 JS |
282 | |
283 | ||
284 | /// checks whether the passed in pointer is NULL and if the string is empty | |
285 | inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; } | |
286 | ||
287 | /// safe version of strlen() (returns 0 if passed NULL pointer) | |
639a9fb5 | 288 | inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz) |
3f4a0c5b | 289 | #if defined(__VISUALC__) |
e35d0039 | 290 | { return psz ? _tcslen(psz) : 0; } |
34f9227c OK |
291 | #elif wxUSE_UNICODE |
292 | { return psz ? wcslen(psz) : 0; } | |
e35d0039 JS |
293 | #else |
294 | { return psz ? strlen(psz) : 0; } | |
295 | #endif | |
296 | ||
297 | /// portable strcasecmp/_stricmp | |
34f9227c | 298 | inline int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2) |
3f4a0c5b | 299 | #if defined(__VISUALC__) |
e35d0039 | 300 | { return _tcsicmp(psz1, psz2); } |
34f9227c | 301 | #elif defined(__BORLANDC__) && !wxUSE_UNICODE |
e35d0039 | 302 | { return stricmp(psz1, psz2); } |
34f9227c OK |
303 | #elif defined(__UNIX__) || defined(__GNUWIN32__) |
304 | #if !wxUSE_UNICODE | |
e35d0039 | 305 | { return strcasecmp(psz1, psz2); } |
34f9227c OK |
306 | #else // glibc doesn't seem to have wide char equivalent |
307 | { | |
308 | register wxChar c1, c2; | |
309 | do { | |
310 | c1 = wxTolower(*psz1++); | |
311 | c2 = wxTolower(*psz2++); | |
312 | } while ( c1 && (c1 == c2) ); | |
313 | ||
314 | return c1 - c2; | |
315 | } | |
316 | #endif | |
e35d0039 JS |
317 | #else |
318 | // almost all compilers/libraries provide this function (unfortunately under | |
319 | // different names), that's why we don't implement our own which will surely | |
320 | // be more efficient than this code (uncomment to use): | |
321 | /* | |
34f9227c | 322 | register wxChar c1, c2; |
e35d0039 | 323 | do { |
34f9227c OK |
324 | c1 = wxTolower(*psz1++); |
325 | c2 = wxTolower(*psz2++); | |
e35d0039 JS |
326 | } while ( c1 && (c1 == c2) ); |
327 | ||
328 | return c1 - c2; | |
329 | */ | |
3f4a0c5b | 330 | |
e35d0039 JS |
331 | #error "Please define string case-insensitive compare for your OS/compiler" |
332 | #endif // OS/compiler | |
333 | ||
e97a90f0 OK |
334 | // multibyte<->widechar conversion |
335 | size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n); | |
336 | size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *psz, size_t n); | |
337 | #if wxUSE_UNICODE | |
338 | #define wxMB2WX wxMB2WC | |
339 | #define wxWX2MB wxWC2MB | |
340 | #define wxWC2WX wxStrncpy | |
341 | #define wxWX2WC wxStrncpy | |
639a9fb5 | 342 | #else |
e97a90f0 OK |
343 | #define wxMB2WX wxStrncpy |
344 | #define wxWX2MB wxStrncpy | |
345 | #define wxWC2WX wxWC2MB | |
346 | #define wxWX2WC wxMB2WC | |
347 | #endif | |
348 | ||
349 | // if libc versions are not available, use replacements defined in wxchar.cpp | |
350 | #ifndef wxStrdup | |
351 | wxChar * WXDLLEXPORT wxStrdup(const wxChar *psz); | |
352 | #endif | |
353 | ||
354 | #ifndef wxStrtok | |
355 | wxChar * WXDLLEXPORT wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr); | |
356 | #endif | |
357 | ||
358 | #ifndef wxSetlocale | |
359 | wxChar * WXDLLEXPORT wxSetlocale(int category, const wxChar *locale); | |
360 | #endif | |
361 | ||
362 | #ifdef wxNEED_WX_STDIO_H | |
363 | #include <stdarg.h> | |
364 | int WXDLLEXPORT wxSprintf(wxChar *buf, const wxChar *fmt, ...); | |
365 | int WXDLLEXPORT wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr); | |
366 | #endif | |
367 | ||
368 | #ifdef wxNEED_WX_STDLIB_H | |
369 | double WXDLLEXPORT wxAtof(const wxChar *psz); | |
370 | int WXDLLEXPORT wxAtoi(const wxChar *psz); | |
371 | long WXDLLEXPORT wxAtol(const wxChar *psz); | |
372 | wxChar * WXDLLEXPORT wxGetenv(const wxChar *name); | |
373 | int WXDLLEXPORT wxSystem(const wxChar *psz); | |
639a9fb5 OK |
374 | #endif |
375 | ||
e35d0039 JS |
376 | #endif |
377 | //_WX_WXCHAR_H_ |