]>
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 wxVsprintf _vstprintf
106 // stdlib.h functions
112 #define wxGetenv _tgetenv
113 #define wxSystem _tsystem
116 #define wxAsctime _tasctime
117 #define wxCtime _tctime
119 // #elif defined(XXX)
120 // #include XXX-specific files here
121 // typeddef YYY wxChar;
123 // translate wxZZZ names
125 #else//!Windows (VC++)
127 // check whether we are doing Unicode
133 // this is probably glibc-specific
134 #if defined(__WCHAR_TYPE__)
136 typedef __WCHAR_TYPE__ wxChar
;
137 typedef signed __WCHAR_TYPE__ wxSChar
;
138 typedef unsigned __WCHAR_TYPE__ wxUChar
;
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
155 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
156 // /usr/include/wctype.h incorrectly declares translations tables which
157 // provokes tons of compile-time warnings - try to correct this
158 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
159 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
161 #define wxTolower towlower
162 #define wxToupper towupper
165 // string.h functions (wchar.h)
166 #define wxStrcat wcscat
167 #define wxStrchr wcschr
168 #define wxStrcmp wcscmp
169 #define wxStrcoll wcscoll
170 #define wxStrcpy wcscpy
171 #define wxStrcspn wcscspn
172 #define wxStrncat wcsncat
173 #define wxStrncmp wcsncmp
174 #define wxStrncpy wcsncpy
175 #define wxStrpbrk wcspbrk
176 #define wxStrrchr wcsrchr
177 #define wxStrspn wcsspn
178 #define wxStrstr wcsstr
179 #define wxStrtod wcstod
180 #define wxStrtok wcstok
181 #define wxStrtol wcstol
182 #define wxStrtoul wcstoul
183 #define wxStrxfrm wcsxfrm
185 // glibc doesn't have wc equivalents of the other stuff
186 #define wxNEED_WX_STDIO_H
187 #define wxNEED_WX_STDLIB_H
188 #define wxNEED_WX_TIME_H
191 #error "Please define your compiler's Unicode conventions in wxChar.h"
198 #if 0 // temporary - preserve binary compatibilty
200 typedef signed char wxSChar
;
201 typedef unsigned char wxUChar
;
204 #define wxSChar signed char
205 #define wxUChar unsigned char
211 #define wxIsalnum isalnum
212 #define wxIsalpha isalpha
213 #define wxIsctrl isctrl
214 #define wxIsdigit isdigit
215 #define wxIsgraph isgraph
216 #define wxIslower islower
217 #define wxIsprint isprint
218 #define wxIspunct ispunct
219 #define wxIsspace isspace
220 #define wxIsupper isupper
221 #define wxIsxdigit isxdigit
222 #define wxTolower tolower
223 #define wxToupper toupper
226 #define wxSetlocale setlocale
228 // string.h functions
229 #define wxStrcat strcat
230 #define wxStrchr strchr
231 #define wxStrcmp strcmp
232 #define wxStrcoll strcoll
233 #define wxStrcpy strcpy
234 #define wxStrcspn strcspn
235 #define wxStrdup strdup
236 #define wxStrncat strncat
237 #define wxStrncmp strncmp
238 #define wxStrncpy strncpy
239 #define wxStrpbrk strpbrk
240 #define wxStrrchr strrchr
241 #define wxStrspn strspn
242 #define wxStrstr strstr
243 #define wxStrtod strtod
244 // #define wxStrtok strtok_r // this needs a configure check
245 #define wxStrtol strtol
246 #define wxStrtoul strtoul
247 #define wxStrxfrm strxfrm
250 #define wxFgetc fgetc
251 #define wxFgetchar fgetchar
252 #define wxFgets fgets
253 #define wxFopen fopen
254 #define wxFputc fputc
255 #define wxFputchar fputchar
256 #define wxFprintf fprintf
257 #define wxFreopen freopen
258 #define wxFscanf fscanf
260 #define wxGetchar getchar
262 #define wxPerror perror
263 #define wxPrintf printf
265 #define wxPutchar putchar
267 #define wxRemove remove
268 #define wxRename rename
269 #define wxScanf scanf
270 #define wxSprintf sprintf
271 #define wxSscanf sscanf
272 #define wxTmpnam tmpnam
273 #define wxUngetc ungetc
274 #define wxVfprint vfprintf
275 #define wxVprintf vprintf
276 #define wxVsprintf vsprintf
278 // stdlib.h functions
282 #define wxGetenv getenv
283 #define wxSystem system
286 #define wxAsctime asctime
287 #define wxCtime ctime
288 #define wxStrftime strftime
294 /// checks whether the passed in pointer is NULL and if the string is empty
295 inline bool WXDLLEXPORT
wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
297 /// safe version of strlen() (returns 0 if passed NULL pointer)
298 inline size_t WXDLLEXPORT
wxStrlen(const wxChar
*psz
)
299 #if defined(__VISUALC__)
300 { return psz
? _tcslen(psz
) : 0; }
302 { return psz
? wcslen(psz
) : 0; }
304 { return psz
? strlen(psz
) : 0; }
307 /// portable strcasecmp/_stricmp
308 inline int WXDLLEXPORT
wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
)
309 #if defined(__VISUALC__)
310 { return _tcsicmp(psz1
, psz2
); }
311 #elif defined(__BORLANDC__) && !wxUSE_UNICODE
312 { return stricmp(psz1
, psz2
); }
313 #elif defined(__UNIX__) || defined(__GNUWIN32__)
315 { return strcasecmp(psz1
, psz2
); }
316 #else // glibc doesn't seem to have wide char equivalent
318 register wxChar c1
, c2
;
320 c1
= wxTolower(*psz1
++);
321 c2
= wxTolower(*psz2
++);
322 } while ( c1
&& (c1
== c2
) );
328 // almost all compilers/libraries provide this function (unfortunately under
329 // different names), that's why we don't implement our own which will surely
330 // be more efficient than this code (uncomment to use):
332 register wxChar c1, c2;
334 c1 = wxTolower(*psz1++);
335 c2 = wxTolower(*psz2++);
336 } while ( c1 && (c1 == c2) );
341 #error "Please define string case-insensitive compare for your OS/compiler"
342 #endif // OS/compiler
344 // multibyte<->widechar conversion
345 size_t WXDLLEXPORT
wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
346 size_t WXDLLEXPORT
wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
348 #define wxMB2WX wxMB2WC
349 #define wxWX2MB wxWC2MB
350 #define wxWC2WX wxStrncpy
351 #define wxWX2WC wxStrncpy
353 #define wxMB2WX wxStrncpy
354 #define wxWX2MB wxStrncpy
355 #define wxWC2WX wxWC2MB
356 #define wxWX2WC wxMB2WC
359 // if libc versions are not available, use replacements defined in wxchar.cpp
361 wxChar
* WXDLLEXPORT
wxStrdup(const wxChar
*psz
);
365 wxChar
* WXDLLEXPORT
wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
369 wxChar
* WXDLLEXPORT
wxSetlocale(int category
, const wxChar
*locale
);
372 #ifdef wxNEED_WX_STDIO_H
375 int WXDLLEXPORT
wxPrintf(const wxChar
*fmt
, ...);
376 int WXDLLEXPORT
wxVprintf(const wxChar
*fmt
, va_list argptr
);
377 int WXDLLEXPORT
wxFprintf(FILE *stream
, const wxChar
*fmt
, ...);
378 int WXDLLEXPORT
wxVfprintf(FILE *stream
, const wxChar
*fmt
, va_list argptr
);
379 int WXDLLEXPORT
wxSprintf(wxChar
*buf
, const wxChar
*fmt
, ...);
380 int WXDLLEXPORT
wxVsprintf(wxChar
*buf
, const wxChar
*fmt
, va_list argptr
);
384 double WXDLLEXPORT
wxAtof(const wxChar
*psz
);
387 #ifdef wxNEED_WX_STDLIB_H
388 int WXDLLEXPORT
wxAtoi(const wxChar
*psz
);
389 long WXDLLEXPORT
wxAtol(const wxChar
*psz
);
390 wxChar
* WXDLLEXPORT
wxGetenv(const wxChar
*name
);
391 int WXDLLEXPORT
wxSystem(const wxChar
*psz
);