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