]>
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 // Windows (VC++) has broad TCHAR support
25 #if defined(__VISUALC__) && defined(__WIN32__)
28 #if wxUSE_UNICODE // temporary - preserve binary compatibility
29 typedef _TCHAR wxChar
;
30 typedef _TSCHAR wxSChar
;
31 typedef _TUCHAR wxUChar
;
34 #define wxSChar signed char
35 #define wxUChar unsigned char
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
54 #define wxSetlocale _tsetlocale
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
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
88 #define wxGetchar _gettchar
90 #define wxPerror _tperror
91 #define wxPrintf _tprintf
93 #define wxPutchar _puttchar
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 wxVsscanf _vstscanf
105 #define wxVsprintf _vstprintf
107 // stdlib.h functions
113 #define wxGetenv _tgetenv
114 #define wxSystem _tsystem
117 #define wxAsctime _tasctime
118 #define wxCtime _tctime
120 // #elif defined(XXX)
121 // #include XXX-specific files here
122 // typeddef YYY wxChar;
124 // translate wxZZZ names
126 #else//!Windows (VC++)
128 // check whether we are doing Unicode
134 // this is probably glibc-specific
135 #if defined(__WCHAR_TYPE__)
137 typedef __WCHAR_TYPE__ wxChar
;
138 typedef signed __WCHAR_TYPE__ wxSChar
;
139 typedef unsigned __WCHAR_TYPE__ wxUChar
;
143 // ctype.h functions (wctype.h)
144 #define wxIsalnum iswalnum
145 #define wxIsalpha iswalpha
146 #define wxIsctrl iswcntrl
147 #define wxIsdigit iswdigit
148 #define wxIsgraph iswgraph
149 #define wxIslower iswlower
150 #define wxIsprint iswprint
151 #define wxIspunct iswpunct
152 #define wxIsspace iswspace
153 #define wxIsupper iswupper
154 #define wxIsxdigit iswxdigit
156 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
157 // /usr/include/wctype.h incorrectly declares translations tables which
158 // provokes tons of compile-time warnings - try to correct this
159 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
160 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
162 #define wxTolower towlower
163 #define wxToupper towupper
166 // string.h functions (wchar.h)
167 #define wxStrcat wcscat
168 #define wxStrchr wcschr
169 #define wxStrcmp wcscmp
170 #define wxStrcoll wcscoll
171 #define wxStrcpy wcscpy
172 #define wxStrcspn wcscspn
173 #define wxStrncat wcsncat
174 #define wxStrncmp wcsncmp
175 #define wxStrncpy wcsncpy
176 #define wxStrpbrk wcspbrk
177 #define wxStrrchr wcsrchr
178 #define wxStrspn wcsspn
179 #define wxStrstr wcsstr
180 #define wxStrtod wcstod
181 #define wxStrtok wcstok
182 #define wxStrtol wcstol
183 #define wxStrtoul wcstoul
184 #define wxStrxfrm wcsxfrm
186 // glibc doesn't have wc equivalents of the other stuff
187 #define wxNEED_WX_STDIO_H
188 #define wxNEED_WX_STDLIB_H
189 #define wxNEED_WX_TIME_H
192 #error "Please define your compiler's Unicode conventions in wxChar.h"
199 #if 0 // temporary - preserve binary compatibilty
201 typedef signed char wxSChar
;
202 typedef unsigned char wxUChar
;
205 #define wxSChar signed char
206 #define wxUChar unsigned char
212 #define wxIsalnum isalnum
213 #define wxIsalpha isalpha
214 #define wxIsctrl isctrl
215 #define wxIsdigit isdigit
216 #define wxIsgraph isgraph
217 #define wxIslower islower
218 #define wxIsprint isprint
219 #define wxIspunct ispunct
220 #define wxIsspace isspace
221 #define wxIsupper isupper
222 #define wxIsxdigit isxdigit
223 #define wxTolower tolower
224 #define wxToupper toupper
227 #define wxSetlocale setlocale
229 // string.h functions
230 #define wxStrcat strcat
231 #define wxStrchr strchr
232 #define wxStrcmp strcmp
233 #define wxStrcoll strcoll
234 #define wxStrcpy strcpy
235 #define wxStrcspn strcspn
236 #define wxStrdup strdup
237 #define wxStrncat strncat
238 #define wxStrncmp strncmp
239 #define wxStrncpy strncpy
240 #define wxStrpbrk strpbrk
241 #define wxStrrchr strrchr
242 #define wxStrspn strspn
243 #define wxStrstr strstr
244 #define wxStrtod strtod
245 // #define wxStrtok strtok_r // this needs a configure check
246 #define wxStrtol strtol
247 #define wxStrtoul strtoul
248 #define wxStrxfrm strxfrm
251 #define wxFgetc fgetc
252 #define wxFgetchar fgetchar
253 #define wxFgets fgets
254 #define wxFopen fopen
255 #define wxFputc fputc
256 #define wxFputchar fputchar
257 #define wxFprintf fprintf
258 #define wxFreopen freopen
259 #define wxFscanf fscanf
261 #define wxGetchar getchar
263 #define wxPerror perror
264 #define wxPrintf printf
266 #define wxPutchar putchar
268 #define wxRemove remove
269 #define wxRename rename
270 #define wxScanf scanf
271 #define wxSprintf sprintf
272 #define wxSscanf sscanf
273 #define wxTmpnam tmpnam
274 #define wxUngetc ungetc
275 #define wxVfprint vfprintf
276 #define wxVprintf vprintf
277 #define wxVsscanf vsscanf
278 #define wxVsprintf vsprintf
280 // stdlib.h functions
284 #define wxGetenv getenv
285 #define wxSystem system
288 #define wxAsctime asctime
289 #define wxCtime ctime
290 #define wxStrftime strftime
296 /// checks whether the passed in pointer is NULL and if the string is empty
297 inline bool WXDLLEXPORT
wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
299 /// safe version of strlen() (returns 0 if passed NULL pointer)
300 inline size_t WXDLLEXPORT
wxStrlen(const wxChar
*psz
)
301 #if defined(__VISUALC__)
302 { return psz
? _tcslen(psz
) : 0; }
304 { return psz
? wcslen(psz
) : 0; }
306 { return psz
? strlen(psz
) : 0; }
309 /// portable strcasecmp/_stricmp
310 inline int WXDLLEXPORT
wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
)
311 #if defined(__VISUALC__)
312 { return _tcsicmp(psz1
, psz2
); }
313 #elif defined(__BORLANDC__) && !wxUSE_UNICODE
314 { return stricmp(psz1
, psz2
); }
315 #elif defined(__UNIX__) || defined(__GNUWIN32__)
317 { return strcasecmp(psz1
, psz2
); }
318 #else // glibc doesn't seem to have wide char equivalent
320 register wxChar c1
, c2
;
322 c1
= wxTolower(*psz1
++);
323 c2
= wxTolower(*psz2
++);
324 } while ( c1
&& (c1
== c2
) );
330 // almost all compilers/libraries provide this function (unfortunately under
331 // different names), that's why we don't implement our own which will surely
332 // be more efficient than this code (uncomment to use):
334 register wxChar c1, c2;
336 c1 = wxTolower(*psz1++);
337 c2 = wxTolower(*psz2++);
338 } while ( c1 && (c1 == c2) );
343 #error "Please define string case-insensitive compare for your OS/compiler"
344 #endif // OS/compiler
346 // multibyte<->widechar conversion
347 size_t WXDLLEXPORT
wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
348 size_t WXDLLEXPORT
wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
350 #define wxMB2WX wxMB2WC
351 #define wxWX2MB wxWC2MB
352 #define wxWC2WX wxStrncpy
353 #define wxWX2WC wxStrncpy
355 #define wxMB2WX wxStrncpy
356 #define wxWX2MB wxStrncpy
357 #define wxWC2WX wxWC2MB
358 #define wxWX2WC wxMB2WC
361 // if libc versions are not available, use replacements defined in wxchar.cpp
363 wxChar
* WXDLLEXPORT
wxStrdup(const wxChar
*psz
);
367 wxChar
* WXDLLEXPORT
wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
371 wxChar
* WXDLLEXPORT
wxSetlocale(int category
, const wxChar
*locale
);
374 #ifdef wxNEED_WX_STDIO_H
377 int WXDLLEXPORT
wxPrintf(const wxChar
*fmt
, ...);
378 int WXDLLEXPORT
wxVprintf(const wxChar
*fmt
, va_list argptr
);
379 int WXDLLEXPORT
wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
380 int WXDLLEXPORT
wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
381 int WXDLLEXPORT
wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
382 int WXDLLEXPORT
wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
383 int WXDLLEXPORT
wxSscanf(const wxChar
*buf
, const wxChar
*fmt
, ...);
384 int WXDLLEXPORT
wxVsscanf(const wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
388 double WXDLLEXPORT
wxAtof(const wxChar
*psz
);
391 #ifdef wxNEED_WX_STDLIB_H
392 int WXDLLEXPORT
wxAtoi(const wxChar
*psz
);
393 long WXDLLEXPORT
wxAtol(const wxChar
*psz
);
394 wxChar
* WXDLLEXPORT
wxGetenv(const wxChar
*name
);
395 int WXDLLEXPORT
wxSystem(const wxChar
*psz
);