]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Declarations common to wx char/wchar_t usage (wide chars)
8 // Copyright: (c) wxWindows copyright
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "wxchar.h"
19 // only do SBCS or _UNICODE
21 #error "MBCS is not supported by wxChar"
24 // set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
25 #if defined(_UNICODE) || defined(UNICODE)
27 #define wxUSE_UNICODE 1
30 #define wxUSE_UNICODE 0
34 // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
44 // Windows (VC++) has broad TCHAR support
45 #if defined(__VISUALC__) && defined(__WIN32__)
48 #if wxUSE_UNICODE // temporary - preserve binary compatibility
49 typedef _TCHAR wxChar
;
50 typedef _TSCHAR wxSChar
;
51 typedef _TUCHAR wxUChar
;
54 #define wxSChar signed char
55 #define wxUChar unsigned char
59 #define wxIsalnum _istalnum
60 #define wxIsalpha _istalpha
61 #define wxIsctrl _istctrl
62 #define wxIsdigit _istdigit
63 #define wxIsgraph _istgraph
64 #define wxIslower _istlower
65 #define wxIsprint _istprint
66 #define wxIspunct _istpunct
67 #define wxIsspace _istspace
68 #define wxIsupper _istupper
69 #define wxIsxdigit _istxdigit
70 #define wxTolower _totlower
71 #define wxToupper _totupper
74 #define wxSetlocale _tsetlocale
77 #define wxStrcat _tcscat
78 #define wxStrchr _tcschr
79 #define wxStrcmp _tcscmp
80 #define wxStrcoll _tcscoll
81 #define wxStrcpy _tcscpy
82 #define wxStrcspn _tcscspn
83 #define wxStrftime _tcsftime
84 #define wxStricmp _tcsicmp
85 #define wxStrlen_ _tcslen // used in wxStrlen inline function
86 #define wxStrncat _tcsncat
87 #define wxStrncmp _tcsncmp
88 #define wxStrncpy _tcsncpy
89 #define wxStrpbrk _tcspbrk
90 #define wxStrrchr _tcsrchr
91 #define wxStrspn _tcsspn
92 #define wxStrstr _tcsstr
93 #define wxStrtod _tcstod
94 // is there a _tcstok[_r] ?
95 #define wxStrtol _tcstol
96 #define wxStrtoul _tcstoul
97 #define wxStrxfrm _tcsxfrm
100 #define wxFgetc _fgettc
101 #define wxFgetchar _fgettchar
102 #define wxFgets _fgetts
103 #define wxFopen _tfopen
104 #define wxFputc _fputtc
105 #define wxFputchar _fputtchar
106 #define wxFprintf _ftprintf
107 #define wxFreopen _tfreopen
108 #define wxFscanf _ftscanf
109 #define wxGetc _gettc
110 #define wxGetchar _gettchar
111 #define wxGets _getts
112 #define wxPerror _tperror
113 #define wxPrintf _tprintf
114 #define wxPutc _puttc
115 #define wxPutchar _puttchar
116 #define wxPuts _putts
117 #define wxRemove _tremove
118 #define wxRename _trename
119 #define wxScanf _tscanf
120 #define wxSprintf _stprintf
121 #define wxSscanf _stscanf
122 #define wxTmpnam _ttmpnam
123 #define wxUngetc _tungetc
124 #define wxVfprint _vftprintf
125 #define wxVprintf _vtprintf
126 #define wxVsscanf _vstscanf
127 #define wxVsprintf _vstprintf
129 // stdlib.h functions
135 #define wxGetenv _tgetenv
136 #define wxSystem _tsystem
139 #define wxAsctime _tasctime
140 #define wxCtime _tctime
142 // #elif defined(XXX)
143 // #include XXX-specific files here
144 // typeddef YYY wxChar;
146 // translate wxZZZ names
148 #elif defined(__BORLANDC__) && defined(__WIN32__)
150 // Borland C++ 4.52 doesn't have much tchar support
151 // maybe Borland C++ 5.02 has, can't check right now
152 // but I'll use the Win32 API instead here
155 #if wxUSE_UNICODE // temporary - preserve binary compatibility
156 typedef _TCHAR wxChar
;
157 typedef _TSCHAR wxSChar
;
158 typedef _TUCHAR wxUChar
;
161 #define wxSChar signed char
162 #define wxUChar unsigned char
171 inline WORD
__wxMSW_ctype(wxChar ch
)
174 GetStringTypeEx(LOCALE_USER_DEFAULT
, CT_CTYPE1
, &ch
, 1, &ret
);
177 #define wxIsalnum(x) IsCharAlphaNumeric
178 #define wxIsalpha IsCharAlpha
179 #define wxIsctrl(x) (__wxMSW_ctype(x) & C1_CNTRL)
180 #define wxIsdigit(x) (__wxMSW_ctype(x) & C1_DIGIT)
181 #define wxIsgraph(x) (__wxMSW_ctype(x) & (C1_DIGIT|C1_PUNCT|C1_ALPHA))
182 #define wxIslower(x) IsCharLower
183 #define wxIsprint(x) (__wxMSW_ctype(x) & (C1_DIGIT|C1_SPACE|C1_PUNCT|C1_ALPHA))
184 #define wxIspunct(x) (__wxMSW_ctype(x) & C1_PUNCT)
185 #define wxIsspace(x) (__wxMSW_ctype(x) & C1_SPACE)
186 #define wxIsupper(x) IsCharUpper
187 #define wxIsxdigit(x) (__wxMSW_ctype(x) & C1_XDIGIT)
188 #define wxTolower(x) (wxChar)CharLower((LPTSTR)(x))
189 #define wxToupper(x) (wxChar)CharUpper((LPTSTR)(x))
191 // #define wxStrtok strtok_r // Borland C++ 4.52 doesn't have strtok_r
192 #define wxNEED_WX_STRING_H
193 #define wxNEED_WX_STDIO_H
194 #define wxNEED_WX_STDLIB_H
195 #define wxNEED_WX_TIME_H
196 #define wxNEED_WCSLEN
200 // check whether we are doing Unicode
206 // this is probably glibc-specific
207 #if defined(__WCHAR_TYPE__)
209 typedef __WCHAR_TYPE__ wxChar
;
210 typedef signed __WCHAR_TYPE__ wxSChar
;
211 typedef unsigned __WCHAR_TYPE__ wxUChar
;
215 // ctype.h functions (wctype.h)
216 #define wxIsalnum iswalnum
217 #define wxIsalpha iswalpha
218 #define wxIsctrl iswcntrl
219 #define wxIsdigit iswdigit
220 #define wxIsgraph iswgraph
221 #define wxIslower iswlower
222 #define wxIsprint iswprint
223 #define wxIspunct iswpunct
224 #define wxIsspace iswspace
225 #define wxIsupper iswupper
226 #define wxIsxdigit iswxdigit
228 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
229 // /usr/include/wctype.h incorrectly declares translations tables which
230 // provokes tons of compile-time warnings - try to correct this
231 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
232 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
234 #define wxTolower towlower
235 #define wxToupper towupper
238 // string.h functions (wchar.h)
239 #define wxStrcat wcscat
240 #define wxStrchr wcschr
241 #define wxStrcmp wcscmp
242 #define wxStrcoll wcscoll
243 #define wxStrcpy wcscpy
244 #define wxStrcspn wcscspn
245 #define wxStrlen_ wcslen // used in wxStrlen inline function
246 #define wxStrncat wcsncat
247 #define wxStrncmp wcsncmp
248 #define wxStrncpy wcsncpy
249 #define wxStrpbrk wcspbrk
250 #define wxStrrchr wcsrchr
251 #define wxStrspn wcsspn
252 #define wxStrstr wcsstr
253 #define wxStrtod wcstod
254 #define wxStrtok wcstok
255 #define wxStrtol wcstol
256 #define wxStrtoul wcstoul
257 #define wxStrxfrm wcsxfrm
259 // glibc doesn't have wc equivalents of the other stuff
260 #define wxNEED_WX_STDIO_H
261 #define wxNEED_WX_STDLIB_H
262 #define wxNEED_WX_TIME_H
265 #error "Please define your compiler's Unicode conventions in wxChar.h"
272 #if 0 // temporary - preserve binary compatibilty
274 typedef signed char wxSChar
;
275 typedef unsigned char wxUChar
;
278 #define wxSChar signed char
279 #define wxUChar unsigned char
285 #define wxIsalnum isalnum
286 #define wxIsalpha isalpha
287 #define wxIsctrl isctrl
288 #define wxIsdigit isdigit
289 #define wxIsgraph isgraph
290 #define wxIslower islower
291 #define wxIsprint isprint
292 #define wxIspunct ispunct
293 #define wxIsspace isspace
294 #define wxIsupper isupper
295 #define wxIsxdigit isxdigit
296 #define wxTolower tolower
297 #define wxToupper toupper
300 #define wxSetlocale setlocale
302 // string.h functions
303 #define wxStricmp strcasecmp
304 // #define wxStrtok strtok_r // this needs a configure check
306 // leave the rest to defaults below
307 #define wxNEED_WX_STRING_H
308 #define wxNEED_WX_STDIO_H
309 #define wxNEED_WX_STDLIB_H
310 #define wxNEED_WX_TIME_H
313 #endif//TCHAR-aware compilers
315 // define wxStricmp for various compilers without Unicode possibilities
316 #if !defined(wxStricmp) && !wxUSE_UNICODE
317 #if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__)
318 #define wxStricmp stricmp
319 #elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS) && defined(__INTEL__))
320 #define wxStricmp _stricmp
321 #elif defined(__UNIX__) || defined(__GNUWIN32__)
322 #define wxStricmp strcasecmp
323 #elif defined(__MWERKS__) && !defined(__INTEL__)
324 // use wxWindows' implementation
326 // if you leave wxStricmp undefined, wxWindows' implementation will be used
327 #error "Please define string case-insensitive compare for your OS/compiler"
331 // if we need to define for standard headers, and we're not using Unicode,
332 // just define to standard C library routines
334 #ifdef wxNEED_WX_STRING_H
335 #define wxStrcat strcat
336 #define wxStrchr strchr
337 #define wxStrcmp strcmp
338 #define wxStrcoll strcoll
339 #define wxStrcpy strcpy
340 #define wxStrcspn strcspn
341 #define wxStrdup strdup
342 #define wxStrlen_ strlen // used in wxStrlen inline function
343 #define wxStrncat strncat
344 #define wxStrncmp strncmp
345 #define wxStrncpy strncpy
346 #define wxStrpbrk strpbrk
347 #define wxStrrchr strrchr
348 #define wxStrspn strspn
349 #define wxStrstr strstr
350 #define wxStrtod strtod
351 #define wxStrtol strtol
352 #define wxStrtoul strtoul
353 #define wxStrxfrm strxfrm
354 #undef wxNEED_WX_STRING_H
357 #ifdef wxNEED_WX_STDIO_H
358 #define wxFgetc fgetc
359 #define wxFgetchar fgetchar
360 #define wxFgets fgets
361 #define wxFopen fopen
362 #define wxFputc fputc
363 #define wxFputchar fputchar
364 #define wxFprintf fprintf
365 #define wxFreopen freopen
366 #define wxFscanf fscanf
368 #define wxGetchar getchar
370 #define wxPerror perror
371 #define wxPrintf printf
373 #define wxPutchar putchar
375 #define wxRemove remove
376 #define wxRename rename
377 #define wxScanf scanf
378 #define wxSprintf sprintf
379 #define wxSscanf sscanf
380 #define wxTmpnam tmpnam
381 #define wxUngetc ungetc
382 #define wxVfprint vfprintf
383 #define wxVprintf vprintf
384 #define wxVsscanf vsscanf
385 #define wxVsprintf vsprintf
386 #undef wxNEED_WX_STDIO_H
389 #ifdef wxNEED_WX_STDLIB_H
393 #define wxGetenv getenv
394 #define wxSystem system
395 #undef wxNEED_WX_STDLIB_H
398 #ifdef wxNEED_WX_TIME_H
399 #define wxAsctime asctime
400 #define wxCtime ctime
401 #define wxStrftime strftime
402 #undef wxNEED_WX_TIME_H
406 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
407 #define wcslen wxStrlen
411 /// checks whether the passed in pointer is NULL and if the string is empty
412 inline bool WXDLLEXPORT
wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
414 #ifndef wxNEED_WX_STRING_H
415 /// safe version of strlen() (returns 0 if passed NULL pointer)
416 inline size_t WXDLLEXPORT
wxStrlen(const wxChar
*psz
)
417 { return psz
? wxStrlen_(psz
) : 0; }
420 // multibyte<->widechar conversion
421 size_t WXDLLEXPORT
wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
422 size_t WXDLLEXPORT
wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
424 #define wxMB2WX wxMB2WC
425 #define wxWX2MB wxWC2MB
426 #define wxWC2WX wxStrncpy
427 #define wxWX2WC wxStrncpy
429 #define wxMB2WX wxStrncpy
430 #define wxWX2MB wxStrncpy
431 #define wxWC2WX wxWC2MB
432 #define wxWX2WC wxMB2WC
435 // if libc versions are not available, use replacements defined in wxchar.cpp
437 wxChar
* WXDLLEXPORT
wxStrdup(const wxChar
*psz
);
441 int WXDLLEXPORT
wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
445 wxChar
* WXDLLEXPORT
wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
449 wxChar
* WXDLLEXPORT
wxSetlocale(int category
, const wxChar
*locale
);
452 #ifdef wxNEED_WCSLEN // for use in buffer.h
453 size_t WXDLLEXPORT
wcslen(const wchar_t *s
);
456 #ifdef wxNEED_WX_STRING_H
457 int WXDLLEXPORT
wxStrcmp(const wxChar
*psz1
, const wxChar
*psz2
);
458 size_t WXDLLEXPORT
wxStrlen(const wxChar
*s
);
461 #ifdef wxNEED_WX_STDIO_H
464 int WXDLLEXPORT
wxPrintf(const wxChar
*fmt
, ...);
465 int WXDLLEXPORT
wxVprintf(const wxChar
*fmt
, va_list argptr
);
466 int WXDLLEXPORT
wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
467 int WXDLLEXPORT
wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
468 int WXDLLEXPORT
wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
469 int WXDLLEXPORT
wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
470 int WXDLLEXPORT
wxSscanf(const wxChar
*buf
, const wxChar
*fmt
, ...);
471 int WXDLLEXPORT
wxVsscanf(const wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
475 double WXDLLEXPORT
wxAtof(const wxChar
*psz
);
478 #ifdef wxNEED_WX_STDLIB_H
479 int WXDLLEXPORT
wxAtoi(const wxChar
*psz
);
480 long WXDLLEXPORT
wxAtol(const wxChar
*psz
);
481 wxChar
* WXDLLEXPORT
wxGetenv(const wxChar
*name
);
482 int WXDLLEXPORT
wxSystem(const wxChar
*psz
);