]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
41ad07a808b2489baf1810613c4596b9774b5791
[wxWidgets.git] / include / wx / wxchar.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/wxchar.h
3 // Purpose: Declarations common to wx char/wchar_t usage (wide chars)
4 // Author: Joel Farley, Ove Kåven
5 // Modified by: Vadim Zeitlin, Robert Roebling
6 // Created: 1998/06/12
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998-2002 wxWindows dev team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WXCHAR_H_
13 #define _WX_WXCHAR_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "wxchar.h"
17 #endif
18
19 #include "wx/defs.h" // for wxUSE_UNICODE
20
21 // ----------------------------------------------------------------------------
22 // check whether we have wchar_t and which size it is if we do
23 // ----------------------------------------------------------------------------
24
25 #if !defined(wxUSE_WCHAR_T)
26 #if defined(__WIN16__)
27 // no wchar_t under Win16 regadrless of compiler used
28 #define wxUSE_WCHAR_T 0
29 #elif defined(__UNIX__)
30 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
31 #define wxUSE_WCHAR_T 1
32 #else
33 #define wxUSE_WCHAR_T 0
34 #endif
35 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
36 #define wxUSE_WCHAR_T 0
37 #elif defined(__WATCOMC__)
38 #define wxUSE_WCHAR_T 0
39 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
40 #define wxUSE_WCHAR_T 0
41 #else
42 // add additional compiler checks if this fails
43 #define wxUSE_WCHAR_T 1
44 #endif
45 #endif // !defined(wxUSE_WCHAR_T)
46
47 // Unicode support requires wchar_t
48 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
49 #error "wchar_t must be available in Unicode build"
50 #endif // Unicode
51
52 // ----------------------------------------------------------------------------
53 // standard headers we need here
54 //
55 // NB: don't include any wxWindows headers here because almost of them include
56 // this one!
57 // ----------------------------------------------------------------------------
58
59 // Required for wxPrintf() etc
60 #include <stdarg.h>
61
62 // Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac
63 // and VC++ for Windows CE don't provide it
64 #if !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
65 // use #define, not inline wrapper, as it is tested with #ifndef below
66 #define wxStrdupA strdup
67 #endif
68
69 // non Unix compilers which do have wchar.h (but not tchar.h which is included
70 // below and which includes wchar.h anyhow).
71 // Actually MinGW has tchar.h, but it does not include wchar.h
72 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__)
73 #ifndef HAVE_WCHAR_H
74 #define HAVE_WCHAR_H
75 #endif
76 #endif
77
78 #if wxUSE_WCHAR_T
79 #ifdef HAVE_WCHAR_H
80 // the current (as of Nov 2002) version of cygwin has a bug in its
81 // wchar.h -- there is no extern "C" around the declarations in it and
82 // this results in linking errors later; also, at least on some
83 // Cygwin versions, wchar.h requires sys/types.h
84 #ifdef __CYGWIN__
85 #include <sys/types.h>
86 extern "C" {
87 #endif // Cygwin
88 #include <wchar.h>
89 #ifdef __CYGWIN__
90 }
91 #endif // Cygwin
92 #elif defined(HAVE_WCSTR_H)
93 // old compilers have relevant declarations here
94 #include <wcstr.h>
95 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
96 // include stdlib.h for wchar_t
97 #include <stdlib.h>
98 #endif // HAVE_WCHAR_H
99 #endif // wxUSE_WCHAR_T
100
101 // ----------------------------------------------------------------------------
102 // define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type
103 // mapped to either char or wchar_t depending on the ASCII/Unicode mode and have
104 // the function mapping _tfoo() -> foo() or wfoo()
105 // ----------------------------------------------------------------------------
106
107 // VC++ and BC++ starting with 5.2 have TCHAR support
108 #ifdef __VISUALC__
109 #define wxHAVE_TCHAR_SUPPORT
110 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
111 #define wxHAVE_TCHAR_SUPPORT
112 #include <ctype.h>
113 #elif defined(__WATCOMC__)
114 #define wxHAVE_TCHAR_SUPPORT
115 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
116 #define wxHAVE_TCHAR_SUPPORT
117 #include <stddef.h>
118 #include <string.h>
119 #include <ctype.h>
120 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
121 // VZ: the old VisualAge definitions were completely wrong and had no
122 // chance at all to work in Unicode build anyhow so let's pretend that
123 // VisualAge does _not_ support TCHAR for the moment (as indicated by
124 // "0 &&" above) until someone really has time to delve into Unicode
125 // issues under OS/2
126
127 // VisualAge 4.0+ supports TCHAR
128 #define wxHAVE_TCHAR_SUPPORT
129 #endif // compilers with (good) TCHAR support
130
131 #ifdef __MWERKS__
132 #define HAVE_WPRINTF
133 #endif
134
135 #ifdef wxHAVE_TCHAR_SUPPORT
136 // get TCHAR definition if we've got it
137 #include <tchar.h>
138
139 // we surely do have wchar_t if we have TCHAR
140 #ifndef wxUSE_WCHAR_T
141 #define wxUSE_WCHAR_T 1
142 #endif // !defined(wxUSE_WCHAR_T)
143
144 // and we also do have wcslen()
145 #ifndef HAVE_WCSLEN
146 #define HAVE_WCSLEN
147 #endif
148 #endif // wxHAVE_TCHAR_SUPPORT
149
150 // ----------------------------------------------------------------------------
151 // define wxChar type
152 // ----------------------------------------------------------------------------
153
154 // TODO: define wxCharInt to be equal to either int or wint_t?
155
156 #if !wxUSE_UNICODE
157 typedef char wxChar;
158 typedef signed char wxSChar;
159 typedef unsigned char wxUChar;
160 #else // Unicode
161 // VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as
162 // signed/unsigned version of it which (a) makes sense to me (unlike
163 // char wchar_t is always unsigned) and (b) was how the previous
164 // definitions worked so keep it like this
165
166 // GNU libc has __WCHAR_TYPE__ which requires special treatment, see
167 // comment below
168 #if !defined(__WCHAR_TYPE__) || \
169 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
170 // standard case
171 typedef wchar_t wxChar;
172 typedef wchar_t wxSChar;
173 typedef wchar_t wxUChar;
174 #else // __WCHAR_TYPE__ and gcc < 2.96
175 // VS: wxWindows used to define wxChar as __WCHAR_TYPE__ here. However,
176 // this doesn't work with new GCC 3.x compilers because wchar_t is
177 // C++'s builtin type in the new standard. OTOH, old compilers (GCC
178 // 2.x) won't accept new definition of wx{S,U}Char, therefore we
179 // have to define wxChar conditionally depending on detected
180 // compiler & compiler version.
181 // with old definition of wxChar.
182 typedef __WCHAR_TYPE__ wxChar;
183 typedef __WCHAR_TYPE__ wxSChar;
184 typedef __WCHAR_TYPE__ wxUChar;
185 #endif // __WCHAR_TYPE__
186 #endif // ASCII/Unicode
187
188 // ----------------------------------------------------------------------------
189 // define _T() and related macros
190 // ----------------------------------------------------------------------------
191
192 // BSD systems define _T() to be something different in ctype.h, override it
193 #if defined(__FreeBSD__) || defined(__DARWIN__)
194 #include <ctype.h>
195 #undef _T
196 #endif
197
198 // could already be defined by tchar.h (it's quasi standard)
199 #ifndef _T
200 #if !wxUSE_UNICODE
201 #define _T(x) x
202 #else // Unicode
203 #define _T(x) L ## x
204 #endif // ASCII/Unicode
205 #endif // !defined(_T)
206
207 // although global macros with such names are normally bad, we want to have
208 // another name for _T() which should be used to avoid confusion between _T()
209 // and _() in wxWindows sources
210 #define wxT(x) _T(x)
211
212 // Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs
213 #ifndef __TFILE__
214 #define __XFILE__(x) wxT(x)
215 #define __TFILE__ __XFILE__(__FILE__)
216 #endif
217
218 #ifndef __TDATE__
219 #define __XDATE__(x) wxT(x)
220 #define __TDATE__ __XDATE__(__DATE__)
221 #endif
222
223 #ifndef __TTIME__
224 #define __XTIME__(x) wxT(x)
225 #define __TTIME__ __XTIME__(__TIME__)
226 #endif
227
228 // ----------------------------------------------------------------------------
229 // define wxFoo() function for each standard foo() function whose signature
230 // (exceptionally including the return type) includes any mention of char:
231 // wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
232 // the same signature but with char replaced by wxChar which allows us to use
233 // it in Unicode build as well
234 // ----------------------------------------------------------------------------
235
236 #ifdef wxHAVE_TCHAR_SUPPORT
237 #include <ctype.h>
238
239 // ctype.h functions
240 #define wxIsalnum _istalnum
241 #define wxIsalpha _istalpha
242 #define wxIsctrl _istctrl
243 #define wxIsdigit _istdigit
244 #define wxIsgraph _istgraph
245 #define wxIslower _istlower
246 #define wxIsprint _istprint
247 #define wxIspunct _istpunct
248 #define wxIsspace _istspace
249 #define wxIsupper _istupper
250 #define wxIsxdigit _istxdigit
251 #define wxTolower _totlower
252 #define wxToupper _totupper
253
254 // locale.h functons
255 #define wxSetlocale _tsetlocale
256
257 // string.h functions
258 #define wxStrcat _tcscat
259 #define wxStrchr _tcschr
260 #define wxStrcmp _tcscmp
261 #define wxStrcoll _tcscoll
262 #define wxStrcpy _tcscpy
263 #define wxStrcspn _tcscspn
264 #define wxStrdupW _wcsdup // notice the 'W'!
265 #define wxStrftime _tcsftime
266 #define wxStricmp _tcsicmp
267 #define wxStrnicmp _tcsnicmp
268 #define wxStrlen_ _tcslen // used in wxStrlen inline function
269 #define wxStrncat _tcsncat
270 #define wxStrncmp _tcsncmp
271 #define wxStrncpy _tcsncpy
272 #define wxStrpbrk _tcspbrk
273 #define wxStrrchr _tcsrchr
274 #define wxStrspn _tcsspn
275 #define wxStrstr _tcsstr
276 #define wxStrtod _tcstod
277 #define wxStrtol _tcstol
278 #define wxStrtoul _tcstoul
279 #define wxStrxfrm _tcsxfrm
280
281 // stdio.h functions
282 #define wxFgetc _fgettc
283 #define wxFgetchar _fgettchar
284 #define wxFgets _fgetts
285 #define wxFopen _tfopen
286 #define wxFputc _fputtc
287 #define wxFputchar _fputtchar
288 #define wxFprintf _ftprintf
289 #define wxFputs _fputts
290 #define wxFreopen _tfreopen
291 #define wxFscanf _ftscanf
292 #define wxGetc _gettc
293 #define wxGetchar _gettchar
294 #define wxGets _getts
295 #define wxPerror _tperror
296 #define wxPrintf _tprintf
297 #define wxPutc _puttc
298 #define wxPutchar _puttchar
299 #define wxPuts _putts
300 #define wxScanf _tscanf
301 #define wxSprintf _stprintf
302 #define wxSscanf _stscanf
303 #define wxTmpnam _ttmpnam
304 #define wxUngetc _tungetc
305 #define wxVfprintf _vftprintf
306 #define wxVprintf _vtprintf
307 #define wxVsscanf _vstscanf
308 #define wxVsprintf _vstprintf
309
310 // special case: not all TCHAR-aware compilers have those
311 #if defined(__VISUALC__) || \
312 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
313 #define wxVsnprintf_ _vsntprintf
314 #define wxSnprintf_ _sntprintf
315 #endif
316
317 // special case: these functions are missing under Win9x with Unicows so we
318 // have to implement them ourselves
319 #if wxUSE_UNICODE_MSLU
320 #define wxRemove wxMSLU__tremove
321 #define wxRename wxMSLU__trename
322 #else
323 #ifdef __WXWINCE__
324 #define wxRemove DeleteFile
325 #else
326 #define wxRemove _tremove
327 #define wxRename _trename
328 #endif
329 #endif
330
331 // stdlib.h functions
332 #define wxAtoi _ttoi
333 #define wxAtol _ttol
334 // #define wxAtof _tttof -- notice that there is no such thing (why?)
335 #define wxGetenv _tgetenv
336 #define wxSystem _tsystem
337
338 // time.h functions
339 #define wxAsctime _tasctime
340 #define wxCtime _tctime
341 #else // !TCHAR-aware compilers
342 #if wxUSE_UNICODE
343 #include <wctype.h>
344
345 // this is probably glibc-specific
346 #if defined(__WCHAR_TYPE__)
347 // ctype.h functions (wctype.h)
348 #define wxIsalnum iswalnum
349 #define wxIsalpha iswalpha
350 #define wxIsctrl iswcntrl
351 #define wxIsdigit iswdigit
352 #define wxIsgraph iswgraph
353 #define wxIslower iswlower
354 #define wxIsprint iswprint
355 #define wxIspunct iswpunct
356 #define wxIsspace iswspace
357 #define wxIsupper iswupper
358 #define wxIsxdigit iswxdigit
359
360 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
361 // /usr/include/wctype.h incorrectly declares translations
362 // tables which provokes tons of compile-time warnings -- try
363 // to correct this
364 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
365 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
366 #else // !glibc 2.0
367 #define wxTolower towlower
368 #define wxToupper towupper
369 #endif // gcc/!gcc
370
371 // string.h functions (wchar.h)
372 #define wxStrcat wcscat
373 #define wxStrchr wcschr
374 #define wxStrcmp wcscmp
375 #define wxStrcoll wcscoll
376 #define wxStrcpy wcscpy
377 #define wxStrcspn wcscspn
378 #define wxStrlen_ wxWcslen // wxStrlen_() is used in wxStrlen()
379 #define wxStrncat wcsncat
380 #define wxStrncmp wcsncmp
381 #define wxStrncpy wcsncpy
382 #define wxStrpbrk wcspbrk
383 #define wxStrrchr wcsrchr
384 #define wxStrspn wcsspn
385 #define wxStrstr wcsstr
386 #define wxStrtod wcstod
387 #define wxStrtol wcstol
388 #define wxStrtoul wcstoul
389 #define wxStrxfrm wcsxfrm
390
391 #define wxFgetc fgetwc
392 #define wxFgetchar fgetwchar
393 #define wxFgets fgetws
394 #define wxFputc fputwc
395 #define wxFputchar fputwchar
396 #define wxGetc getwc
397 #define wxGetchar getwchar
398 #define wxGets getws
399 #define wxUngetc ungetwc
400
401 #ifdef HAVE_FPUTWC
402 #define wxPutc wputc
403 #define wxPutchar wputchar
404 #define wxPuts putws
405 #define wxFputs fputws
406 #else
407 #define wxNEED_FPUTWC
408
409 #include <stdio.h>
410
411 int wxFputs(const wxChar *ch, FILE *stream);
412 int wxPutc(wxChar ch, FILE *stream);
413
414 #define wxPuts(ws) wxFputs(ws, stdout)
415 #define wxPutchar(wch) wxPutc(wch, stdout)
416 #endif
417
418 // we need %s to %ls conversion for printf and scanf etc
419 #define wxNEED_PRINTF_CONVERSION
420
421 // glibc doesn't have wide char equivalents of the other stuff so
422 // use our own versions
423 #define wxNEED_WX_STDIO_H
424 #define wxNEED_WX_STDLIB_H
425 #define wxNEED_WX_TIME_H
426 #elif defined(__MWERKS__) && ( defined(macintosh) || defined(__MACH__) )
427 // ctype.h functions (wctype.h)
428 #define wxIsalnum iswalnum
429 #define wxIsalpha iswalpha
430 #define wxIsctrl iswcntrl
431 #define wxIsdigit iswdigit
432 #define wxIsgraph iswgraph
433 #define wxIslower iswlower
434 #define wxIsprint iswprint
435 #define wxIspunct iswpunct
436 #define wxIsspace iswspace
437 #define wxIsupper iswupper
438 #define wxIsxdigit iswxdigit
439 #define wxTolower towlower
440 #define wxToupper towupper
441
442 // string.h functions (wchar.h)
443 #define wxStrcat wcscat
444 #define wxStrchr wcschr
445 #define wxStrcmp wcscmp
446 #define wxStrcoll wcscoll
447 #define wxStrcpy wcscpy
448 #define wxStrcspn wcscspn
449 #define wxStrlen_ wxWcslen // wxStrlen_() is used in wxStrlen()
450 #define wxStrncat wcsncat
451 #define wxStrncmp wcsncmp
452 #define wxStrncpy wcsncpy
453 #define wxStrpbrk wcspbrk
454 #define wxStrrchr wcsrchr
455 #define wxStrspn wcsspn
456 #define wxStrstr wcsstr
457 #define wxStrtod wcstod
458 #define wxStrtol wcstol
459 #define wxStrtoul wcstoul
460 #define wxStrxfrm wcsxfrm
461
462 #define wxFgetc fgetwc
463 #define wxFgetchar fgetwchar
464 #define wxFgets fgetws
465 #define wxFputc fputwc
466 #define wxFputchar fputwchar
467 #define wxGetc getwc
468 #define wxGetchar getwchar
469 #define wxGets getws
470 #define wxUngetc ungetwc
471
472 #define wxNEED_PRINTF_CONVERSION
473
474 #define wxPutc putwc
475 #define wxPutchar putwchar
476 #define wxFputs fputws
477
478 // stdio.h functions
479
480 #define wxNEED_WX_STDIO_H
481
482 // stdlib.h functions
483 #define wxAtof watof
484 #define wxAtoi watoi
485 #define wxAtol watol
486 #define wxGetenv(a) ((wxChar*)NULL)
487 #define wxSystem(a) ((int)NULL)
488
489 // time.h functions
490 #define wxAsctime wasciitime
491 #define wxCtime wctime
492 // #define wxStrftime wcsftime
493
494 /*
495 #define wxNEED_FPUTWC
496
497 #include <stdio.h>
498
499 int wxFputs(const wxChar *ch, FILE *stream);
500 int wxPutc(wxChar ch, FILE *stream);
501
502 #define wxPuts(ws) wxFputs(ws, stdout)
503 #define wxPutchar(wch) wxPutc(wch, stdout)
504
505 // we need %s to %ls conversion for printf and scanf etc
506 #define wxNEED_PRINTF_CONVERSION
507 // glibc doesn't have wide char equivalents of the other stuff so
508 // use our own versions
509 #define wxNEED_WX_STDIO_H
510 #define wxNEED_WX_STDLIB_H
511 */
512 #define wxNEED_WX_TIME_H
513 #else // !metrowerks for apple
514 #error "Please define wide character functions for your environment"
515 #endif
516 #else // ASCII
517 #include <ctype.h>
518 #include <string.h>
519
520 // ctype.h functions
521 #define wxIsalnum isalnum
522 #define wxIsalpha isalpha
523 #define wxIsctrl isctrl
524 #define wxIsdigit isdigit
525 #define wxIsgraph isgraph
526 #define wxIslower islower
527 #define wxIsprint isprint
528 #define wxIspunct ispunct
529 #define wxIsspace isspace
530 #define wxIsupper isupper
531 #define wxIsxdigit isxdigit
532 #define wxTolower tolower
533 #define wxToupper toupper
534
535 // locale.h functons
536 #define wxSetlocale setlocale
537
538 // string.h functions
539 #define wxStrcat strcat
540 #define wxStrchr strchr
541 #define wxStrcmp strcmp
542 #define wxStrcoll strcoll
543 #define wxStrcpy strcpy
544 #define wxStrcspn strcspn
545
546 // wxStricmp and wxStrnicmp are defined below
547 #define wxStrlen_ strlen // used in wxStrlen inline function
548 #define wxStrncat strncat
549 #define wxStrncmp strncmp
550 #define wxStrncpy strncpy
551 #define wxStrpbrk strpbrk
552 #define wxStrrchr strrchr
553 #define wxStrspn strspn
554 #define wxStrstr strstr
555 #define wxStrtod strtod
556 #ifdef HAVE_STRTOK_R
557 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
558 #endif
559 #define wxStrtol strtol
560 #define wxStrtoul strtoul
561 #define wxStrxfrm strxfrm
562
563 // stdio.h functions
564 #define wxFopen fopen
565 #define wxFreopen freopen
566 #define wxRemove remove
567 #define wxRename rename
568
569 #define wxPerror perror
570 #define wxTmpnam tmpnam
571
572 #define wxFgetc fgetc
573 #define wxFgetchar fgetchar
574 #define wxFgets fgets
575 #define wxFputc fputc
576 #define wxFputs fputs
577 #define wxFputchar fputchar
578 #define wxFprintf fprintf
579 #define wxFscanf fscanf
580 #define wxGetc getc
581 #define wxGetchar getchar
582 #define wxGets gets
583 #define wxPrintf printf
584 #define wxPutc putc
585 #define wxPutchar putchar
586 #define wxPuts puts
587 #define wxScanf scanf
588 #define wxSprintf sprintf
589 #define wxSscanf sscanf
590 #define wxUngetc ungetc
591 #define wxVfprintf vfprintf
592 #define wxVprintf vprintf
593 #define wxVsscanf vsscanf
594 #define wxVsprintf vsprintf
595
596 // stdlib.h functions
597 #define wxAtof atof
598 #define wxAtoi atoi
599 #define wxAtol atol
600 #define wxGetenv getenv
601 #define wxSystem system
602
603 // time.h functions
604 #define wxAsctime asctime
605 #define wxCtime ctime
606 #define wxStrftime strftime
607 #endif // Unicode/ASCII
608 #endif // TCHAR-aware compilers/the others
609
610 // ----------------------------------------------------------------------------
611 // various special cases
612 // ----------------------------------------------------------------------------
613
614 // define wxStricmp and wxStrnicmp for various compilers
615 //
616 // note that in Unicode mode we definitely are going to need our own version
617 #if !defined(wxStricmp) && !wxUSE_UNICODE
618 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
619 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
620 defined(__EMX__) || defined(__DJGPP__)
621 #define wxStricmp stricmp
622 #define wxStrnicmp strnicmp
623 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
624 (defined(__MWERKS__) && defined(__INTEL__))
625 #define wxStricmp _stricmp
626 #define wxStrnicmp _strnicmp
627 #elif defined(__UNIX__) || defined(__GNUWIN32__)
628 #define wxStricmp strcasecmp
629 #define wxStrnicmp strncasecmp
630 // #else -- use wxWindows implementation
631 #endif
632 #endif // !defined(wxStricmp)
633
634 // define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as
635 // it's used in wx/buffer.h -- and also might be used just below by wxStrlen()
636 // when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen)
637 #if wxUSE_WCHAR_T
638 #ifdef HAVE_WCSLEN
639 #define wxWcslen wcslen
640 #else
641 inline size_t wxWcslen(const wchar_t *s)
642 {
643 size_t n = 0;
644 while ( *s++ )
645 n++;
646
647 return n;
648 }
649 #endif
650 #endif // wxUSE_WCHAR_T
651
652 // checks whether the passed in pointer is NULL and if the string is empty
653 inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
654
655 // safe version of strlen() (returns 0 if passed NULL pointer)
656 inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
657
658 // each of strdup() and wcsdup() may or may not be available but we need both
659 // of them anyhow for wx/buffer.h so we define the missing one(s) in
660 // wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
661 // defined -- if this is somehow not the case in some situations, please
662 // correct that and not the lines here
663 #if wxUSE_UNICODE
664 #define wxStrdup wxStrdupW
665 #else
666 #define wxStrdup wxStrdupA
667 #endif
668
669 WXDLLIMPEXP_BASE bool wxOKlibc(); // for internal use
670
671 // ----------------------------------------------------------------------------
672 // printf() family saga
673 // ----------------------------------------------------------------------------
674
675 /*
676 For some systems vsnprintf() exists in the system libraries but not in the
677 headers, so we need to declare it ourselves to be able to use it.
678 */
679 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
680 extern "C"
681 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
682 #endif // !HAVE_VSNPRINTF_DECL
683
684 /*
685 First of all, we always want to define safe snprintf() function to be used
686 instead of sprintf(). Some compilers already have it (or rather vsnprintf()
687 which we really need...), otherwise we implement it using our own printf()
688 code.
689
690 We define function with a trailing underscore here because the real one is a
691 wrapper around it as explained below
692 */
693 #ifndef wxVsnprintf_
694 #if wxUSE_UNICODE
695 #if defined(__MWERKS__)
696 #define HAVE_WCSRTOMBS 1
697 #define HAVE_VSWPRINTF 1
698 #endif
699 #if defined(HAVE__VSNWPRINTF)
700 #define wxVsnprintf_ _vsnwprintf
701 /* MinGW?MSVCRT has the wrong vswprintf */
702 #elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
703 #define wxVsnprintf_ vswprintf
704 #endif
705 #else // ASCII
706 // all versions of CodeWarrior supported by wxWindows apparently have
707 // vsnprintf()
708 #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__)
709 // assume we have snprintf() too if we have vsnprintf()
710 #define wxVsnprintf_ vsnprintf
711 #define wxSnprintf_ snprintf
712 #endif
713 #endif
714 #endif // wxVsnprintf_ not defined yet
715
716 #ifndef wxSnprintf_
717 // no [v]snprintf(), cook our own
718 WXDLLIMPEXP_BASE int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
719 ...) ATTRIBUTE_PRINTF_3;
720 #endif
721 #ifndef wxVsnprintf_
722 WXDLLIMPEXP_BASE int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
723 va_list argptr);
724 #endif
725
726 /*
727 In Unicode mode we need to have all standard functions such as wprintf() and
728 so on but not all systems have them so use our own implementations in this
729 case.
730 */
731 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
732 #define wxNEED_WPRINTF
733 #endif
734
735 /*
736 More Unicode complications: although both ANSI C and C++ define a number of
737 wide character functions such as wprintf(), not all environments have them.
738 Worse, those which do have different behaviours: under Windows, %s format
739 specifier changes its meaning in Unicode build and expects a Unicode string
740 while under Unix/POSIX it still means an ASCII string even for wprintf() and
741 %ls has to be used for wide strings.
742
743 We choose to always emulate Windows behaviour as more useful for us so even
744 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
745
746 However, if we don't have any vswprintf() at all we don't need to redefine
747 anything as our own wxVsnprintf_() already behaves as needed.
748 */
749 #ifndef wxVsnprintf_
750 #undef wxNEED_PRINTF_CONVERSION
751 #endif
752
753 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
754 // we need to implement all wide character printf and scanf functions
755 // either because we don't have them at all or because they don't have the
756 // semantics we need
757
758 #include <stdio.h> // for FILE
759
760 int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
761 int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
762 int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
763 int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
764 int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
765 int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
766 int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
767 int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
768 int wxVprintf( const wxChar *format, va_list ap );
769 int wxVsprintf( wxChar *str, const wxChar *format, va_list ap );
770 #endif // wxNEED_PRINTF_CONVERSION
771
772 // these 2 can be simply mapped to the versions with underscore at the end
773 // if we don't have to do the conversion
774 #ifdef wxNEED_PRINTF_CONVERSION
775 int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
776 int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
777 #else
778 #define wxSnprintf wxSnprintf_
779 #define wxVsnprintf wxVsnprintf_
780 #endif
781
782 // ----------------------------------------------------------------------------
783 // various functions which might not be available in libc and for which we
784 // provide our own replacements in wxchar.cpp
785 // ----------------------------------------------------------------------------
786
787 // ctype.h functions
788 //
789 // VZ: note that this is never defined currently
790 #ifdef wxNEED_WX_CTYPE_H
791 WXDLLIMPEXP_BASE int wxIsalnum(wxChar ch);
792 WXDLLIMPEXP_BASE int wxIsalpha(wxChar ch);
793 WXDLLIMPEXP_BASE int wxIsctrl(wxChar ch);
794 WXDLLIMPEXP_BASE int wxIsdigit(wxChar ch);
795 WXDLLIMPEXP_BASE int wxIsgraph(wxChar ch);
796 WXDLLIMPEXP_BASE int wxIslower(wxChar ch);
797 WXDLLIMPEXP_BASE int wxIsprint(wxChar ch);
798 WXDLLIMPEXP_BASE int wxIspunct(wxChar ch);
799 WXDLLIMPEXP_BASE int wxIsspace(wxChar ch);
800 WXDLLIMPEXP_BASE int wxIsupper(wxChar ch);
801 WXDLLIMPEXP_BASE int wxIsxdigit(wxChar ch);
802 WXDLLIMPEXP_BASE int wxTolower(wxChar ch);
803 WXDLLIMPEXP_BASE int wxToupper(wxChar ch);
804 #endif // wxNEED_WX_CTYPE_H
805
806 // under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks
807 // the file parsing -- this may be true for 5.0 as well, update #ifdef then
808 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
809 #undef wxIsspace
810 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
811 #endif // VC++
812
813
814 // string.h functions
815 //
816 // VZ: this is never defined neither currently
817 #ifdef wxNEED_WX_STRING_H
818 WXDLLIMPEXP_BASE wxChar * wxStrcat(wxChar *dest, const wxChar *src);
819 WXDLLIMPEXP_BASE const wxChar * wxStrchr(const wxChar *s, wxChar c);
820 WXDLLIMPEXP_BASE wxChar * wxStrchr(wxChar *s, wxChar c)
821 { return (wxChar *)wxStrchr((const wxChar *)s, c); }
822 WXDLLIMPEXP_BASE int wxStrcmp(const wxChar *s1, const wxChar *s2);
823 WXDLLIMPEXP_BASE int wxStrcoll(const wxChar *s1, const wxChar *s2);
824 WXDLLIMPEXP_BASE wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
825 WXDLLIMPEXP_BASE size_t wxStrcspn(const wxChar *s, const wxChar *reject);
826 WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar *s);
827 WXDLLIMPEXP_BASE wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
828 WXDLLIMPEXP_BASE int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
829 WXDLLIMPEXP_BASE wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
830 WXDLLIMPEXP_BASE const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
831 WXDLLIMPEXP_BASE wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
832 { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
833 WXDLLIMPEXP_BASE const wxChar * wxStrrchr(const wxChar *s, wxChar c);
834 WXDLLIMPEXP_BASE wxChar * wxStrrchr(wxChar *s, wxChar c)
835 { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
836 WXDLLIMPEXP_BASE size_t wxStrspn(const wxChar *s, const wxChar *accept);
837 WXDLLIMPEXP_BASE const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
838 WXDLLIMPEXP_BASE wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
839 { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
840 WXDLLIMPEXP_BASE double wxStrtod(const wxChar *nptr, wxChar **endptr);
841 WXDLLIMPEXP_BASE long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
842 WXDLLIMPEXP_BASE unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
843 WXDLLIMPEXP_BASE size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
844 #endif // wxNEED_WX_STRING_H
845
846 #ifndef wxStrdupA
847 WXDLLIMPEXP_BASE char *wxStrdupA(const char *psz);
848 #endif
849
850 #ifndef wxStrdupW
851 WXDLLIMPEXP_BASE wchar_t *wxStrdupW(const wchar_t *pwz);
852 #endif
853
854 #ifndef wxStricmp
855 WXDLLIMPEXP_BASE int wxStricmp(const wxChar *psz1, const wxChar *psz2);
856 #endif
857
858 #ifndef wxStrnicmp
859 WXDLLIMPEXP_BASE int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
860 #endif
861
862 #ifndef wxStrtok
863 WXDLLIMPEXP_BASE wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
864 #endif
865
866 #ifndef wxSetlocale
867 class WXDLLIMPEXP_BASE wxWCharBuffer;
868 WXDLLIMPEXP_BASE wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
869 #endif
870
871 // stdio.h functions
872 #ifdef wxNEED_WX_STDIO_H
873 #include <stdio.h>
874 WXDLLIMPEXP_BASE FILE * wxFopen(const wxChar *path, const wxChar *mode);
875 WXDLLIMPEXP_BASE FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
876 WXDLLIMPEXP_BASE int wxRemove(const wxChar *path);
877 WXDLLIMPEXP_BASE int wxRename(const wxChar *oldpath, const wxChar *newpath);
878
879 // *printf() family is handled separately
880 #endif // wxNEED_WX_STDIO_H
881
882
883 // stdlib.h functions
884 #ifndef wxAtof
885 WXDLLIMPEXP_BASE double wxAtof(const wxChar *psz);
886 #endif
887
888 #ifdef wxNEED_WX_STDLIB_H
889 WXDLLIMPEXP_BASE int wxAtoi(const wxChar *psz);
890 WXDLLIMPEXP_BASE long wxAtol(const wxChar *psz);
891 WXDLLIMPEXP_BASE wxChar * wxGetenv(const wxChar *name);
892 WXDLLIMPEXP_BASE int wxSystem(const wxChar *psz);
893 #endif
894
895
896 // time.h functions
897 #ifdef wxNEED_WX_TIME_H
898 #if defined(__MWERKS__) && defined(macintosh)
899 #include <time.h>
900 #endif
901 WXDLLIMPEXP_BASE size_t wxStrftime(wxChar *s, size_t max,
902 const wxChar *fmt, const struct tm *tm);
903 #endif // wxNEED_WX_TIME_H
904
905 // missing functions in some WinCE versions
906 #ifdef _WIN32_WCE
907 #if (_WIN32_WCE < 300)
908 WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
909 #endif
910 WXDLLIMPEXP_BASE char* strdup(const char* s);
911
912 #if _WIN32_WCE <= 211
913 WXDLLIMPEXP_BASE int isspace(int c);
914 WXDLLIMPEXP_BASE int isascii( int c );
915 #endif
916 #endif
917
918 // ----------------------------------------------------------------------------
919 // multibyte to wide char conversion functions and macros
920 // ----------------------------------------------------------------------------
921
922 #if wxUSE_WCHAR_T
923 // multibyte<->widechar conversion
924 WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
925 WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
926
927 #if wxUSE_UNICODE
928 #define wxMB2WX wxMB2WC
929 #define wxWX2MB wxWC2MB
930 #define wxWC2WX wxStrncpy
931 #define wxWX2WC wxStrncpy
932 #else
933 #define wxMB2WX wxStrncpy
934 #define wxWX2MB wxStrncpy
935 #define wxWC2WX wxWC2MB
936 #define wxWX2WC wxMB2WC
937 #endif
938 #else // !wxUSE_UNICODE
939 // No wxUSE_WCHAR_T: we have to do something (JACS)
940 #define wxMB2WC wxStrncpy
941 #define wxWC2MB wxStrncpy
942 #define wxMB2WX wxStrncpy
943 #define wxWX2MB wxStrncpy
944 #define wxWC2WX wxWC2MB
945 #define wxWX2WC wxMB2WC
946 #endif
947
948 #endif //_WX_WXCHAR_H_
949