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, Ron Lee
8 * Copyright: (c) 1998-2006 wxWidgets dev team
9 * Licence: wxWindows licence
12 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
17 /* defs.h indirectly includes this file, so don't include it here */
18 #include "wx/platform.h"
19 #include "wx/dlimpexp.h"
22 #include "wx/strvararg.h"
24 /* make the file compile without doing anything in C code: */
25 #define WX_DEFINE_VARARG_FUNC(rettype, name, impl)
28 #include <stdio.h> /* we use FILE below */
30 #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
31 char *strtok_r(char *, const char *, char **);
34 /* check whether we have wchar_t and which size it is if we do */
35 #if !defined(wxUSE_WCHAR_T)
37 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
38 #define wxUSE_WCHAR_T 1
40 #define wxUSE_WCHAR_T 0
42 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
43 #define wxUSE_WCHAR_T 0
44 #elif defined(__WATCOMC__)
45 #define wxUSE_WCHAR_T 0
46 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
47 #define wxUSE_WCHAR_T 0
49 /* add additional compiler checks if this fails */
50 #define wxUSE_WCHAR_T 1
52 #endif /* !defined(wxUSE_WCHAR_T) */
54 /* Unicode support requires wchar_t */
55 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
56 #error "wchar_t must be available in Unicode build"
60 Standard headers we need here.
62 NB: don't include any wxWidgets headers here because almost all of them include
66 /* Required for wxPrintf() etc */
69 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac */
70 /* and VC++ for Windows CE don't provide it */
71 #if defined(__VISUALC__) && __VISUALC__ >= 1400
72 #define wxStrdupA _strdup
73 #elif !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
74 /* use #define, not inline wrapper, as it is tested with #ifndef below */
75 #define wxStrdupA strdup
79 non Unix compilers which do have wchar.h (but not tchar.h which is included
80 below and which includes wchar.h anyhow).
82 Actually MinGW has tchar.h, but it does not include wchar.h
84 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
89 #if defined(__MWERKS__) && !defined(__MACH__)
97 /* the current (as of Nov 2002) version of cygwin has a bug in its */
98 /* wchar.h -- there is no extern "C" around the declarations in it and */
99 /* this results in linking errors later; also, at least on some */
100 /* Cygwin versions, wchar.h requires sys/types.h */
102 #include <sys/types.h>
110 #if defined(__CYGWIN__) && defined(__cplusplus)
112 #endif /* Cygwin and C++ */
114 #elif defined(HAVE_WCSTR_H)
115 /* old compilers have relevant declarations here */
117 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
118 /* include stdlib.h for wchar_t */
120 #endif /* HAVE_WCHAR_H */
126 #if !defined(__GNUC__) || defined(__DARWIN__)
127 #define wxWINT_T_IS_TYPEDEF
129 #endif /* wxUSE_WCHAR_T */
131 /* ---------------------------------------------------------------------------- */
132 /* define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type */
133 /* mapped to either char or wchar_t depending on the ASCII/Unicode mode and have */
134 /* the function mapping _tfoo() -> foo() or wfoo() */
135 /* ---------------------------------------------------------------------------- */
137 /* VC++ and BC++ starting with 5.2 have TCHAR support */
139 #define wxHAVE_TCHAR_SUPPORT
140 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
141 #define wxHAVE_TCHAR_SUPPORT
143 #elif defined(__WATCOMC__)
144 #define wxHAVE_TCHAR_SUPPORT
145 #elif defined(__DMC__)
146 #define wxHAVE_TCHAR_SUPPORT
147 #elif defined(__WXPALMOS__)
149 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
150 #define wxHAVE_TCHAR_SUPPORT
154 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
155 /* VZ: the old VisualAge definitions were completely wrong and had no */
156 /* chance at all to work in Unicode build anyhow so let's pretend that */
157 /* VisualAge does _not_ support TCHAR for the moment (as indicated by */
158 /* "0 &&" above) until someone really has time to delve into Unicode */
159 /* issues under OS/2 */
161 /* VisualAge 4.0+ supports TCHAR */
162 #define wxHAVE_TCHAR_SUPPORT
163 #endif /* compilers with (good) TCHAR support */
165 #if defined(__MWERKS__)
166 /* Metrowerks only has wide char support for OS X >= 10.3 */
167 #if !defined(__DARWIN__) || \
168 (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
169 #define wxHAVE_MWERKS_UNICODE
172 #ifdef wxHAVE_MWERKS_UNICODE
173 #define HAVE_WPRINTF 1
174 #define HAVE_WCSRTOMBS 1
175 #define HAVE_VSWPRINTF 1
177 #endif /* __MWERKS__ */
179 #ifdef wxHAVE_TCHAR_SUPPORT
180 /* get TCHAR definition if we've got it */
183 /* we surely do have wchar_t if we have TCHAR */
184 #ifndef wxUSE_WCHAR_T
185 #define wxUSE_WCHAR_T 1
186 #endif /* !defined(wxUSE_WCHAR_T) */
188 /* and we also do have wcslen() */
192 #endif /* wxHAVE_TCHAR_SUPPORT */
194 /* ---------------------------------------------------------------------------- */
195 /* define wxChar type */
196 /* ---------------------------------------------------------------------------- */
198 /* TODO: define wxCharInt to be equal to either int or wint_t? */
202 typedef signed char wxSChar
;
203 typedef unsigned char wxUChar
;
205 /* VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as */
206 /* signed/unsigned version of it which (a) makes sense to me (unlike */
207 /* char wchar_t is always unsigned) and (b) was how the previous */
208 /* definitions worked so keep it like this */
210 /* Sun's SunPro compiler supports the wchar_t type and wide character */
211 /* functions, but does not define __WCHAR_TYPE__. Define it here to */
212 /* allow unicode enabled builds. */
213 #if defined(__SUNPRO_CC) || defined(__SUNPRO_C)
214 #define __WCHAR_TYPE__ wxchar_t
217 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
219 #if !defined(__WCHAR_TYPE__) || \
220 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
222 typedef wchar_t wxChar
;
223 typedef wchar_t wxSChar
;
224 typedef wchar_t wxUChar
;
225 #else /* __WCHAR_TYPE__ and gcc < 2.96 */
226 /* VS: wxWidgets used to define wxChar as __WCHAR_TYPE__ here. */
227 /* However, this doesn't work with new GCC 3.x compilers because */
228 /* wchar_t is C++'s builtin type in the new standard. OTOH, old */
229 /* compilers (GCC 2.x) won't accept new definition of */
230 /* wx{S,U}CharType, so we have to define wxChar */
231 /* conditionally depending on detected compiler & compiler */
234 /* with old definition of wxChar. */
235 #define wchar_t __WCHAR_TYPE__
236 typedef __WCHAR_TYPE__ wxChar
;
237 typedef __WCHAR_TYPE__ wxSChar
;
238 typedef __WCHAR_TYPE__ wxUChar
;
239 #endif /* __WCHAR_TYPE__ */
240 #endif /* ASCII/Unicode */
242 /* ---------------------------------------------------------------------------- */
243 /* define _T() and related macros */
244 /* ---------------------------------------------------------------------------- */
246 /* BSD systems define _T() to be something different in ctype.h, override it */
247 #if defined(__FreeBSD__) || defined(__DARWIN__)
252 /* could already be defined by tchar.h (it's quasi standard) */
257 /* use wxCONCAT_HELPER so that x could be expanded if it's a macro */
258 #define _T(x) wxCONCAT_HELPER(L, x)
259 #endif /* ASCII/Unicode */
260 #endif /* !defined(_T) */
262 /* although global macros with such names are normally bad, we want to have */
263 /* another name for _T() which should be used to avoid confusion between _T() */
264 /* and _() in wxWidgets sources */
267 /* a helper macro allowing to make another macro Unicode-friendly, see below */
268 #define wxAPPLY_T(x) _T(x)
270 /* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
272 #define __TFILE__ wxAPPLY_T(__FILE__)
276 #define __TDATE__ wxAPPLY_T(__DATE__)
280 #define __TTIME__ wxAPPLY_T(__TIME__)
284 define wxFoo() function for each standard foo() function whose signature
285 (exceptionally including the return type) includes any mention of char:
286 wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
287 the same signature but with char replaced by wxChar which allows us to
288 use it in Unicode build as well
291 #ifdef wxHAVE_TCHAR_SUPPORT
294 #if defined(__WATCOMC__) && defined(UNICODE)
295 #define WXWCHAR_T_CAST(c) (wint_t)(c)
297 #define WXWCHAR_T_CAST(c) c
300 /* ctype.h functions */
301 #define wxIsalnum(c) _istalnum(WXWCHAR_T_CAST(c))
302 #define wxIsalpha(c) _istalpha(WXWCHAR_T_CAST(c))
303 #define wxIscntrl(c) _istcntrl(WXWCHAR_T_CAST(c))
304 #define wxIsdigit(c) _istdigit(WXWCHAR_T_CAST(c))
305 #define wxIsgraph(c) _istgraph(WXWCHAR_T_CAST(c))
306 #define wxIslower(c) _istlower(WXWCHAR_T_CAST(c))
307 #define wxIsprint(c) _istprint(WXWCHAR_T_CAST(c))
308 #define wxIspunct(c) _istpunct(WXWCHAR_T_CAST(c))
309 #define wxIsspace(c) _istspace(WXWCHAR_T_CAST(c))
310 #define wxIsupper(c) _istupper(WXWCHAR_T_CAST(c))
311 #define wxIsxdigit(c) _istxdigit(WXWCHAR_T_CAST(c))
314 There is a bug in VC6 C RTL: toxxx() functions dosn't do anything with
315 signed chars < 0, so "fix" it here.
317 #define wxTolower(c) _totlower((wxUChar)(wxChar)(c))
318 #define wxToupper(c) _totupper((wxUChar)(wxChar)(c))
320 /* locale.h functons */
321 #define wxSetlocale _tsetlocale
323 /* string.h functions */
324 #define wxStrcat _tcscat
325 #define wxStrchr _tcschr
326 #define wxStrcmp _tcscmp
327 #define wxStrcoll _tcscoll
328 #define wxStrcpy _tcscpy
329 #define wxStrcspn _tcscspn
330 #define wxStrdupW _wcsdup /* notice the 'W'! */
331 #define wxStrftime _tcsftime
332 #define wxStricmp _tcsicmp
333 #define wxStrnicmp _tcsnicmp
334 #define wxStrlen_ _tcslen /* used in wxStrlen inline function */
335 #define wxStrncat _tcsncat
336 #define wxStrncmp _tcsncmp
337 #define wxStrncpy _tcsncpy
338 #define wxStrpbrk _tcspbrk
339 #define wxStrrchr _tcsrchr
340 #define wxStrspn _tcsspn
341 #define wxStrstr _tcsstr
342 #define wxStrtod _tcstod
343 #define wxStrtol _tcstol
344 #define wxStrtoul _tcstoul
346 #if __VISUALC__ >= 1300 && !defined(__WXWINCE__)
347 #define wxStrtoll _tcstoi64
348 #define wxStrtoull _tcstoui64
351 #define wxStrxfrm _tcsxfrm
353 /* stdio.h functions */
354 #define wxFgetc _fgettc
355 #define wxFgetchar _fgettchar
356 #define wxFgets _fgetts
357 #if wxUSE_UNICODE_MSLU
358 WXDLLIMPEXP_BASE
FILE * wxMSLU__tfopen(const wxChar
*name
, const wxChar
*mode
);
360 #define wxFopen wxMSLU__tfopen
362 #define wxFopen _tfopen
364 #define wxFputc _fputtc
365 #define wxFputchar _fputtchar
366 WX_DEFINE_VARARG_FUNC(int, wxFprintf
, _ftprintf
)
367 #define wxFputs _fputts
368 #define wxFreopen _tfreopen
369 #define wxFscanf _ftscanf
370 #define wxGetc _gettc
371 #define wxGetchar _gettchar
372 #define wxGets _getts
373 #define wxPerror _tperror
374 WX_DEFINE_VARARG_FUNC(int, wxPrintf
, _tprintf
)
375 #define wxPutc(c,f) _puttc(WXWCHAR_T_CAST(c),f)
376 #define wxPutchar _puttchar
377 #define wxPuts _putts
378 #define wxScanf _tscanf
381 /* Digital Mars adds count to _stprintf (C99) so prototype conversion see wxchar.cpp */
382 int wxDoSprintf (wchar_t * __RESTRICT s
, const wchar_t * __RESTRICT format
, ... ) ;
383 WX_DEFINE_VARARG_FUNC(int, wxSprintf
, wxDoSprintf
)
385 /* and there is a bug in D Mars tchar.h prior to 8.39.4n, so define as sprintf */
386 WX_DEFINE_VARARG_FUNC(int, wxSprintf
, sprintf
)
389 WX_DEFINE_VARARG_FUNC(int, wxSprintf
, _stprintf
)
392 #define wxSscanf _stscanf
393 #define wxTmpnam _ttmpnam
394 #define wxUngetc _tungetc
395 #define wxVfprintf _vftprintf
396 #define wxVprintf _vtprintf
397 #define wxVsscanf _vstscanf
398 #define wxVsprintf _vstprintf
400 /* special case: these functions are missing under Win9x with Unicows so we */
401 /* have to implement them ourselves */
402 #if wxUSE_UNICODE_MSLU
403 WXDLLIMPEXP_BASE
int wxMSLU__trename(const wxChar
*oldname
, const wxChar
*newname
);
404 WXDLLIMPEXP_BASE
int wxMSLU__tremove(const wxChar
*name
);
406 #define wxRemove wxMSLU__tremove
407 #define wxRename wxMSLU__trename
410 /* carefully: wxRemove() must return 0 on success while DeleteFile()
411 returns 0 on error, so don't just define one as the other */
412 int wxRemove(const wxChar
*path
);
414 #define wxRemove _tremove
415 #define wxRename _trename
419 /* stdlib.h functions */
422 /* #define wxAtof _tttof -- notice that there is no such thing (why?) */
423 /* there are no env vars at all under CE, so no _tgetenv neither */
425 /* can't define as inline function as this is a C file... */
426 #define wxGetenv(name) ((wxChar *)NULL)
428 #define wxGetenv _tgetenv
430 #define wxSystem _tsystem
432 /* time.h functions */
433 #define wxAsctime _tasctime
434 #define wxCtime _tctime
436 #define wxMbstowcs mbstowcs
437 #define wxWcstombs wcstombs
438 #else /* !TCHAR-aware compilers */
440 There are 2 unrelated problems with these functions under Mac:
441 a) Metrowerks MSL CRT implements them strictly in C99 sense and
442 doesn't support (very common) extension of allowing to call
443 mbstowcs(NULL, ...) which makes it pretty useless as you can't
444 know the size of the needed buffer
445 b) OS X <= 10.2 declares and even defined these functions but
446 doesn't really implement them -- they always return an error
448 So use our own replacements in both cases.
450 #if defined(__MWERKS__) && defined(__MSL__)
451 #define wxNEED_WX_MBSTOWCS
455 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
456 #define wxNEED_WX_MBSTOWCS
460 #ifdef wxNEED_WX_MBSTOWCS
461 /* even though they are defined and "implemented", they are bad and just
462 stubs so we need our own - we need these even in ANSI builds!! */
463 WXDLLIMPEXP_BASE
size_t wxMbstowcs (wchar_t *, const char *, size_t);
464 WXDLLIMPEXP_BASE
size_t wxWcstombs (char *, const wchar_t *, size_t);
466 #define wxMbstowcs mbstowcs
467 #define wxWcstombs wcstombs
471 The system C library on Mac OS X 10.2 and below does not support
472 unicode: in other words all wide-character functions such as towupper et
473 al. do simply not exist so we need to provide our own in that context,
474 except for the wchar_t definition/typedef itself.
476 We need to do this for both project builder and CodeWarrior as
477 the latter uses the system C library in Mach builds for wide character
478 support, which as mentioned does not exist on 10.2 and below.
480 #if wxUSE_UNICODE && \
481 defined(__DARWIN__) && \
482 ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
483 /* we need everything! */
484 #define wxNEED_WX_STRING_H
485 #define wxNEED_WX_CTYPE_H
487 #define wxFgetchar(c) wxFgetc(c, stdin)
488 #define wxFputc wxPutc
489 #define wxFputchar(c) wxPutc(c, stdout)
490 #define wxGetc wxFgetc
491 #define wxGetchar(c) wxFgetc(c, stdin)
498 #define wxNEED_UNGETC
504 int wxFputs(const wxChar
*ch
, FILE *stream
);
505 int wxPuts(const wxChar
*ws
);
506 int wxPutc(wxChar ch
, FILE *stream
);
511 WXDLLIMPEXP_BASE
size_t wxStrlen_(const wxChar
*s
);
516 #define wxPutchar(wch) wxPutc(wch, stdout)
518 #define wxNEED_PRINTF_CONVERSION
519 #define wxNEED_WX_STDIO_H
520 #define wxNEED_WX_STDLIB_H
521 #define wxNEED_WX_TIME_H
526 /* this is probably glibc-specific */
527 #if defined(__WCHAR_TYPE__) && !defined(__MWERKS__)
528 /* ctype.h functions (wctype.h) */
529 #define wxIsalnum iswalnum
530 #define wxIsalpha iswalpha
531 #define wxIscntrl iswcntrl
532 #define wxIsdigit iswdigit
533 #define wxIsgraph iswgraph
534 #define wxIslower iswlower
535 #define wxIsprint iswprint
536 #define wxIspunct iswpunct
537 #define wxIsspace iswspace
538 #define wxIsupper iswupper
539 #define wxIsxdigit iswxdigit
541 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
542 /* /usr/include/wctype.h incorrectly declares translations */
543 /* tables which provokes tons of compile-time warnings -- try */
544 /* to correct this */
545 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
546 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
547 #else /* !glibc 2.0 */
548 #define wxTolower towlower
549 #define wxToupper towupper
550 #endif /* gcc/!gcc */
552 /* string.h functions (wchar.h) */
553 #define wxStrcat wcscat
554 #define wxStrchr wcschr
555 #define wxStrcmp wcscmp
556 #define wxStrcoll wcscoll
557 #define wxStrcpy wcscpy
558 #define wxStrcspn wcscspn
559 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
560 #define wxStrncat wcsncat
561 #define wxStrncmp wcsncmp
562 #define wxStrncpy wcsncpy
563 #define wxStrpbrk wcspbrk
564 #define wxStrrchr wcsrchr
565 #define wxStrspn wcsspn
566 #define wxStrstr wcsstr
567 #define wxStrtod wcstod
568 #define wxStrtol wcstol
569 #define wxStrtoul wcstoul
571 /* assume that we have wcstoull(), which is also C99, too */
572 #define wxStrtoll wcstoll
573 #define wxStrtoull wcstoull
574 #endif /* HAVE_WCSTOULL */
575 #define wxStrxfrm wcsxfrm
577 #define wxFgetc fgetwc
578 #define wxFgetchar fgetwchar
579 #define wxFgets fgetws
580 #define wxFputc fputwc
581 #define wxFputchar fputwchar
583 #define wxGetchar getwchar
585 #define wxUngetc ungetwc
588 #define wxFputs fputws
592 int wxFputs(const wxChar
*ch
, FILE *stream
);
600 int wxPutc(wxChar ch
, FILE *stream
);
604 #define wxPutchar wputchar
606 #define wxPutchar(wch) wxPutc(wch, stdout)
613 int wxPuts(const wxChar
*ws
);
616 /* we need %s to %ls conversion for printf and scanf etc */
617 #define wxNEED_PRINTF_CONVERSION
619 /* glibc doesn't have wide char equivalents of the other stuff so */
620 /* use our own versions */
621 #define wxNEED_WX_STDIO_H
622 #define wxNEED_WX_STDLIB_H
623 #define wxNEED_WX_TIME_H
624 #elif defined(__MWERKS__) && ( defined(__MSL__) || defined(__MACH__) )
625 /* ctype.h functions (wctype.h) */
626 #define wxIsalnum iswalnum
627 #define wxIsalpha iswalpha
628 #define wxIscntrl iswcntrl
629 #define wxIsdigit iswdigit
630 #define wxIsgraph iswgraph
631 #define wxIslower iswlower
632 #define wxIsprint iswprint
633 #define wxIspunct iswpunct
634 #define wxIsspace iswspace
635 #define wxIsupper iswupper
636 #define wxIsxdigit iswxdigit
637 #define wxTolower towlower
638 #define wxToupper towupper
640 /* string.h functions (wchar.h) */
641 #define wxStrcat wcscat
642 #define wxStrchr wcschr
643 #define wxStrcmp wcscmp
644 #define wxStrcoll wcscoll
645 #define wxStrcpy wcscpy
646 #define wxStrcspn wcscspn
647 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
648 #define wxStrncat wcsncat
649 #define wxStrncmp wcsncmp
650 #define wxStrncpy wcsncpy
651 #define wxStrpbrk wcspbrk
652 #define wxStrrchr wcsrchr
653 #define wxStrspn wcsspn
654 #define wxStrstr wcsstr
655 #define wxStrtod wcstod
656 #define wxStrtol wcstol
657 #define wxStrtoul wcstoul
658 #define wxStrxfrm wcsxfrm
660 #define wxFgetc fgetwc
661 #define wxFgetchar fgetwchar
662 #define wxFgets fgetws
663 #define wxFputc fputwc
664 #define wxFputchar fputwchar
666 #define wxGetchar getwchar
668 #define wxUngetc ungetwc
670 #define wxNEED_PRINTF_CONVERSION
673 #define wxPutchar putwchar
674 #define wxFputs fputws
676 /* stdio.h functions */
678 #define wxNEED_WX_STDIO_H
680 /* stdlib.h functions */
682 #define wxNEED_WX_STDLIB_H
687 #define wxGetenv(a) ((wxChar*)NULL)
688 #define wxSystem(a) ((int)NULL)
690 /* time.h functions */
691 #define wxAsctime wasciitime
692 #define wxCtime wctime
693 /* #define wxStrftime wcsftime */
695 #define wxNEED_WX_TIME_H
696 #else /* !metrowerks for apple */
697 #error "Please define wide character functions for your environment"
703 /* ctype.h functions */
704 #define wxIsalnum isalnum
705 #define wxIsalpha isalpha
706 #define wxIscntrl iscntrl
707 #define wxIsdigit isdigit
708 #define wxIsgraph isgraph
709 #define wxIslower islower
710 #define wxIsprint isprint
711 #define wxIspunct ispunct
712 #define wxIsspace isspace
713 #define wxIsupper isupper
714 #define wxIsxdigit isxdigit
715 #define wxTolower tolower
716 #define wxToupper toupper
718 /* locale.h functons */
719 #define wxSetlocale setlocale
721 /* string.h functions */
722 #define wxStrcat strcat
723 #define wxStrchr strchr
724 #define wxStrcmp strcmp
725 #define wxStrcoll strcoll
726 #define wxStrcpy strcpy
727 #define wxStrcspn strcspn
729 /* wxStricmp and wxStrnicmp are defined below */
730 #define wxStrlen_ strlen /* used in wxStrlen inline function */
731 #define wxStrncat strncat
732 #define wxStrncmp strncmp
733 #define wxStrncpy strncpy
734 #define wxStrpbrk strpbrk
735 #define wxStrrchr strrchr
736 #define wxStrspn strspn
737 #define wxStrstr strstr
738 #define wxStrtod strtod
740 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
742 #define wxStrtol strtol
743 #define wxStrtoul strtoul
745 /* assume that we have wcstoull(), which is also C99, too */
746 #define wxStrtoll strtoll
747 #define wxStrtoull strtoull
748 #endif /* HAVE_WCSTOULL */
749 #define wxStrxfrm strxfrm
751 /* stdio.h functions */
752 #define wxFopen fopen
753 #define wxFreopen freopen
754 #define wxRemove remove
755 #define wxRename rename
757 #define wxPerror perror
758 #define wxTmpnam tmpnam
760 #define wxFgetc fgetc
761 #define wxFgetchar fgetchar
762 #define wxFgets fgets
763 #define wxFputc fputc
764 #define wxFputs fputs
765 #define wxFputchar fputchar
766 WX_DEFINE_VARARG_FUNC(int, wxFprintf
, fprintf
)
767 #define wxFscanf fscanf
769 #define wxGetchar getchar
771 WX_DEFINE_VARARG_FUNC(int, wxPrintf
, printf
)
773 #define wxPutchar putchar
775 #define wxScanf scanf
776 WX_DEFINE_VARARG_FUNC(int, wxSprintf
, sprintf
)
777 #define wxSscanf sscanf
778 #define wxUngetc ungetc
779 #define wxVfprintf vfprintf
780 #define wxVprintf vprintf
781 #define wxVsscanf vsscanf
782 #define wxVsprintf vsprintf
784 /* stdlib.h functions */
788 #define wxGetenv getenv
789 #define wxSystem system
791 /* time.h functions */
792 #define wxAsctime asctime
793 #define wxCtime ctime
794 #define wxStrftime strftime
795 #endif /* Unicode/ASCII */
796 #endif /* TCHAR-aware compilers/the others */
799 #define wxHAS_STRTOLL
803 various special cases
806 /* define wxStricmp and wxStrnicmp for various compilers */
808 /* note that in Unicode mode we definitely are going to need our own version */
809 #if !defined(wxStricmp) && !wxUSE_UNICODE
810 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
811 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
812 defined(__EMX__) || defined(__DJGPP__)
813 #define wxStricmp stricmp
814 #define wxStrnicmp strnicmp
815 #elif defined(__WXPALMOS__)
816 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
817 * quick hack should do until one can be written.
819 #define wxStricmp StrCaselessCompare
820 #define wxStrnicmp strnicmp
821 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
822 (defined(__MWERKS__) && defined(__INTEL__))
823 #define wxStricmp _stricmp
824 #define wxStrnicmp _strnicmp
825 #elif defined(__UNIX__) || defined(__GNUWIN32__)
826 #define wxStricmp strcasecmp
827 #define wxStrnicmp strncasecmp
828 /* #else -- use wxWidgets implementation */
830 #endif /* !defined(wxStricmp) */
832 /* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
833 /* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
834 /* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
837 #define wxWcslen wcslen
839 WXDLLIMPEXP_BASE
size_t wxWcslen(const wchar_t *s
);
841 #endif /* wxUSE_WCHAR_T */
844 /* checks whether the passed in pointer is NULL and if the string is empty */
845 inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
847 /* safe version of strlen() (returns 0 if passed NULL pointer) */
848 inline size_t wxStrlen(const wxChar
*psz
) { return psz
? wxStrlen_(psz
) : 0; }
852 each of strdup() and wcsdup() may or may not be available but we need both
853 of them anyhow for wx/buffer.h so we define the missing one(s) in
854 wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
855 defined -- if this is somehow not the case in some situations, please
856 correct that and not the lines here
859 #define wxStrdup wxStrdupW
861 #define wxStrdup wxStrdupA
865 WXDLLIMPEXP_BASE
bool wxOKlibc(); /* for internal use */
868 /* printf() family saga */
871 For some systems [v]snprintf() exists in the system libraries but not in the
872 headers, so we need to declare it ourselves to be able to use it.
874 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
880 int vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
);
881 #endif /* !HAVE_VSNPRINTF_DECL */
883 #if defined(HAVE_SNPRINTF) && !defined(HAVE_SNPRINTF_DECL)
889 WXDLLIMPEXP_BASE
int snprintf(char *str
, size_t size
, const char *format
, ...);
890 #endif /* !HAVE_SNPRINTF_DECL */
892 /* Wrapper for vsnprintf if it's 3rd parameter is non-const. Note: the
893 * same isn't done for snprintf below, the builtin wxSnprintf_ is used
894 * instead since it's already a simple wrapper */
895 #if defined __cplusplus && defined HAVE_BROKEN_VSNPRINTF_DECL
896 inline int wx_fixed_vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
)
898 return vsnprintf(str
, size
, (char*)format
, ap
);
903 MinGW MSVCRT has non-standard vswprintf() (for MSVC compatibility
904 presumably) and normally _vsnwprintf() is used instead
906 #if defined(HAVE_VSWPRINTF) && defined(__MINGW32__)
907 #undef HAVE_VSWPRINTF
910 #if wxUSE_PRINTF_POS_PARAMS
912 The systems where vsnprintf() supports positional parameters should
913 define the HAVE_UNIX98_PRINTF symbol.
915 On systems which don't (e.g. Windows) we are forced to use
916 our wxVsnprintf() implementation.
918 #if defined(HAVE_UNIX98_PRINTF)
920 #ifdef HAVE_VSWPRINTF
921 #define wxVsnprintf_ vswprintf
924 #ifdef HAVE_BROKEN_VSNPRINTF_DECL
925 #define wxVsnprintf_ wx_fixed_vsnprintf
927 #define wxVsnprintf_ vsnprintf
930 #else /* !HAVE_UNIX98_PRINTF */
932 The only compiler with positional parameters support under Windows
933 is VC++ 8.0 which provides a new xxprintf_p() functions family.
934 The 2003 PSDK includes a slightly earlier version of VC8 than the
935 main release and does not have the printf_p functions.
937 #if defined _MSC_FULL_VER && _MSC_FULL_VER >= 140050727 && !defined __WXWINCE__
939 #define wxVsnprintf_ _vswprintf_p
941 #define wxVsnprintf_ _vsprintf_p
944 #endif /* HAVE_UNIX98_PRINTF/!HAVE_UNIX98_PRINTF */
945 #else /* !wxUSE_PRINTF_POS_PARAMS */
947 We always want to define safe snprintf() function to be used instead of
948 sprintf(). Some compilers already have it (or rather vsnprintf() which
949 we really need...), otherwise we implement it using our own printf()
952 We define function with a trailing underscore here because the real one
953 is a wrapper around it as explained below
956 /* first deal with TCHAR-aware compilers which have _vsntprintf */
958 #if defined(__VISUALC__) || \
959 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
960 #define wxVsnprintf_ _vsntprintf
961 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, _sntprintf
)
965 /* if this didn't work, define it separately for Unicode and ANSI builds */
968 #if defined(HAVE__VSNWPRINTF)
969 #define wxVsnprintf_ _vsnwprintf
970 #elif defined(HAVE_VSWPRINTF)
971 #define wxVsnprintf_ vswprintf
972 #elif defined(__WATCOMC__)
973 #define wxVsnprintf_ _vsnwprintf
974 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, _snwprintf
)
978 All versions of CodeWarrior supported by wxWidgets apparently
979 have both snprintf() and vsnprintf()
981 #if defined(HAVE_SNPRINTF) \
982 || defined(__MWERKS__) || defined(__WATCOMC__)
983 #ifndef HAVE_BROKEN_SNPRINTF_DECL
984 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, snprintf
)
987 #if defined(HAVE_VSNPRINTF) \
988 || defined(__MWERKS__) || defined(__WATCOMC__)
989 #ifdef HAVE_BROKEN_VSNPRINTF_DECL
990 #define wxVsnprintf_ wx_fixed_vsnprintf
992 #define wxVsnprintf_ vsnprintf
995 #endif /* Unicode/ASCII */
996 #endif /* wxVsnprintf_ */
997 #endif /* wxUSE_PRINTF_POS_PARAMS/!wxUSE_PRINTF_POS_PARAMS */
1000 /* no snprintf(), cook our own */
1001 WXDLLIMPEXP_BASE
int
1002 wxDoSnprintf_(wxChar
*buf
, size_t len
,
1003 const wxChar
*format
, ...) ATTRIBUTE_PRINTF_3
;
1004 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, wxDoSnprintf_
)
1006 #ifndef wxVsnprintf_
1007 /* no (suitable) vsnprintf(), cook our own */
1008 WXDLLIMPEXP_BASE
int
1009 wxVsnprintf_(wxChar
*buf
, size_t len
,
1010 const wxChar
*format
, va_list argptr
);
1012 #define wxUSE_WXVSNPRINTF 1
1014 #define wxUSE_WXVSNPRINTF 0
1018 In Unicode mode we need to have all standard functions such as wprintf() and
1019 so on but not all systems have them so use our own implementations in this
1022 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
1023 #define wxNEED_WPRINTF
1027 More Unicode complications: although both ANSI C and C++ define a number of
1028 wide character functions such as wprintf(), not all environments have them.
1029 Worse, those which do have different behaviours: under Windows, %s format
1030 specifier changes its meaning in Unicode build and expects a Unicode string
1031 while under Unix/POSIX it still means an ASCII string even for wprintf() and
1032 %ls has to be used for wide strings.
1034 We choose to always emulate Windows behaviour as more useful for us so even
1035 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
1039 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
1041 we need to implement all wide character printf and scanf functions
1042 either because we don't have them at all or because they don't have the
1045 WX_DEFINE_VARARG_FUNC(int, wxScanf
, wxDoScanf
)
1046 int wxDoScanf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
1048 WX_DEFINE_VARARG_FUNC(int, wxSscanf
, wxDoSscanf
)
1049 int wxDoSscanf( const wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
1051 WX_DEFINE_VARARG_FUNC(int, wxFscanf
, wxDoFscanf
)
1052 int wxDoFscanf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
1054 WX_DEFINE_VARARG_FUNC(int, wxPrintf
, wxDoPrintf
)
1055 int wxDoPrintf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
1057 WX_DEFINE_VARARG_FUNC(int, wxSprintf
, wxDoSprintf
)
1058 int wxDoSprintf( wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
1060 WX_DEFINE_VARARG_FUNC(int, wxFprintf
, wxDoFprintf
)
1061 int wxDoFprintf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
1063 int wxVsscanf( const wxChar
*str
, const wxChar
*format
, va_list ap
);
1064 int wxVfprintf( FILE *stream
, const wxChar
*format
, va_list ap
);
1065 int wxVprintf( const wxChar
*format
, va_list ap
);
1066 int wxVsprintf( wxChar
*str
, const wxChar
*format
, va_list ap
);
1067 #endif /* wxNEED_PRINTF_CONVERSION */
1069 /* these 2 can be simply mapped to the versions with underscore at the end */
1070 /* if we don't have to do the conversion */
1072 However, if we don't have any vswprintf() at all we don't need to redefine
1073 anything as our own wxVsnprintf_() already behaves as needed.
1075 #if defined(wxNEED_PRINTF_CONVERSION) && defined(wxVsnprintf_)
1076 WX_DEFINE_VARARG_FUNC(int, wxSnprintf
, wxDoSnprintf
)
1077 int wxDoSnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_3
;
1078 int wxVsnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, va_list ap
);
1080 #define wxSnprintf wxSnprintf_
1081 #define wxVsnprintf wxVsnprintf_
1085 various functions which might not be available in libc and for which we
1086 provide our own replacements in wxchar.cpp
1089 /* ctype.h functions */
1091 /* RN: Used only under OSX <= 10.2 currently */
1092 #ifdef wxNEED_WX_CTYPE_H
1093 WXDLLIMPEXP_BASE
int wxIsalnum(wxChar ch
);
1094 WXDLLIMPEXP_BASE
int wxIsalpha(wxChar ch
);
1095 WXDLLIMPEXP_BASE
int wxIscntrl(wxChar ch
);
1096 WXDLLIMPEXP_BASE
int wxIsdigit(wxChar ch
);
1097 WXDLLIMPEXP_BASE
int wxIsgraph(wxChar ch
);
1098 WXDLLIMPEXP_BASE
int wxIslower(wxChar ch
);
1099 WXDLLIMPEXP_BASE
int wxIsprint(wxChar ch
);
1100 WXDLLIMPEXP_BASE
int wxIspunct(wxChar ch
);
1101 WXDLLIMPEXP_BASE
int wxIsspace(wxChar ch
);
1102 WXDLLIMPEXP_BASE
int wxIsupper(wxChar ch
);
1103 WXDLLIMPEXP_BASE
int wxIsxdigit(wxChar ch
);
1104 WXDLLIMPEXP_BASE
int wxTolower(wxChar ch
);
1105 WXDLLIMPEXP_BASE
int wxToupper(wxChar ch
);
1106 #endif /* wxNEED_WX_CTYPE_H */
1108 /* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
1109 /* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
1110 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
1112 #define wxIsspace(c) ((((unsigned)(wxChar)c) < 128) && isspace(c))
1116 a few compilers don't have the (non standard but common) isascii function,
1117 define it ourselves for them
1120 #if defined(__MWERKS__)
1121 #define wxNEED_ISASCII
1122 #elif defined(_WIN32_WCE)
1123 #if _WIN32_WCE <= 211
1124 #define wxNEED_ISASCII
1127 #endif /* isascii */
1129 #ifdef wxNEED_ISASCII
1130 inline int isascii(int c
) { return (unsigned)c
< 0x80; }
1134 #if _WIN32_WCE <= 211
1135 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
1137 #endif /* _WIN32_WCE */
1140 we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
1141 initial versions of this header -- now it is too late to remove it so
1142 although we fixed the function/macro name above, still provide the
1143 backwards-compatible synonym.
1145 #define wxIsctrl wxIscntrl
1147 /* string.h functions */
1149 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
1150 #define wxNEED_STRDUP
1151 #elif defined(__WXWINCE__)
1152 #if _WIN32_WCE <= 211
1153 #define wxNEED_STRDUP
1158 #ifdef wxNEED_STRDUP
1159 WXDLLIMPEXP_BASE
char *strdup(const char* s
);
1162 /* RN: Used only under OSX <= 10.2 currently
1163 The __cplusplus ifdefs are messy, but they are required to build
1164 the regex library, since c does not support function overloading
1166 #ifdef wxNEED_WX_STRING_H
1170 WXDLLIMPEXP_BASE wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
1171 WXDLLIMPEXP_BASE
const wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
1172 WXDLLIMPEXP_BASE
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
1173 WXDLLIMPEXP_BASE
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
1174 WXDLLIMPEXP_BASE wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
1175 WXDLLIMPEXP_BASE
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
1176 WXDLLIMPEXP_BASE wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
1177 WXDLLIMPEXP_BASE
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
1178 WXDLLIMPEXP_BASE wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
1179 WXDLLIMPEXP_BASE
const wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
1180 WXDLLIMPEXP_BASE
const wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
1181 WXDLLIMPEXP_BASE
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
1182 WXDLLIMPEXP_BASE
const wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
1187 /* These functions use C++, so we can't c extern them */
1188 WXDLLIMPEXP_BASE
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
1189 WXDLLIMPEXP_BASE
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
1190 WXDLLIMPEXP_BASE
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
1191 WXDLLIMPEXP_BASE
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
1193 /* inlined versions */
1195 inline wxChar
* wxStrchr(wxChar
*s
, wxChar c
)
1196 { return (wxChar
*)wxStrchr((const wxChar
*)s
, c
); }
1197 inline wxChar
* wxStrpbrk(wxChar
*s
, const wxChar
*accept
)
1198 { return (wxChar
*)wxStrpbrk((const wxChar
*)s
, accept
); }
1199 inline wxChar
* wxStrrchr(wxChar
*s
, wxChar c
)
1200 { return (wxChar
*)wxStrrchr((const wxChar
*)s
, c
); }
1201 inline wxChar
*wxStrstr(wxChar
*haystack
, const wxChar
*needle
)
1202 { return (wxChar
*)wxStrstr((const wxChar
*)haystack
, needle
); }
1205 #endif /* wxNEED_WX_STRING_H */
1208 WXDLLIMPEXP_BASE
char *wxStrdupA(const char *psz
);
1212 WXDLLIMPEXP_BASE
wchar_t *wxStrdupW(const wchar_t *pwz
);
1216 WXDLLIMPEXP_BASE
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
1220 WXDLLIMPEXP_BASE
int wxStrnicmp(const wxChar
*psz1
, const wxChar
*psz2
, size_t len
);
1224 WXDLLIMPEXP_BASE wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
1229 class WXDLLIMPEXP_BASE wxWCharBuffer
;
1230 WXDLLIMPEXP_BASE wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
1234 /* stdio.h functions */
1235 #ifdef wxNEED_WX_STDIO_H
1237 WXDLLIMPEXP_BASE
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
1238 WXDLLIMPEXP_BASE
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
1239 WXDLLIMPEXP_BASE
int wxRemove(const wxChar
*path
);
1240 WXDLLIMPEXP_BASE
int wxRename(const wxChar
*oldpath
, const wxChar
*newpath
);
1242 /* *printf() family is handled separately */
1243 #endif /* wxNEED_WX_STDIO_H */
1246 /* stdlib.h functions */
1248 WXDLLIMPEXP_BASE
double wxAtof(const wxChar
*psz
);
1251 #ifdef wxNEED_WX_STDLIB_H
1252 WXDLLIMPEXP_BASE
int wxAtoi(const wxChar
*psz
);
1253 WXDLLIMPEXP_BASE
long wxAtol(const wxChar
*psz
);
1254 WXDLLIMPEXP_BASE wxChar
* wxGetenv(const wxChar
*name
);
1255 WXDLLIMPEXP_BASE
int wxSystem(const wxChar
*psz
);
1259 /* time.h functions */
1260 #ifdef wxNEED_WX_TIME_H
1261 #if defined(__MWERKS__) && defined(macintosh)
1264 /*silent gabby compilers*/
1266 WXDLLIMPEXP_BASE
size_t wxStrftime(wxChar
*s
, size_t max
,
1268 const struct tm
*tm
);
1269 #endif /* wxNEED_WX_TIME_H */
1273 WXDLLIMPEXP_BASE wxChar
*wxCtime(const time_t *timep
);
1277 /* missing functions in some WinCE versions */
1279 #if (_WIN32_WCE < 300)
1280 WXDLLIMPEXP_BASE
void *calloc( size_t num
, size_t size
);
1282 #endif /* _WIN32_WCE */
1284 /* multibyte to wide char conversion functions and macros */
1287 /* multibyte<->widechar conversion */
1288 WXDLLIMPEXP_BASE
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
1289 WXDLLIMPEXP_BASE
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
1292 #define wxMB2WX wxMB2WC
1293 #define wxWX2MB wxWC2MB
1294 #define wxWC2WX wxStrncpy
1295 #define wxWX2WC wxStrncpy
1297 #define wxMB2WX wxStrncpy
1298 #define wxWX2MB wxStrncpy
1299 #define wxWC2WX wxWC2MB
1300 #define wxWX2WC wxMB2WC
1302 #else /* !wxUSE_UNICODE */
1303 /* Why is this here?
1305 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
1306 #define wxMB2WC wxStrncpy
1307 #define wxWC2MB wxStrncpy
1308 #define wxMB2WX wxStrncpy
1309 #define wxWX2MB wxStrncpy
1310 #define wxWC2WX wxWC2MB
1311 #define wxWX2WC wxMB2WC
1315 RN: The following are not normal versions of memcpy et al., rather
1316 these are either char or widechar versions depending on
1317 if unicode is used or not.
1323 // RN: We could do the usual tricky compiler detection here,
1324 // and use their variant (such as wmemchr, etc.). The problem
1325 // is that these functions are quite rare, even though they are
1326 // part of the current POSIX standard. In addition, most compilers
1327 // (including even MSC) inline them just like we do right in their
1331 #include <string.h> //for mem funcs
1333 //implement our own wmem variants
1334 inline wxChar
* wxTmemchr(const wxChar
* s
, wxChar c
, size_t l
)
1336 for(;l
&& *s
!= c
;--l
, ++s
) {}
1343 inline int wxTmemcmp(const wxChar
* sz1
, const wxChar
* sz2
, size_t len
)
1345 for(; *sz1
== *sz2
&& len
; --len
, ++sz1
, ++sz2
) {}
1348 return *sz1
< *sz2
? -1 : *sz1
> *sz2
;
1353 inline wxChar
* wxTmemcpy(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
1355 return (wxChar
*) memcpy(szOut
, szIn
, len
* sizeof(wxChar
));
1358 inline wxChar
* wxTmemmove(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
1360 return (wxChar
*) memmove(szOut
, szIn
, len
* sizeof(wxChar
));
1363 inline wxChar
* wxTmemset(wxChar
* szOut
, const wxChar cIn
, size_t len
)
1365 wxChar
* szRet
= szOut
;
1373 #else /* !wxUSE_UNICODE */
1374 # define wxTmemchr memchr
1375 # define wxTmemcmp memcmp
1376 # define wxTmemcpy memcpy
1377 # define wxTmemmove memmove
1378 # define wxTmemset memset
1379 #endif /* wxUSE_UNICODE/!wxUSE_UNICODE */
1381 #endif /*__cplusplus*/
1384 FIXME-UTF8: split this header into more:
1385 wxchartype.h for wxChar definition (only this one will have to
1386 remain C header, the rest can be C++)
1387 wxcrt.h for CRT wrappers
1388 wxchar.h for wxChar+wxCharRef classes
1391 class WXDLLIMPEXP_BASE wxString
;
1392 class WXDLLIMPEXP_BASE wxUniCharRef
;
1394 // This class represents single Unicode character. It can be converted to
1395 // and from char or wchar_t and implements commonly used character operations.
1396 class WXDLLIMPEXP_BASE wxUniChar
1399 // NB: this is not wchar_t on purpose, it needs to represent the entire
1400 // Unicode code points range and wchar_t may be too small for that
1401 // (e.g. on Win32 where wchar_t* is encoded in UTF-16)
1402 typedef unsigned int unicode_type
;
1404 wxUniChar() : m_value(0) {}
1406 // Create the character from 8bit character value encoded in the current
1407 // locale's charset.
1408 wxUniChar(char c
) { m_value
= From8bit(c
); }
1410 // Create the character from a wchar_t character value.
1411 wxUniChar(wchar_t c
) { m_value
= c
; }
1413 #ifndef wxWINT_T_IS_TYPEDEF
1414 // Create the character from a wint_t character value.
1415 wxUniChar(wint_t c
) { m_value
= c
; }
1418 wxUniChar(int c
) { m_value
= c
; }
1420 wxUniChar(const wxUniCharRef
& c
);
1422 // Returns Unicode code point value of the character
1423 unicode_type
GetValue() const { return m_value
; }
1425 // Casts to char and wchar_t types:
1426 operator char() const { return To8bit(m_value
); }
1427 operator wchar_t() const { return m_value
; }
1428 #ifndef wxWINT_T_IS_TYPEDEF
1429 operator wint_t() const { return m_value
; }
1431 operator int() const { return m_value
; }
1433 // We need this operator for the "*p" part of expressions like "for (
1434 // const_iterator p = begin() + nStart; *p; ++p )". In this case,
1435 // compilation would fail without it because the conversion to bool would
1436 // be ambiguous (there are all these int types conversions...). (And adding
1437 // operator unspecified_bool_type() would only makes the ambiguity worse.)
1438 operator bool() const { return m_value
!= 0; }
1439 bool operator!() const { return !((bool)*this); }
1440 #if (defined(__VISUALC__) && __VISUALC__ < 1400) || \
1441 defined(__DIGITALMARS__) || defined(__BORLANDC__)
1442 // We need this for VC++ < 8 or DigitalMars and expressions like
1444 bool operator&&(bool v
) const { return (bool)*this && v
; }
1447 // Assignment operators:
1448 wxUniChar
& operator=(const wxUniChar
& c
) { m_value
= c
.m_value
; return *this; }
1449 wxUniChar
& operator=(char c
) { m_value
= From8bit(c
); return *this; }
1450 wxUniChar
& operator=(wchar_t c
) { m_value
= c
; return *this; }
1451 #ifndef wxWINT_T_IS_TYPEDEF
1452 wxUniChar
& operator=(wint_t c
) { m_value
= c
; return *this; }
1455 // Comparision operators:
1456 bool operator==(const wxUniChar
& c
) const { return m_value
== c
.m_value
; }
1457 bool operator==(char c
) const { return m_value
== From8bit(c
); }
1458 bool operator==(wchar_t c
) const { return m_value
== (unicode_type
)c
; }
1459 #ifndef wxWINT_T_IS_TYPEDEF
1460 bool operator==(wint_t c
) const { return m_value
== (unicode_type
)c
; }
1463 bool operator!=(const wxUniChar
& c
) const { return m_value
!= c
.m_value
; }
1464 bool operator!=(char c
) const { return m_value
!= From8bit(c
); }
1465 bool operator!=(wchar_t c
) const { return m_value
!= (unicode_type
)c
; }
1466 #ifndef wxWINT_T_IS_TYPEDEF
1467 bool operator!=(wint_t c
) const { return m_value
!= (unicode_type
)c
; }
1470 bool operator>(const wxUniChar
& c
) const { return m_value
> c
.m_value
; }
1471 bool operator>(char c
) const { return m_value
> (unicode_type
)c
; }
1472 bool operator>(wchar_t c
) const { return m_value
> (unicode_type
)c
; }
1473 #ifndef wxWINT_T_IS_TYPEDEF
1474 bool operator>(wint_t c
) const { return m_value
> (unicode_type
)c
; }
1477 bool operator<(const wxUniChar
& c
) const { return m_value
< c
.m_value
; }
1478 bool operator<(char c
) const { return m_value
< From8bit(c
); }
1479 bool operator<(wchar_t c
) const { return m_value
< (unicode_type
)c
; }
1480 #ifndef wxWINT_T_IS_TYPEDEF
1481 bool operator<(wint_t c
) const { return m_value
< (unicode_type
)c
; }
1484 bool operator>=(const wxUniChar
& c
) const { return m_value
>= c
.m_value
; }
1485 bool operator>=(char c
) const { return m_value
>= From8bit(c
); }
1486 bool operator>=(wchar_t c
) const { return m_value
>= (unicode_type
)c
; }
1487 #ifndef wxWINT_T_IS_TYPEDEF
1488 bool operator>=(wint_t c
) const { return m_value
>= (unicode_type
)c
; }
1491 bool operator<=(const wxUniChar
& c
) const { return m_value
<= c
.m_value
; }
1492 bool operator<=(char c
) const { return m_value
<= From8bit(c
); }
1493 bool operator<=(wchar_t c
) const { return m_value
<= (unicode_type
)c
; }
1494 #ifndef wxWINT_T_IS_TYPEDEF
1495 bool operator<=(wint_t c
) const { return m_value
<= (unicode_type
)c
; }
1498 int operator-(const wxUniChar
& c
) const { return m_value
- c
.m_value
; }
1499 int operator-(char c
) const { return m_value
- From8bit(c
); }
1500 int operator-(wchar_t c
) const { return m_value
- (unicode_type
)c
; }
1501 #ifndef wxWINT_T_IS_TYPEDEF
1502 int operator-(wint_t c
) const { return m_value
- (unicode_type
)c
; }
1506 static unicode_type
From8bit(char c
);
1507 static char To8bit(unicode_type c
);
1510 unicode_type m_value
;
1514 // Writeable reference to a character in wxString.
1516 // This class can be used in the same way wxChar is used, except that changing
1517 // its value updates the underlying string object.
1518 class WXDLLIMPEXP_BASE wxUniCharRef
1521 // create the reference
1522 // FIXME: the interface will need changes for UTF-8 build
1523 wxUniCharRef(wxChar
*pos
) : m_pos(pos
) {}
1526 // NB: we have to make this public, because we don't have wxString
1527 // declaration available here and so can't declare wxString::iterator
1528 // as friend; so at least don't use a ctor but a static function
1529 // that must be used explicitly (this is more than using 'explicit'
1530 // keyword on ctor!):
1532 // FIXME: the interface will need changes for UTF-8 build
1533 static wxUniCharRef
CreateForString(wxChar
*pos
)
1534 { return wxUniCharRef(pos
); }
1536 wxUniChar::unicode_type
GetValue() const { return UniChar().GetValue(); }
1538 // Assignment operators:
1539 wxUniCharRef
& operator=(const wxUniCharRef
& c
)
1545 wxUniCharRef
& operator=(const wxUniChar
& c
)
1551 wxUniCharRef
& operator=(char c
) { return *this = wxUniChar(c
); }
1552 wxUniCharRef
& operator=(wchar_t c
) { return *this = wxUniChar(c
); }
1554 // Casts to wxUniChar type:
1555 operator char() const { return UniChar(); }
1556 operator wchar_t() const { return UniChar(); }
1557 #ifndef wxWINT_T_IS_TYPEDEF
1558 operator wint_t() const { return UniChar(); }
1560 operator int() const { return UniChar(); }
1562 // see wxUniChar::operator bool etc. for explanation
1563 operator bool() const { return (bool)UniChar(); }
1564 bool operator!() const { return !UniChar(); }
1565 #if (defined(__VISUALC__) && __VISUALC__ < 1400) || \
1566 defined(__DIGITALMARS__) || defined(__BORLANDC__)
1567 bool operator&&(bool v
) const { return UniChar() && v
; }
1570 // Comparision operators:
1571 bool operator==(const wxUniCharRef
& c
) const { return m_pos
== c
.m_pos
; }
1572 bool operator==(const wxUniChar
& c
) const { return UniChar() == c
; }
1573 bool operator==(char c
) const { return UniChar() == c
; }
1574 bool operator==(wchar_t c
) const { return UniChar() == c
; }
1575 #ifndef wxWINT_T_IS_TYPEDEF
1576 bool operator==(wint_t c
) const { return UniChar() == c
; }
1579 bool operator!=(const wxUniCharRef
& c
) const { return m_pos
!= c
.m_pos
; }
1580 bool operator!=(const wxUniChar
& c
) const { return UniChar() != c
; }
1581 bool operator!=(char c
) const { return UniChar() != c
; }
1582 bool operator!=(wchar_t c
) const { return UniChar() != c
; }
1583 #ifndef wxWINT_T_IS_TYPEDEF
1584 bool operator!=(wint_t c
) const { return UniChar() != c
; }
1587 bool operator>(const wxUniCharRef
& c
) const { return UniChar() > c
.UniChar(); }
1588 bool operator>(const wxUniChar
& c
) const { return UniChar() > c
; }
1589 bool operator>(char c
) const { return UniChar() > c
; }
1590 bool operator>(wchar_t c
) const { return UniChar() > c
; }
1591 #ifndef wxWINT_T_IS_TYPEDEF
1592 bool operator>(wint_t c
) const { return UniChar() > c
; }
1595 bool operator<(const wxUniCharRef
& c
) const { return UniChar() < c
.UniChar(); }
1596 bool operator<(const wxUniChar
& c
) const { return UniChar() < c
; }
1597 bool operator<(char c
) const { return UniChar() < c
; }
1598 bool operator<(wchar_t c
) const { return UniChar() < c
; }
1599 #ifndef wxWINT_T_IS_TYPEDEF
1600 bool operator<(wint_t c
) const { return UniChar() < c
; }
1603 bool operator>=(const wxUniCharRef
& c
) const { return UniChar() >= c
.UniChar(); }
1604 bool operator>=(const wxUniChar
& c
) const { return UniChar() >= c
; }
1605 bool operator>=(char c
) const { return UniChar() >= c
; }
1606 bool operator>=(wchar_t c
) const { return UniChar() >= c
; }
1607 #ifndef wxWINT_T_IS_TYPEDEF
1608 bool operator>=(wint_t c
) const { return UniChar() >= c
; }
1611 bool operator<=(const wxUniCharRef
& c
) const { return UniChar() <= c
.UniChar(); }
1612 bool operator<=(const wxUniChar
& c
) const { return UniChar() <= c
; }
1613 bool operator<=(char c
) const { return UniChar() <= c
; }
1614 bool operator<=(wchar_t c
) const { return UniChar() <= c
; }
1615 #ifndef wxWINT_T_IS_TYPEDEF
1616 bool operator<=(wint_t c
) const { return UniChar() <= c
; }
1619 int operator-(const wxUniCharRef
& c
) const { return UniChar() - c
.UniChar(); }
1620 int operator-(const wxUniChar
& c
) const { return UniChar() - c
; }
1621 int operator-(char c
) const { return UniChar() - c
; }
1622 int operator-(wchar_t c
) const { return UniChar() - c
; }
1623 #ifndef wxWINT_T_IS_TYPEDEF
1624 int operator-(wint_t c
) const { return UniChar() - c
; }
1628 wxUniChar
UniChar() const { return *m_pos
; }
1629 friend class WXDLLIMPEXP_BASE wxUniChar
;
1632 // pointer to the character in string
1636 inline wxUniChar::wxUniChar(const wxUniCharRef
& c
)
1638 m_value
= c
.UniChar().m_value
;
1641 // Comparision operators for the case when wxUniChar(Ref) is the second operand:
1642 inline bool operator==(char c1
, const wxUniChar
& c2
) { return c2
== c1
; }
1643 inline bool operator==(wchar_t c1
, const wxUniChar
& c2
) { return c2
== c1
; }
1644 #ifndef wxWINT_T_IS_TYPEDEF
1645 inline bool operator==(wint_t c1
, const wxUniChar
& c2
) { return c2
== c1
; }
1648 inline bool operator!=(char c1
, const wxUniChar
& c2
) { return c2
!= c1
; }
1649 inline bool operator!=(wchar_t c1
, const wxUniChar
& c2
) { return c2
!= c1
; }
1650 #ifndef wxWINT_T_IS_TYPEDEF
1651 inline bool operator!=(wint_t c1
, const wxUniChar
& c2
) { return c2
!= c1
; }
1654 inline bool operator>(char c1
, const wxUniChar
& c2
) { return c2
< c1
; }
1655 inline bool operator>(wchar_t c1
, const wxUniChar
& c2
) { return c2
< c1
; }
1656 #ifndef wxWINT_T_IS_TYPEDEF
1657 inline bool operator>(wint_t c1
, const wxUniChar
& c2
) { return c2
< c1
; }
1660 inline bool operator<(char c1
, const wxUniChar
& c2
) { return c2
> c1
; }
1661 inline bool operator<(wchar_t c1
, const wxUniChar
& c2
) { return c2
> c1
; }
1662 #ifndef wxWINT_T_IS_TYPEDEF
1663 inline bool operator<(wint_t c1
, const wxUniChar
& c2
) { return c2
> c1
; }
1666 inline bool operator>=(char c1
, const wxUniChar
& c2
) { return c2
<= c1
; }
1667 inline bool operator>=(wchar_t c1
, const wxUniChar
& c2
) { return c2
<= c1
; }
1668 #ifndef wxWINT_T_IS_TYPEDEF
1669 inline bool operator>=(wint_t c1
, const wxUniChar
& c2
) { return c2
<= c1
; }
1672 inline bool operator<=(char c1
, const wxUniChar
& c2
) { return c2
>= c1
; }
1673 inline bool operator<=(wchar_t c1
, const wxUniChar
& c2
) { return c2
>= c1
; }
1674 #ifndef wxWINT_T_IS_TYPEDEF
1675 inline bool operator<=(wint_t c1
, const wxUniChar
& c2
) { return c2
>= c1
; }
1679 inline bool operator==(char c1
, const wxUniCharRef
& c2
) { return c2
== c1
; }
1680 inline bool operator==(wchar_t c1
, const wxUniCharRef
& c2
) { return c2
== c1
; }
1681 #ifndef wxWINT_T_IS_TYPEDEF
1682 inline bool operator==(wint_t c1
, const wxUniCharRef
& c2
) { return c2
== c1
; }
1684 inline bool operator==(const wxUniChar
& c1
, const wxUniCharRef
& c2
) { return c2
== c1
; }
1686 inline bool operator!=(char c1
, const wxUniCharRef
& c2
) { return c2
!= c1
; }
1687 inline bool operator!=(wchar_t c1
, const wxUniCharRef
& c2
) { return c2
!= c1
; }
1688 #ifndef wxWINT_T_IS_TYPEDEF
1689 inline bool operator!=(wint_t c1
, const wxUniCharRef
& c2
) { return c2
!= c1
; }
1691 inline bool operator!=(const wxUniChar
& c1
, const wxUniCharRef
& c2
) { return c2
!= c1
; }
1693 inline bool operator>(char c1
, const wxUniCharRef
& c2
) { return c2
< c1
; }
1694 inline bool operator>(wchar_t c1
, const wxUniCharRef
& c2
) { return c2
< c1
; }
1695 #ifndef wxWINT_T_IS_TYPEDEF
1696 inline bool operator>(wint_t c1
, const wxUniCharRef
& c2
) { return c2
< c1
; }
1698 inline bool operator>(const wxUniChar
& c1
, const wxUniCharRef
& c2
) { return c2
< c1
; }
1700 inline bool operator<(char c1
, const wxUniCharRef
& c2
) { return c2
> c1
; }
1701 inline bool operator<(wchar_t c1
, const wxUniCharRef
& c2
) { return c2
> c1
; }
1702 #ifndef wxWINT_T_IS_TYPEDEF
1703 inline bool operator<(wint_t c1
, const wxUniCharRef
& c2
) { return c2
> c1
; }
1705 inline bool operator<(const wxUniChar
& c1
, const wxUniCharRef
& c2
) { return c2
> c1
; }
1707 inline bool operator>=(char c1
, const wxUniCharRef
& c2
) { return c2
<= c1
; }
1708 inline bool operator>=(wchar_t c1
, const wxUniCharRef
& c2
) { return c2
<= c1
; }
1709 #ifndef wxWINT_T_IS_TYPEDEF
1710 inline bool operator>=(wint_t c1
, const wxUniCharRef
& c2
) { return c2
<= c1
; }
1712 inline bool operator>=(const wxUniChar
& c1
, const wxUniCharRef
& c2
) { return c2
<= c1
; }
1714 inline bool operator<=(char c1
, const wxUniCharRef
& c2
) { return c2
>= c1
; }
1715 inline bool operator<=(wchar_t c1
, const wxUniCharRef
& c2
) { return c2
>= c1
; }
1716 #ifndef wxWINT_T_IS_TYPEDEF
1717 inline bool operator<=(wint_t c1
, const wxUniCharRef
& c2
) { return c2
>= c1
; }
1719 inline bool operator<=(const wxUniChar
& c1
, const wxUniCharRef
& c2
) { return c2
>= c1
; }
1721 inline int operator-(char c1
, const wxUniCharRef
& c2
) { return -(c2
- c1
); }
1722 inline int operator-(wchar_t c1
, const wxUniCharRef
& c2
) { return -(c2
- c1
); }
1723 #ifndef wxWINT_T_IS_TYPEDEF
1724 inline int operator-(wint_t c1
, const wxUniCharRef
& c2
) { return -(c2
- c1
); }
1726 inline int operator-(const wxUniChar
& c1
, const wxUniCharRef
& c2
) { return -(c2
- c1
); }
1728 #endif // __cplusplus
1730 #endif /* _WX_WXCHAR_H_ */