-/*
- * Name: wx/wxcrt.h
- * Purpose: Type-safe ANSI and Unicode builds compatible wrappers for
- * CRT functions
- * Author: Joel Farley, Ove Kåven
- * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
- * Created: 1998/06/12
- * RCS-ID: $Id$
- * Copyright: (c) 1998-2006 wxWidgets dev team
- * Licence: wxWindows licence
- */
-
-/* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
+///////////////////////////////////////////////////////////////////////////////
+// Name: wx/wxcrt.h
+// Purpose: Type-safe ANSI and Unicode builds compatible wrappers for
+// CRT functions
+// Author: Joel Farley, Ove K�ven
+// Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee, Vaclav Slavik
+// Created: 1998/06/12
+// RCS-ID: $Id$
+// Copyright: (c) 1998-2006 wxWidgets dev team
+// Licence: wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_WXCRT_H_
#define _WX_WXCRT_H_
-#include "wx/chartype.h"
+// NB: User code should include wx/crt.h instead of including this
+// header directly.
-#include <stdio.h> /* we use FILE below */
+#include "wx/wxcrtbase.h"
+#include "wx/string.h"
-#ifdef __cplusplus
- #if wxUSE_UNICODE_UTF8
- // flag indicating whether the current locale uses UTF-8 or not; must be
- // updated every time the locale is changed!
- #if !wxUSE_UTF8_LOCALE_ONLY
- extern WXDLLIMPEXP_BASE bool wxLocaleIsUtf8;
- #endif
- // function used to update the flag:
- extern WXDLLIMPEXP_BASE void wxUpdateLocaleIsUtf8();
- #else // !wxUSE_UNICODE_UTF8
- inline WXDLLIMPEXP_BASE void wxUpdateLocaleIsUtf8() {}
- #endif // wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8
-#endif // __cplusplus
-
-#if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
- char *strtok_r(char *, const char *, char **);
-#endif
-
-
-/*
- Standard headers we need here.
-
- NB: don't include any wxWidgets headers here because almost all of them include
- this one!
- */
-
-/* Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac */
-/* and VC++ for Windows CE don't provide it */
-#if defined(__VISUALC__) && __VISUALC__ >= 1400
- #define wxStrdupA _strdup
-#elif !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
- /* use #define, not inline wrapper, as it is tested with #ifndef below */
- #define wxStrdupA strdup
-#endif
-
-#if defined(__MWERKS__)
- /* Metrowerks only has wide char support for OS X >= 10.3 */
- #if !defined(__DARWIN__) || \
- (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
- #define wxHAVE_MWERKS_UNICODE
- #endif
+// ============================================================================
+// misc functions
+// ============================================================================
- #ifdef wxHAVE_MWERKS_UNICODE
- #define HAVE_WPRINTF 1
- #define HAVE_WCSRTOMBS 1
- #define HAVE_VSWPRINTF 1
- #endif
-#endif /* __MWERKS__ */
-
-#ifdef wxHAVE_TCHAR_SUPPORT
- /* we surely have wchar_t if we have TCHAR have wcslen() */
- #ifndef HAVE_WCSLEN
- #define HAVE_WCSLEN
- #endif
-#endif /* wxHAVE_TCHAR_SUPPORT */
-
-/*
- define wxFoo() function for each standard foo() function whose signature
- (exceptionally including the return type) includes any mention of char:
- wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
- the same signature but with char replaced by wxChar which allows us to
- use it in Unicode build as well
- */
-
-#ifdef wxHAVE_TCHAR_SUPPORT
- #include <ctype.h>
-
- #if defined(__WATCOMC__) && defined(UNICODE)
- #define WXWCHAR_T_CAST(c) (wint_t)(c)
- #else
- #define WXWCHAR_T_CAST(c) c
- #endif
-
- /* ctype.h functions */
- #define wxIsalnum(c) _istalnum(WXWCHAR_T_CAST(c))
- #define wxIsalpha(c) _istalpha(WXWCHAR_T_CAST(c))
- #define wxIscntrl(c) _istcntrl(WXWCHAR_T_CAST(c))
- #define wxIsdigit(c) _istdigit(WXWCHAR_T_CAST(c))
- #define wxIsgraph(c) _istgraph(WXWCHAR_T_CAST(c))
- #define wxIslower(c) _istlower(WXWCHAR_T_CAST(c))
- #define wxIsprint(c) _istprint(WXWCHAR_T_CAST(c))
- #define wxIspunct(c) _istpunct(WXWCHAR_T_CAST(c))
- #define wxIsspace(c) _istspace(WXWCHAR_T_CAST(c))
- #define wxIsupper(c) _istupper(WXWCHAR_T_CAST(c))
- #define wxIsxdigit(c) _istxdigit(WXWCHAR_T_CAST(c))
-
- /*
- There is a bug in VC6 C RTL: toxxx() functions dosn't do anything with
- signed chars < 0, so "fix" it here.
- */
- #define wxTolower(c) _totlower((wxUChar)(wxChar)(c))
- #define wxToupper(c) _totupper((wxUChar)(wxChar)(c))
-
- /* locale.h functons */
- #define wxSetlocale_ _tsetlocale
-
- /* string.h functions */
- #define wxStrcat _tcscat
- #define wxStrchr _tcschr
- #define wxStrcmp _tcscmp
- #define wxStrcoll _tcscoll
- #define wxStrcpy _tcscpy
- #define wxStrcspn _tcscspn
- #define wxStrdupW _wcsdup /* notice the 'W'! */
- #define wxStrftime _tcsftime
- #define wxStricmp _tcsicmp
- #define wxStrnicmp _tcsnicmp
- #define wxStrlen_ _tcslen /* used in wxStrlen inline function */
- #define wxStrncat _tcsncat
- #define wxStrncmp _tcsncmp
- #define wxStrncpy _tcsncpy
- #define wxStrpbrk _tcspbrk
- #define wxStrrchr _tcsrchr
- #define wxStrspn _tcsspn
- #define wxStrstr _tcsstr
- #define wxStrtod _tcstod
- #define wxStrtol _tcstol
- #define wxStrtoul _tcstoul
- #ifdef __VISUALC__
- #if __VISUALC__ >= 1300 && !defined(__WXWINCE__)
- #define wxStrtoll _tcstoi64
- #define wxStrtoull _tcstoui64
- #endif /* VC++ 7+ */
- #endif
- #define wxStrxfrm _tcsxfrm
-
- /* stdio.h functions */
- #define wxFgetc _fgettc
- #define wxFgetchar _fgettchar
- #define wxFgets _fgetts
- #if wxUSE_UNICODE_MSLU
- WXDLLIMPEXP_BASE FILE * wxMSLU__tfopen(const wxChar *name, const wxChar *mode);
-
- #define wxFopen wxMSLU__tfopen
- #else
- #define wxFopen _tfopen
- #endif
- #define wxFputc _fputtc
- #define wxFputchar _fputtchar
- #define wxFputs _fputts
- #define wxFreopen _tfreopen
- #define wxGetc _gettc
- #define wxGetchar _gettchar
- #define wxGets _getts
- #define wxPerror _tperror
- #define wxPutc(c,f) _puttc(WXWCHAR_T_CAST(c),f)
- #define wxPutchar _puttchar
- #define wxPuts _putts
-
- #define wxTmpnam _ttmpnam
- #define wxUngetc _tungetc
-
- /* special case: these functions are missing under Win9x with Unicows so we */
- /* have to implement them ourselves */
- #if wxUSE_UNICODE_MSLU
- WXDLLIMPEXP_BASE int wxMSLU__trename(const wxChar *oldname, const wxChar *newname);
- WXDLLIMPEXP_BASE int wxMSLU__tremove(const wxChar *name);
-
- #define wxRemove wxMSLU__tremove
- #define wxRename wxMSLU__trename
- #else
- #ifdef __WXWINCE__
- /* carefully: wxRemove() must return 0 on success while DeleteFile()
- returns 0 on error, so don't just define one as the other */
- int wxRemove(const wxChar *path);
- #else
- #define wxRemove _tremove
- #define wxRename _trename
- #endif
- #endif
+/* checks whether the passed in pointer is NULL and if the string is empty */
+inline bool wxIsEmpty(const char *s) { return !s || !*s; }
+inline bool wxIsEmpty(const wchar_t *s) { return !s || !*s; }
+inline bool wxIsEmpty(const wxCharBuffer& s) { return wxIsEmpty(s.data()); }
+inline bool wxIsEmpty(const wxWCharBuffer& s) { return wxIsEmpty(s.data()); }
+inline bool wxIsEmpty(const wxString& s) { return s.empty(); }
+inline bool wxIsEmpty(const wxCStrData& s) { return s.AsString().empty(); }
- /* stdlib.h functions */
- #define wxAtoi _ttoi
- #define wxAtol _ttol
- /* #define wxAtof _tttof -- notice that there is no such thing (why?) */
- /* there are no env vars at all under CE, so no _tgetenv neither */
- #ifdef __WXWINCE__
- /* can't define as inline function as this is a C file... */
- #define wxGetenv(name) ((wxChar *)NULL)
- #else
- #define wxGetenv _tgetenv
- #endif
- #define wxSystem _tsystem
-
- /* time.h functions */
- #define wxAsctime _tasctime
- #define wxCtime _tctime
-
- #define wxMbstowcs mbstowcs
- #define wxWcstombs wcstombs
-#else /* !TCHAR-aware compilers */
- /*
- There are 2 unrelated problems with these functions under Mac:
- a) Metrowerks MSL CRT implements them strictly in C99 sense and
- doesn't support (very common) extension of allowing to call
- mbstowcs(NULL, ...) which makes it pretty useless as you can't
- know the size of the needed buffer
- b) OS X <= 10.2 declares and even defined these functions but
- doesn't really implement them -- they always return an error
-
- So use our own replacements in both cases.
- */
- #if defined(__MWERKS__) && defined(__MSL__)
- #define wxNEED_WX_MBSTOWCS
- #endif
- #ifdef __DARWIN__
- #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
- #define wxNEED_WX_MBSTOWCS
- #endif
- #endif
+// FIXME-UTF8: get rid of this, it's ANSI only anyway
+WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
- #ifdef wxNEED_WX_MBSTOWCS
- /* even though they are defined and "implemented", they are bad and just
- stubs so we need our own - we need these even in ANSI builds!! */
- WXDLLIMPEXP_BASE size_t wxMbstowcs (wchar_t *, const char *, size_t);
- WXDLLIMPEXP_BASE size_t wxWcstombs (char *, const wchar_t *, size_t);
- #else
- #define wxMbstowcs mbstowcs
- #define wxWcstombs wcstombs
- #endif
- /*
- The system C library on Mac OS X 10.2 and below does not support
- unicode: in other words all wide-character functions such as towupper et
- al. do simply not exist so we need to provide our own in that context,
- except for the wchar_t definition/typedef itself.
-
- We need to do this for both project builder and CodeWarrior as
- the latter uses the system C library in Mach builds for wide character
- support, which as mentioned does not exist on 10.2 and below.
- */
- #if wxUSE_UNICODE && \
- defined(__DARWIN__) && \
- ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
- /* we need everything! */
- #define wxNEED_WX_STRING_H
- #define wxNEED_WX_CTYPE_H
-
- #define wxFgetchar(c) wxFgetc(c, stdin)
- #define wxFputc wxPutc
- #define wxFputchar(c) wxPutc(c, stdout)
- #define wxGetc wxFgetc
- #define wxGetchar(c) wxFgetc(c, stdin)
-
- #include <stdio.h>
-
- #define wxNEED_FGETC
- #define wxNEED_FGETS
- #define wxNEED_GETS
- #define wxNEED_UNGETC
-
- #define wxNEED_FPUTS
- #define wxNEED_PUTS
- #define wxNEED_PUTC
-
- int wxFputs(const wxChar *ch, FILE *stream);
- int wxPuts(const wxChar *ws);
- int wxPutc(wxChar ch, FILE *stream);
-
- #ifdef __cplusplus
- extern "C" {
- #endif
- WXDLLIMPEXP_BASE size_t wxStrlen_(const wxChar *s);
- #ifdef __cplusplus
- }
- #endif
-
- #define wxPutchar(wch) wxPutc(wch, stdout)
-
- #define wxNEED_PRINTF_CONVERSION
- #define wxNEED_WX_STDIO_H
- #define wxNEED_WX_STDLIB_H
- #define wxNEED_WX_TIME_H
-
- #elif wxUSE_UNICODE
- #include <wctype.h>
-
- /* this is probably glibc-specific */
- #if defined(__WCHAR_TYPE__) && !defined(__MWERKS__)
- /* ctype.h functions (wctype.h) */
- #define wxIsalnum iswalnum
- #define wxIsalpha iswalpha
- #define wxIscntrl iswcntrl
- #define wxIsdigit iswdigit
- #define wxIsgraph iswgraph
- #define wxIslower iswlower
- #define wxIsprint iswprint
- #define wxIspunct iswpunct
- #define wxIsspace iswspace
- #define wxIsupper iswupper
- #define wxIsxdigit iswxdigit
-
- #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
- /* /usr/include/wctype.h incorrectly declares translations */
- /* tables which provokes tons of compile-time warnings -- try */
- /* to correct this */
- #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
- #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
- #else /* !glibc 2.0 */
- #define wxTolower towlower
- #define wxToupper towupper
- #endif /* gcc/!gcc */
-
- /* string.h functions (wchar.h) */
- #define wxStrcat wcscat
- #define wxStrchr wcschr
- #define wxStrcmp wcscmp
- #define wxStrcoll wcscoll
- #define wxStrcpy wcscpy
- #define wxStrcspn wcscspn
- #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
- #define wxStrncat wcsncat
- #define wxStrncmp wcsncmp
- #define wxStrncpy wcsncpy
- #define wxStrpbrk wcspbrk
- #define wxStrrchr wcsrchr
- #define wxStrspn wcsspn
- #define wxStrstr wcsstr
- #define wxStrtod wcstod
- #define wxStrtol wcstol
- #define wxStrtoul wcstoul
- #ifdef HAVE_WCSTOULL
- /* assume that we have wcstoull(), which is also C99, too */
- #define wxStrtoll wcstoll
- #define wxStrtoull wcstoull
- #endif /* HAVE_WCSTOULL */
- #define wxStrxfrm wcsxfrm
-
- #define wxFgetc fgetwc
- #define wxFgetchar fgetwchar
- #define wxFgets fgetws
- #define wxFputc fputwc
- #define wxFputchar fputwchar
- #define wxGetc getwc
- #define wxGetchar getwchar
- #define wxGets getws
- #define wxUngetc ungetwc
-
- #ifdef HAVE_FPUTWS
- #define wxFputs fputws
- #else
- #define wxNEED_FPUTS
- #include <stdio.h>
- int wxFputs(const wxChar *ch, FILE *stream);
- #endif
-
- #ifdef HAVE_WPUTC
- #define wxPutc wputc
- #else
- #define wxNEED_PUTC
- #include <stdio.h>
- int wxPutc(wxChar ch, FILE *stream);
- #endif
-
- #ifdef HAVE_WPUTCHAR
- #define wxPutchar wputchar
- #else
- #define wxPutchar(wch) wxPutc(wch, stdout)
- #endif
-
- #ifdef HAVE_PUTWS
- #define wxPuts putws
- #else
- #define wxNEED_PUTS
- int wxPuts(const wxChar *ws);
- #endif
-
- /* we need %s to %ls conversion for printf and scanf etc */
- #define wxNEED_PRINTF_CONVERSION
-
- /* glibc doesn't have wide char equivalents of the other stuff so */
- /* use our own versions */
- #define wxNEED_WX_STDIO_H
- #define wxNEED_WX_STDLIB_H
- #define wxNEED_WX_TIME_H
- #elif defined(__MWERKS__) && ( defined(__MSL__) || defined(__MACH__) )
- /* ctype.h functions (wctype.h) */
- #define wxIsalnum iswalnum
- #define wxIsalpha iswalpha
- #define wxIscntrl iswcntrl
- #define wxIsdigit iswdigit
- #define wxIsgraph iswgraph
- #define wxIslower iswlower
- #define wxIsprint iswprint
- #define wxIspunct iswpunct
- #define wxIsspace iswspace
- #define wxIsupper iswupper
- #define wxIsxdigit iswxdigit
- #define wxTolower towlower
- #define wxToupper towupper
-
- /* string.h functions (wchar.h) */
- #define wxStrcat wcscat
- #define wxStrchr wcschr
- #define wxStrcmp wcscmp
- #define wxStrcoll wcscoll
- #define wxStrcpy wcscpy
- #define wxStrcspn wcscspn
- #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
- #define wxStrncat wcsncat
- #define wxStrncmp wcsncmp
- #define wxStrncpy wcsncpy
- #define wxStrpbrk wcspbrk
- #define wxStrrchr wcsrchr
- #define wxStrspn wcsspn
- #define wxStrstr wcsstr
- #define wxStrtod wcstod
- #define wxStrtol wcstol
- #define wxStrtoul wcstoul
- #define wxStrxfrm wcsxfrm
-
- #define wxFgetc fgetwc
- #define wxFgetchar fgetwchar
- #define wxFgets fgetws
- #define wxFputc fputwc
- #define wxFputchar fputwchar
- #define wxGetc getwc
- #define wxGetchar getwchar
- #define wxGets getws
- #define wxUngetc ungetwc
-
- #define wxNEED_PRINTF_CONVERSION
-
- #define wxPutc putwc
- #define wxPutchar putwchar
- #define wxFputs fputws
-
- /* stdio.h functions */
-
- #define wxNEED_WX_STDIO_H
-
- /* stdlib.h functions */
- #ifdef __MACH__
- #define wxNEED_WX_STDLIB_H
- #else
- #define wxAtof watof
- #define wxAtoi watoi
- #define wxAtol watol
- #define wxGetenv(a) ((wxChar*)NULL)
- #define wxSystem(a) ((int)NULL)
- #endif
- /* time.h functions */
- #define wxAsctime wasciitime
- #define wxCtime wctime
- /* #define wxStrftime wcsftime */
-
- #define wxNEED_WX_TIME_H
- #else /* !metrowerks for apple */
- #error "Please define wide character functions for your environment"
- #endif
- #else /* ASCII */
- #include <ctype.h>
- #include <string.h>
-
- /* ctype.h functions */
- #define wxIsalnum isalnum
- #define wxIsalpha isalpha
- #define wxIscntrl iscntrl
- #define wxIsdigit isdigit
- #define wxIsgraph isgraph
- #define wxIslower islower
- #define wxIsprint isprint
- #define wxIspunct ispunct
- #define wxIsspace isspace
- #define wxIsupper isupper
- #define wxIsxdigit isxdigit
- #define wxTolower tolower
- #define wxToupper toupper
-
- /* locale.h functons */
- #define wxSetlocale_ setlocale
-
- /* string.h functions */
- #define wxStrcat strcat
- #define wxStrchr strchr
- #define wxStrcmp strcmp
- #define wxStrcoll strcoll
- #define wxStrcpy strcpy
- #define wxStrcspn strcspn
-
- /* wxStricmp and wxStrnicmp are defined below */
- #define wxStrlen_ strlen /* used in wxStrlen inline function */
- #define wxStrncat strncat
- #define wxStrncmp strncmp
- #define wxStrncpy strncpy
- #define wxStrpbrk strpbrk
- #define wxStrrchr strrchr
- #define wxStrspn strspn
- #define wxStrstr strstr
- #define wxStrtod strtod
- #ifdef HAVE_STRTOK_R
- #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
- #endif
- #define wxStrtol strtol
- #define wxStrtoul strtoul
- #ifdef HAVE_STRTOULL
- /* assume that we have wcstoull(), which is also C99, too */
- #define wxStrtoll strtoll
- #define wxStrtoull strtoull
- #endif /* HAVE_WCSTOULL */
- #define wxStrxfrm strxfrm
-
- /* stdio.h functions */
- #define wxFopen fopen
- #define wxFreopen freopen
- #define wxRemove remove
- #define wxRename rename
-
- #define wxPerror perror
- #define wxTmpnam tmpnam
-
- #define wxFgetc fgetc
- #define wxFgetchar fgetchar
- #define wxFgets fgets
- #define wxFputc fputc
- #define wxFputs fputs
- #define wxFputchar fputchar
- #define wxGetc getc
- #define wxGetchar getchar
- #define wxGets gets
- #define wxPutc putc
- #define wxPutchar putchar
- #define wxPuts puts
- #define wxUngetc ungetc
-
- /* stdlib.h functions */
- #define wxAtof atof
- #define wxAtoi atoi
- #define wxAtol atol
- #define wxGetenv getenv
- #define wxSystem system
-
- /* time.h functions */
- #define wxAsctime asctime
- #define wxCtime ctime
- #define wxStrftime strftime
- #endif /* Unicode/ASCII */
-#endif /* TCHAR-aware compilers/the others */
-
-/*
- various special cases
- */
-
-/* define wxStricmp and wxStrnicmp for various compilers */
-
-/* note that in Unicode mode we definitely are going to need our own version */
-#if !defined(wxStricmp) && !wxUSE_UNICODE
- #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
- defined(__SALFORDC__) || defined(__VISAGECPP__) || \
- defined(__EMX__) || defined(__DJGPP__)
- #define wxStricmp stricmp
- #define wxStrnicmp strnicmp
- #elif defined(__WXPALMOS__)
- /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
- * quick hack should do until one can be written.
- */
- #define wxStricmp StrCaselessCompare
- #define wxStrnicmp strnicmp
- #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
- (defined(__MWERKS__) && defined(__INTEL__))
- #define wxStricmp _stricmp
- #define wxStrnicmp _strnicmp
- #elif defined(__UNIX__) || defined(__GNUWIN32__)
- #define wxStricmp strcasecmp
- #define wxStrnicmp strncasecmp
- /* #else -- use wxWidgets implementation */
- #endif
-#endif /* !defined(wxStricmp) */
+/* multibyte to wide char conversion functions and macros */
-/* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
-/* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
-/* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
#if wxUSE_WCHAR_T
- #ifdef HAVE_WCSLEN
- #define wxWcslen wcslen
+ /* multibyte<->widechar conversion */
+ WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
+ WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
+
+ #if wxUSE_UNICODE
+ #define wxMB2WX wxMB2WC
+ #define wxWX2MB wxWC2MB
+ #define wxWC2WX wxStrncpy
+ #define wxWX2WC wxStrncpy
#else
- WXDLLIMPEXP_BASE size_t wxWcslen(const wchar_t *s);
+ #define wxMB2WX wxStrncpy
+ #define wxWX2MB wxStrncpy
+ #define wxWC2WX wxWC2MB
+ #define wxWX2WC wxMB2WC
#endif
-#endif /* wxUSE_WCHAR_T */
-
-#ifdef __cplusplus
-/* checks whether the passed in pointer is NULL and if the string is empty */
-inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
-
-/* safe version of strlen() (returns 0 if passed NULL pointer) */
-inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
+#else /* !wxUSE_UNICODE */
+ /* No wxUSE_WCHAR_T: we have to do something (JACS) */
+ #define wxMB2WC wxStrncpy
+ #define wxWC2MB wxStrncpy
+ #define wxMB2WX wxStrncpy
+ #define wxWX2MB wxStrncpy
+ #define wxWC2WX wxWC2MB
+ #define wxWX2WC wxMB2WC
#endif
-/*
- each of strdup() and wcsdup() may or may not be available but we need both
- of them anyhow for wx/buffer.h so we define the missing one(s) in
- wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
- defined -- if this is somehow not the case in some situations, please
- correct that and not the lines here
- */
+
+// RN: We could do the usual tricky compiler detection here,
+// and use their variant (such as wmemchr, etc.). The problem
+// is that these functions are quite rare, even though they are
+// part of the current POSIX standard. In addition, most compilers
+// (including even MSC) inline them just like we do right in their
+// headers.
+//
#if wxUSE_UNICODE
- #define wxStrdup wxStrdupW
-#else
- #define wxStrdup wxStrdupA
-#endif
+ #include <string.h> //for mem funcs
-#ifdef __cplusplus
-WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
-#endif
+ //implement our own wmem variants
+ inline wxChar* wxTmemchr(const wxChar* s, wxChar c, size_t l)
+ {
+ for(;l && *s != c;--l, ++s) {}
-#ifndef wxStrtoll
- /* supply strtoll and strtoull, if needed */
- WXDLLIMPEXP_BASE wxLongLong_t wxStrtoll(const wxChar* nptr, wxChar** endptr, int base);
- WXDLLIMPEXP_BASE wxULongLong_t wxStrtoull(const wxChar* nptr, wxChar** endptr, int base);
-#endif
+ if(l)
+ return (wxChar*)s;
+ return NULL;
+ }
-#define wxHAS_STRTOLL
+ inline int wxTmemcmp(const wxChar* sz1, const wxChar* sz2, size_t len)
+ {
+ for(; *sz1 == *sz2 && len; --len, ++sz1, ++sz2) {}
-/*
- In Unicode mode we need to have all standard functions such as wprintf() and
- so on but not all systems have them so use our own implementations in this
- case.
- */
-#if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
- #define wxNEED_WPRINTF
-#endif
+ if(len)
+ return *sz1 < *sz2 ? -1 : *sz1 > *sz2;
+ else
+ return 0;
+ }
-/*
- various functions which might not be available in libc and for which we
- provide our own replacements in wxchar.cpp
- */
-
-/* ctype.h functions */
-
-/* RN: Used only under OSX <= 10.2 currently */
-#ifdef wxNEED_WX_CTYPE_H
- WXDLLIMPEXP_BASE int wxIsalnum(wxChar ch);
- WXDLLIMPEXP_BASE int wxIsalpha(wxChar ch);
- WXDLLIMPEXP_BASE int wxIscntrl(wxChar ch);
- WXDLLIMPEXP_BASE int wxIsdigit(wxChar ch);
- WXDLLIMPEXP_BASE int wxIsgraph(wxChar ch);
- WXDLLIMPEXP_BASE int wxIslower(wxChar ch);
- WXDLLIMPEXP_BASE int wxIsprint(wxChar ch);
- WXDLLIMPEXP_BASE int wxIspunct(wxChar ch);
- WXDLLIMPEXP_BASE int wxIsspace(wxChar ch);
- WXDLLIMPEXP_BASE int wxIsupper(wxChar ch);
- WXDLLIMPEXP_BASE int wxIsxdigit(wxChar ch);
- WXDLLIMPEXP_BASE int wxTolower(wxChar ch);
- WXDLLIMPEXP_BASE int wxToupper(wxChar ch);
-#endif /* wxNEED_WX_CTYPE_H */
-
-/* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
-/* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
-#if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
- #undef wxIsspace
- #define wxIsspace(c) ((((unsigned)(wxChar)c) < 128) && isspace(c))
-#endif /* VC++ */
-
-/*
- a few compilers don't have the (non standard but common) isascii function,
- define it ourselves for them
- */
-#ifndef isascii
- #if defined(__MWERKS__)
- #define wxNEED_ISASCII
- #elif defined(_WIN32_WCE)
- #if _WIN32_WCE <= 211
- #define wxNEED_ISASCII
- #endif
- #endif
-#endif /* isascii */
+ inline wxChar* wxTmemcpy(wxChar* szOut, const wxChar* szIn, size_t len)
+ {
+ return (wxChar*) memcpy(szOut, szIn, len * sizeof(wxChar));
+ }
-#ifdef wxNEED_ISASCII
- inline int isascii(int c) { return (unsigned)c < 0x80; }
-#endif
+ inline wxChar* wxTmemmove(wxChar* szOut, const wxChar* szIn, size_t len)
+ {
+ return (wxChar*) memmove(szOut, szIn, len * sizeof(wxChar));
+ }
-#ifdef _WIN32_WCE
- #if _WIN32_WCE <= 211
- #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
- #endif
-#endif /* _WIN32_WCE */
-
-/*
- we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
- initial versions of this header -- now it is too late to remove it so
- although we fixed the function/macro name above, still provide the
- backwards-compatible synonym.
- */
-#define wxIsctrl wxIscntrl
-
-/* string.h functions */
-#ifndef strdup
- #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
- #define wxNEED_STRDUP
- #elif defined(__WXWINCE__)
- #if _WIN32_WCE <= 211
- #define wxNEED_STRDUP
- #endif
- #endif
-#endif /* strdup */
+ inline wxChar* wxTmemset(wxChar* szOut, const wxChar cIn, size_t len)
+ {
+ wxChar* szRet = szOut;
-#ifdef wxNEED_STRDUP
- WXDLLIMPEXP_BASE char *strdup(const char* s);
-#endif
+ while (len--)
+ *szOut++ = cIn;
-/* RN: Used only under OSX <= 10.2 currently
- The __cplusplus ifdefs are messy, but they are required to build
- the regex library, since c does not support function overloading
-*/
-#ifdef wxNEED_WX_STRING_H
-# ifdef __cplusplus
- extern "C" {
-# endif
- WXDLLIMPEXP_BASE wxChar * wxStrcat(wxChar *dest, const wxChar *src);
- WXDLLIMPEXP_BASE const wxChar * wxStrchr(const wxChar *s, wxChar c);
- WXDLLIMPEXP_BASE int wxStrcmp(const wxChar *s1, const wxChar *s2);
- WXDLLIMPEXP_BASE int wxStrcoll(const wxChar *s1, const wxChar *s2);
- WXDLLIMPEXP_BASE wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
- WXDLLIMPEXP_BASE size_t wxStrcspn(const wxChar *s, const wxChar *reject);
- WXDLLIMPEXP_BASE wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
- WXDLLIMPEXP_BASE int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
- WXDLLIMPEXP_BASE wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
- WXDLLIMPEXP_BASE const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
- WXDLLIMPEXP_BASE const wxChar * wxStrrchr(const wxChar *s, wxChar c);
- WXDLLIMPEXP_BASE size_t wxStrspn(const wxChar *s, const wxChar *accept);
- WXDLLIMPEXP_BASE const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
-# ifdef __cplusplus
+ return szRet;
}
-# endif
-
- /* These functions use C++, so we can't c extern them */
- WXDLLIMPEXP_BASE double wxStrtod(const wxChar *nptr, wxChar **endptr);
- WXDLLIMPEXP_BASE long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
- WXDLLIMPEXP_BASE unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
- WXDLLIMPEXP_BASE size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
-
- /* inlined versions */
- #ifdef __cplusplus
- inline wxChar * wxStrchr(wxChar *s, wxChar c)
- { return (wxChar *)wxStrchr((const wxChar *)s, c); }
- inline wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
- { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
- inline wxChar * wxStrrchr(wxChar *s, wxChar c)
- { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
- inline wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
- { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
- #endif
-#endif /* wxNEED_WX_STRING_H */
-
-#ifndef wxStrdupA
-WXDLLIMPEXP_BASE char *wxStrdupA(const char *psz);
-#endif
-
-#ifndef wxStrdupW
-WXDLLIMPEXP_BASE wchar_t *wxStrdupW(const wchar_t *pwz);
-#endif
+ // and trivial wrappers for char* versions:
+ inline char* wxTmemchr(const char* s, char c, size_t len)
+ { return (char*)memchr(s, c, len); }
+ inline int wxTmemcmp(const char* sz1, const char* sz2, size_t len)
+ { return memcmp(sz1, sz2, len); }
+ inline char* wxTmemcpy(char* szOut, const char* szIn, size_t len)
+ { return (char*)memcpy(szOut, szIn, len); }
+ inline char* wxTmemmove(char* szOut, const char* szIn, size_t len)
+ { return (char*)memmove(szOut, szIn, len); }
+ inline char* wxTmemset(char* szOut, const char cIn, size_t len)
+ { return (char*)memset(szOut, cIn, len); }
-#ifndef wxStricmp
-WXDLLIMPEXP_BASE int wxStricmp(const wxChar *psz1, const wxChar *psz2);
-#endif
+#else /* !wxUSE_UNICODE */
+ #define wxTmemchr memchr
+ #define wxTmemcmp memcmp
+ #define wxTmemcpy memcpy
+ #define wxTmemmove memmove
+ #define wxTmemset memset
+#endif /* wxUSE_UNICODE/!wxUSE_UNICODE */
+
+
+
+// ============================================================================
+// wx wrappers for CRT functions in both char* and wchar_t* versions
+// ============================================================================
+
+// A few notes on implementation of these wrappers:
+//
+// We need both char* and wchar_t* versions of functions like wxStrlen() for
+// compatibility with both ANSI and Unicode builds.
+//
+// This makes passing wxString or c_str()/mb_str()/wc_str() result to them
+// ambiguous, so we need to provide overrides for that as well (in cases where
+// it makes sense).
+//
+// We can do this without problems for some functions (wxStrlen()), but in some
+// cases, we can't stay compatible with both ANSI and Unicode builds, e.g. for
+// wxStrcpy(const wxString&), which can only return either char* or wchar_t*.
+// In these cases, we preserve ANSI build compatibility by returning char*.
+
+// ----------------------------------------------------------------------------
+// locale functions
+// ----------------------------------------------------------------------------
+
+// NB: we can't provide const wchar_t* (= wxChar*) overload, because calling
+// wxSetlocale(category, NULL) -- which is a common thing to do --would be
+// ambiguous
+WXDLLIMPEXP_BASE char* wxSetlocale(int category, const char *locale);
+inline char* wxSetlocale(int category, const wxCharBuffer& locale)
+ { return wxSetlocale(category, locale.data()); }
+inline char* wxSetlocale(int category, const wxString& locale)
+ { return wxSetlocale(category, locale.mb_str()); }
+inline char* wxSetlocale(int category, const wxCStrData& locale)
+ { return wxSetlocale(category, locale.AsCharBuf()); }
+
+// ----------------------------------------------------------------------------
+// string functions
+// ----------------------------------------------------------------------------
-#ifndef wxStrnicmp
-WXDLLIMPEXP_BASE int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
+/* safe version of strlen() (returns 0 if passed NULL pointer) */
+// NB: these are defined in wxcrtbase.h, see the comment there
+// inline size_t wxStrlen(const char *s) { return s ? strlen(s) : 0; }
+// inline size_t wxStrlen(const wchar_t *s) { return s ? wxCRT_Strlen_(s) : 0; }
+inline size_t wxStrlen(const wxCharBuffer& s) { return wxStrlen(s.data()); }
+inline size_t wxStrlen(const wxWCharBuffer& s) { return wxStrlen(s.data()); }
+inline size_t wxStrlen(const wxString& s) { return s.length(); }
+inline size_t wxStrlen(const wxCStrData& s) { return s.AsString().length(); }
+
+// NB: these are defined in wxcrtbase.h, see the comment there
+// inline char* wxStrdup(const char *s) { return wxStrdupA(s); }
+// inline wchar_t* wxStrdup(const wchar_t *s) { return wxStrdupW(s); }
+inline char* wxStrdup(const wxCharBuffer& s) { return wxStrdup(s.data()); }
+inline wchar_t* wxStrdup(const wxWCharBuffer& s) { return wxStrdup(s.data()); }
+inline char* wxStrdup(const wxString& s) { return wxStrdup(s.mb_str()); }
+inline char* wxStrdup(const wxCStrData& s) { return wxStrdup(s.AsCharBuf()); }
+
+inline char *wxStrcpy(char *dest, const char *src)
+ { return wxCRT_StrcpyA(dest, src); }
+inline wchar_t *wxStrcpy(wchar_t *dest, const wchar_t *src)
+ { return wxCRT_StrcpyW(dest, src); }
+inline char *wxStrcpy(char *dest, const wxString& src)
+ { return wxCRT_StrcpyA(dest, src.mb_str()); }
+inline char *wxStrcpy(char *dest, const wxCStrData& src)
+ { return wxCRT_StrcpyA(dest, src.AsCharBuf()); }
+inline char *wxStrcpy(char *dest, const wxCharBuffer& src)
+ { return wxCRT_StrcpyA(dest, src.data()); }
+inline wchar_t *wxStrcpy(wchar_t *dest, const wxString& src)
+ { return wxCRT_StrcpyW(dest, src.wc_str()); }
+inline wchar_t *wxStrcpy(wchar_t *dest, const wxCStrData& src)
+ { return wxCRT_StrcpyW(dest, src.AsWCharBuf()); }
+inline wchar_t *wxStrcpy(wchar_t *dest, const wxWCharBuffer& src)
+ { return wxCRT_StrcpyW(dest, src.data()); }
+inline char *wxStrcpy(char *dest, const wchar_t *src)
+ { return wxCRT_StrcpyA(dest, wxConvLibc.cWC2MB(src)); }
+inline wchar_t *wxStrcpy(wchar_t *dest, const char *src)
+ { return wxCRT_StrcpyW(dest, wxConvLibc.cMB2WC(src)); }
+
+inline char *wxStrncpy(char *dest, const char *src, size_t n)
+ { return wxCRT_StrncpyA(dest, src, n); }
+inline wchar_t *wxStrncpy(wchar_t *dest, const wchar_t *src, size_t n)
+ { return wxCRT_StrncpyW(dest, src, n); }
+inline char *wxStrncpy(char *dest, const wxString& src, size_t n)
+ { return wxCRT_StrncpyA(dest, src.mb_str(), n); }
+inline char *wxStrncpy(char *dest, const wxCStrData& src, size_t n)
+ { return wxCRT_StrncpyA(dest, src.AsCharBuf(), n); }
+inline char *wxStrncpy(char *dest, const wxCharBuffer& src, size_t n)
+ { return wxCRT_StrncpyA(dest, src.data(), n); }
+inline wchar_t *wxStrncpy(wchar_t *dest, const wxString& src, size_t n)
+ { return wxCRT_StrncpyW(dest, src.wc_str(), n); }
+inline wchar_t *wxStrncpy(wchar_t *dest, const wxCStrData& src, size_t n)
+ { return wxCRT_StrncpyW(dest, src.AsWCharBuf(), n); }
+inline wchar_t *wxStrncpy(wchar_t *dest, const wxWCharBuffer& src, size_t n)
+ { return wxCRT_StrncpyW(dest, src.data(), n); }
+inline char *wxStrncpy(char *dest, const wchar_t *src, size_t n)
+ { return wxCRT_StrncpyA(dest, wxConvLibc.cWC2MB(src), n); }
+inline wchar_t *wxStrncpy(wchar_t *dest, const char *src, size_t n)
+ { return wxCRT_StrncpyW(dest, wxConvLibc.cMB2WC(src), n); }
+
+inline char *wxStrcat(char *dest, const char *src)
+ { return wxCRT_StrcatA(dest, src); }
+inline wchar_t *wxStrcat(wchar_t *dest, const wchar_t *src)
+ { return wxCRT_StrcatW(dest, src); }
+inline char *wxStrcat(char *dest, const wxString& src)
+ { return wxCRT_StrcatA(dest, src.mb_str()); }
+inline char *wxStrcat(char *dest, const wxCStrData& src)
+ { return wxCRT_StrcatA(dest, src.AsCharBuf()); }
+inline char *wxStrcat(char *dest, const wxCharBuffer& src)
+ { return wxCRT_StrcatA(dest, src.data()); }
+inline wchar_t *wxStrcat(wchar_t *dest, const wxString& src)
+ { return wxCRT_StrcatW(dest, src.wc_str()); }
+inline wchar_t *wxStrcat(wchar_t *dest, const wxCStrData& src)
+ { return wxCRT_StrcatW(dest, src.AsWCharBuf()); }
+inline wchar_t *wxStrcat(wchar_t *dest, const wxWCharBuffer& src)
+ { return wxCRT_StrcatW(dest, src.data()); }
+inline char *wxStrcat(char *dest, const wchar_t *src)
+ { return wxCRT_StrcatA(dest, wxConvLibc.cWC2MB(src)); }
+inline wchar_t *wxStrcat(wchar_t *dest, const char *src)
+ { return wxCRT_StrcatW(dest, wxConvLibc.cMB2WC(src)); }
+
+inline char *wxStrncat(char *dest, const char *src, size_t n)
+ { return wxCRT_StrncatA(dest, src, n); }
+inline wchar_t *wxStrncat(wchar_t *dest, const wchar_t *src, size_t n)
+ { return wxCRT_StrncatW(dest, src, n); }
+inline char *wxStrncat(char *dest, const wxString& src, size_t n)
+ { return wxCRT_StrncatA(dest, src.mb_str(), n); }
+inline char *wxStrncat(char *dest, const wxCStrData& src, size_t n)
+ { return wxCRT_StrncatA(dest, src.AsCharBuf(), n); }
+inline char *wxStrncat(char *dest, const wxCharBuffer& src, size_t n)
+ { return wxCRT_StrncatA(dest, src.data(), n); }
+inline wchar_t *wxStrncat(wchar_t *dest, const wxString& src, size_t n)
+ { return wxCRT_StrncatW(dest, src.wc_str(), n); }
+inline wchar_t *wxStrncat(wchar_t *dest, const wxCStrData& src, size_t n)
+ { return wxCRT_StrncatW(dest, src.AsWCharBuf(), n); }
+inline wchar_t *wxStrncat(wchar_t *dest, const wxWCharBuffer& src, size_t n)
+ { return wxCRT_StrncatW(dest, src.data(), n); }
+inline char *wxStrncat(char *dest, const wchar_t *src, size_t n)
+ { return wxCRT_StrncatA(dest, wxConvLibc.cWC2MB(src), n); }
+inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n)
+ { return wxCRT_StrncatW(dest, wxConvLibc.cMB2WC(src), n); }
+
+
+#define WX_STR_DECL(name, T1, T2) name(T1 s1, T2 s2)
+#define WX_STR_CALL(func, a1, a2) func(a1, a2)
+
+// This macro defines string function for all possible variants of arguments,
+// except for those taking wxString or wxCStrData as second argument.
+// Parameters:
+// rettype - return type
+// name - name of the (overloaded) function to define
+// crtA - function to call for char* versions (takes two arguments)
+// crtW - ditto for wchar_t* function
+// forString - function to call when the *first* argument is wxString;
+// the second argument can be any string type, so this is
+// typically a template
+#define WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \
+ inline rettype WX_STR_DECL(name, const char *, const char *) \
+ { return WX_STR_CALL(crtA, s1, s2); } \
+ inline rettype WX_STR_DECL(name, const char *, const wchar_t *) \
+ { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
+ inline rettype WX_STR_DECL(name, const char *, const wxCharBuffer&) \
+ { return WX_STR_CALL(crtA, s1, s2.data()); } \
+ inline rettype WX_STR_DECL(name, const char *, const wxWCharBuffer&) \
+ { return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
+ \
+ inline rettype WX_STR_DECL(name, const wchar_t *, const wchar_t *) \
+ { return WX_STR_CALL(crtW, s1, s2); } \
+ inline rettype WX_STR_DECL(name, const wchar_t *, const char *) \
+ { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
+ inline rettype WX_STR_DECL(name, const wchar_t *, const wxWCharBuffer&) \
+ { return WX_STR_CALL(crtW, s1, s2.data()); } \
+ inline rettype WX_STR_DECL(name, const wchar_t *, const wxCharBuffer&) \
+ { return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
+ \
+ inline rettype WX_STR_DECL(name, const wxCharBuffer&, const char *) \
+ { return WX_STR_CALL(crtA, s1.data(), s2); } \
+ inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wchar_t *) \
+ { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
+ inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCharBuffer&)\
+ { return WX_STR_CALL(crtA, s1.data(), s2.data()); } \
+ inline int WX_STR_DECL(name, const wxCharBuffer&, const wxWCharBuffer&) \
+ { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
+ \
+ inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wchar_t *) \
+ { return WX_STR_CALL(crtW, s1.data(), s2); } \
+ inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const char *) \
+ { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
+ inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxWCharBuffer&) \
+ { return WX_STR_CALL(crtW, s1.data(), s2.data()); } \
+ inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxCharBuffer&) \
+ { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
+ \
+ inline rettype WX_STR_DECL(name, const wxString&, const char*) \
+ { return WX_STR_CALL(forString, s1, s2); } \
+ inline rettype WX_STR_DECL(name, const wxString&, const wchar_t*) \
+ { return WX_STR_CALL(forString, s1, s2); } \
+ inline rettype WX_STR_DECL(name, const wxString&, const wxCharBuffer&) \
+ { return WX_STR_CALL(forString, s1, s2); } \
+ inline rettype WX_STR_DECL(name, const wxString&, const wxWCharBuffer&) \
+ { return WX_STR_CALL(forString, s1, s2); } \
+ inline rettype WX_STR_DECL(name, const wxString&, const wxString&) \
+ { return WX_STR_CALL(forString, s1, s2); } \
+ inline rettype WX_STR_DECL(name, const wxString&, const wxCStrData&) \
+ { return WX_STR_CALL(forString, s1, s2); } \
+ \
+ inline rettype WX_STR_DECL(name, const wxCStrData&, const char*) \
+ { return WX_STR_CALL(forString, s1.AsString(), s2); } \
+ inline rettype WX_STR_DECL(name, const wxCStrData&, const wchar_t*) \
+ { return WX_STR_CALL(forString, s1.AsString(), s2); } \
+ inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCharBuffer&) \
+ { return WX_STR_CALL(forString, s1.AsString(), s2); } \
+ inline rettype WX_STR_DECL(name, const wxCStrData&, const wxWCharBuffer&) \
+ { return WX_STR_CALL(forString, s1.AsString(), s2); } \
+ inline rettype WX_STR_DECL(name, const wxCStrData&, const wxString&) \
+ { return WX_STR_CALL(forString, s1.AsString(), s2); } \
+ inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCStrData&) \
+ { return WX_STR_CALL(forString, s1.AsString(), s2); }
+
+// This defines strcmp-like function, i.e. one returning the result of
+// comparison; see WX_STR_FUNC_NO_INVERT for explanation of the arguments
+#define WX_STRCMP_FUNC(name, crtA, crtW, forString) \
+ WX_STR_FUNC_NO_INVERT(int, name, crtA, crtW, forString) \
+ \
+ inline int WX_STR_DECL(name, const char *, const wxCStrData&) \
+ { return -WX_STR_CALL(forString, s2.AsString(), s1); } \
+ inline int WX_STR_DECL(name, const char *, const wxString&) \
+ { return -WX_STR_CALL(forString, s2, s1); } \
+ \
+ inline int WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \
+ { return -WX_STR_CALL(forString, s2.AsString(), s1); } \
+ inline int WX_STR_DECL(name, const wchar_t *, const wxString&) \
+ { return -WX_STR_CALL(forString, s2, s1); } \
+ \
+ inline int WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&) \
+ { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
+ inline int WX_STR_DECL(name, const wxCharBuffer&, const wxString&) \
+ { return -WX_STR_CALL(forString, s2, s1.data()); } \
+ \
+ inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&) \
+ { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
+ inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxString&) \
+ { return -WX_STR_CALL(forString, s2, s1.data()); }
+
+
+// This defines a string function that is *not* strcmp-like, i.e. doesn't
+// return the result of comparison and so if the second argument is a string,
+// it has to be converted to char* or wchar_t*
+#define WX_STR_FUNC(rettype, name, crtA, crtW, forString) \
+ WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \
+ \
+ inline rettype WX_STR_DECL(name, const char *, const wxCStrData&) \
+ { return WX_STR_CALL(crtA, s1, s2.AsCharBuf()); } \
+ inline rettype WX_STR_DECL(name, const char *, const wxString&) \
+ { return WX_STR_CALL(crtA, s1, s2.mb_str()); } \
+ \
+ inline rettype WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \
+ { return WX_STR_CALL(crtW, s1, s2.AsWCharBuf()); } \
+ inline rettype WX_STR_DECL(name, const wchar_t *, const wxString&) \
+ { return WX_STR_CALL(crtW, s1, s2.wc_str()); } \
+ \
+ inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&) \
+ { return WX_STR_CALL(crtA, s1.data(), s2.AsCharBuf()); } \
+ inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxString&) \
+ { return WX_STR_CALL(crtA, s1.data(), s2.mb_str()); } \
+ \
+ inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&) \
+ { return WX_STR_CALL(crtW, s1.data(), s2.AsWCharBuf()); } \
+ inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxString&) \
+ { return WX_STR_CALL(crtW, s1.data(), s2.wc_str()); }
+
+template<typename T>
+inline int wxStrcmp_String(const wxString& s1, const T& s2)
+ { return s1.compare(s2); }
+WX_STRCMP_FUNC(wxStrcmp, wxCRT_StrcmpA, wxCRT_StrcmpW, wxStrcmp_String)
+
+template<typename T>
+inline int wxStricmp_String(const wxString& s1, const T& s2)
+ { return s1.CmpNoCase(s2); }
+WX_STRCMP_FUNC(wxStricmp, wxCRT_StricmpA, wxCRT_StricmpW, wxStricmp_String)
+
+
+// GCC 3.3 and other compilers have a bug that causes it to fail compilation if
+// the template's implementation uses overloaded function declared later (see
+// the wxStrcoll() call in wxStrcoll_String<T>()), so we have to
+// forward-declare the template and implement it below WX_STRCMP_FUNC. OTOH,
+// this fails to compile with VC6, so don't do it for VC. It also causes
+// problems with GCC visibility in newer GCC versions.
+#if !(defined(__VISUALC__) || wxCHECK_GCC_VERSION(3,4))
+template<typename T>
+inline int wxStrcoll_String(const wxString& s1, const T& s2);
+WX_STRCMP_FUNC(wxStrcoll, wxCRT_StrcollA, wxCRT_StrcollW, wxStrcoll_String)
+#endif // !__VISUALC__
+
+template<typename T>
+inline int wxStrcoll_String(const wxString& s1, const T& s2)
+{
+#if wxUSE_UNICODE
+ // NB: strcoll() doesn't work correctly on UTF-8 strings, so we have to use
+ // wc_str() even if wxUSE_UNICODE_UTF8; the (const wchar_t*) cast is
+ // there just as optimization to avoid going through
+ // wxStrcoll<wxWCharBuffer>:
+ return wxStrcoll((const wchar_t*)s1.wc_str(), s2);
+#else
+ return wxStrcoll((const char*)s1.mb_str(), s2);
#endif
+}
-#ifndef wxStrtok
-WXDLLIMPEXP_BASE wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
+#if defined(__VISUALC__) || wxCHECK_GCC_VERSION(3,4)
+// this is exactly the same WX_STRCMP_FUNC line as above wxStrcoll_String<>
+WX_STRCMP_FUNC(wxStrcoll, wxCRT_StrcollA, wxCRT_StrcollW, wxStrcoll_String)
#endif
-#ifdef __cplusplus
- #ifndef wxSetlocale_
- class WXDLLIMPEXP_BASE wxWCharBuffer;
- WXDLLIMPEXP_BASE wxWCharBuffer wxSetlocale_(int category, const wxChar *locale);
- WXDLLIMPEXP_BASE wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
- #else
- WXDLLIMPEXP_BASE const wxChar *wxSetlocale(int category, const wxChar *locale);
- #endif // defined(wxSetlocale_)
-#endif // __cplusplus
-
-/* stdio.h functions */
-#ifdef wxNEED_WX_STDIO_H
- #include <stdio.h>
- WXDLLIMPEXP_BASE FILE * wxFopen(const wxChar *path, const wxChar *mode);
- WXDLLIMPEXP_BASE FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
- WXDLLIMPEXP_BASE int wxRemove(const wxChar *path);
- WXDLLIMPEXP_BASE int wxRename(const wxChar *oldpath, const wxChar *newpath);
-
- /* *printf() family is handled separately */
-#endif /* wxNEED_WX_STDIO_H */
-
-/* stdlib.h functions */
-#ifndef wxAtof
-WXDLLIMPEXP_BASE double wxAtof(const wxChar *psz);
-#endif
-
-#ifdef wxNEED_WX_STDLIB_H
-WXDLLIMPEXP_BASE int wxAtoi(const wxChar *psz);
-WXDLLIMPEXP_BASE long wxAtol(const wxChar *psz);
-WXDLLIMPEXP_BASE wxChar * wxGetenv(const wxChar *name);
-WXDLLIMPEXP_BASE int wxSystem(const wxChar *psz);
+template<typename T>
+inline int wxStrspn_String(const wxString& s1, const T& s2)
+{
+ size_t pos = s1.find_first_not_of(s2);
+ return (pos == wxString::npos) ? s1.length() : pos;
+}
+WX_STR_FUNC(size_t, wxStrspn, wxCRT_StrspnA, wxCRT_StrspnW, wxStrspn_String)
+
+template<typename T>
+inline int wxStrcspn_String(const wxString& s1, const T& s2)
+{
+ size_t pos = s1.find_first_of(s2);
+ return (pos == wxString::npos) ? s1.length() : pos;
+}
+WX_STR_FUNC(size_t, wxStrcspn, wxCRT_StrcspnA, wxCRT_StrcspnW, wxStrcspn_String)
+
+#undef WX_STR_DECL
+#undef WX_STR_CALL
+#define WX_STR_DECL(name, T1, T2) name(T1 s1, T2 s2, size_t n)
+#define WX_STR_CALL(func, a1, a2) func(a1, a2, n)
+
+template<typename T>
+inline int wxStrncmp_String(const wxString& s1, const T& s2, size_t n)
+ { return s1.compare(0, n, s2, 0, n); }
+WX_STRCMP_FUNC(wxStrncmp, wxCRT_StrncmpA, wxCRT_StrncmpW, wxStrncmp_String)
+
+template<typename T>
+inline int wxStrnicmp_String(const wxString& s1, const T& s2, size_t n)
+ { return s1.substr(0, n).CmpNoCase(wxString(s2).substr(0, n)); }
+WX_STRCMP_FUNC(wxStrnicmp, wxCRT_StrnicmpA, wxCRT_StrnicmpW, wxStrnicmp_String)
+
+#undef WX_STR_DECL
+#undef WX_STR_CALL
+#undef WX_STRCMP_FUNC
+#undef WX_STR_FUNC
+#undef WX_STR_FUNC_NO_INVERT
+
+inline size_t wxStrxfrm(char *dest, const char *src, size_t n)
+ { return wxCRT_StrxfrmA(dest, src, n); }
+inline size_t wxStrxfrm(wchar_t *dest, const wchar_t *src, size_t n)
+ { return wxCRT_StrxfrmW(dest, src, n); }
+template<typename T>
+inline size_t wxStrxfrm(T *dest, const wxCharTypeBuffer<T>& src, size_t n)
+ { return wxStrxfrm(dest, src.data(), n); }
+inline size_t wxStrxfrm(char *dest, const wxString& src, size_t n)
+ { return wxCRT_StrxfrmA(dest, src.mb_str(), n); }
+inline size_t wxStrxfrm(wchar_t *dest, const wxString& src, size_t n)
+ { return wxCRT_StrxfrmW(dest, src.wc_str(), n); }
+inline size_t wxStrxfrm(char *dest, const wxCStrData& src, size_t n)
+ { return wxCRT_StrxfrmA(dest, src.AsCharBuf(), n); }
+inline size_t wxStrxfrm(wchar_t *dest, const wxCStrData& src, size_t n)
+ { return wxCRT_StrxfrmW(dest, src.AsWCharBuf(), n); }
+
+inline char *wxStrtok(char *str, const char *delim, char **saveptr)
+ { return wxCRT_StrtokA(str, delim, saveptr); }
+inline wchar_t *wxStrtok(wchar_t *str, const wchar_t *delim, wchar_t **saveptr)
+ { return wxCRT_StrtokW(str, delim, saveptr); }
+template<typename T>
+inline T *wxStrtok(T *str, const wxCharTypeBuffer<T>& delim, T **saveptr)
+ { return wxStrtok(str, delim.data(), saveptr); }
+inline char *wxStrtok(char *str, const wxCStrData& delim, char **saveptr)
+ { return wxCRT_StrtokA(str, delim.AsCharBuf(), saveptr); }
+inline wchar_t *wxStrtok(wchar_t *str, const wxCStrData& delim, wchar_t **saveptr)
+ { return wxCRT_StrtokW(str, delim.AsWCharBuf(), saveptr); }
+inline char *wxStrtok(char *str, const wxString& delim, char **saveptr)
+ { return wxCRT_StrtokA(str, delim.mb_str(), saveptr); }
+inline wchar_t *wxStrtok(wchar_t *str, const wxString& delim, wchar_t **saveptr)
+ { return wxCRT_StrtokW(str, delim.wc_str(), saveptr); }
+
+inline const char *wxStrstr(const char *haystack, const char *needle)
+ { return wxCRT_StrstrA(haystack, needle); }
+inline const wchar_t *wxStrstr(const wchar_t *haystack, const wchar_t *needle)
+ { return wxCRT_StrstrW(haystack, needle); }
+inline const char *wxStrstr(const char *haystack, const wxString& needle)
+ { return wxCRT_StrstrA(haystack, needle.mb_str()); }
+inline const wchar_t *wxStrstr(const wchar_t *haystack, const wxString& needle)
+ { return wxCRT_StrstrW(haystack, needle.wc_str()); }
+// these functions return char* pointer into the non-temporary conversion buffer
+// used by c_str()'s implicit conversion to char*, for ANSI build compatibility
+inline const char *wxStrstr(const wxString& haystack, const wxString& needle)
+ { return wxCRT_StrstrA(haystack.c_str(), needle.mb_str()); }
+inline const char *wxStrstr(const wxCStrData& haystack, const wxString& needle)
+ { return wxCRT_StrstrA(haystack, needle.mb_str()); }
+inline const char *wxStrstr(const wxCStrData& haystack, const wxCStrData& needle)
+ { return wxCRT_StrstrA(haystack, needle.AsCharBuf()); }
+// if 'needle' is char/wchar_t, then the same is probably wanted as return value
+inline const char *wxStrstr(const wxString& haystack, const char *needle)
+ { return wxCRT_StrstrA(haystack.c_str(), needle); }
+inline const char *wxStrstr(const wxCStrData& haystack, const char *needle)
+ { return wxCRT_StrstrA(haystack, needle); }
+inline const wchar_t *wxStrstr(const wxString& haystack, const wchar_t *needle)
+ { return wxCRT_StrstrW(haystack.c_str(), needle); }
+inline const wchar_t *wxStrstr(const wxCStrData& haystack, const wchar_t *needle)
+ { return wxCRT_StrstrW(haystack, needle); }
+
+inline const char *wxStrchr(const char *s, char c)
+ { return wxCRT_StrchrA(s, c); }
+inline const wchar_t *wxStrchr(const wchar_t *s, wchar_t c)
+ { return wxCRT_StrchrW(s, c); }
+inline const char *wxStrrchr(const char *s, char c)
+ { return wxCRT_StrrchrA(s, c); }
+inline const wchar_t *wxStrrchr(const wchar_t *s, wchar_t c)
+ { return wxCRT_StrrchrW(s, c); }
+inline const char *wxStrchr(const char *s, const wxUniChar& c)
+ { return wxCRT_StrchrA(s, (char)c); }
+inline const wchar_t *wxStrchr(const wchar_t *s, const wxUniChar& c)
+ { return wxCRT_StrchrW(s, (wchar_t)c); }
+inline const char *wxStrrchr(const char *s, const wxUniChar& c)
+ { return wxCRT_StrrchrA(s, (char)c); }
+inline const wchar_t *wxStrrchr(const wchar_t *s, const wxUniChar& c)
+ { return wxCRT_StrrchrW(s, (wchar_t)c); }
+inline const char *wxStrchr(const char *s, const wxUniCharRef& c)
+ { return wxCRT_StrchrA(s, (char)c); }
+inline const wchar_t *wxStrchr(const wchar_t *s, const wxUniCharRef& c)
+ { return wxCRT_StrchrW(s, (wchar_t)c); }
+inline const char *wxStrrchr(const char *s, const wxUniCharRef& c)
+ { return wxCRT_StrrchrA(s, (char)c); }
+inline const wchar_t *wxStrrchr(const wchar_t *s, const wxUniCharRef& c)
+ { return wxCRT_StrrchrW(s, (wchar_t)c); }
+template<typename T>
+inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, T c)
+ { return wxStrchr(s.data(), c); }
+template<typename T>
+inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, T c)
+ { return wxStrrchr(s.data(), c); }
+template<typename T>
+inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, const wxUniChar& c)
+ { return wxStrchr(s.data(), (T)c); }
+template<typename T>
+inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, const wxUniChar& c)
+ { return wxStrrchr(s.data(), (T)c); }
+template<typename T>
+inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, const wxUniCharRef& c)
+ { return wxStrchr(s.data(), (T)c); }
+template<typename T>
+inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, const wxUniCharRef& c)
+ { return wxStrrchr(s.data(), (T)c); }
+// these functions return char* pointer into the non-temporary conversion buffer
+// used by c_str()'s implicit conversion to char*, for ANSI build compatibility
+inline const char* wxStrchr(const wxString& s, char c)
+ { return wxCRT_StrchrA((const char*)s.c_str(), c); }
+inline const char* wxStrrchr(const wxString& s, char c)
+ { return wxCRT_StrrchrA((const char*)s.c_str(), c); }
+inline const char* wxStrchr(const wxString& s, int c)
+ { return wxCRT_StrchrA((const char*)s.c_str(), c); }
+inline const char* wxStrrchr(const wxString& s, int c)
+ { return wxCRT_StrrchrA((const char*)s.c_str(), c); }
+inline const char* wxStrchr(const wxString& s, const wxUniChar& c)
+ { return wxCRT_StrchrA((const char*)s.c_str(), (char)c); }
+inline const char* wxStrrchr(const wxString& s, const wxUniChar& c)
+ { return wxCRT_StrrchrA((const char*)s.c_str(), (char)c); }
+inline const char* wxStrchr(const wxString& s, const wxUniCharRef& c)
+ { return wxCRT_StrchrA((const char*)s.c_str(), (char)c); }
+inline const char* wxStrrchr(const wxString& s, const wxUniCharRef& c)
+ { return wxCRT_StrrchrA((const char*)s.c_str(), (char)c); }
+inline const wchar_t* wxStrchr(const wxString& s, wchar_t c)
+ { return wxCRT_StrchrW((const wchar_t*)s.c_str(), c); }
+inline const wchar_t* wxStrrchr(const wxString& s, wchar_t c)
+ { return wxCRT_StrrchrW((const wchar_t*)s.c_str(), c); }
+inline const char* wxStrchr(const wxCStrData& s, char c)
+ { return wxCRT_StrchrA(s.AsChar(), c); }
+inline const char* wxStrrchr(const wxCStrData& s, char c)
+ { return wxCRT_StrrchrA(s.AsChar(), c); }
+inline const char* wxStrchr(const wxCStrData& s, int c)
+ { return wxCRT_StrchrA(s.AsChar(), c); }
+inline const char* wxStrrchr(const wxCStrData& s, int c)
+ { return wxCRT_StrrchrA(s.AsChar(), c); }
+inline const char* wxStrchr(const wxCStrData& s, const wxUniChar& c)
+ { return wxCRT_StrchrA(s.AsChar(), (char)c); }
+inline const char* wxStrrchr(const wxCStrData& s, const wxUniChar& c)
+ { return wxCRT_StrrchrA(s.AsChar(), (char)c); }
+inline const char* wxStrchr(const wxCStrData& s, const wxUniCharRef& c)
+ { return wxCRT_StrchrA(s.AsChar(), (char)c); }
+inline const char* wxStrrchr(const wxCStrData& s, const wxUniCharRef& c)
+ { return wxCRT_StrrchrA(s.AsChar(), (char)c); }
+inline const wchar_t* wxStrchr(const wxCStrData& s, wchar_t c)
+ { return wxCRT_StrchrW(s.AsWChar(), c); }
+inline const wchar_t* wxStrrchr(const wxCStrData& s, wchar_t c)
+ { return wxCRT_StrrchrW(s.AsWChar(), c); }
+
+inline const char *wxStrpbrk(const char *s, const char *accept)
+ { return wxCRT_StrpbrkA(s, accept); }
+inline const wchar_t *wxStrpbrk(const wchar_t *s, const wchar_t *accept)
+ { return wxCRT_StrpbrkW(s, accept); }
+inline const char *wxStrpbrk(const char *s, const wxString& accept)
+ { return wxCRT_StrpbrkA(s, accept.mb_str()); }
+inline const char *wxStrpbrk(const char *s, const wxCStrData& accept)
+ { return wxCRT_StrpbrkA(s, accept.AsCharBuf()); }
+inline const wchar_t *wxStrpbrk(const wchar_t *s, const wxString& accept)
+ { return wxCRT_StrpbrkW(s, accept.wc_str()); }
+inline const wchar_t *wxStrpbrk(const wchar_t *s, const wxCStrData& accept)
+ { return wxCRT_StrpbrkW(s, accept.AsWCharBuf()); }
+inline const char *wxStrpbrk(const wxString& s, const wxString& accept)
+ { return wxCRT_StrpbrkA(s.c_str(), accept.mb_str()); }
+inline const char *wxStrpbrk(const wxString& s, const char *accept)
+ { return wxCRT_StrpbrkA(s.c_str(), accept); }
+inline const wchar_t *wxStrpbrk(const wxString& s, const wchar_t *accept)
+ { return wxCRT_StrpbrkW(s.wc_str(), accept); }
+inline const char *wxStrpbrk(const wxString& s, const wxCStrData& accept)
+ { return wxCRT_StrpbrkA(s.c_str(), accept.AsCharBuf()); }
+inline const char *wxStrpbrk(const wxCStrData& s, const wxString& accept)
+ { return wxCRT_StrpbrkA(s.AsChar(), accept.mb_str()); }
+inline const char *wxStrpbrk(const wxCStrData& s, const char *accept)
+ { return wxCRT_StrpbrkA(s.AsChar(), accept); }
+inline const wchar_t *wxStrpbrk(const wxCStrData& s, const wchar_t *accept)
+ { return wxCRT_StrpbrkW(s.AsWChar(), accept); }
+inline const char *wxStrpbrk(const wxCStrData& s, const wxCStrData& accept)
+ { return wxCRT_StrpbrkA(s.AsChar(), accept.AsCharBuf()); }
+template <typename S, typename T>
+inline const T *wxStrpbrk(const S& s, const wxCharTypeBuffer<T>& accept)
+ { return wxStrpbrk(s, accept.data()); }
+
+
+/* inlined non-const versions */
+inline char *wxStrstr(char *haystack, const char *needle)
+ { return (char *)wxStrstr((const char *)haystack, needle); }
+inline wchar_t *wxStrstr(wchar_t *haystack, const wchar_t *needle)
+ { return (wchar_t *)wxStrstr((const wchar_t *)haystack, needle); }
+inline char *wxStrstr(char *haystack, const wxString& needle)
+ { return (char *)wxStrstr((const char *)haystack, needle); }
+inline wchar_t *wxStrstr(wchar_t *haystack, const wxString& needle)
+ { return (wchar_t *)wxStrstr((const wchar_t *)haystack, needle); }
+
+inline char * wxStrchr(char *s, char c)
+ { return (char *)wxStrchr((const char *)s, c); }
+inline char * wxStrrchr(char *s, char c)
+ { return (char *)wxStrrchr((const char *)s, c); }
+inline wchar_t * wxStrchr(wchar_t *s, wchar_t c)
+ { return (wchar_t *)wxStrchr((const wchar_t *)s, c); }
+inline wchar_t * wxStrrchr(wchar_t *s, wchar_t c)
+ { return (wchar_t *)wxStrrchr((const wchar_t *)s, c); }
+
+inline char * wxStrpbrk(char *s, const char *accept)
+ { return (char *)wxStrpbrk((const char *)s, accept); }
+inline wchar_t * wxStrpbrk(wchar_t *s, const wchar_t *accept)
+ { return (wchar_t *)wxStrpbrk((const wchar_t *)s, accept); }
+inline char * wxStrpbrk(char *s, const wxString& accept)
+ { return (char *)wxStrpbrk((const char *)s, accept); }
+inline wchar_t * wxStrpbrk(wchar_t *s, const wxString& accept)
+ { return (wchar_t *)wxStrpbrk((const wchar_t *)s, accept); }
+
+
+// ----------------------------------------------------------------------------
+// stdio.h functions
+// ----------------------------------------------------------------------------
+
+// NB: using fn_str() for mode is a hack to get the same type (char*/wchar_t*)
+// as needed, the conversion itself doesn't matter, it's ASCII
+inline FILE *wxFopen(const wxString& path, const wxString& mode)
+ { return wxCRT_Fopen(path.fn_str(), mode.fn_str()); }
+inline FILE *wxFreopen(const wxString& path, const wxString& mode, FILE *stream)
+ { return wxCRT_Freopen(path.fn_str(), mode.fn_str(), stream); }
+inline int wxRemove(const wxString& path)
+ { return wxCRT_Remove(path.fn_str()); }
+inline int wxRename(const wxString& oldpath, const wxString& newpath)
+ { return wxCRT_Rename(oldpath.fn_str(), newpath.fn_str()); }
+
+extern WXDLLIMPEXP_BASE int wxPuts(const wxString& s);
+extern WXDLLIMPEXP_BASE int wxFputs(const wxString& s, FILE *stream);
+extern WXDLLIMPEXP_BASE void wxPerror(const wxString& s);
+
+extern WXDLLIMPEXP_BASE int wxFputc(const wxUniChar& c, FILE *stream);
+
+#define wxPutc(c, stream) wxFputc(c, stream)
+#define wxPutchar(c) wxFputc(c, stdout)
+#define wxFputchar(c) wxPutchar(c)
+
+// NB: We only provide ANSI version of fgets() because fgetws() interprets the
+// stream according to current locale, which is rarely what is desired.
+inline char *wxFgets(char *s, int size, FILE *stream)
+ { return wxCRT_FgetsA(s, size, stream); }
+// This version calls ANSI version and converts the string using wxConvLibc
+extern WXDLLIMPEXP_BASE wchar_t *wxFgets(wchar_t *s, int size, FILE *stream);
+
+#define wxGets(s) wxGets_is_insecure_and_dangerous_use_wxFgets_instead
+
+// NB: We only provide ANSI versions of this for the same reasons as in the
+// case of wxFgets() above
+inline int wxFgetc(FILE *stream) { return wxCRT_FgetcA(stream); }
+inline int wxUngetc(int c, FILE *stream) { return wxCRT_UngetcA(c, stream); }
+
+#define wxGetc(stream) wxFgetc(stream)
+#define wxGetchar() wxFgetc(stdin)
+#define wxFgetchar() wxGetchar()
+
+// ----------------------------------------------------------------------------
+// stdlib.h functions
+// ----------------------------------------------------------------------------
+
+#ifdef wxCRT_AtoiW
+inline int wxAtoi(const wxString& str) { return wxCRT_AtoiW(str.wc_str()); }
+#else
+inline int wxAtoi(const wxString& str) { return wxCRT_AtoiA(str.mb_str()); }
#endif
-
-/* time.h functions */
-#ifdef wxNEED_WX_TIME_H
-#if defined(__MWERKS__) && defined(macintosh)
- #include <time.h>
-#endif
- /*silent gabby compilers*/
- struct tm;
- WXDLLIMPEXP_BASE size_t wxStrftime(wxChar *s, size_t max,
- const wxChar *fmt,
- const struct tm *tm);
-#endif /* wxNEED_WX_TIME_H */
-
-#ifndef wxCtime
-#include <time.h>
-WXDLLIMPEXP_BASE wxChar *wxCtime(const time_t *timep);
+#ifdef wxCRT_AtolW
+inline long wxAtol(const wxString& str) { return wxCRT_AtolW(str.wc_str()); }
+#else
+inline long wxAtol(const wxString& str) { return wxCRT_AtolA(str.mb_str()); }
#endif
-
-/* missing functions in some WinCE versions */
-#ifdef _WIN32_WCE
-#if (_WIN32_WCE < 300)
-WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
+#ifdef wxCRT_AtofW
+inline double wxAtof(const wxString& str) { return wxCRT_AtofW(str.wc_str()); }
+#else
+inline double wxAtof(const wxString& str) { return wxCRT_AtofA(str.mb_str()); }
#endif
-#endif /* _WIN32_WCE */
-
-/* multibyte to wide char conversion functions and macros */
-
-#if wxUSE_WCHAR_T
- /* multibyte<->widechar conversion */
- WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
- WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
- #if wxUSE_UNICODE
- #define wxMB2WX wxMB2WC
- #define wxWX2MB wxWC2MB
- #define wxWC2WX wxStrncpy
- #define wxWX2WC wxStrncpy
- #else
- #define wxMB2WX wxStrncpy
- #define wxWX2MB wxStrncpy
- #define wxWC2WX wxWC2MB
- #define wxWX2WC wxMB2WC
- #endif
-#else /* !wxUSE_UNICODE */
-/* Why is this here?
-#error ha */
- /* No wxUSE_WCHAR_T: we have to do something (JACS) */
- #define wxMB2WC wxStrncpy
- #define wxWC2MB wxStrncpy
- #define wxMB2WX wxStrncpy
- #define wxWX2MB wxStrncpy
- #define wxWC2WX wxWC2MB
- #define wxWX2WC wxMB2WC
+inline double wxStrtod(const char *nptr, char **endptr)
+ { return wxCRT_StrtodA(nptr, endptr); }
+inline double wxStrtod(const wchar_t *nptr, wchar_t **endptr)
+ { return wxCRT_StrtodW(nptr, endptr); }
+template<typename T>
+inline double wxStrtod(const wxCharTypeBuffer<T>& nptr, T **endptr)
+ { return wxStrtod(nptr.data(), endptr); }
+
+// We implement wxStrto*() like this so that the code compiles when NULL is
+// passed in - - if we had just char** and wchar_t** overloads for 'endptr', it
+// would be ambiguous. The solution is to use a template so that endptr can be
+// any type: when NULL constant is used, the type will be int and we can handle
+// that case specially. Otherwise, we infer the type that 'nptr' should be
+// converted to from the type of 'endptr'. We need wxStrtoxCharType<T> template
+// to make the code compile even for T=int (that's the case when it's not going
+// to be ever used, but it still has to compile).
+template<typename T> struct wxStrtoxCharType {};
+template<> struct wxStrtoxCharType<char**>
+{
+ typedef const char* Type;
+ static char** AsPointer(char **p) { return p; }
+};
+template<> struct wxStrtoxCharType<wchar_t**>
+{
+ typedef const wchar_t* Type;
+ static wchar_t** AsPointer(wchar_t **p) { return p; }
+};
+template<> struct wxStrtoxCharType<int>
+{
+ typedef const char* Type; /* this one is never used */
+ static char** AsPointer(int WXUNUSED_UNLESS_DEBUG(p))
+ {
+ wxASSERT_MSG( p == 0, "passing non-NULL int is invalid" );
+ return NULL;
+ }
+};
+
+template<typename T>
+inline double wxStrtod(const wxString& nptr, T endptr)
+{
+ if ( endptr == 0 )
+ {
+ // when we don't care about endptr, use the string representation that
+ // doesn't require any conversion (it doesn't matter for this function
+ // even if its UTF-8):
+ return wxStrtod(nptr.wx_str(), (wxStringCharType**)NULL);
+ }
+ else
+ {
+ // note that it is important to use c_str() here and not mb_str() or
+ // wc_str(), because we store the pointer into (possibly converted)
+ // buffer in endptr and so it must be valid even when wxStrtod() returns
+ typedef typename wxStrtoxCharType<T>::Type CharType;
+ return wxStrtod((CharType)nptr.c_str(),
+ wxStrtoxCharType<T>::AsPointer(endptr));
+ }
+}
+template<typename T>
+inline double wxStrtod(const wxCStrData& nptr, T endptr)
+ { return wxStrtod(nptr.AsString(), endptr); }
+
+
+#define WX_STRTOX_FUNC(rettype, name, implA, implW) \
+ /* see wxStrtod() above for explanation of this code: */ \
+ inline rettype name(const char *nptr, char **endptr, int base) \
+ { return implA(nptr, endptr, base); } \
+ inline rettype name(const wchar_t *nptr, wchar_t **endptr, int base) \
+ { return implW(nptr, endptr, base); } \
+ template<typename T> \
+ inline rettype name(const wxCharTypeBuffer<T>& nptr, T **endptr, int base)\
+ { return name(nptr.data(), endptr); } \
+ template<typename T> \
+ inline rettype name(const wxString& nptr, T endptr, int base) \
+ { \
+ if ( endptr == 0 ) \
+ return name(nptr.wx_str(), (wxStringCharType**)NULL, base); \
+ else \
+ { \
+ typedef typename wxStrtoxCharType<T>::Type CharType; \
+ return name((CharType)nptr.c_str(), \
+ wxStrtoxCharType<T>::AsPointer(endptr), \
+ base); \
+ } \
+ } \
+ template<typename T> \
+ inline rettype name(const wxCStrData& nptr, T endptr, int base) \
+ { return name(nptr.AsString(), endptr, base); }
+
+WX_STRTOX_FUNC(long, wxStrtol, wxCRT_StrtolA, wxCRT_StrtolW)
+WX_STRTOX_FUNC(unsigned long, wxStrtoul, wxCRT_StrtoulA, wxCRT_StrtoulW)
+#ifdef wxLongLong_t
+WX_STRTOX_FUNC(wxLongLong_t, wxStrtoll, wxCRT_StrtollA, wxCRT_StrtollW)
+WX_STRTOX_FUNC(wxULongLong_t, wxStrtoull, wxCRT_StrtoullA, wxCRT_StrtoullW)
+#endif // wxLongLong_t
+
+#undef WX_STRTOX_FUNC
+
+
+// mingw32 doesn't provide _tsystem() even though it provides other stdlib.h
+// functions in their wide versions
+#ifdef wxCRT_SystemW
+inline int wxSystem(const wxString& str) { return wxCRT_SystemW(str.wc_str()); }
+#else
+inline int wxSystem(const wxString& str) { return wxCRT_SystemA(str.mb_str()); }
#endif
-/*
- RN: The following are not normal versions of memcpy et al., rather
- these are either char or widechar versions depending on
- if unicode is used or not.
-*/
-
-#ifdef __cplusplus
-
- //
- // RN: We could do the usual tricky compiler detection here,
- // and use their variant (such as wmemchr, etc.). The problem
- // is that these functions are quite rare, even though they are
- // part of the current POSIX standard. In addition, most compilers
- // (including even MSC) inline them just like we do right in their
- // headers.
- //
- #if wxUSE_UNICODE
- #include <string.h> //for mem funcs
-
- //implement our own wmem variants
- inline wxChar* wxTmemchr(const wxChar* s, wxChar c, size_t l)
- {
- for(;l && *s != c;--l, ++s) {}
-
- if(l)
- return (wxChar*)s;
- return NULL;
- }
-
- inline int wxTmemcmp(const wxChar* sz1, const wxChar* sz2, size_t len)
- {
- for(; *sz1 == *sz2 && len; --len, ++sz1, ++sz2) {}
-
- if(len)
- return *sz1 < *sz2 ? -1 : *sz1 > *sz2;
- else
- return 0;
- }
-
- inline wxChar* wxTmemcpy(wxChar* szOut, const wxChar* szIn, size_t len)
- {
- return (wxChar*) memcpy(szOut, szIn, len * sizeof(wxChar));
- }
-
- inline wxChar* wxTmemmove(wxChar* szOut, const wxChar* szIn, size_t len)
- {
- return (wxChar*) memmove(szOut, szIn, len * sizeof(wxChar));
- }
-
- inline wxChar* wxTmemset(wxChar* szOut, const wxChar cIn, size_t len)
- {
- wxChar* szRet = szOut;
-
- while (len--)
- *szOut++ = cIn;
-
- return szRet;
- }
-
- #else /* !wxUSE_UNICODE */
- # define wxTmemchr memchr
- # define wxTmemcmp memcmp
- # define wxTmemcpy memcpy
- # define wxTmemmove memmove
- # define wxTmemset memset
- #endif /* wxUSE_UNICODE/!wxUSE_UNICODE */
-
-#endif /*__cplusplus*/
+inline char* wxGetenv(const char *name) { return wxCRT_GetenvA(name); }
+inline wchar_t* wxGetenv(const wchar_t *name) { return wxCRT_GetenvW(name); }
+inline char* wxGetenv(const wxString& name) { return wxCRT_GetenvA(name.mb_str()); }
+inline char* wxGetenv(const wxCStrData& name) { return wxCRT_GetenvA(name.AsCharBuf()); }
+inline char* wxGetenv(const wxCharBuffer& name) { return wxCRT_GetenvA(name.data()); }
+inline wchar_t* wxGetenv(const wxWCharBuffer& name) { return wxCRT_GetenvW(name.data()); }
+
+
+// ----------------------------------------------------------------------------
+// time.h functions
+// ----------------------------------------------------------------------------
+
+inline size_t wxStrftime(char *s, size_t max,
+ const wxString& format, const struct tm *tm)
+ { return wxCRT_StrftimeA(s, max, format.mb_str(), tm); }
+
+inline size_t wxStrftime(wchar_t *s, size_t max,
+ const wxString& format, const struct tm *tm)
+ { return wxCRT_StrftimeW(s, max, format.wc_str(), tm); }
+
+// NB: we can't provide both char* and wchar_t* versions for obvious reasons
+// and returning wxString wouldn't work either (it would be immediately
+// destroyed and if assigned to char*/wchar_t*, the pointer would be
+// invalid), so we only keep ASCII version, because the returned value
+// is always ASCII anyway
+#define wxAsctime asctime
+#define wxCtime ctime
+
+
+// ----------------------------------------------------------------------------
+// ctype.h functions
+// ----------------------------------------------------------------------------
+
+// FIXME-UTF8: we'd be better off implementing these ourselves, as the CRT
+// version is locale-dependent
+// FIXME-UTF8: these don't work when EOF is passed in because of wxUniChar,
+// is this OK or not?
+
+inline bool wxIsalnum(const wxUniChar& c) { return wxCRT_IsalnumW(c) != 0; }
+inline bool wxIsalpha(const wxUniChar& c) { return wxCRT_IsalphaW(c) != 0; }
+inline bool wxIscntrl(const wxUniChar& c) { return wxCRT_IscntrlW(c) != 0; }
+inline bool wxIsdigit(const wxUniChar& c) { return wxCRT_IsdigitW(c) != 0; }
+inline bool wxIsgraph(const wxUniChar& c) { return wxCRT_IsgraphW(c) != 0; }
+inline bool wxIslower(const wxUniChar& c) { return wxCRT_IslowerW(c) != 0; }
+inline bool wxIsprint(const wxUniChar& c) { return wxCRT_IsprintW(c) != 0; }
+inline bool wxIspunct(const wxUniChar& c) { return wxCRT_IspunctW(c) != 0; }
+inline bool wxIsspace(const wxUniChar& c) { return wxCRT_IsspaceW(c) != 0; }
+inline bool wxIsupper(const wxUniChar& c) { return wxCRT_IsupperW(c) != 0; }
+inline bool wxIsxdigit(const wxUniChar& c) { return wxCRT_IsxdigitW(c) != 0; }
+
+inline wxUniChar wxTolower(const wxUniChar& c) { return wxCRT_TolowerW(c); }
+inline wxUniChar wxToupper(const wxUniChar& c) { return wxCRT_ToupperW(c); }
+
+#if WXWIN_COMPATIBILITY_2_8
+// we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
+// initial versions of this header -- now it is too late to remove it so
+// although we fixed the function/macro name above, still provide the
+// backwards-compatible synonym.
+wxDEPRECATED( inline int wxIsctrl(const wxUniChar& c) );
+inline int wxIsctrl(const wxUniChar& c) { return wxIscntrl(c); }
+#endif // WXWIN_COMPATIBILITY_2_8
#endif /* _WX_WXCRT_H_ */