3 * Purpose: Type-safe ANSI and Unicode builds compatible wrappers for
5 * Author: Joel Farley, Ove Kåven
6 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
9 * Copyright: (c) 1998-2006 wxWidgets dev team
10 * Licence: wxWindows licence
13 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
18 #include "wx/chartype.h"
20 #include <stdio.h> /* we use FILE below */
23 #if wxUSE_UNICODE_UTF8
24 // flag indicating whether the current locale uses UTF-8 or not; must be
25 // updated every time the locale is changed!
26 #if wxUSE_UTF8_LOCALE_ONLY
27 #define wxLocaleIsUtf8 true
29 extern WXDLLIMPEXP_BASE
bool wxLocaleIsUtf8
;
31 // function used to update the flag:
32 extern WXDLLIMPEXP_BASE
void wxUpdateLocaleIsUtf8();
33 #else // !wxUSE_UNICODE_UTF8
34 inline void wxUpdateLocaleIsUtf8() {}
35 #endif // wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8
38 #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
39 char *strtok_r(char *, const char *, char **);
44 Standard headers we need here.
46 NB: don't include any wxWidgets headers here because almost all of them include
50 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac */
51 /* and VC++ for Windows CE don't provide it */
52 #if defined(__VISUALC__) && __VISUALC__ >= 1400
53 #define wxStrdupA _strdup
54 #elif !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
55 /* use #define, not inline wrapper, as it is tested with #ifndef below */
56 #define wxStrdupA strdup
59 #if defined(__MWERKS__)
60 /* Metrowerks only has wide char support for OS X >= 10.3 */
61 #if !defined(__DARWIN__) || \
62 (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
63 #define wxHAVE_MWERKS_UNICODE
66 #ifdef wxHAVE_MWERKS_UNICODE
67 #define HAVE_WPRINTF 1
68 #define HAVE_WCSRTOMBS 1
69 #define HAVE_VSWPRINTF 1
71 #endif /* __MWERKS__ */
73 #ifdef wxHAVE_TCHAR_SUPPORT
74 /* we surely have wchar_t if we have TCHAR have wcslen() */
78 #endif /* wxHAVE_TCHAR_SUPPORT */
81 define wxFoo() function for each standard foo() function whose signature
82 (exceptionally including the return type) includes any mention of char:
83 wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
84 the same signature but with char replaced by wxChar which allows us to
85 use it in Unicode build as well
88 #ifdef wxHAVE_TCHAR_SUPPORT
91 #if defined(__WATCOMC__) && defined(UNICODE)
92 #define WXWCHAR_T_CAST(c) (wint_t)(c)
94 #define WXWCHAR_T_CAST(c) c
97 /* ctype.h functions */
98 #define wxIsalnum(c) _istalnum(WXWCHAR_T_CAST(c))
99 #define wxIsalpha(c) _istalpha(WXWCHAR_T_CAST(c))
100 #define wxIscntrl(c) _istcntrl(WXWCHAR_T_CAST(c))
101 #define wxIsdigit(c) _istdigit(WXWCHAR_T_CAST(c))
102 #define wxIsgraph(c) _istgraph(WXWCHAR_T_CAST(c))
103 #define wxIslower(c) _istlower(WXWCHAR_T_CAST(c))
104 #define wxIsprint(c) _istprint(WXWCHAR_T_CAST(c))
105 #define wxIspunct(c) _istpunct(WXWCHAR_T_CAST(c))
106 #define wxIsspace(c) _istspace(WXWCHAR_T_CAST(c))
107 #define wxIsupper(c) _istupper(WXWCHAR_T_CAST(c))
108 #define wxIsxdigit(c) _istxdigit(WXWCHAR_T_CAST(c))
111 There is a bug in VC6 C RTL: toxxx() functions dosn't do anything with
112 signed chars < 0, so "fix" it here.
114 #define wxTolower(c) _totlower((wxUChar)(wxChar)(c))
115 #define wxToupper(c) _totupper((wxUChar)(wxChar)(c))
117 /* locale.h functons */
118 #define wxSetlocale_ _tsetlocale
120 /* string.h functions */
121 #define wxStrcat _tcscat
122 #define wxStrchr _tcschr
123 #define wxStrcmp _tcscmp
124 #define wxStrcoll _tcscoll
125 #define wxStrcpy _tcscpy
126 #define wxStrcspn _tcscspn
127 #define wxStrdupW _wcsdup /* notice the 'W'! */
128 #define wxStrftime _tcsftime
129 #define wxStricmp _tcsicmp
130 #define wxStrnicmp _tcsnicmp
131 #define wxStrlen_ _tcslen /* used in wxStrlen inline function */
132 #define wxStrncat _tcsncat
133 #define wxStrncmp _tcsncmp
134 #define wxStrncpy _tcsncpy
135 #define wxStrpbrk _tcspbrk
136 #define wxStrrchr _tcsrchr
137 #define wxStrspn _tcsspn
138 #define wxStrstr _tcsstr
139 #define wxStrtod _tcstod
140 #define wxStrtol _tcstol
141 #define wxStrtoul _tcstoul
143 #if __VISUALC__ >= 1300 && !defined(__WXWINCE__)
144 #define wxStrtoll _tcstoi64
145 #define wxStrtoull _tcstoui64
148 #define wxStrxfrm _tcsxfrm
150 /* stdio.h functions */
151 #define wxFgetc _fgettc
152 #define wxFgetchar _fgettchar
153 #define wxFgets _fgetts
154 #if wxUSE_UNICODE_MSLU
155 WXDLLIMPEXP_BASE
FILE * wxMSLU__tfopen(const wxChar
*name
, const wxChar
*mode
);
157 #define wxFopen wxMSLU__tfopen
159 #define wxFopen _tfopen
161 #define wxFputc _fputtc
162 #define wxFputchar _fputtchar
163 #define wxFputs _fputts
164 #define wxFreopen _tfreopen
165 #define wxGetc _gettc
166 #define wxGetchar _gettchar
167 #define wxGets _getts
168 #define wxPerror _tperror
169 #define wxPutc(c,f) _puttc(WXWCHAR_T_CAST(c),f)
170 #define wxPutchar _puttchar
171 #define wxPuts _putts
173 #define wxTmpnam _ttmpnam
174 #define wxUngetc _tungetc
176 /* special case: these functions are missing under Win9x with Unicows so we */
177 /* have to implement them ourselves */
178 #if wxUSE_UNICODE_MSLU
179 WXDLLIMPEXP_BASE
int wxMSLU__trename(const wxChar
*oldname
, const wxChar
*newname
);
180 WXDLLIMPEXP_BASE
int wxMSLU__tremove(const wxChar
*name
);
182 #define wxRemove wxMSLU__tremove
183 #define wxRename wxMSLU__trename
186 /* carefully: wxRemove() must return 0 on success while DeleteFile()
187 returns 0 on error, so don't just define one as the other */
188 int wxRemove(const wxChar
*path
);
190 #define wxRemove _tremove
191 #define wxRename _trename
195 /* stdlib.h functions */
198 /* #define wxAtof _tttof -- notice that there is no such thing (why?) */
199 /* there are no env vars at all under CE, so no _tgetenv neither */
201 /* can't define as inline function as this is a C file... */
202 #define wxGetenv(name) ((wxChar *)NULL)
204 #define wxGetenv _tgetenv
206 #define wxSystem _tsystem
208 /* time.h functions */
209 #define wxAsctime _tasctime
210 #define wxCtime _tctime
212 #define wxMbstowcs mbstowcs
213 #define wxWcstombs wcstombs
214 #else /* !TCHAR-aware compilers */
216 There are 2 unrelated problems with these functions under Mac:
217 a) Metrowerks MSL CRT implements them strictly in C99 sense and
218 doesn't support (very common) extension of allowing to call
219 mbstowcs(NULL, ...) which makes it pretty useless as you can't
220 know the size of the needed buffer
221 b) OS X <= 10.2 declares and even defined these functions but
222 doesn't really implement them -- they always return an error
224 So use our own replacements in both cases.
226 #if defined(__MWERKS__) && defined(__MSL__)
227 #define wxNEED_WX_MBSTOWCS
231 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
232 #define wxNEED_WX_MBSTOWCS
236 #ifdef wxNEED_WX_MBSTOWCS
237 /* even though they are defined and "implemented", they are bad and just
238 stubs so we need our own - we need these even in ANSI builds!! */
239 WXDLLIMPEXP_BASE
size_t wxMbstowcs (wchar_t *, const char *, size_t);
240 WXDLLIMPEXP_BASE
size_t wxWcstombs (char *, const wchar_t *, size_t);
242 #define wxMbstowcs mbstowcs
243 #define wxWcstombs wcstombs
247 The system C library on Mac OS X 10.2 and below does not support
248 unicode: in other words all wide-character functions such as towupper et
249 al. do simply not exist so we need to provide our own in that context,
250 except for the wchar_t definition/typedef itself.
252 We need to do this for both project builder and CodeWarrior as
253 the latter uses the system C library in Mach builds for wide character
254 support, which as mentioned does not exist on 10.2 and below.
256 #if wxUSE_UNICODE && \
257 defined(__DARWIN__) && \
258 ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
259 /* we need everything! */
260 #define wxNEED_WX_STRING_H
261 #define wxNEED_WX_CTYPE_H
263 #define wxFgetchar(c) wxFgetc(c, stdin)
264 #define wxFputc wxPutc
265 #define wxFputchar(c) wxPutc(c, stdout)
266 #define wxGetc wxFgetc
267 #define wxGetchar(c) wxFgetc(c, stdin)
274 #define wxNEED_UNGETC
280 int wxFputs(const wxChar
*ch
, FILE *stream
);
281 int wxPuts(const wxChar
*ws
);
282 int wxPutc(wxChar ch
, FILE *stream
);
287 WXDLLIMPEXP_BASE
size_t wxStrlen_(const wxChar
*s
);
292 #define wxPutchar(wch) wxPutc(wch, stdout)
294 #define wxNEED_PRINTF_CONVERSION
295 #define wxNEED_WX_STDIO_H
296 #define wxNEED_WX_STDLIB_H
297 #define wxNEED_WX_TIME_H
302 /* this is probably glibc-specific */
303 #if defined(__WCHAR_TYPE__) && !defined(__MWERKS__)
304 /* ctype.h functions (wctype.h) */
305 #define wxIsalnum iswalnum
306 #define wxIsalpha iswalpha
307 #define wxIscntrl iswcntrl
308 #define wxIsdigit iswdigit
309 #define wxIsgraph iswgraph
310 #define wxIslower iswlower
311 #define wxIsprint iswprint
312 #define wxIspunct iswpunct
313 #define wxIsspace iswspace
314 #define wxIsupper iswupper
315 #define wxIsxdigit iswxdigit
317 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
318 /* /usr/include/wctype.h incorrectly declares translations */
319 /* tables which provokes tons of compile-time warnings -- try */
320 /* to correct this */
321 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
322 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
323 #else /* !glibc 2.0 */
324 #define wxTolower towlower
325 #define wxToupper towupper
326 #endif /* gcc/!gcc */
328 /* string.h functions (wchar.h) */
329 #define wxStrcat wcscat
330 #define wxStrchr wcschr
331 #define wxStrcmp wcscmp
332 #define wxStrcoll wcscoll
333 #define wxStrcpy wcscpy
334 #define wxStrcspn wcscspn
335 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
336 #define wxStrncat wcsncat
337 #define wxStrncmp wcsncmp
338 #define wxStrncpy wcsncpy
339 #define wxStrpbrk wcspbrk
340 #define wxStrrchr wcsrchr
341 #define wxStrspn wcsspn
342 #define wxStrstr wcsstr
343 #define wxStrtod wcstod
344 #define wxStrtol wcstol
345 #define wxStrtoul wcstoul
347 /* assume that we have wcstoull(), which is also C99, too */
348 #define wxStrtoll wcstoll
349 #define wxStrtoull wcstoull
350 #endif /* HAVE_WCSTOULL */
351 #define wxStrxfrm wcsxfrm
353 #define wxFgetc fgetwc
354 #define wxFgetchar fgetwchar
355 #define wxFgets fgetws
356 #define wxFputc fputwc
357 #define wxFputchar fputwchar
359 #define wxGetchar getwchar
361 #define wxUngetc ungetwc
364 #define wxFputs fputws
368 int wxFputs(const wxChar
*ch
, FILE *stream
);
376 int wxPutc(wxChar ch
, FILE *stream
);
380 #define wxPutchar wputchar
382 #define wxPutchar(wch) wxPutc(wch, stdout)
389 int wxPuts(const wxChar
*ws
);
392 /* we need %s to %ls conversion for printf and scanf etc */
393 #define wxNEED_PRINTF_CONVERSION
395 /* glibc doesn't have wide char equivalents of the other stuff so */
396 /* use our own versions */
397 #define wxNEED_WX_STDIO_H
398 #define wxNEED_WX_STDLIB_H
399 #define wxNEED_WX_TIME_H
400 #elif defined(__MWERKS__) && ( defined(__MSL__) || defined(__MACH__) )
401 /* ctype.h functions (wctype.h) */
402 #define wxIsalnum iswalnum
403 #define wxIsalpha iswalpha
404 #define wxIscntrl iswcntrl
405 #define wxIsdigit iswdigit
406 #define wxIsgraph iswgraph
407 #define wxIslower iswlower
408 #define wxIsprint iswprint
409 #define wxIspunct iswpunct
410 #define wxIsspace iswspace
411 #define wxIsupper iswupper
412 #define wxIsxdigit iswxdigit
413 #define wxTolower towlower
414 #define wxToupper towupper
416 /* string.h functions (wchar.h) */
417 #define wxStrcat wcscat
418 #define wxStrchr wcschr
419 #define wxStrcmp wcscmp
420 #define wxStrcoll wcscoll
421 #define wxStrcpy wcscpy
422 #define wxStrcspn wcscspn
423 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
424 #define wxStrncat wcsncat
425 #define wxStrncmp wcsncmp
426 #define wxStrncpy wcsncpy
427 #define wxStrpbrk wcspbrk
428 #define wxStrrchr wcsrchr
429 #define wxStrspn wcsspn
430 #define wxStrstr wcsstr
431 #define wxStrtod wcstod
432 #define wxStrtol wcstol
433 #define wxStrtoul wcstoul
434 #define wxStrxfrm wcsxfrm
436 #define wxFgetc fgetwc
437 #define wxFgetchar fgetwchar
438 #define wxFgets fgetws
439 #define wxFputc fputwc
440 #define wxFputchar fputwchar
442 #define wxGetchar getwchar
444 #define wxUngetc ungetwc
446 #define wxNEED_PRINTF_CONVERSION
449 #define wxPutchar putwchar
450 #define wxFputs fputws
452 /* stdio.h functions */
454 #define wxNEED_WX_STDIO_H
456 /* stdlib.h functions */
458 #define wxNEED_WX_STDLIB_H
463 #define wxGetenv(a) ((wxChar*)NULL)
464 #define wxSystem(a) ((int)NULL)
466 /* time.h functions */
467 #define wxAsctime wasciitime
468 #define wxCtime wctime
469 /* #define wxStrftime wcsftime */
471 #define wxNEED_WX_TIME_H
472 #else /* !metrowerks for apple */
473 #error "Please define wide character functions for your environment"
479 /* ctype.h functions */
480 #define wxIsalnum isalnum
481 #define wxIsalpha isalpha
482 #define wxIscntrl iscntrl
483 #define wxIsdigit isdigit
484 #define wxIsgraph isgraph
485 #define wxIslower islower
486 #define wxIsprint isprint
487 #define wxIspunct ispunct
488 #define wxIsspace isspace
489 #define wxIsupper isupper
490 #define wxIsxdigit isxdigit
491 #define wxTolower tolower
492 #define wxToupper toupper
494 /* locale.h functons */
495 #define wxSetlocale_ setlocale
497 /* string.h functions */
498 #define wxStrcat strcat
499 #define wxStrchr strchr
500 #define wxStrcmp strcmp
501 #define wxStrcoll strcoll
502 #define wxStrcpy strcpy
503 #define wxStrcspn strcspn
505 /* wxStricmp and wxStrnicmp are defined below */
506 #define wxStrlen_ strlen /* used in wxStrlen inline function */
507 #define wxStrncat strncat
508 #define wxStrncmp strncmp
509 #define wxStrncpy strncpy
510 #define wxStrpbrk strpbrk
511 #define wxStrrchr strrchr
512 #define wxStrspn strspn
513 #define wxStrstr strstr
514 #define wxStrtod strtod
516 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
518 #define wxStrtol strtol
519 #define wxStrtoul strtoul
521 /* assume that we have wcstoull(), which is also C99, too */
522 #define wxStrtoll strtoll
523 #define wxStrtoull strtoull
524 #endif /* HAVE_WCSTOULL */
525 #define wxStrxfrm strxfrm
527 /* stdio.h functions */
528 #define wxFopen fopen
529 #define wxFreopen freopen
530 #define wxRemove remove
531 #define wxRename rename
533 #define wxPerror perror
534 #define wxTmpnam tmpnam
536 #define wxFgetc fgetc
537 #define wxFgetchar fgetchar
538 #define wxFgets fgets
539 #define wxFputc fputc
540 #define wxFputs fputs
541 #define wxFputchar fputchar
543 #define wxGetchar getchar
546 #define wxPutchar putchar
548 #define wxUngetc ungetc
550 /* stdlib.h functions */
554 #define wxGetenv getenv
555 #define wxSystem system
557 /* time.h functions */
558 #define wxAsctime asctime
559 #define wxCtime ctime
560 #define wxStrftime strftime
561 #endif /* Unicode/ASCII */
562 #endif /* TCHAR-aware compilers/the others */
565 various special cases
568 /* define wxStricmp and wxStrnicmp for various compilers */
570 /* note that in Unicode mode we definitely are going to need our own version */
571 #if !defined(wxStricmp) && !wxUSE_UNICODE
572 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
573 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
574 defined(__EMX__) || defined(__DJGPP__)
575 #define wxStricmp stricmp
576 #define wxStrnicmp strnicmp
577 #elif defined(__WXPALMOS__)
578 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
579 * quick hack should do until one can be written.
581 #define wxStricmp StrCaselessCompare
582 #define wxStrnicmp strnicmp
583 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
584 (defined(__MWERKS__) && defined(__INTEL__))
585 #define wxStricmp _stricmp
586 #define wxStrnicmp _strnicmp
587 #elif defined(__UNIX__) || defined(__GNUWIN32__)
588 #define wxStricmp strcasecmp
589 #define wxStrnicmp strncasecmp
590 /* #else -- use wxWidgets implementation */
592 #endif /* !defined(wxStricmp) */
594 /* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
595 /* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
596 /* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
599 #define wxWcslen wcslen
601 WXDLLIMPEXP_BASE
size_t wxWcslen(const wchar_t *s
);
603 #endif /* wxUSE_WCHAR_T */
606 /* checks whether the passed in pointer is NULL and if the string is empty */
607 inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
609 /* safe version of strlen() (returns 0 if passed NULL pointer) */
610 inline size_t wxStrlen(const wxChar
*psz
) { return psz
? wxStrlen_(psz
) : 0; }
614 each of strdup() and wcsdup() may or may not be available but we need both
615 of them anyhow for wx/buffer.h so we define the missing one(s) in
616 wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
617 defined -- if this is somehow not the case in some situations, please
618 correct that and not the lines here
621 #define wxStrdup wxStrdupW
623 #define wxStrdup wxStrdupA
627 WXDLLIMPEXP_BASE
bool wxOKlibc(); /* for internal use */
631 /* supply strtoll and strtoull, if needed */
632 WXDLLIMPEXP_BASE wxLongLong_t
wxStrtoll(const wxChar
* nptr
, wxChar
** endptr
, int base
);
633 WXDLLIMPEXP_BASE wxULongLong_t
wxStrtoull(const wxChar
* nptr
, wxChar
** endptr
, int base
);
636 #define wxHAS_STRTOLL
639 In Unicode mode we need to have all standard functions such as wprintf() and
640 so on but not all systems have them so use our own implementations in this
643 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
644 #define wxNEED_WPRINTF
648 various functions which might not be available in libc and for which we
649 provide our own replacements in wxchar.cpp
652 /* ctype.h functions */
654 /* RN: Used only under OSX <= 10.2 currently */
655 #ifdef wxNEED_WX_CTYPE_H
656 WXDLLIMPEXP_BASE
int wxIsalnum(wxChar ch
);
657 WXDLLIMPEXP_BASE
int wxIsalpha(wxChar ch
);
658 WXDLLIMPEXP_BASE
int wxIscntrl(wxChar ch
);
659 WXDLLIMPEXP_BASE
int wxIsdigit(wxChar ch
);
660 WXDLLIMPEXP_BASE
int wxIsgraph(wxChar ch
);
661 WXDLLIMPEXP_BASE
int wxIslower(wxChar ch
);
662 WXDLLIMPEXP_BASE
int wxIsprint(wxChar ch
);
663 WXDLLIMPEXP_BASE
int wxIspunct(wxChar ch
);
664 WXDLLIMPEXP_BASE
int wxIsspace(wxChar ch
);
665 WXDLLIMPEXP_BASE
int wxIsupper(wxChar ch
);
666 WXDLLIMPEXP_BASE
int wxIsxdigit(wxChar ch
);
667 WXDLLIMPEXP_BASE
int wxTolower(wxChar ch
);
668 WXDLLIMPEXP_BASE
int wxToupper(wxChar ch
);
669 #endif /* wxNEED_WX_CTYPE_H */
671 /* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
672 /* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
673 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
675 #define wxIsspace(c) ((((unsigned)(wxChar)c) < 128) && isspace(c))
679 a few compilers don't have the (non standard but common) isascii function,
680 define it ourselves for them
683 #if defined(__MWERKS__)
684 #define wxNEED_ISASCII
685 #elif defined(_WIN32_WCE)
686 #if _WIN32_WCE <= 211
687 #define wxNEED_ISASCII
692 #ifdef wxNEED_ISASCII
693 inline int isascii(int c
) { return (unsigned)c
< 0x80; }
697 #if _WIN32_WCE <= 211
698 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
700 #endif /* _WIN32_WCE */
703 we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
704 initial versions of this header -- now it is too late to remove it so
705 although we fixed the function/macro name above, still provide the
706 backwards-compatible synonym.
708 #define wxIsctrl wxIscntrl
710 /* string.h functions */
712 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
713 #define wxNEED_STRDUP
714 #elif defined(__WXWINCE__)
715 #if _WIN32_WCE <= 211
716 #define wxNEED_STRDUP
722 WXDLLIMPEXP_BASE
char *strdup(const char* s
);
725 /* RN: Used only under OSX <= 10.2 currently
726 The __cplusplus ifdefs are messy, but they are required to build
727 the regex library, since c does not support function overloading
729 #ifdef wxNEED_WX_STRING_H
733 WXDLLIMPEXP_BASE wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
734 WXDLLIMPEXP_BASE
const wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
735 WXDLLIMPEXP_BASE
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
736 WXDLLIMPEXP_BASE
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
737 WXDLLIMPEXP_BASE wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
738 WXDLLIMPEXP_BASE
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
739 WXDLLIMPEXP_BASE wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
740 WXDLLIMPEXP_BASE
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
741 WXDLLIMPEXP_BASE wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
742 WXDLLIMPEXP_BASE
const wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
743 WXDLLIMPEXP_BASE
const wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
744 WXDLLIMPEXP_BASE
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
745 WXDLLIMPEXP_BASE
const wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
750 /* These functions use C++, so we can't c extern them */
751 WXDLLIMPEXP_BASE
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
752 WXDLLIMPEXP_BASE
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
753 WXDLLIMPEXP_BASE
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
754 WXDLLIMPEXP_BASE
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
756 /* inlined versions */
758 inline wxChar
* wxStrchr(wxChar
*s
, wxChar c
)
759 { return (wxChar
*)wxStrchr((const wxChar
*)s
, c
); }
760 inline wxChar
* wxStrpbrk(wxChar
*s
, const wxChar
*accept
)
761 { return (wxChar
*)wxStrpbrk((const wxChar
*)s
, accept
); }
762 inline wxChar
* wxStrrchr(wxChar
*s
, wxChar c
)
763 { return (wxChar
*)wxStrrchr((const wxChar
*)s
, c
); }
764 inline wxChar
*wxStrstr(wxChar
*haystack
, const wxChar
*needle
)
765 { return (wxChar
*)wxStrstr((const wxChar
*)haystack
, needle
); }
768 #endif /* wxNEED_WX_STRING_H */
771 WXDLLIMPEXP_BASE
char *wxStrdupA(const char *psz
);
775 WXDLLIMPEXP_BASE
wchar_t *wxStrdupW(const wchar_t *pwz
);
779 WXDLLIMPEXP_BASE
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
783 WXDLLIMPEXP_BASE
int wxStrnicmp(const wxChar
*psz1
, const wxChar
*psz2
, size_t len
);
787 WXDLLIMPEXP_BASE wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
792 class WXDLLIMPEXP_BASE wxWCharBuffer
;
793 WXDLLIMPEXP_BASE wxWCharBuffer
wxSetlocale_(int category
, const wxChar
*locale
);
794 WXDLLIMPEXP_BASE wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
796 WXDLLIMPEXP_BASE wxChar
*wxSetlocale(int category
, const wxChar
*locale
);
797 #endif // defined(wxSetlocale_)
798 #endif // __cplusplus
800 /* stdio.h functions */
801 #ifdef wxNEED_WX_STDIO_H
803 WXDLLIMPEXP_BASE
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
804 WXDLLIMPEXP_BASE
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
805 WXDLLIMPEXP_BASE
int wxRemove(const wxChar
*path
);
806 WXDLLIMPEXP_BASE
int wxRename(const wxChar
*oldpath
, const wxChar
*newpath
);
808 /* *printf() family is handled separately */
809 #endif /* wxNEED_WX_STDIO_H */
812 /* stdlib.h functions */
814 WXDLLIMPEXP_BASE
double wxAtof(const wxChar
*psz
);
817 #ifdef wxNEED_WX_STDLIB_H
818 WXDLLIMPEXP_BASE
int wxAtoi(const wxChar
*psz
);
819 WXDLLIMPEXP_BASE
long wxAtol(const wxChar
*psz
);
820 WXDLLIMPEXP_BASE wxChar
* wxGetenv(const wxChar
*name
);
821 WXDLLIMPEXP_BASE
int wxSystem(const wxChar
*psz
);
825 /* time.h functions */
826 #ifdef wxNEED_WX_TIME_H
827 #if defined(__MWERKS__) && defined(macintosh)
830 /*silent gabby compilers*/
832 WXDLLIMPEXP_BASE
size_t wxStrftime(wxChar
*s
, size_t max
,
834 const struct tm
*tm
);
835 #endif /* wxNEED_WX_TIME_H */
839 WXDLLIMPEXP_BASE wxChar
*wxCtime(const time_t *timep
);
843 /* missing functions in some WinCE versions */
845 #if (_WIN32_WCE < 300)
846 WXDLLIMPEXP_BASE
void *calloc( size_t num
, size_t size
);
848 #endif /* _WIN32_WCE */
850 /* multibyte to wide char conversion functions and macros */
853 /* multibyte<->widechar conversion */
854 WXDLLIMPEXP_BASE
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
855 WXDLLIMPEXP_BASE
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
858 #define wxMB2WX wxMB2WC
859 #define wxWX2MB wxWC2MB
860 #define wxWC2WX wxStrncpy
861 #define wxWX2WC wxStrncpy
863 #define wxMB2WX wxStrncpy
864 #define wxWX2MB wxStrncpy
865 #define wxWC2WX wxWC2MB
866 #define wxWX2WC wxMB2WC
868 #else /* !wxUSE_UNICODE */
871 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
872 #define wxMB2WC wxStrncpy
873 #define wxWC2MB wxStrncpy
874 #define wxMB2WX wxStrncpy
875 #define wxWX2MB wxStrncpy
876 #define wxWC2WX wxWC2MB
877 #define wxWX2WC wxMB2WC
881 RN: The following are not normal versions of memcpy et al., rather
882 these are either char or widechar versions depending on
883 if unicode is used or not.
889 // RN: We could do the usual tricky compiler detection here,
890 // and use their variant (such as wmemchr, etc.). The problem
891 // is that these functions are quite rare, even though they are
892 // part of the current POSIX standard. In addition, most compilers
893 // (including even MSC) inline them just like we do right in their
897 #include <string.h> //for mem funcs
899 //implement our own wmem variants
900 inline wxChar
* wxTmemchr(const wxChar
* s
, wxChar c
, size_t l
)
902 for(;l
&& *s
!= c
;--l
, ++s
) {}
909 inline int wxTmemcmp(const wxChar
* sz1
, const wxChar
* sz2
, size_t len
)
911 for(; *sz1
== *sz2
&& len
; --len
, ++sz1
, ++sz2
) {}
914 return *sz1
< *sz2
? -1 : *sz1
> *sz2
;
919 inline wxChar
* wxTmemcpy(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
921 return (wxChar
*) memcpy(szOut
, szIn
, len
* sizeof(wxChar
));
924 inline wxChar
* wxTmemmove(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
926 return (wxChar
*) memmove(szOut
, szIn
, len
* sizeof(wxChar
));
929 inline wxChar
* wxTmemset(wxChar
* szOut
, const wxChar cIn
, size_t len
)
931 wxChar
* szRet
= szOut
;
939 #else /* !wxUSE_UNICODE */
940 # define wxTmemchr memchr
941 # define wxTmemcmp memcmp
942 # define wxTmemcpy memcpy
943 # define wxTmemmove memmove
944 # define wxTmemset memset
945 #endif /* wxUSE_UNICODE/!wxUSE_UNICODE */
947 #endif /*__cplusplus*/
949 #endif /* _WX_WXCRT_H_ */