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