wx/wx.h \
wx/wxchar.h \
wx/wxcrt.h \
+ wx/wxcrtbase.h \
wx/wxcrtvararg.h \
wx/wxprec.h \
wx/xti.h \
wx/wx.h \
wx/wxchar.h \
wx/wxcrt.h \
+ wx/wxcrtbase.h \
wx/wxcrtvararg.h \
wx/wxprec.h \
wx/xti.h \
wx/wx.h
wx/wxchar.h
wx/wxcrt.h
+ wx/wxcrtbase.h
wx/wxcrtvararg.h
wx/wxprec.h
wx/xti.h
# End Source File
# Begin Source File
+SOURCE=..\..\include\wx\wxcrtbase.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\wx\wxcrtvararg.h
# End Source File
# Begin Source File
to const wxChar*:
wxLogError(_("error: %s"), !err.empty() ? (const wxChar*)err.c_str() : "")
+- wxCtime() and wxAsctime() return char*; this is incompatible with Unicode
+ build in wxWidgets 2.8 that returned wchar_t*.
+
- DigitalMars compiler has a bug that prevents it from using
wxUniChar::operator bool in conditions and it erroneously reports type
conversion ambiguity in expressions such as this:
#define _WX_BUFFER_H
#include "wx/chartype.h"
-#include "wx/wxcrt.h"
+#include "wx/wxcrtbase.h"
#include <stdlib.h> // malloc() and free()
class WXDLLIMPEXP_BASE wxCStrData;
-inline char *wxStrDup(const char *s) { return wxStrdupA(s); }
-#if wxUSE_WCHAR_T
- inline wchar_t *wxStrDup(const wchar_t *ws) { return wxStrdupW(ws); }
-#endif
-
// ----------------------------------------------------------------------------
// Special classes for (wide) character strings: they use malloc/free instead
// of new/delete
typedef T CharType;
wxCharTypeBuffer(const CharType *str = NULL)
- : m_str(str ? wxStrDup(str) : NULL),
+ : m_str(str ? wxStrdup(str) : NULL),
m_owned(true)
{
}
{
if ( m_owned )
free(m_str);
- m_str = str ? wxStrDup(str) : NULL;
+ m_str = str ? wxStrdup(str) : NULL;
m_owned = true;
return *this;
}
// constants
// ----------------------------------------------------------------------------
+#if defined(__VISUALC__) || defined(__DIGITALMARS__)
+ typedef int mode_t;
+#endif
+
#ifdef __WXWINCE__
typedef long off_t;
#else
#if defined( __WXWINCE__)
typedef __int64 wxFileOffset;
#define wxFileOffsetFmtSpec _("I64")
- WXDLLIMPEXP_BASE int wxOpen(const wxChar *filename, int oflag, int WXUNUSED(pmode));
- WXDLLIMPEXP_BASE int wxAccess(const wxChar *name, int WXUNUSED(how));
+ WXDLLIMPEXP_BASE int wxCRT_Open(const wxChar *filename, int oflag, int WXUNUSED(pmode));
+ WXDLLIMPEXP_BASE int wxCRT_Access(const wxChar *name, int WXUNUSED(how));
WXDLLIMPEXP_BASE int wxClose(int fd);
WXDLLIMPEXP_BASE int wxFsync(int WXUNUSED(fd));
WXDLLIMPEXP_BASE int wxRead(int fd, void *buf, unsigned int count);
WXDLLIMPEXP_BASE wxFileOffset wxTell(int fd);
// always Unicode under WinCE
- #define wxMkDir _wmkdir
- #define wxRmDir _wrmdir
- #define wxStat _wstat
+ #define wxCRT_MkDir _wmkdir
+ #define wxCRT_RmDir _wrmdir
+ #define wxCRT_Stat _wstat
#define wxStructStat struct _stat
#elif defined(__WXMSW__) && !defined(__WXPALMOS__) && \
( \
wxPOSIX_STRUCT(stati64) *buffer);
#endif // Windows compilers with MSLU support
- #define wxOpen wxMSLU__wopen
+ #define wxCRT_Open wxMSLU__wopen
- #define wxAccess wxMSLU__waccess
- #define wxMkDir wxMSLU__wmkdir
- #define wxRmDir wxMSLU__wrmdir
+ #define wxCRT_Access wxMSLU__waccess
+ #define wxCRT_MkDir wxMSLU__wmkdir
+ #define wxCRT_RmDir wxMSLU__wrmdir
#ifdef wxHAS_HUGE_FILES
- #define wxStat wxMSLU__wstati64
+ #define wxCRT_Stat wxMSLU__wstati64
#else
- #define wxStat wxMSLU__wstat
+ #define wxCRT_Stat wxMSLU__wstat
#endif
#else // !wxUSE_UNICODE_MSLU
#ifdef __BORLANDC__
#if __BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551
- WXDLLIMPEXP_BASE int wxOpen(const wxChar *pathname,
- int flags, mode_t mode);
+ WXDLLIMPEXP_BASE int wxCRT_Open(const wxChar *pathname,
+ int flags, mode_t mode);
#else
- #define wxOpen _wopen
+ #define wxCRT_Open _wopen
#endif
- #define wxAccess _waccess
- #define wxMkDir _wmkdir
- #define wxRmDir _wrmdir
+ #define wxCRT_Access _waccess
+ #define wxCRT_MkDir _wmkdir
+ #define wxCRT_RmDir _wrmdir
#ifdef wxHAS_HUGE_FILES
- #define wxStat _wstati64
+ #define wxCRT_Stat _wstati64
#else
- #define wxStat _wstat
+ #define wxCRT_Stat _wstat
#endif
#else
- #define wxOpen _wopen
- #define wxAccess _waccess
- #define wxMkDir _wmkdir
- #define wxRmDir _wrmdir
+ #define wxCRT_Open _wopen
+ #define wxCRT_Access _waccess
+ #define wxCRT_MkDir _wmkdir
+ #define wxCRT_RmDir _wrmdir
#ifdef wxHAS_HUGE_FILES
- #define wxStat _wstati64
+ #define wxCRT_Stat _wstati64
#else
- #define wxStat _wstat
+ #define wxCRT_Stat _wstat
#endif
#endif
#endif // wxUSE_UNICODE_MSLU/!wxUSE_UNICODE_MSLU
#else // !wxUSE_UNICODE
- #define wxOpen wxPOSIX_IDENT(open)
- #define wxAccess wxPOSIX_IDENT(access)
- #define wxMkDir wxPOSIX_IDENT(mkdir)
- #define wxRmDir wxPOSIX_IDENT(rmdir)
+ #define wxCRT_Open wxPOSIX_IDENT(open)
+ #define wxCRT_Access wxPOSIX_IDENT(access)
+ #define wxCRT_MkDir wxPOSIX_IDENT(mkdir)
+ #define wxCRT_RmDir wxPOSIX_IDENT(rmdir)
#ifdef wxHAS_HUGE_FILES
- #define wxStat wxPOSIX_IDENT(stati64)
+ #define wxCRT_Stat wxPOSIX_IDENT(stati64)
#else
- #define wxStat wxPOSIX_IDENT(stat)
+ #define wxCRT_Stat wxPOSIX_IDENT(stat)
#endif
#endif // wxUSE_UNICODE/!wxUSE_UNICODE
#define wxFsync fsync
#define wxEof eof
- #define wxMkDir mkdir
- #define wxRmDir rmdir
+ #define wxCRT_MkDir mkdir
+ #define wxCRT_RmDir rmdir
#define wxTell(fd) lseek(fd, 0, SEEK_CUR)
#define wxStructStat struct stat
- #if wxUSE_UNICODE
- #define wxNEED_WX_UNISTD_H
- #if defined(__DMC__)
- typedef unsigned long mode_t;
- #endif
- WXDLLIMPEXP_BASE int wxStat( const wxChar *file_name, wxStructStat *buf );
- WXDLLIMPEXP_BASE int wxLstat( const wxChar *file_name, wxStructStat *buf );
- WXDLLIMPEXP_BASE int wxAccess( const wxChar *pathname, int mode );
- WXDLLIMPEXP_BASE int wxOpen( const wxChar *pathname, int flags, mode_t mode );
- #else
- #define wxOpen open
- #define wxStat stat
- #define wxLstat lstat
- #define wxAccess access
- #endif
+ #define wxCRT_Open open
+ #define wxCRT_Stat stat
+ #define wxCRT_Lstat lstat
+ #define wxCRT_Access access
#define wxHAS_NATIVE_LSTAT
#endif // platforms
+// if the platform doesn't have symlinks, define wxCRT_Lstat to be the same as
+// wxCRT_Stat to avoid #ifdefs in the code using it
+#ifndef wxHAS_NATIVE_LSTAT
+ #define wxCRT_Lstat wxCRT_Stat
+#endif
+
+inline int wxStat(const wxString& path, wxStructStat *buf)
+ { return wxCRT_Stat(path.fn_str(), buf); }
+inline int wxLstat(const wxString& path, wxStructStat *buf)
+ { return wxCRT_Lstat(path.fn_str(), buf); }
+inline int wxAccess(const wxString& path, mode_t mode)
+ { return wxCRT_Access(path.fn_str(), mode); }
+inline int wxOpen(const wxString& path, int flags, mode_t mode)
+ { return wxCRT_Open(path.fn_str(), flags, mode); }
+inline int wxRmDir(const wxString& path)
+ { return wxCRT_RmDir(path.fn_str()); }
+#ifdef __WINDOWS__
+inline int wxMkDir(const wxString& path, mode_t WXUNUSED(mode) = 0)
+ { return wxCRT_MkDir(path.fn_str()); }
+#else
+inline int wxMkDir(const wxString& path, mode_t mode)
+ { return wxCRT_MkDir(path.fn_str(), mode); }
+#endif
+
#ifdef O_BINARY
#define wxO_BINARY O_BINARY
#else
#define wxO_BINARY 0
#endif
-// if the platform doesn't have symlinks, define wxLstat to be the same as
-// wxStat to avoid #ifdefs in the code using it
-#ifndef wxHAS_NATIVE_LSTAT
- #define wxLstat wxStat
-#endif
-
#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
//
// VisualAge C++ V4.0 cannot have any external linkage const decs
// Get directory
WXDLLIMPEXP_BASE wxString wxPathOnly(const wxString& path);
-// wxString version
-WXDLLIMPEXP_BASE wxString wxRealPath(const wxString& path);
-
-WXDLLIMPEXP_BASE void wxDos2UnixFilename(wxChar *s);
+WXDLLIMPEXP_BASE void wxDos2UnixFilename(char *s);
+WXDLLIMPEXP_BASE void wxDos2UnixFilename(wchar_t *s);
-WXDLLIMPEXP_BASE void wxUnix2DosFilename(wxChar *s);
+WXDLLIMPEXP_BASE void wxUnix2DosFilename(char *s);
+WXDLLIMPEXP_BASE void wxUnix2DosFilename(wchar_t *s);
// Strip the extension, in situ
-WXDLLIMPEXP_BASE void wxStripExtension(wxChar *buffer);
+WXDLLIMPEXP_BASE void wxStripExtension(char *buffer);
+WXDLLIMPEXP_BASE void wxStripExtension(wchar_t *buffer);
WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer);
// Get a temporary filename
WXDLLIMPEXP_BASE bool wxGetTempFileName(const wxString& prefix, wxString& buf);
// Expand file name (~/ and ${OPENWINHOME}/ stuff)
-WXDLLIMPEXP_BASE wxChar* wxExpandPath(wxChar *dest, const wxChar *path);
-WXDLLIMPEXP_BASE bool wxExpandPath(wxString& dest, const wxChar *path);
+WXDLLIMPEXP_BASE char* wxExpandPath(char *dest, const wxString& path);
+WXDLLIMPEXP_BASE wchar_t* wxExpandPath(wchar_t *dest, const wxString& path);
+// FIXME-UTF8: add some wxString version
// Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
// and make (if under the home tree) relative to home
const wxString& user = wxEmptyString);
// Destructive removal of /./ and /../ stuff
-WXDLLIMPEXP_BASE wxChar* wxRealPath(wxChar *path);
+// FIXME-UTF8: deprecate these two (and similar)
+WXDLLIMPEXP_BASE char* wxRealPath(char *path);
+WXDLLIMPEXP_BASE wchar_t* wxRealPath(wchar_t *path);
+WXDLLIMPEXP_BASE wxString wxRealPath(const wxString& path);
// Allocate a copy of the full absolute path
WXDLLIMPEXP_BASE wxChar* wxCopyAbsolutePath(const wxString& path);
// Flags are reserved for future use.
#define wxFILE 1
#define wxDIR 2
-WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxChar *spec, int flags = wxFILE);
+WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
WXDLLIMPEXP_BASE wxString wxFindNextFile();
// Does the pattern contain wildcards?
}
// does the string ends with path separator?
-WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxChar *pszFileName);
+WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxString& filename);
// split the full path into path (including drive for DOS), name and extension
// (understands both '/' and '\\')
-WXDLLIMPEXP_BASE void wxSplitPath(const wxChar *pszFileName,
+WXDLLIMPEXP_BASE void wxSplitPath(const wxString& fileName,
wxString *pstrPath,
wxString *pstrName,
wxString *pstrExt);
// find a file in a list of directories, returns false if not found
-WXDLLIMPEXP_BASE bool wxFindFileInPath(wxString *pStr, const wxChar *pszPath, const wxChar *pszFile);
+WXDLLIMPEXP_BASE bool wxFindFileInPath(wxString *pStr, const wxString& szPath, const wxString& szFile);
// Get the OS directory if appropriate (such as the Windows directory).
// On non-Windows platform, probably just return the empty string.
m_strShort; // short name for the locale
int m_language; // this locale wxLanguage value
- const wxChar *m_pszOldLocale; // previous locale from setlocale()
+ const char *m_pszOldLocale; // previous locale from setlocale()
wxLocale *m_pOldLocale; // previous wxLocale
wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs
// ----------------------------------------------------------------------------
// filenames are multibyte on Unix and widechar on Windows
-#if defined(__UNIX__) || defined(__WXMAC__)
- #define wxMBFILES 1
-#else
- #define wxMBFILES 0
-#endif
-
#if wxMBFILES && wxUSE_UNICODE
#define wxFNCONV(name) wxConvFileName->cWX2MB(name)
#define wxFNSTRINGCAST wxMBSTRINGCAST
#include <StringMgr.h>
#endif
-#include "wx/wxcrt.h" // for wxChar, wxStrlen() etc.
+#include "wx/wxcrtbase.h" // for wxChar, wxStrlen() etc.
#include "wx/strvararg.h"
#include "wx/buffer.h" // for wxCharBuffer
#include "wx/strconv.h" // for wxConvertXXX() macros and wxMBConv classes
bool IsSameAs(const wxWCharBuffer& str, bool compareWithCase = true) const
{ return IsSameAs(str.data(), compareWithCase); }
// comparison with a single character: returns true if equal
- bool IsSameAs(wxUniChar c, bool compareWithCase = true) const
- {
- return (length() == 1) && (compareWithCase ? GetChar(0u) == c
- : wxToupper(GetChar(0u)) == wxToupper(c));
- }
+ bool IsSameAs(wxUniChar c, bool compareWithCase = true) const;
// FIXME-UTF8: remove these overloads
bool IsSameAs(wxUniCharRef c, bool compareWithCase = true) const
{ return IsSameAs(wxUniChar(c), compareWithCase); }
#include "wx/defs.h" // everybody should include this
#include "wx/chartype.h" // for wxChar
-#include "wx/wxcrt.h" // for wxStrlen() etc.
+#include "wx/wxcrtbase.h" // for wxStrlen() etc.
#include <stdlib.h>
{ ConcatSelf(str.length(), str.c_str()); return *this; }
// append first n (or all if n == npos) characters of sz
wxStringImpl& append(const wxStringCharType *sz)
- { ConcatSelf(Strsize(sz), sz); return *this; }
+ { ConcatSelf(wxStrlen(sz), sz); return *this; }
wxStringImpl& append(const wxStringCharType *sz, size_t n)
{ ConcatSelf(n, sz); return *this; }
// append n copies of ch
{ clear(); return append(str, pos, n); }
// same as `= first n (or all if n == npos) characters of sz'
wxStringImpl& assign(const wxStringCharType *sz)
- { clear(); return append(sz, Strsize(sz)); }
+ { clear(); return append(sz, wxStrlen(sz)); }
wxStringImpl& assign(const wxStringCharType *sz, size_t n)
{ clear(); return append(sz, n); }
// same as `= n copies of ch'
void DoUngetWriteBuf();
void DoUngetWriteBuf(size_t nLen);
-private:
-#if wxUSE_UNICODE_UTF8
- static size_t Strsize(const wxStringCharType *s) { return strlen(s); }
-#else
- static size_t Strsize(const wxStringCharType *s) { return wxStrlen(s); }
-#endif
-
friend class WXDLLIMPEXP_BASE wxString;
};
-/*
- * 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"
+#include "wx/wxcrtbase.h"
+#include "wx/string.h"
-#include <stdio.h> /* we use FILE below */
+// ============================================================================
+// misc functions
+// ============================================================================
-#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
- #define wxLocaleIsUtf8 true
- #else
- extern WXDLLIMPEXP_BASE bool wxLocaleIsUtf8;
- #endif
- // function used to update the flag:
- extern WXDLLIMPEXP_BASE void wxUpdateLocaleIsUtf8();
- #else // !wxUSE_UNICODE_UTF8
- inline 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
-
- #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
-
- /* 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
-
- #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) */
-
-/* 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
- #else
- WXDLLIMPEXP_BASE size_t wxWcslen(const wchar_t *s);
- #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; }
+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(); }
-/* safe version of strlen() (returns 0 if passed NULL pointer) */
-inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
-#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
- */
-#if wxUSE_UNICODE
- #define wxStrdup wxStrdupW
-#else
- #define wxStrdup wxStrdupA
-#endif
-#ifdef __cplusplus
+// FIXME-UTF8: get rid of this, it's ANSI only anyway
WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
-#endif
-
-#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
-
-#define wxHAS_STRTOLL
-/*
- 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
-
-/*
- 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 */
-
-#ifdef wxNEED_ISASCII
- inline int isascii(int c) { return (unsigned)c < 0x80; }
-#endif
-
-#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 */
-
-#ifdef wxNEED_STRDUP
- WXDLLIMPEXP_BASE char *strdup(const char* s);
-#endif
-
-/* 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
- }
-# 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
-
-#ifndef wxStricmp
-WXDLLIMPEXP_BASE int wxStricmp(const wxChar *psz1, const wxChar *psz2);
-#endif
-
-#ifndef wxStrnicmp
-WXDLLIMPEXP_BASE int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
-#endif
-
-#ifndef wxStrtok
-WXDLLIMPEXP_BASE wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
-#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 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
-
-/*
- mingw32 doesn't provide _tsystem() even though it does provide all the other
- stdlib.h functions wrappers so check for it separately:
- */
-#if defined(__MINGW32__) && wxUSE_UNICODE && !defined(_tsystem)
- #define wxNEED_WXSYSTEM
-#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);
-#define wxNEED_WXSYSTEM
-#endif
-
-#ifdef wxNEED_WXSYSTEM
-WXDLLIMPEXP_BASE int wxSystem(const wxChar *psz);
-#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);
-#endif
-
-
-/* missing functions in some WinCE versions */
-#ifdef _WIN32_WCE
-#if (_WIN32_WCE < 300)
-WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
-#endif
-#endif /* _WIN32_WCE */
/* multibyte to wide char conversion functions and macros */
#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 wxWX2WC wxMB2WC
#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*/
+
+// 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;
+ }
+
+ // 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); }
+
+#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
+// ----------------------------------------------------------------------------
+
+/* 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)
+
+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:
+ return wxStrcoll(s1.wc_str(), s2);
+#else
+ return wxStrcoll(s1.mb_str(), s2);
+#endif
+}
+WX_STRCMP_FUNC(wxStrcoll, wxCRT_StrcollA, wxCRT_StrcollW, wxStrcoll_String)
+
+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); }
+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); }
+// 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 wxCStrData& s, char c)
+ { return wxCRT_StrchrA((const char*)s.AsCharBuf(), c); }
+inline const char* wxStrrchr(const wxCStrData& s, char c)
+ { return wxCRT_StrrchrA((const char*)s.AsCharBuf(), 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 wxCharBuffer& accept)
+ { return wxCRT_StrpbrkA(s, accept.data()); }
+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 wxWCharBuffer& accept)
+ { return wxCRT_StrpbrkW(s, accept.data()); }
+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 wxCStrData& s, const wxString& accept)
+ { return wxCRT_StrpbrkA(s.AsChar(), accept.mb_str()); }
+
+
+/* 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()); }
+
+// NB: we don't provide wxString/wxCStrData versions of wxTmpnam, because 's'
+// is writable
+inline char *wxTmpnam(char *s)
+ { return wxCRT_TmpnamA(s); }
+inline wchar_t *wxTmpnam(wchar_t *s)
+ { return wxCRT_TmpnamW(s); }
+
+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
+
+#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
+
+#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
+
+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; };
+template<> struct wxStrtoxCharType<wchar_t**>
+ { typedef const wchar_t* Type; };
+template<> struct wxStrtoxCharType<int>
+ { typedef const char* Type; /* this one is never used */ };
+
+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
+ return wxStrtod((typename wxStrtoxCharType<T>::Type)nptr.c_str(), 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 \
+ return name((typename wxStrtoxCharType<T>::Type)nptr.c_str(), \
+ 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)
+WX_STRTOX_FUNC(wxLongLong_t, wxStrtoll, wxCRT_StrtollA, wxCRT_StrtollW)
+WX_STRTOX_FUNC(wxULongLong_t, wxStrtoull, wxCRT_StrtoullA, wxCRT_StrtoullW)
+
+#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
+
+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: should we return bool from these instead of int?
+// FIXME-UTF8: these don't work when EOF is passed in because of wxUniChar,
+// is this OK or not?
+
+inline int wxIsalnum(const wxUniChar& c) { return wxCRT_IsalnumW(c); }
+inline int wxIsalpha(const wxUniChar& c) { return wxCRT_IsalphaW(c); }
+inline int wxIscntrl(const wxUniChar& c) { return wxCRT_IscntrlW(c); }
+inline int wxIsdigit(const wxUniChar& c) { return wxCRT_IsdigitW(c); }
+inline int wxIsgraph(const wxUniChar& c) { return wxCRT_IsgraphW(c); }
+inline int wxIslower(const wxUniChar& c) { return wxCRT_IslowerW(c); }
+inline int wxIsprint(const wxUniChar& c) { return wxCRT_IsprintW(c); }
+inline int wxIspunct(const wxUniChar& c) { return wxCRT_IspunctW(c); }
+inline int wxIsspace(const wxUniChar& c) { return wxCRT_IsspaceW(c); }
+inline int wxIsupper(const wxUniChar& c) { return wxCRT_IsupperW(c); }
+inline int wxIsxdigit(const wxUniChar& c) { return wxCRT_IsxdigitW(c); }
+
+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_ */
/* Required for wxPrintf() etc */
#include <stdarg.h>
-#ifdef wxHAVE_TCHAR_SUPPORT
- #define wxCRT_Fprintf _ftprintf
- #define wxCRT_Printf _tprintf
- #define wxCRT_Vfprintf _vftprintf
- #define wxCRT_Vprintf _vtprintf
- #define wxCRT_Vsprintf _vstprintf
-#else /* !TCHAR-aware compilers */
-
- #if !wxUSE_UNICODE /* ASCII */
- #define wxCRT_Fprintf fprintf
- #define wxCRT_Printf printf
- #define wxCRT_Vfprintf vfprintf
- #define wxCRT_Vprintf vprintf
- #define wxCRT_Vsprintf vsprintf
- #endif /* ASCII */
-#endif /* TCHAR-aware compilers/the others */
-
-
/* printf() family saga */
/*
#else
extern
#endif
- WXDLLIMPEXP_BASE int snprintf(char *str, size_t size, const char *format, ...);
+ int snprintf(char *str, size_t size, const char *format, ...);
#endif /* !HAVE_SNPRINTF_DECL */
/* Wrapper for vsnprintf if it's 3rd parameter is non-const. Note: the
our wxVsnprintf() implementation.
*/
#if defined(HAVE_UNIX98_PRINTF)
- #if wxUSE_UNICODE
- #ifdef HAVE_VSWPRINTF
- #define wxVsnprintf_ vswprintf
- #endif
- #else /* ASCII */
- #ifdef HAVE_BROKEN_VSNPRINTF_DECL
- #define wxVsnprintf_ wx_fixed_vsnprintf
- #else
- #define wxVsnprintf_ vsnprintf
- #endif
+ #ifdef HAVE_VSWPRINTF
+ #define wxCRT_VsnprintfW_ vswprintf
+ #endif
+ #ifdef HAVE_BROKEN_VSNPRINTF_DECL
+ #define wxCRT_VsnprintfA wx_fixed_vsnprintf
+ #else
+ #define wxCRT_VsnprintfA vsnprintf
#endif
#else /* !HAVE_UNIX98_PRINTF */
/*
main release and does not have the printf_p functions.
*/
#if defined _MSC_FULL_VER && _MSC_FULL_VER >= 140050727 && !defined __WXWINCE__
- #if wxUSE_UNICODE
- #define wxVsnprintf_ _vswprintf_p
- #else
- #define wxVsnprintf_ _vsprintf_p
- #endif
+ #define wxCRT_VsnprintfA _vsprintf_p
+ #define wxCRT_VsnprintfW_ _vswprintf_p
#endif
#endif /* HAVE_UNIX98_PRINTF/!HAVE_UNIX98_PRINTF */
#else /* !wxUSE_PRINTF_POS_PARAMS */
is a wrapper around it as explained below
*/
- /* first deal with TCHAR-aware compilers which have _vsntprintf */
- #ifndef wxVsnprintf_
- #if defined(__VISUALC__) || \
- (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
- #define wxVsnprintf_ _vsntprintf
+ #if defined(__VISUALC__) || \
+ (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
+ #define wxCRT_VsnprintfA _vsnprintf
+ #define wxCRT_VsnprintfW_ _vsnwprintf
+ #else
+ #if defined(HAVE__VSNWPRINTF)
+ #define wxCRT_VsnprintfW_ _vsnwprintf
+ #elif defined(HAVE_VSWPRINTF)
+ #define wxCRT_VsnprintfW_ vswprintf
+ #elif defined(__WATCOMC__)
+ #define wxCRT_VsnprintfW_ _vsnwprintf
#endif
- #endif
- /* if this didn't work, define it separately for Unicode and ANSI builds */
- #ifndef wxVsnprintf_
- #if wxUSE_UNICODE
- #if defined(HAVE__VSNWPRINTF)
- #define wxVsnprintf_ _vsnwprintf
- #elif defined(HAVE_VSWPRINTF)
- #define wxVsnprintf_ vswprintf
- #elif defined(__WATCOMC__)
- #define wxVsnprintf_ _vsnwprintf
- #endif
- #else /* ASCII */
- /*
- All versions of CodeWarrior supported by wxWidgets apparently
- have both snprintf() and vsnprintf()
- */
- #if defined(HAVE_VSNPRINTF) \
- || defined(__MWERKS__) || defined(__WATCOMC__)
- #ifdef HAVE_BROKEN_VSNPRINTF_DECL
- #define wxVsnprintf_ wx_fixed_vsnprintf
- #else
- #define wxVsnprintf_ vsnprintf
- #endif
+ /*
+ All versions of CodeWarrior supported by wxWidgets apparently
+ have both snprintf() and vsnprintf()
+ */
+ #if defined(HAVE_VSNPRINTF) \
+ || defined(__MWERKS__) || defined(__WATCOMC__)
+ #ifdef HAVE_BROKEN_VSNPRINTF_DECL
+ #define wxCRT_VsnprintfA wx_fixed_vsnprintf
+ #else
+ #define wxCRT_VsnprintfA vsnprintf
#endif
- #endif /* Unicode/ASCII */
- #endif /* wxVsnprintf_ */
+ #endif
+ #endif
#endif /* wxUSE_PRINTF_POS_PARAMS/!wxUSE_PRINTF_POS_PARAMS */
-#ifndef wxVsnprintf_
+#ifndef wxCRT_VsnprintfW_
/* no (suitable) vsnprintf(), cook our own */
WXDLLIMPEXP_BASE int
- wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format, va_list argptr);
+ wxCRT_VsnprintfW_(wchar_t *buf, size_t len, const wchar_t *format, va_list argptr);
+ #define wxUSE_WXVSNPRINTFW 1
+#else
+ #define wxUSE_WXVSNPRINTFW 0
+#endif
- #define wxUSE_WXVSNPRINTF 1
+#ifndef wxCRT_VsnprintfA
+ /* no (suitable) vsnprintf(), cook our own */
+ WXDLLIMPEXP_BASE int
+ wxCRT_VsnprintfA(char *buf, size_t len, const char *format, va_list argptr);
+ #define wxUSE_WXVSNPRINTFA 1
#else
- #define wxUSE_WXVSNPRINTF 0
+ #define wxUSE_WXVSNPRINTFA 0
#endif
-/*
- 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
+// for wxString code, define wxUSE_WXVSNPRINTF to indicate that wx
+// implementation is used no matter what (in UTF-8 build, either *A or *W
+// version may be called):
+#if !wxUSE_UNICODE
+ #define wxUSE_WXVSNPRINTF wxUSE_WXVSNPRINTFA
+#elif wxUSE_UNICODE_WCHAR
+ #define wxUSE_WXVSNPRINTF wxUSE_WXVSNPRINTFW
+#elif wxUSE_UTF8_LOCALE_ONLY
+ #define wxUSE_WXVSNPRINTF wxUSE_WXVSNPRINTFA
+#else // UTF-8 under any locale
+ #define wxUSE_WXVSNPRINTF (wxUSE_WXVSNPRINTFA && wxUSE_WXVSNPRINTFW)
#endif
+#define wxCRT_FprintfA fprintf
+#define wxCRT_PrintfA printf
+#define wxCRT_VfprintfA vfprintf
+#define wxCRT_VprintfA vprintf
+#define wxCRT_VsprintfA vsprintf
+
/*
More Unicode complications: although both ANSI C and C++ define a number of
wide character functions such as wprintf(), not all environments have them.
if we have wprintf() we still must wrap it in a non trivial wxPrintf().
*/
+#ifndef __WINDOWS__
+ #define wxNEED_PRINTF_CONVERSION
+#endif
+
+// FIXME-UTF8: format conversion should be moved outside of wxCRT_* and to the
+// vararg templates; after then, wxNEED_PRINTF_CONVERSION should
+// be removed and this code simplified
+#ifndef wxNEED_PRINTF_CONVERSION
+ #ifdef wxHAVE_TCHAR_SUPPORT
+ #define wxCRT_FprintfW fwprintf
+ #define wxCRT_PrintfW wprintf
+ #define wxCRT_VfprintfW vfwprintf
+ #define wxCRT_VprintfW vwprintf
+ #define wxCRT_VsprintfW vswprintf
+ #endif
+#endif // !defined(wxNEED_PRINTF_CONVERSION)
+
+/*
+ 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 defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
/*
we don't have them at all or because they don't have the semantics we
need
*/
- int wxCRT_Printf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
- int wxCRT_Fprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
- int wxCRT_Vfprintf( FILE *stream, const wxChar *format, va_list ap );
- int wxCRT_Vprintf( const wxChar *format, va_list ap );
- int wxCRT_Vsprintf( wxChar *str, const wxChar *format, va_list ap );
+ int wxCRT_PrintfW( const wchar_t *format, ... ) ATTRIBUTE_PRINTF_1;
+ int wxCRT_FprintfW( FILE *stream, const wchar_t *format, ... ) ATTRIBUTE_PRINTF_2;
+ int wxCRT_VfprintfW( FILE *stream, const wchar_t *format, va_list ap );
+ int wxCRT_VprintfW( const wchar_t *format, va_list ap );
+ int wxCRT_VsprintfW( wchar_t *str, const wchar_t *format, va_list ap );
#endif /* wxNEED_PRINTF_CONVERSION */
/* these 2 can be simply mapped to the versions with underscore at the end */
/* if we don't have to do the conversion */
/*
However, if we don't have any vswprintf() at all we don't need to redefine
- anything as our own wxVsnprintf_() already behaves as needed.
+ anything as our own wxCRT_VsnprintfW_() already behaves as needed.
*/
-#if defined(wxNEED_PRINTF_CONVERSION) && defined(wxVsnprintf_)
- int wxCRT_Vsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
+#if defined(wxNEED_PRINTF_CONVERSION) && defined(wxCRT_VsnprintfW_)
+ int wxCRT_VsnprintfW( wchar_t *str, size_t size, const wchar_t *format, va_list ap );
#else
- #define wxCRT_Vsnprintf wxVsnprintf_
+ #define wxCRT_VsnprintfW wxCRT_VsnprintfW_
#endif
// we'll also need wxArgNormalizer<T> specializations for char,
// wchar_t, wxUniChar and wxUniCharRef to handle this correctly
+ // FIXME-UTF8: remove this
+#if wxUSE_UNICODE
+ #define wxCRT_PrintfNative wxCRT_PrintfW
+ #define wxCRT_FprintfNative wxCRT_FprintfW
+#else
+ #define wxCRT_PrintfNative wxCRT_PrintfA
+ #define wxCRT_FprintfNative wxCRT_FprintfA
+#endif
+
WX_DEFINE_VARARG_FUNC(int, wxPrintf, 1, (const wxFormatString&),
- wxCRT_Printf, printf)
+ wxCRT_PrintfNative, wxCRT_PrintfA)
WX_DEFINE_VARARG_FUNC(int, wxFprintf, 2, (FILE*, const wxFormatString&),
- wxCRT_Fprintf, fprintf)
+ wxCRT_FprintfNative, wxCRT_FprintfA)
// va_list versions of printf functions simply forward to the respective
// CRT function; note that they assume that va_list was created using
// wxArgNormalizer<T>!
#if wxUSE_UNICODE_UTF8
#if wxUSE_UTF8_LOCALE_ONLY
- #define WX_VARARG_VFOO_IMPL(args, implWchar, implUtf8) \
- return implUtf8 args
+ #define WX_VARARG_VFOO_IMPL(args, implW, implA) \
+ return implA args
#else
- #define WX_VARARG_VFOO_IMPL(args, implWchar, implUtf8) \
- if ( wxLocaleIsUtf8 ) return implUtf8 args; \
- else return implWchar args
+ #define WX_VARARG_VFOO_IMPL(args, implW, implA) \
+ if ( wxLocaleIsUtf8 ) return implA args; \
+ else return implW args
#endif
-#else // wxUSE_UNICODE_WCHAR / ANSI
- #define WX_VARARG_VFOO_IMPL(args, implWchar, implUtf8) \
- return implWchar args
+#elif wxUSE_UNICODE_WCHAR
+ #define WX_VARARG_VFOO_IMPL(args, implW, implA) \
+ return implW args
+#else // ANSI
+ #define WX_VARARG_VFOO_IMPL(args, implW, implA) \
+ return implA args
#endif
inline int
wxVprintf(const wxString& format, va_list ap)
{
WX_VARARG_VFOO_IMPL((wxFormatString(format), ap),
- wxCRT_Vprintf, vprintf);
+ wxCRT_VprintfW, wxCRT_VprintfA);
}
inline int
wxVfprintf(FILE *f, const wxString& format, va_list ap)
{
WX_VARARG_VFOO_IMPL((f, wxFormatString(format), ap),
- wxCRT_Vfprintf, vfprintf);
+ wxCRT_VfprintfW, wxCRT_VfprintfA);
}
#undef WX_VARARG_VFOO_IMPL
// according to http://www.w3.org/TR/REC-CSS2/syndata.html#color-units
// values outside 0-255 range are allowed but should be clipped
int red, green, blue;
- if (wxSscanf(str.substr(3), wxT("(%d, %d, %d)"), &red, &green, &blue) != 3)
+ if (wxSscanf(str.wx_str() + 3, wxT("(%d, %d, %d)"), &red, &green, &blue) != 3)
return false;
Set((unsigned char)wxClip(red,0,255),
{
// hexadecimal prefixed with # (HTML syntax)
unsigned long tmp;
- if (wxSscanf(str.substr(1), wxT("%lx"), &tmp) != 1)
+ if (wxSscanf(str.wx_str() + 1, wxT("%lx"), &tmp) != 1)
return false;
Set((unsigned char)(tmp >> 16),
// wrappers around standard POSIX functions
// ----------------------------------------------------------------------------
-#ifdef wxNEED_WX_UNISTD_H
-
-WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf )
-{
- return stat( wxConvFile.cWX2MB( file_name ), buf );
-}
-
-WXDLLEXPORT int wxLstat( const wxChar *file_name, wxStructStat *buf )
-{
- return lstat( wxConvFile.cWX2MB( file_name ), buf );
-}
-
-WXDLLEXPORT int wxAccess( const wxChar *pathname, int mode )
-{
- return access( wxConvFile.cWX2MB( pathname ), mode );
-}
-
-WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode )
-{
- return open( wxConvFile.cWX2MB( pathname ), flags, mode );
-}
-
-#endif // wxNEED_WX_UNISTD_H
-
#if wxUSE_UNICODE && defined __BORLANDC__ \
&& __BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551
// regardless of the mode parameter. This hack works around the problem by
// setting the mode with _wchmod.
//
-int wxOpen(const wchar_t *pathname, int flags, mode_t mode)
+int wxCRT_Open(const wchar_t *pathname, int flags, mode_t mode)
{
int moreflags = 0;
return wxStrcpy(copy, s.c_str());
}
-static inline wxChar* MYcopystring(const wxChar* s)
+template<typename CharType>
+static inline CharType* MYcopystring(const CharType* s)
{
- wxChar* copy = new wxChar[wxStrlen(s) + 1];
+ CharType* copy = new CharType[wxStrlen(s) + 1];
return wxStrcpy(copy, s);
}
*
*/
-void wxStripExtension(wxChar *buffer)
+template<typename T>
+static void wxDoStripExtension(T *buffer)
{
int len = wxStrlen(buffer);
int i = len-1;
}
}
+void wxStripExtension(char *buffer) { wxDoStripExtension(buffer); }
+void wxStripExtension(wchar_t *buffer) { wxDoStripExtension(buffer); }
+
void wxStripExtension(wxString& buffer)
{
//RN: Be careful about the handling the case where
}
// Destructive removal of /./ and /../ stuff
-wxChar *wxRealPath (wxChar *path)
+template<typename CharType>
+static CharType *wxDoRealPath (CharType *path)
{
#ifdef __WXMSW__
- static const wxChar SEP = wxT('\\');
+ static const CharType SEP = wxT('\\');
wxUnix2DosFilename(path);
#else
- static const wxChar SEP = wxT('/');
+ static const CharType SEP = wxT('/');
#endif
if (path[0] && path[1]) {
/* MATTHEW: special case "/./x" */
- wxChar *p;
+ CharType *p;
if (path[2] == SEP && path[1] == wxT('.'))
p = &path[0];
else
{
if (p[1] == wxT('.') && p[2] == wxT('.') && (p[3] == SEP || p[3] == wxT('\0')))
{
- wxChar *q;
+ CharType *q;
for (q = p - 1; q >= path && *q != SEP; q--)
{
// Empty
return path;
}
+char *wxRealPath(char *path)
+{
+ return wxDoRealPath(path);
+}
+
+wchar_t *wxRealPath(wchar_t *path)
+{
+ return wxDoRealPath(path);
+}
+
wxString wxRealPath(const wxString& path)
{
wxChar *buf1=MYcopystring(path);
/* input name in name, pathname output to buf. */
-wxChar *wxExpandPath(wxChar *buf, const wxChar *name)
+template<typename CharType>
+static CharType *wxDoExpandPath(CharType *buf, const wxString& name)
{
- register wxChar *d, *s, *nm;
- wxChar lnm[_MAXPATHLEN];
+ register CharType *d, *s, *nm;
+ CharType lnm[_MAXPATHLEN];
int q;
// Some compilers don't like this line.
-// const wxChar trimchars[] = wxT("\n \t");
+// const CharType trimchars[] = wxT("\n \t");
- wxChar trimchars[4];
+ CharType trimchars[4];
trimchars[0] = wxT('\n');
trimchars[1] = wxT(' ');
trimchars[2] = wxT('\t');
trimchars[3] = 0;
#ifdef __WXMSW__
- const wxChar SEP = wxT('\\');
+ const CharType SEP = wxT('\\');
#else
- const wxChar SEP = wxT('/');
+ const CharType SEP = wxT('/');
#endif
buf[0] = wxT('\0');
- if (name == NULL || *name == wxT('\0'))
+ if (name.empty())
return buf;
- nm = MYcopystring(name); // Make a scratch copy
- wxChar *nm_tmp = nm;
+ nm = MYcopystring((const CharType*)name.c_str()); // Make a scratch copy
+ CharType *nm_tmp = nm;
/* Skip leading whitespace and cr */
- while (wxStrchr((wxChar *)trimchars, *nm) != NULL)
+ while (wxStrchr(trimchars, *nm) != NULL)
nm++;
/* And strip off trailing whitespace and cr */
s = nm + (q = wxStrlen(nm)) - 1;
- while (q-- && wxStrchr((wxChar *)trimchars, *s) != NULL)
+ while (q-- && wxStrchr(trimchars, *s) != NULL)
*s = wxT('\0');
s = nm;
if (*s++ == wxT('$'))
#endif
{
- register wxChar *start = d;
+ register CharType *start = d;
register int braces = (*s == wxT('{') || *s == wxT('('));
- register wxChar *value;
+ register CharType *value;
while ((*d++ = *s) != 0)
if (braces ? (*s == wxT('}') || *s == wxT(')')) : !(wxIsalnum(*s) || *s == wxT('_')) )
break;
}
/* Expand ~ and ~user */
+ wxString homepath;
nm = lnm;
if (nm[0] == wxT('~') && !q)
{
/* prefix ~ */
if (nm[1] == SEP || nm[1] == 0)
{ /* ~/filename */
- // FIXME: wxGetUserHome could return temporary storage in Unicode mode
- if ((s = WXSTRINGCAST wxGetUserHome(wxEmptyString)) != NULL) {
+ homepath = wxGetUserHome(wxEmptyString);
+ if (!homepath.empty()) {
+ s = (CharType*)(const CharType*)homepath.c_str();
if (*++nm)
nm++;
}
} else
{ /* ~user/filename */
- register wxChar *nnm;
- register wxChar *home;
+ register CharType *nnm;
for (s = nm; *s && *s != SEP; s++)
{
// Empty
was_sep = (*s == SEP);
nnm = *s ? s + 1 : s;
*s = 0;
- // FIXME: wxGetUserHome could return temporary storage in Unicode mode
- if ((home = WXSTRINGCAST wxGetUserHome(wxString(nm + 1))) == NULL)
+ homepath = wxGetUserHome(wxString(nm + 1));
+ if (homepath.empty())
{
if (was_sep) /* replace only if it was there: */
*s = SEP;
else
{
nm = nnm;
- s = home;
+ s = (CharType*)(const CharType*)homepath.c_str();
}
}
}
return wxRealPath(buf);
}
+char *wxExpandPath(char *buf, const wxString& name)
+{
+ return wxDoExpandPath(buf, name);
+}
+
+wchar_t *wxExpandPath(wchar_t *buf, const wxString& name)
+{
+ return wxDoExpandPath(buf, name);
+}
+
+
/* Contract Paths to be build upon an environment variable
component:
if (filename.empty())
return (wxChar *) NULL;
- wxStrcpy (dest, WXSTRINGCAST filename);
+ wxStrcpy (dest, filename);
#ifdef __WXMSW__
wxUnix2DosFilename(dest);
#endif
// Handle environment
- const wxChar *val;
+ wxString val;
#ifndef __WXWINCE__
wxChar *tcp;
- if (!envname.empty() && (val = wxGetenv (WXSTRINGCAST envname)) != NULL &&
+ if (!envname.empty() && !(val = wxGetenv (envname)).empty() &&
(tcp = wxStrstr (dest, val)) != NULL)
{
- wxStrcpy (wxFileFunctionsBuffer, tcp + wxStrlen (val));
+ wxStrcpy (wxFileFunctionsBuffer, tcp + val.length());
*tcp++ = wxT('$');
*tcp++ = wxT('{');
- wxStrcpy (tcp, WXSTRINGCAST envname);
+ wxStrcpy (tcp, envname);
wxStrcat (tcp, wxT("}"));
wxStrcat (tcp, wxFileFunctionsBuffer);
}
// Handle User's home (ignore root homes!)
val = wxGetUserHome (user);
- if (!val)
+ if (val.empty())
return dest;
- const size_t len = wxStrlen(val);
+ const size_t len = val.length();
if (len <= 2)
return dest;
{
wxStrcpy(wxFileFunctionsBuffer, wxT("~"));
if (!user.empty())
- wxStrcat(wxFileFunctionsBuffer, (const wxChar*) user);
+ wxStrcat(wxFileFunctionsBuffer, user);
wxStrcat(wxFileFunctionsBuffer, dest + len);
wxStrcpy (dest, wxFileFunctionsBuffer);
}
wxChar buf[_MAXPATHLEN];
// Local copy
- wxStrcpy (buf, WXSTRINGCAST path);
+ wxStrcpy(buf, path);
int l = path.length();
int i = l - 1;
#endif // __WXMAC__
-void
-wxDos2UnixFilename (wxChar *s)
+template<typename T>
+static void wxDoDos2UnixFilename(T *s)
{
if (s)
while (*s)
*s = _T('/');
#ifdef __WXMSW__
else
- *s = (wxChar)wxTolower (*s); // Case INDEPENDENT
+ *s = wxTolower(*s); // Case INDEPENDENT
#endif
s++;
}
}
-void
+void wxDos2UnixFilename(char *s) { wxDoDos2UnixFilename(s); }
+void wxDos2UnixFilename(wchar_t *s) { wxDoDos2UnixFilename(s); }
+
+template<typename T>
+static void
#if defined(__WXMSW__) || defined(__OS2__)
-wxUnix2DosFilename (wxChar *s)
+wxDoUnix2DosFilename(T *s)
#else
-wxUnix2DosFilename (wxChar *WXUNUSED(s) )
+wxDoUnix2DosFilename(T *WXUNUSED(s) )
#endif
{
// Yes, I really mean this to happen under DOS only! JACS
#endif
}
+void wxUnix2DosFilename(char *s) { wxDoUnix2DosFilename(s); }
+void wxUnix2DosFilename(wchar_t *s) { wxDoUnix2DosFilename(s); }
+
// Concatenate two files to form third
bool
wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& file3)
static wxDir *gs_dir = NULL;
static wxString gs_dirPath;
-wxString wxFindFirstFile(const wxChar *spec, int flags)
+wxString wxFindFirstFile(const wxString& spec, int flags)
{
wxSplitPath(spec, &gs_dirPath, NULL, NULL);
if ( gs_dirPath.empty() )
}
wxString result;
- gs_dir->GetFirst(&result, wxFileNameFromPath(wxString(spec)), dirFlags);
+ gs_dir->GetFirst(&result, wxFileNameFromPath(spec), dirFlags);
if ( result.empty() )
{
wxDELETE(gs_dir);
#endif
}
-bool wxEndsWithPathSeparator(const wxChar *pszFileName)
+bool wxEndsWithPathSeparator(const wxString& filename)
{
- size_t len = wxStrlen(pszFileName);
-
- return len && wxIsPathSeparator(pszFileName[len - 1]);
+ return !filename.empty() && wxIsPathSeparator(filename.Last());
}
// find a file in a list of directories, returns false if not found
-bool wxFindFileInPath(wxString *pStr, const wxChar *pszPath, const wxChar *pszFile)
+bool wxFindFileInPath(wxString *pStr, const wxString& szPath, const wxString& szFile)
{
// we assume that it's not empty
- wxCHECK_MSG( !wxIsEmpty(pszFile), false,
+ wxCHECK_MSG( !szFile.empty(), false,
_T("empty file name in wxFindFileInPath"));
// skip path separator in the beginning of the file name if present
- if ( wxIsPathSeparator(*pszFile) )
- pszFile++;
-
- // copy the path (strtok will modify it)
- wxChar *szPath = new wxChar[wxStrlen(pszPath) + 1];
- wxStrcpy(szPath, pszPath);
-
- wxString strFile;
- wxChar *pc, *save_ptr;
- for ( pc = wxStrtok(szPath, wxPATH_SEP, &save_ptr);
- pc != NULL;
- pc = wxStrtok((wxChar *) NULL, wxPATH_SEP, &save_ptr) )
+ wxString szFile2;
+ if ( wxIsPathSeparator(szFile[0u]) )
+ szFile2 = szFile.Mid(1);
+ else
+ szFile2 = szFile;
+
+ wxStringTokenizer tkn(szPath, wxPATH_SEP);
+
+ while ( tkn.HasMoreTokens() )
{
- // search for the file in this directory
- strFile = pc;
- if ( !wxEndsWithPathSeparator(pc) )
+ wxString strFile = tkn.GetNextToken();
+ if ( !wxEndsWithPathSeparator(strFile) )
strFile += wxFILE_SEP_PATH;
- strFile += pszFile;
+ strFile += szFile2;
- if ( wxFileExists(strFile) ) {
+ if ( wxFileExists(strFile) )
+ {
*pStr = strFile;
- break;
+ return true;
}
}
- // suppress warning about unused variable save_ptr when wxStrtok() is a
- // macro which throws away its third argument
- save_ptr = pc;
-
- delete [] szPath;
-
- return pc != NULL; // if true => we breaked from the loop
+ return false;
}
-void WXDLLEXPORT wxSplitPath(const wxChar *pszFileName,
+void WXDLLEXPORT wxSplitPath(const wxString& fileName,
wxString *pstrPath,
wxString *pstrName,
wxString *pstrExt)
{
- // it can be empty, but it shouldn't be NULL
- wxCHECK_RET( pszFileName, wxT("NULL file name in wxSplitPath") );
-
- wxFileName::SplitPath(pszFileName, pstrPath, pstrName, pstrExt);
+ wxFileName::SplitPath(fileName, pstrPath, pstrName, pstrExt);
}
#if wxUSE_DATETIME
HANDLE h = ::CreateFile
(
- path.c_str(),
+ path.wx_str(),
access,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL,
{
#if defined( __UNIX__ ) || defined(__OS2__)
// access() will take in count also symbolic links
- return access(wxConvFile.cWX2MB(path), W_OK) == 0;
+ return access(path.fn_str(), W_OK) == 0;
#elif defined( __WINDOWS__ )
return wxCheckWin32Permission(path, GENERIC_WRITE);
#else
{
#if defined( __UNIX__ ) || defined(__OS2__)
// access() will take in count also symbolic links
- return access(wxConvFile.cWX2MB(path), R_OK) == 0;
+ return access(path.fn_str(), R_OK) == 0;
#elif defined( __WINDOWS__ )
return wxCheckWin32Permission(path, GENERIC_READ);
#else
{
#if defined( __UNIX__ ) || defined(__OS2__)
// access() will take in count also symbolic links
- return access(wxConvFile.cWX2MB(path), X_OK) == 0;
+ return access(path.fn_str(), X_OK) == 0;
#elif defined( __WINDOWS__ )
return wxCheckWin32Permission(path, GENERIC_EXECUTE);
#else
bool wxIsWild( const wxString& pattern )
{
- wxString tmp = pattern;
- wxChar *pat = WXSTRINGCAST(tmp);
- while (*pat)
+ for ( wxString::const_iterator p = pattern.begin(); p != pattern.end(); ++p )
{
- switch (*pat++)
+ switch ( (*p).GetValue() )
{
- case wxT('?'): case wxT('*'): case wxT('['): case wxT('{'):
- return true;
- case wxT('\\'):
- if (!*pat++)
- return false;
+ case wxT('?'):
+ case wxT('*'):
+ case wxT('['):
+ case wxT('{'):
+ return true;
+
+ case wxT('\\'):
+ if ( ++p == pattern.end() )
+ return false;
}
}
return false;
~wxMsgCatalogFile();
// load the catalog from disk (szDirPrefix corresponds to language)
- bool Load(const wxChar *szDirPrefix, const wxChar *szName,
+ bool Load(const wxString& szDirPrefix, const wxString& szName,
wxPluralFormsCalculatorPtr& rPluralFormsCalculator);
// fills the hash with string-translation pairs
// return the directories to search for message catalogs under the given
// prefix, separated by wxPATH_SEP
static
-wxString GetMsgCatalogSubdirs(const wxChar *prefix, const wxChar *lang)
+wxString GetMsgCatalogSubdirs(const wxString& prefix, const wxString& lang)
{
wxString searchPath;
searchPath << prefix << wxFILE_SEP_PATH << lang;
}
// construct the search path for the given language
-static wxString GetFullSearchPath(const wxChar *lang)
+static wxString GetFullSearchPath(const wxString& lang)
{
// first take the entries explicitly added by the program
wxArrayString paths;
}
// open disk file and read in it's contents
-bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName,
+bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName,
wxPluralFormsCalculatorPtr& rPluralFormsCalculator)
{
wxString searchPath;
searchPath += GetFullSearchPath(szDirPrefix);
- const wxChar *sublocale = wxStrchr(szDirPrefix, wxT('_'));
- if ( sublocale )
+ size_t sublocaleIndex = szDirPrefix.find(wxT('_'));
+ if ( sublocaleIndex != wxString::npos )
{
// also add just base locale name: for things like "fr_BE" (belgium
// french) we should use "fr" if no belgium specific message catalogs
// exist
searchPath << wxPATH_SEP
- << GetFullSearchPath(wxString(szDirPrefix).
- Left((size_t)(sublocale - szDirPrefix)));
+ << GetFullSearchPath(szDirPrefix.Left(sublocaleIndex));
}
// don't give translation errors here because the wxstd catalog might
256);
if (ret != 0)
{
- m_pszOldLocale = wxStrdup(localeName);
+ m_pszOldLocale = wxStrdup(wxConvLibc.cWC2MB(localeName));
}
else
m_pszOldLocale = NULL;
// TODO: how to find languageId
// SetLocaleInfo(languageId, SORT_DEFAULT, localeName);
#else
- wxMB2WXbuf oldLocale = wxSetlocale(LC_ALL, szLocale);
+ const char *oldLocale = wxSetlocale(LC_ALL, szLocale);
if ( oldLocale )
m_pszOldLocale = wxStrdup(oldLocale);
else
#if defined(__UNIX__) && wxUSE_UNICODE && !defined(__WXMAC__)
-static wxWCharBuffer wxSetlocaleTryUTF8(int c, const wxChar *lc)
+static const char *wxSetlocaleTryUTF8(int c, const wxString& lc)
{
- wxMB2WXbuf l;
+ const char *l;
// NB: We prefer to set UTF-8 locale if it's possible and only fall back to
// non-UTF-8 locale if it fails
- if ( lc && lc[0] != 0 )
+ if ( !lc.empty() )
{
wxString buf(lc);
wxString buf2;
buf2 = buf + wxT(".UTF-8");
- l = wxSetlocale(c, buf2.c_str());
+ l = wxSetlocale(c, buf2);
if ( !l )
{
buf2 = buf + wxT(".utf-8");
- l = wxSetlocale(c, buf2.c_str());
+ l = wxSetlocale(c, buf2);
}
if ( !l )
{
buf2 = buf + wxT(".UTF8");
- l = wxSetlocale(c, buf2.c_str());
+ l = wxSetlocale(c, buf2);
}
if ( !l )
{
buf2 = buf + wxT(".utf8");
- l = wxSetlocale(c, buf2.c_str());
+ l = wxSetlocale(c, buf2);
}
}
// Set the locale:
#if defined(__OS2__)
- wxMB2WXbuf retloc = wxSetlocale(LC_ALL , wxEmptyString);
+ const char *retloc = wxSetlocale(LC_ALL , wxEmptyString);
#elif defined(__UNIX__) && !defined(__WXMAC__)
if (language != wxLANGUAGE_DEFAULT)
locale = info->CanonicalName;
- wxMB2WXbuf retloc = wxSetlocaleTryUTF8(LC_ALL, locale);
+ const char *retloc = wxSetlocaleTryUTF8(LC_ALL, locale);
const wxString langOnly = locale.Left(2);
if ( !retloc )
//
// this contradicts IBM own docs but this is not of much help, so just work
// around it in the crudest possible manner
- wxChar *p = wxStrchr((wxChar *)retloc, _T(' '));
+ char *p = wxStrchr(retloc, ' ');
if ( p )
- *p = _T('\0');
+ *p = '\0';
#endif // __AIX__
#elif defined(__WIN32__)
#define SETLOCALE_FAILS_ON_UNICODE_LANGS
#endif
-#if !wxUSE_UNICODE
- const
-#endif
- wxMB2WXbuf retloc = wxT("C");
+ const char *retloc = "C";
if (language != wxLANGUAGE_DEFAULT)
{
if (info->WinLang == 0)
retloc = wxSetlocale(LC_ALL, locale);
#endif
#ifdef SETLOCALE_FAILS_ON_UNICODE_LANGS
- if (codepage == 0 && (const wxChar*)retloc == NULL)
+ if (codepage == 0 && retloc == NULL)
{
- retloc = wxT("C");
+ retloc = "C";
}
#endif
}
retloc = NULL;
#endif
#ifdef SETLOCALE_FAILS_ON_UNICODE_LANGS
- if ((const wxChar*)retloc == NULL)
+ if (retloc == NULL)
{
wxChar buffer[16];
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_IDEFAULTANSICODEPAGE, buffer, 16) > 0 &&
wxStrcmp(buffer, wxT("0")) == 0)
{
- retloc = wxT("C");
+ retloc = "C";
}
}
#endif
else
locale = info->CanonicalName;
- wxMB2WXbuf retloc = wxSetlocale(LC_ALL, locale);
+ const char *retloc = wxSetlocale(LC_ALL, locale);
if ( !retloc )
{
// looking
//
// OTOH, maybe we had already found a language match and in this
- // case don't overwrite it becauce the entry for the default
+ // case don't overwrite it because the entry for the default
// country always appears first in ms_languagesDB
if ( !infoRet )
infoRet = info;
return false;
#elif defined(__UNIX__)
-
- // Test if setting the locale works, then set it back.
- wxMB2WXbuf oldLocale = wxSetlocale(LC_ALL, wxEmptyString);
- wxMB2WXbuf tmp = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName);
+
+ // Test if setting the locale works, then set it back.
+ const char *oldLocale = wxSetlocale(LC_ALL, "");
+ const char *tmp = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName);
if ( !tmp )
{
// Some C libraries don't like xx_YY form and require xx only
return false;
}
// restore the original locale
- wxSetlocale(LC_ALL, oldLocale);
-#endif
+ wxSetlocale(LC_ALL, oldLocale);
+#endif
return true;
}
#ifdef __REG_NOFRONT
# define WXREGEX_USING_BUILTIN
# define WXREGEX_IF_NEED_LEN(x) ,x
-# define WXREGEX_CHAR(x) x
+# if wxUSE_UNICODE
+# define WXREGEX_CHAR(x) x.wc_str()
+# else
+# define WXREGEX_CHAR(x) x.mb_str()
+# endif
#else
# ifdef HAVE_RE_SEARCH
# define WXREGEX_IF_NEED_LEN(x) ,x
# if wxUSE_UNICODE
# define WXREGEX_CONVERT_TO_MB
# endif
-# define WXREGEX_CHAR(x) wxConvertWX2MB(x)
+# define WXREGEX_CHAR(x) x.mb_str()
# define wx_regfree regfree
# define wx_regerror regerror
#endif
// compile it
#ifdef WXREGEX_USING_BUILTIN
bool conv = true;
- int errorcode = wx_re_comp(&m_RegEx, expr, expr.length(), flagsRE);
+ // FIXME-UTF8: use wc_str() after removing ANSI build
+ int errorcode = wx_re_comp(&m_RegEx, expr.c_str(), expr.length(), flagsRE);
#else
+ // FIXME-UTF8: this is potentially broken, we shouldn't even try it
+ // and should always use builtin regex library (or PCRE?)
const wxWX2MBbuf conv = expr.mbc_str();
int errorcode = conv ? regcomp(&m_RegEx, conv, flagsRE) : REG_BADPAT;
#endif
// string comparison
// ---------------------------------------------------------------------------
+bool wxString::IsSameAs(wxUniChar c, bool compareWithCase) const
+{
+ return (length() == 1) && (compareWithCase ? GetChar(0u) == c
+ : wxToupper(GetChar(0u)) == wxToupper(c));
+}
+
#ifdef HAVE_STD_STRING_COMPARE
// NB: Comparison code (both if HAVE_STD_STRING_COMPARE and if not) works with
// conversion to numbers
// ----------------------------------------------------------------------------
-// the implementation of all the functions below is exactly the same so factor
-// it out
+// The implementation of all the functions below is exactly the same so factor
+// it out. Note that number extraction works correctly on UTF-8 strings, so
+// we can use wxStringCharType and wx_str() for maximum efficiency.
-template <typename T, typename F>
-bool wxStringToIntType(const wxChar *start,
+template <typename T>
+bool wxStringToIntType(const wxStringCharType *start,
T *val,
int base,
- F func)
+ T (*func)(const wxStringCharType*, wxStringCharType**, int))
{
wxCHECK_MSG( val, false, _T("NULL output pointer") );
wxASSERT_MSG( !base || (base > 1 && base <= 36), _T("invalid base") );
errno = 0;
#endif
- wxChar *end;
+ wxStringCharType *end;
*val = (*func)(start, &end, base);
// return true only if scan was stopped by the terminating NUL and if the
bool wxString::ToLong(long *val, int base) const
{
- return wxStringToIntType((const wxChar*)c_str(), val, base, wxStrtol);
+ return wxStringToIntType(wx_str(), val, base, wxStrtol);
}
bool wxString::ToULong(unsigned long *val, int base) const
{
- return wxStringToIntType((const wxChar*)c_str(), val, base, wxStrtoul);
+ return wxStringToIntType(wx_str(), val, base, wxStrtoul);
}
bool wxString::ToLongLong(wxLongLong_t *val, int base) const
{
- return wxStringToIntType((const wxChar*)c_str(), val, base, wxStrtoll);
+ return wxStringToIntType(wx_str(), val, base, wxStrtoll);
}
bool wxString::ToULongLong(wxULongLong_t *val, int base) const
{
- return wxStringToIntType((const wxChar*)c_str(), val, base, wxStrtoull);
+ return wxStringToIntType(wx_str(), val, base, wxStrtoull);
}
bool wxString::ToDouble(double *val) const
// buffer were large enough (newer standards such as Unix98)
if ( len < 0 )
{
+ // NB: wxVsnprintf() may call either wxCRT_VsnprintfW or
+ // wxCRT_VsnprintfA in UTF-8 build; wxUSE_WXVSNPRINTF
+ // is true if *both* of them use our own implementation,
+ // otherwise we can't be sure
#if wxUSE_WXVSNPRINTF
// we know that our own implementation of wxVsnprintf() returns -1
// only for a format error - thus there's something wrong with
// the user's format string
return -1;
-#else // assume that system version only returns error if not enough space
- // still not enough, as we don't know how much we need, double the
- // current size of the buffer
+#else // possibly using system version
+ // assume it only returns error if there is not enough space, but
+ // as we don't know how much we need, double the current size of
+ // the buffer
size *= 2;
#endif // wxUSE_WXVSNPRINTF/!wxUSE_WXVSNPRINTF
}
// if the length is not given, assume the string to be NUL terminated
if ( nLength == npos ) {
- wxASSERT_MSG( nPos <= Strsize(psz), _T("index out of bounds") );
+ wxASSERT_MSG( nPos <= wxStrlen(psz), _T("index out of bounds") );
- nLength = Strsize(psz + nPos);
+ nLength = wxStrlen(psz + nPos);
}
STATISTICS_ADD(InitialLength, nLength);
{
wxASSERT( nPos <= length() );
- if ( n == npos ) n = Strsize(sz);
+ if ( n == npos ) n = wxStrlen(sz);
if ( n == 0 ) return *this;
if ( !Alloc(length() + n) || !CopyBeforeWrite() ) {
// assigns C string
wxStringImpl& wxStringImpl::operator=(const wxStringCharType *psz)
{
- if ( !AssignCopy(Strsize(psz), psz) ) {
+ if ( !AssignCopy(wxStrlen(psz), psz) ) {
wxFAIL_MSG( _T("out of memory in wxStringImpl::operator=(const wxStringCharType *)") );
}
return *this;
// put string back in a reasonable state after GetWriteBuf
void wxStringImpl::DoUngetWriteBuf()
{
- DoUngetWriteBuf(Strsize(m_pchData));
+ DoUngetWriteBuf(wxStrlen(m_pchData));
}
void wxStringImpl::DoUngetWriteBuf(size_t nLen)
bool wxVariantDataLong::Read(wxString& str)
{
- m_value = wxAtol((const wxChar*) str);
+ m_value = wxAtol(str);
return true;
}
bool wxVariantDoubleData::Read(wxString& str)
{
- m_value = wxAtof((const wxChar*) str);
+ m_value = wxAtof(str);
return true;
}
bool wxVariantDataBool::Read(wxString& str)
{
- m_value = (wxAtol((const wxChar*) str) != 0);
+ m_value = (wxAtol(str) != 0);
return true;
}
bool wxVariantDataDateTime::Read(wxString& str)
{
- if(! m_value.ParseDateTime(str))
+ if(! m_value.ParseDateTime(str.c_str()/*FIXME-UTF8*/))
return false;
return true;
}
*value = (long) (((wxVariantDataBool*)GetData())->GetValue());
#endif
else if (type == wxT("string"))
- *value = wxAtol((const wxChar*) ((wxVariantDataString*)GetData())->GetValue());
+ *value = wxAtol(((wxVariantDataString*)GetData())->GetValue());
else
return false;
*value = (double) (((wxVariantDataBool*)GetData())->GetValue());
#endif
else if (type == wxT("string"))
- *value = (double) wxAtof((const wxChar*) ((wxVariantDataString*)GetData())->GetValue());
+ *value = (double) wxAtof(((wxVariantDataString*)GetData())->GetValue());
else
return false;
// Fallback to string conversion
wxString val;
return Convert(&val) &&
- (value->ParseDateTime(val) || value->ParseDate(val) || value->ParseTime(val));
+ (value->ParseDateTime(val.c_str()/*FIXME-UTF8*/) ||
+ value->ParseDate(val.c_str()/*FIXME-UTF8*/) ||
+ value->ParseTime(val.c_str()/*FIXME-UTF8*/));
}
#endif // wxUSE_DATETIME
#include <winnt.h>
#endif
-#ifndef wxStrtoll
- #ifdef __WXWINCE__
- // there is no errno.h under CE apparently
- #define wxSET_ERRNO(value)
- #else
- #include <errno.h>
+#ifdef __WXWINCE__
+ // there is no errno.h under CE apparently
+ #define wxSET_ERRNO(value)
+#else
+ #include <errno.h>
- #define wxSET_ERRNO(value) errno = value
- #endif
+ #define wxSET_ERRNO(value) errno = value
#endif
#if defined(__MWERKS__) && __MSL__ >= 0x6000
return true;
}
+char* wxSetlocale(int category, const char *locale)
+{
+ char *rv = setlocale(category, locale);
+ if ( locale != NULL /* setting locale, not querying */ &&
+ rv /* call was successful */ )
+ {
+ wxUpdateLocaleIsUtf8();
+ }
+ return rv;
+}
+
// ============================================================================
// printf() functions business
// ============================================================================
#define wxNEED_WPRINTF
- int wxVfprintf( FILE *stream, const wxChar *format, va_list argptr );
+ int wxCRT_VfprintfW( FILE *stream, const wchar_t *format, va_list argptr );
#endif
#if defined(__DMC__)
- /* Digital Mars adds count to _stprintf (C99) so convert */
- #if wxUSE_UNICODE
- int wxSprintf (wchar_t * __RESTRICT s, const wchar_t * __RESTRICT format, ... )
- {
- va_list arglist;
-
- va_start( arglist, format );
- int iLen = swprintf ( s, -1, format, arglist );
- va_end( arglist );
- return iLen ;
- }
-
- #endif // wxUSE_UNICODE
+/* Digital Mars adds count to _stprintf (C99) so convert */
+int wxCRT_SprintfW (wchar_t * __RESTRICT s, const wchar_t * __RESTRICT format, ... )
+{
+ va_list arglist;
+ va_start( arglist, format );
+ int iLen = swprintf ( s, -1, format, arglist );
+ va_end( arglist );
+ return iLen ;
+}
#endif //__DMC__
// ----------------------------------------------------------------------------
// implement the standard IO functions for wide char if libc doesn't have them
// ----------------------------------------------------------------------------
-#ifdef wxNEED_FPUTS
-int wxFputs(const wchar_t *ws, FILE *stream)
+#ifndef wxCRT_FputsW
+int wxCRT_FputsW(const wchar_t *ws, FILE *stream)
{
wxCharBuffer buf(wxConvLibc.cWC2MB(ws));
if ( !buf )
// counting the number of wide characters written isn't worth the trouble,
// simply distinguish between ok and error
- return fputs(buf, stream) == -1 ? -1 : 0;
+ return wxCRT_FputsA(buf, stream) == -1 ? -1 : 0;
}
-#endif // wxNEED_FPUTS
+#endif // !wxCRT_FputsW
-#ifdef wxNEED_PUTS
-int wxPuts(const wxChar *ws)
+#ifndef wxCRT_PutsW
+int wxCRT_PutsW(const wchar_t *ws)
{
- int rc = wxFputs(ws, stdout);
+ int rc = wxCRT_FputsW(ws, stdout);
if ( rc != -1 )
{
- if ( wxFputs(L"\n", stdout) == -1 )
+ if ( wxCRT_FputsW(L"\n", stdout) == -1 )
return -1;
rc++;
return rc;
}
-#endif // wxNEED_PUTS
+#endif // !wxCRT_PutsW
-#ifdef wxNEED_PUTC
-int /* not wint_t */ wxPutc(wchar_t wc, FILE *stream)
+#ifndef wxCRT_FputcW
+int /* not wint_t */ wxCRT_FputcW(wchar_t wc, FILE *stream)
{
wchar_t ws[2] = { wc, L'\0' };
- return wxFputs(ws, stream);
+ return wxCRT_FputsW(ws, stream);
}
-#endif // wxNEED_PUTC
+#endif // !wxCRT_FputcW
// NB: we only implement va_list functions here, the ones taking ... are
// defined below for wxNEED_PRINTF_CONVERSION case anyhow and we reuse
#ifdef wxNEED_WPRINTF
// TODO: implement the scanf() functions
-static int vwscanf(const wxChar *format, va_list argptr)
+static int vwscanf(const wchar_t *format, va_list argptr)
{
wxFAIL_MSG( _T("TODO") );
return -1;
}
-static int vswscanf(const wxChar *ws, const wxChar *format, va_list argptr)
+static int vswscanf(const wchar_t *ws, const wchar_t *format, va_list argptr)
{
// The best we can do without proper Unicode support in glibc is to
// convert the strings into MB representation and run ANSI version
return vsscanf(wxConvLibc.cWX2MB(ws), wxConvLibc.cWX2MB(format), argptr);
}
-static int vfwscanf(FILE *stream, const wxChar *format, va_list argptr)
+static int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr)
{
wxFAIL_MSG( _T("TODO") );
return -1;
}
-#define vswprintf wxVsnprintf_
+#define vswprintf wxCRT_VsnprintfW_
-static int vfwprintf(FILE *stream, const wxChar *format, va_list argptr)
+static int vfwprintf(FILE *stream, const wchar_t *format, va_list argptr)
{
wxString s;
int rc = s.PrintfV(format, argptr);
return rc;
}
-static int vwprintf(const wxChar *format, va_list argptr)
+static int vwprintf(const wchar_t *format, va_list argptr)
{
- return wxVfprintf(stdout, format, argptr);
+ return wxCRT_VfprintfW(stdout, format, argptr);
}
#endif // wxNEED_WPRINTF
// wxPrintf(), wxScanf() and relatives
// ----------------------------------------------------------------------------
-#if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
-
// FIXME-UTF8: do format conversion using (modified) wxFormatConverter in
// template wrappers, not here; note that it will needed to
// translate all forms of string specifiers to %(l)s for wxPrintf(),
// but it only should do what it did in 2.8 for wxScanf()!
-int wxCRT_Printf( const wxChar *format, ... )
+#ifndef wxCRT_PrintfW
+int wxCRT_PrintfW( const wchar_t *format, ... )
{
va_list argptr;
va_start(argptr, format);
return ret;
}
+#endif
-int wxCRT_Fprintf( FILE *stream, const wxChar *format, ... )
+#ifndef wxCRT_FprintfW
+int wxCRT_FprintfW( FILE *stream, const wchar_t *format, ... )
{
va_list argptr;
va_start( argptr, format );
return ret;
}
+#endif
-int wxCRT_Vfprintf( FILE *stream, const wxChar *format, va_list argptr )
+#ifndef wxCRT_VfprintfW
+int wxCRT_VfprintfW( FILE *stream, const wchar_t *format, va_list argptr )
{
return vfwprintf( stream, wxFormatConverter(format), argptr );
}
+#endif
-int wxCRT_Vprintf( const wxChar *format, va_list argptr )
+#ifndef wxCRT_VprintfW
+int wxCRT_VprintfW( const wchar_t *format, va_list argptr )
{
return vwprintf( wxFormatConverter(format), argptr );
}
+#endif
-#ifndef wxCRT_Vsnprintf
-int wxCRT_Vsnprintf( wxChar *str, size_t size, const wxChar *format, va_list argptr )
+#ifndef wxCRT_VsnprintfW
+int wxCRT_VsnprintfW(wchar_t *str, size_t size, const wchar_t *format, va_list argptr )
{
return vswprintf( str, size, wxFormatConverter(format), argptr );
}
-#endif // wxCRT_Vsnprintf
+#endif // !wxCRT_VsnprintfW
-int wxCRT_Vsprintf( wxChar *str, const wxChar *format, va_list argptr )
+// FIXME-UTF8: we only implement widechar version of vsnprintf() in wxprint.cpp,
+// so this one has to convert the data for now
+#ifndef wxCRT_VsnprintfA
+int wxCRT_VsnprintfA(char *buf, size_t len, const char *format, va_list argptr)
+{
+ wxWCharBuffer wbuf(len);
+ int rt = wxCRT_VsnprintfW(wbuf.data(), len,
+ (const wchar_t*)wxConvLibc.cMB2WC(format),
+ argptr);
+ if ( rt < 0 || rt >= len )
+ return rt;
+
+ if ( wxConvLibc.FromWChar(buf, len, wbuf) == wxCONV_FAILED )
+ return -1;
+
+ return rt;
+}
+#endif // !wxCRT_VsnprintfA
+
+#ifndef wxCRT_VsprintfW
+int wxCRT_VsprintfW( wchar_t *str, const wchar_t *format, va_list argptr )
{
// same as for wxSprintf()
return vswprintf(str, INT_MAX / 4, wxFormatConverter(format), argptr);
}
+#endif
+#ifndef wxCRT_ScanfW
int wxCRT_ScanfW(const wchar_t *format, ...)
{
va_list argptr;
return ret;
}
+#endif
+#ifndef wxCRT_SscanfW
int wxCRT_SscanfW(const wchar_t *str, const wchar_t *format, ...)
{
va_list argptr;
return ret;
}
+#endif
+#ifndef wxCRT_FscanfW
int wxCRT_FscanfW(FILE *stream, const wchar_t *format, ...)
{
va_list argptr;
return ret;
}
+#endif
+#ifndef wxCRT_VsscanfW
int wxCRT_VsscanfW(const wchar_t *str, const wchar_t *format, va_list argptr)
{
return vswscanf(str, wxFormatConverter(format), argptr);
}
-
-#endif // wxNEED_PRINTF_CONVERSION
+#endif
// ----------------------------------------------------------------------------
#if wxUSE_UNICODE
return PrintfViaString(str, wxNO_LEN, format, argptr);
#else
- return wxCRT_Vsprintf(str, format, argptr);
+ return wxCRT_VsprintfA(str, format.mb_str(), argptr);
#endif
#endif
}
int wxVsprintf(wchar_t *str, const wxString& format, va_list argptr)
{
#if wxUSE_UNICODE_WCHAR
- return wxCRT_Vsprintf(str, format, argptr);
+ return wxCRT_VsprintfW(str, format.wc_str(), argptr);
#else // wxUSE_UNICODE_UTF8
#if !wxUSE_UTF8_LOCALE_ONLY
if ( !wxLocaleIsUtf8 )
- return wxCRT_Vsprintf(str, format, argptr);
+ return wxCRT_VsprintfW(str, format.wc_str(), argptr);
else
#endif
return PrintfViaString(str, wxNO_LEN, format, argptr);
{
int rv;
#if wxUSE_UTF8_LOCALE_ONLY
- rv = vsnprintf(str, size, format.wx_str(), argptr);
+ rv = wxCRT_VsnprintfA(str, size, format.wx_str(), argptr);
#else
#if wxUSE_UNICODE_UTF8
if ( wxLocaleIsUtf8 )
- rv = vsnprintf(str, size, format.wx_str(), argptr);
+ rv = wxCRT_VsnprintfA(str, size, format.wx_str(), argptr);
else
#endif
#if wxUSE_UNICODE
rv = PrintfViaString(str, size, format, argptr);
}
#else
- rv = wxCRT_Vsnprintf(str, size, format, argptr);
+ rv = wxCRT_VsnprintfA(str, size, format.mb_str(), argptr);
#endif
#endif
int rv;
#if wxUSE_UNICODE_WCHAR
- rv = wxCRT_Vsnprintf(str, size, format, argptr);
+ rv = wxCRT_VsnprintfW(str, size, format.wc_str(), argptr);
#else // wxUSE_UNICODE_UTF8
#if !wxUSE_UTF8_LOCALE_ONLY
if ( !wxLocaleIsUtf8 )
- rv = wxCRT_Vsnprintf(str, size, format, argptr);
+ rv = wxCRT_VsnprintfW(str, size, format.wc_str(), argptr);
else
#endif
{
// ----------------------------------------------------------------------------
#if defined(__WIN32__) && defined(wxNEED_WX_CTYPE_H)
-inline WORD wxMSW_ctype(wxChar ch)
+static inline WORD wxMSW_ctype(wchar_t ch)
{
WORD ret;
GetStringTypeEx(LOCALE_USER_DEFAULT, CT_CTYPE1, &ch, 1, &ret);
return ret;
}
-WXDLLEXPORT int wxIsalnum(wxChar ch) { return IsCharAlphaNumeric(ch); }
-WXDLLEXPORT int wxIsalpha(wxChar ch) { return IsCharAlpha(ch); }
-WXDLLEXPORT int wxIscntrl(wxChar ch) { return wxMSW_ctype(ch) & C1_CNTRL; }
-WXDLLEXPORT int wxIsdigit(wxChar ch) { return wxMSW_ctype(ch) & C1_DIGIT; }
-WXDLLEXPORT int wxIsgraph(wxChar ch) { return wxMSW_ctype(ch) & (C1_DIGIT|C1_PUNCT|C1_ALPHA); }
-WXDLLEXPORT int wxIslower(wxChar ch) { return IsCharLower(ch); }
-WXDLLEXPORT int wxIsprint(wxChar ch) { return wxMSW_ctype(ch) & (C1_DIGIT|C1_SPACE|C1_PUNCT|C1_ALPHA); }
-WXDLLEXPORT int wxIspunct(wxChar ch) { return wxMSW_ctype(ch) & C1_PUNCT; }
-WXDLLEXPORT int wxIsspace(wxChar ch) { return wxMSW_ctype(ch) & C1_SPACE; }
-WXDLLEXPORT int wxIsupper(wxChar ch) { return IsCharUpper(ch); }
-WXDLLEXPORT int wxIsxdigit(wxChar ch) { return wxMSW_ctype(ch) & C1_XDIGIT; }
-WXDLLEXPORT int wxTolower(wxChar ch) { return (wxChar)CharLower((LPTSTR)(ch)); }
-WXDLLEXPORT int wxToupper(wxChar ch) { return (wxChar)CharUpper((LPTSTR)(ch)); }
+int wxCRT_IsalnumW(wchar_t ch) { return IsCharAlphaNumeric(ch); }
+int wxCRT_IsalphaW(wchar_t ch) { return IsCharAlpha(ch); }
+int wxCRT_IscntrlW(wchar_t ch) { return wxMSW_ctype(ch) & C1_CNTRL; }
+int wxCRT_IsdigitW(wchar_t ch) { return wxMSW_ctype(ch) & C1_DIGIT; }
+int wxCRT_IsgraphW(wchar_t ch) { return wxMSW_ctype(ch) & (C1_DIGIT|C1_PUNCT|C1_ALPHA); }
+int wxCRT_IslowerW(wchar_t ch) { return IsCharLower(ch); }
+int wxCRT_IsprintW(wchar_t ch) { return wxMSW_ctype(ch) & (C1_DIGIT|C1_SPACE|C1_PUNCT|C1_ALPHA); }
+int wxCRT_IspunctW(wchar_t ch) { return wxMSW_ctype(ch) & C1_PUNCT; }
+int wxCRT_IsspaceW(wchar_t ch) { return wxMSW_ctype(ch) & C1_SPACE; }
+int wxCRT_IsupperW(wchar_t ch) { return IsCharUpper(ch); }
+int wxCRT_IsxdigitW(wchar_t ch) { return wxMSW_ctype(ch) & C1_XDIGIT; }
+int wxCRT_Tolower(wchar_t ch) { return (wchar_t)CharLower((LPTSTR)(ch)); }
+int wxCRT_Toupper(wchar_t ch) { return (wchar_t)CharUpper((LPTSTR)(ch)); }
#endif
#ifdef wxNEED_WX_MBSTOWCS
#define cfspaceset CFCharacterSetGetPredefined(kCFCharacterSetWhitespaceAndNewline)
#define cfupperset CFCharacterSetGetPredefined(kCFCharacterSetUppercaseLetter)
-WXDLLEXPORT int wxIsalnum(wxChar ch) { return CFCharacterSetIsCharacterMember(cfalnumset, ch); }
-WXDLLEXPORT int wxIsalpha(wxChar ch) { return CFCharacterSetIsCharacterMember(cfalphaset, ch); }
-WXDLLEXPORT int wxIscntrl(wxChar ch) { return CFCharacterSetIsCharacterMember(cfcntrlset, ch); }
-WXDLLEXPORT int wxIsdigit(wxChar ch) { return CFCharacterSetIsCharacterMember(cfdigitset, ch); }
-WXDLLEXPORT int wxIsgraph(wxChar ch) { return !CFCharacterSetIsCharacterMember(cfcntrlset, ch) && ch != ' '; }
-WXDLLEXPORT int wxIslower(wxChar ch) { return CFCharacterSetIsCharacterMember(cflowerset, ch); }
-WXDLLEXPORT int wxIsprint(wxChar ch) { return !CFCharacterSetIsCharacterMember(cfcntrlset, ch); }
-WXDLLEXPORT int wxIspunct(wxChar ch) { return CFCharacterSetIsCharacterMember(cfpunctset, ch); }
-WXDLLEXPORT int wxIsspace(wxChar ch) { return CFCharacterSetIsCharacterMember(cfspaceset, ch); }
-WXDLLEXPORT int wxIsupper(wxChar ch) { return CFCharacterSetIsCharacterMember(cfupperset, ch); }
-WXDLLEXPORT int wxIsxdigit(wxChar ch) { return wxIsdigit(ch) || (ch>='a' && ch<='f') || (ch>='A' && ch<='F'); }
-WXDLLEXPORT int wxTolower(wxChar ch) { return (wxChar)tolower((char)(ch)); }
-WXDLLEXPORT int wxToupper(wxChar ch) { return (wxChar)toupper((char)(ch)); }
+int wxCRT_IsalnumW(wchar_t ch) { return CFCharacterSetIsCharacterMember(cfalnumset, ch); }
+int wxCRT_IsalphaW(wchar_t ch) { return CFCharacterSetIsCharacterMember(cfalphaset, ch); }
+int wxCRT_IscntrlW(wchar_t ch) { return CFCharacterSetIsCharacterMember(cfcntrlset, ch); }
+int wxCRT_IsdigitW(wchar_t ch) { return CFCharacterSetIsCharacterMember(cfdigitset, ch); }
+int wxCRT_IsgraphW(wchar_t ch) { return !CFCharacterSetIsCharacterMember(cfcntrlset, ch) && ch != ' '; }
+int wxCRT_IslowerW(wchar_t ch) { return CFCharacterSetIsCharacterMember(cflowerset, ch); }
+int wxCRT_IsprintW(wchar_t ch) { return !CFCharacterSetIsCharacterMember(cfcntrlset, ch); }
+int wxCRT_IspunctW(wchar_t ch) { return CFCharacterSetIsCharacterMember(cfpunctset, ch); }
+int wxCRT_IsspaceW(wchar_t ch) { return CFCharacterSetIsCharacterMember(cfspaceset, ch); }
+int wxCRT_IsupperW(wchar_t ch) { return CFCharacterSetIsCharacterMember(cfupperset, ch); }
+int wxCRT_IsxdigitW(wchar_t ch) { return wxCRT_IsdigitW(ch) || (ch>='a' && ch<='f') || (ch>='A' && ch<='F'); }
+
+// FIXME: these are broken!
+extern "C" int wxCRT_TolowerW(wchar_t ch) { return (wchar_t)tolower((char)(ch)); }
+extern "C" int wxCRT_ToupperW(wchar_t ch) { return (wchar_t)toupper((char)(ch)); }
#endif // wxNEED_WX_CTYPE_H
-#ifndef wxStrdupA
-
-WXDLLEXPORT char *wxStrdupA(const char *s)
+#ifndef wxCRT_StrdupA
+WXDLLEXPORT char *wxCRT_StrdupA(const char *s)
{
return strcpy((char *)malloc(strlen(s) + 1), s);
}
+#endif // wxCRT_StrdupA
-#endif // wxStrdupA
-
-#ifndef wxStrdupW
-
-WXDLLEXPORT wchar_t * wxStrdupW(const wchar_t *pwz)
+#ifndef wxCRT_StrdupW
+WXDLLEXPORT wchar_t * wxCRT_StrdupW(const wchar_t *pwz)
{
size_t size = (wxWcslen(pwz) + 1) * sizeof(wchar_t);
wchar_t *ret = (wchar_t *) malloc(size);
memcpy(ret, pwz, size);
return ret;
}
+#endif // wxCRT_StrdupW
-#endif // wxStrdupW
+#ifndef wxCRT_StricmpA
+int WXDLLEXPORT wxCRT_StricmpA(const char *psz1, const char *psz2)
+{
+ register char c1, c2;
+ do {
+ c1 = wxTolower(*psz1++);
+ c2 = wxTolower(*psz2++);
+ } while ( c1 && (c1 == c2) );
+ return c1 - c2;
+}
+#endif // !defined(wxCRT_StricmpA)
-#ifndef wxStricmp
-int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2)
+#ifndef wxCRT_StricmpW
+int WXDLLEXPORT wxCRT_StricmpW(const wchar_t *psz1, const wchar_t *psz2)
{
- register wxChar c1, c2;
+ register wchar_t c1, c2;
do {
c1 = wxTolower(*psz1++);
c2 = wxTolower(*psz2++);
} while ( c1 && (c1 == c2) );
return c1 - c2;
}
-#endif
+#endif // !defined(wxCRT_StricmpW)
-#ifndef wxStricmp
-int WXDLLEXPORT wxStrnicmp(const wxChar *s1, const wxChar *s2, size_t n)
+#ifndef wxCRT_StrnicmpA
+int WXDLLEXPORT wxCRT_StrnicmpA(const char *s1, const char *s2, size_t n)
{
// initialize the variables just to suppress stupid gcc warning
- register wxChar c1 = 0, c2 = 0;
+ register char c1 = 0, c2 = 0;
while (n && ((c1 = wxTolower(*s1)) == (c2 = wxTolower(*s2)) ) && c1) n--, s1++, s2++;
if (n) {
if (c1 < c2) return -1;
}
return 0;
}
-#endif
-
-#ifndef wxSetlocale_
-wxWCharBuffer wxSetlocale_(int category, const wxChar *locale)
-{
- char *localeOld = setlocale(category, wxConvLibc.cWX2MB(locale));
-
- return wxWCharBuffer(wxConvLibc.cMB2WC(localeOld));
-}
+#endif // !defined(wxCRT_StrnicmpA)
-wxWCharBuffer wxSetlocale(int category, const wxChar *locale)
+#ifndef wxCRT_StrnicmpW
+int WXDLLEXPORT wxCRT_StrnicmpW(const wchar_t *s1, const wchar_t *s2, size_t n)
{
- wxWCharBuffer rv = wxSetlocale_(category, locale);
- if ( rv )
- wxUpdateLocaleIsUtf8();
- return rv;
-}
-#else // defined(wxSetlocale_)
-wxChar *wxSetlocale(int category, const wxChar *locale)
-{
- wxChar *rv = wxSetlocale_(category, locale);
- if ( rv )
- wxUpdateLocaleIsUtf8();
- return rv;
-}
-#endif // wxSetlocale_ defined or not
-
-#if wxUSE_WCHAR_T && !defined(HAVE_WCSLEN)
-WXDLLEXPORT size_t wxWcslen(const wchar_t *s)
-{
- size_t n = 0;
- while ( *s++ )
- n++;
-
- return n;
+ // initialize the variables just to suppress stupid gcc warning
+ register wchar_t c1 = 0, c2 = 0;
+ while (n && ((c1 = wxTolower(*s1)) == (c2 = wxTolower(*s2)) ) && c1) n--, s1++, s2++;
+ if (n) {
+ if (c1 < c2) return -1;
+ if (c1 > c2) return 1;
+ }
+ return 0;
}
-#endif
+#endif // !defined(wxCRT_StrnicmpW)
// ----------------------------------------------------------------------------
// string.h functions
// ----------------------------------------------------------------------------
-#ifdef wxNEED_WX_STRING_H
-
-// RN: These need to be c externed for the regex lib
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src)
+#ifndef wxCRT_StrcatW
+WXDLLEXPORT wchar_t *wxCRT_StrcatW(wchar_t *dest, const wchar_t *src)
{
- wxChar *ret = dest;
+ wchar_t *ret = dest;
while (*dest) dest++;
while ((*dest++ = *src++));
return ret;
}
+#endif
-WXDLLEXPORT const wxChar * wxStrchr(const wxChar *s, wxChar c)
+#ifndef wxCRT_StrchrW
+WXDLLEXPORT const wchar_t *wxCRT_StrchrW(const wchar_t *s, wchar_t c)
{
// be careful here as the terminating NUL makes part of the string
while ( *s != c )
return s;
}
+#endif
-WXDLLEXPORT int wxStrcmp(const wxChar *s1, const wxChar *s2)
+#ifndef wxCRT_StrcmpW
+WXDLLEXPORT int wxCRT_StrcmpW(const wchar_t *s1, const wchar_t *s2)
{
while ((*s1 == *s2) && *s1) s1++, s2++;
if ((wxUChar)*s1 < (wxUChar)*s2) return -1;
if ((wxUChar)*s1 > (wxUChar)*s2) return 1;
return 0;
}
+#endif
-WXDLLEXPORT wxChar * wxStrcpy(wxChar *dest, const wxChar *src)
+#ifndef wxCRT_StrcpyW
+WXDLLEXPORT wchar_t * wxCRT_StrcpyW(wchar_t *dest, const wchar_t *src)
{
- wxChar *ret = dest;
+ wchar_t *ret = dest;
while ((*dest++ = *src++));
return ret;
}
+#endif
-WXDLLEXPORT size_t wxStrlen_(const wxChar *s)
+template<typename T>
+static inline size_t wxCRT_DoStrlen(const T *s)
{
size_t n = 0;
while ( *s++ )
return n;
}
+// these two (and wxCRT_StrncmpW below) are extern "C" because they are needed
+// by regex code, the rest isn't needed, so it's not declared as extern "C"
+#ifndef wxCRT_StrlenA
+WXDLLEXPORT size_t wxCRT_StrlenA(const char *s)
+ { return wxCRT_DoStrlen(s); }
+#endif
+#ifndef wxCRT_StrlenW
+extern "C" WXDLLEXPORT size_t wxCRT_StrlenW(const wchar_t *s)
+ { return wxCRT_DoStrlen(s); }
+#endif
-WXDLLEXPORT wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n)
+#ifndef wxCRT_StrncatW
+WXDLLEXPORT wchar_t * wxCRT_StrncatW(wchar_t *dest, const wchar_t *src, size_t n)
{
- wxChar *ret = dest;
+ wchar_t *ret = dest;
while (*dest) dest++;
while (n && (*dest++ = *src++)) n--;
return ret;
}
+#endif
-WXDLLEXPORT int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n)
+#ifndef wxCRT_StrncmpW
+extern "C"
+WXDLLEXPORT int wxCRT_StrncmpW(const wchar_t *s1, const wchar_t *s2, size_t n)
{
while (n && (*s1 == *s2) && *s1) n--, s1++, s2++;
if (n) {
}
return 0;
}
+#endif
-WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n)
+#ifndef wxCRT_StrncpyW
+WXDLLEXPORT wchar_t * wxCRT_StrncpyW(wchar_t *dest, const wchar_t *src, size_t n)
{
- wxChar *ret = dest;
+ wchar_t *ret = dest;
while (n && (*dest++ = *src++)) n--;
while (n) *dest++=0, n--; // the docs specify padding with zeroes
return ret;
}
+#endif
-WXDLLEXPORT const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept)
+#ifndef wxCRT_StrpbrkW
+WXDLLEXPORT const wchar_t * wxCRT_StrpbrkW(const wchar_t *s, const wchar_t *accept)
{
- while (*s && !wxStrchr(accept, *s))
+ while (*s && !wxCRT_Strchr(accept, *s))
s++;
return *s ? s : NULL;
}
+#endif
-WXDLLEXPORT const wxChar * wxStrrchr(const wxChar *s, wxChar c)
+#ifndef wxCRT_StrrchrW
+WXDLLEXPORT const wchar_t * wxCRT_StrrchrW(const wchar_t *s, wchar_t c)
{
- const wxChar *ret = NULL;
+ const wchar_t *ret = NULL;
do
{
if ( *s == c )
return ret;
}
+#endif
-WXDLLEXPORT size_t wxStrspn(const wxChar *s, const wxChar *accept)
+#ifndef wxCRT_StrspnW
+WXDLLEXPORT size_t wxCRT_StrspnW(const wchar_t *s, const wchar_t *accept)
{
size_t len = 0;
- while (wxStrchr(accept, *s++)) len++;
+ while (wxCRT_Strchr(accept, *s++)) len++;
return len;
}
+#endif
-WXDLLEXPORT const wxChar *wxStrstr(const wxChar *haystack, const wxChar *needle)
+#ifndef wxCRT_StrstrW
+WXDLLEXPORT const wchar_t *wxCRT_StrstrW(const wchar_t *haystack, const wchar_t *needle)
{
- wxASSERT_MSG( needle != NULL, _T("NULL argument in wxStrstr") );
+ wxASSERT_MSG( needle != NULL, _T("NULL argument in wxCRT_Strstr") );
// VZ: this is not exactly the most efficient string search algorithm...
const size_t len = wxStrlen(needle);
- while ( const wxChar *fnd = wxStrchr(haystack, *needle) )
+ while ( const wchar_t *fnd = wxCRT_Strchr(haystack, *needle) )
{
- if ( !wxStrncmp(fnd, needle, len) )
+ if ( !wxCRT_Strncmp(fnd, needle, len) )
return fnd;
haystack = fnd + 1;
return NULL;
}
-
-#ifdef __cplusplus
-}
#endif
-WXDLLEXPORT double wxStrtod(const wxChar *nptr, wxChar **endptr)
+#ifndef wxCRT_StrtodW
+WXDLLEXPORT double wxCRT_StrtodW(const wchar_t *nptr, wchar_t **endptr)
{
- const wxChar *start = nptr;
+ const wchar_t *start = nptr;
// FIXME: only correct for C locale
while (wxIsspace(*nptr)) nptr++;
char *rdat = wxMBSTRINGCAST dat;
double ret = strtod(dat, &rdat);
- if (endptr) *endptr = (wxChar *)(start + (rdat - (const char *)dat));
+ if (endptr) *endptr = (wchar_t *)(start + (rdat - (const char *)dat));
return ret;
}
+#endif // !wxCRT_StrtodW
-WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base)
+#ifndef wxCRT_StrtolW
+WXDLLEXPORT long int wxCRT_StrtolW(const wchar_t *nptr, wchar_t **endptr, int base)
{
- const wxChar *start = nptr;
+ const wchar_t *start = nptr;
// FIXME: only correct for C locale
while (wxIsspace(*nptr)) nptr++;
char *rdat = wxMBSTRINGCAST dat;
long int ret = strtol(dat, &rdat, base);
- if (endptr) *endptr = (wxChar *)(start + (rdat - (const char *)dat));
+ if (endptr) *endptr = (wchar_t *)(start + (rdat - (const char *)dat));
return ret;
}
+#endif // !wxCRT_StrtolW
-WXDLLEXPORT unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base)
-{
- return (unsigned long int) wxStrtol(nptr, endptr, base);
-}
-
-#endif // wxNEED_WX_STRING_H
-
-#ifdef wxNEED_WX_STDIO_H
-WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode)
-{
- char mode_buffer[10];
- for (size_t i = 0; i < wxStrlen(mode)+1; i++)
- mode_buffer[i] = (char) mode[i];
-
- return fopen( wxConvFile.cWX2MB(path), mode_buffer );
-}
-
-WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream)
+#ifndef wxCRT_StrtoulW
+WXDLLEXPORT unsigned long int wxCRT_StrtoulW(const wchar_t *nptr, wchar_t **endptr, int base)
{
- char mode_buffer[10];
- for (size_t i = 0; i < wxStrlen(mode)+1; i++)
- mode_buffer[i] = (char) mode[i];
-
- return freopen( wxConvFile.cWX2MB(path), mode_buffer, stream );
-}
-
-WXDLLEXPORT int wxRemove(const wxChar *path)
-{
- return remove( wxConvFile.cWX2MB(path) );
-}
-
-WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath)
-{
- return rename( wxConvFile.cWX2MB(oldpath), wxConvFile.cWX2MB(newpath) );
+ return (unsigned long int) wxCRT_StrtolW(nptr, endptr, base);
}
#endif
-#ifndef wxAtof
-double WXDLLEXPORT wxAtof(const wxChar *psz)
-{
-#ifdef __WXWINCE__
- double d;
- wxString str(psz);
- if (str.ToDouble(& d))
- return d;
- return 0.0;
-#else
- return atof(wxConvLibc.cWX2MB(psz));
-#endif
-}
-#endif
-#ifdef wxNEED_WX_STDLIB_H
-int WXDLLEXPORT wxAtoi(const wxChar *psz)
+#ifndef wxCRT_GetenvW
+wchar_t* WXDLLEXPORT wxCRT_GetenvW(const wchar_t *name)
{
- return atoi(wxConvLibc.cWX2MB(psz));
-}
-
-long WXDLLEXPORT wxAtol(const wxChar *psz)
-{
- return atol(wxConvLibc.cWX2MB(psz));
-}
-
-wxChar * WXDLLEXPORT wxGetenv(const wxChar *name)
-{
-#if wxUSE_UNICODE
// NB: buffer returned by getenv() is allowed to be overwritten next
// time getenv() is called, so it is OK to use static string
// buffer to hold the data.
static wxWCharBuffer value((wxChar*)NULL);
value = wxConvLibc.cMB2WX(getenv(wxConvLibc.cWX2MB(name)));
return value.data();
-#else
- return getenv(name);
-#endif
-}
-
-#endif // wxNEED_WX_STDLIB_H
-
-#ifdef wxNEED_WXSYSTEM
-int WXDLLEXPORT wxSystem(const wxChar *psz)
-{
- return system(wxConvLibc.cWX2MB(psz));
}
-#endif // wxNEED_WXSYSTEM
+#endif // !wxCRT_GetenvW
-#ifdef wxNEED_WX_TIME_H
+#ifndef wxCRT_StrftimeW
WXDLLEXPORT size_t
-wxStrftime(wxChar *s, size_t maxsize, const wxChar *fmt, const struct tm *tm)
+wxCRT_StrftimeW(wchar_t *s, size_t maxsize, const wchar_t *fmt, const struct tm *tm)
{
if ( !maxsize )
return 0;
if ( !wbuf )
return 0;
- wxStrncpy(s, wbuf, maxsize);
- return wxStrlen(s);
-}
-#endif // wxNEED_WX_TIME_H
-
-#ifndef wxCtime
-WXDLLEXPORT wxChar *wxCtime(const time_t *timep)
-{
- // normally the string is 26 chars but give one more in case some broken
- // DOS compiler decides to use "\r\n" instead of "\n" at the end
- static wxChar buf[27];
-
- // ctime() is guaranteed to return a string containing only ASCII
- // characters, as its format is always the same for any locale
- wxStrncpy(buf, wxString::FromAscii(ctime(timep)), WXSIZEOF(buf));
- buf[WXSIZEOF(buf) - 1] = _T('\0');
-
- return buf;
+ wxCRT_StrncpyW(s, wbuf, maxsize);
+ return wxCRT_StrlenW(s);
}
-#endif // wxCtime
+#endif // !wxCRT_StrftimeW
#endif // wxUSE_WCHAR_T
-#ifndef wxStrtoll
-static wxULongLong_t wxStrtoullBase(const wxChar* nptr, wxChar** endptr, int base, wxChar* sign)
+template<typename T>
+static wxULongLong_t
+wxCRT_StrtoullBase(const T* nptr, T** endptr, int base, T* sign)
{
wxULongLong_t sum = 0;
wxString wxstr(nptr);
*sign = wxT(' ');
if ( i != end )
{
- wxChar c = *i;
+ T c = *i;
if ( c == wxT('+') || c == wxT('-') )
{
*sign = c;
else
{
if ( endptr )
- *endptr = (wxChar*) nptr;
+ *endptr = (T*) nptr;
wxSET_ERRNO(EINVAL);
return sum;
}
{
unsigned int n;
- wxChar c = *i;
+ T c = *i;
if ( c >= wxT('0') )
{
if ( c <= wxT('9') )
if ( endptr )
{
- *endptr = (wxChar*)(nptr + (i - wxstr.begin()));
+ *endptr = (T*)(nptr + (i - wxstr.begin()));
}
return sum;
}
-wxULongLong_t wxStrtoull(const wxChar* nptr, wxChar** endptr, int base)
+template<typename T>
+static wxULongLong_t wxCRT_DoStrtoull(const T* nptr, T** endptr, int base)
{
- wxChar sign;
- wxULongLong_t uval = wxStrtoullBase(nptr, endptr, base, &sign);
+ T sign;
+ wxULongLong_t uval = wxCRT_StrtoullBase(nptr, endptr, base, &sign);
if ( sign == wxT('-') )
{
return uval;
}
-wxLongLong_t wxStrtoll(const wxChar* nptr, wxChar** endptr, int base)
+template<typename T>
+static wxLongLong_t wxCRT_DoStrtoll(const T* nptr, T** endptr, int base)
{
- wxChar sign;
- wxULongLong_t uval = wxStrtoullBase(nptr, endptr, base, &sign);
+ T sign;
+ wxULongLong_t uval = wxCRT_StrtoullBase(nptr, endptr, base, &sign);
wxLongLong_t val = 0;
if ( sign == wxT('-') )
return val;
}
-#endif // wxStrtoll
+
+#ifndef wxCRT_StrtollA
+wxLongLong_t wxCRT_StrtollA(const char* nptr, char** endptr, int base)
+ { return wxCRT_DoStrtoll(nptr, endptr, base); }
+#endif
+#ifndef wxCRT_StrtollW
+wxLongLong_t wxCRT_StrtollW(const wchar_t* nptr, wchar_t** endptr, int base)
+ { return wxCRT_DoStrtoll(nptr, endptr, base); }
+#endif
+
+#ifndef wxCRT_StrtoullA
+wxULongLong_t wxCRT_StrtoullA(const char* nptr, char** endptr, int base)
+ { return wxCRT_DoStrtoull(nptr, endptr, base); }
+#endif
+#ifndef wxCRT_StrtoullW
+wxULongLong_t wxCRT_StrtoullW(const wchar_t* nptr, wchar_t** endptr, int base)
+ { return wxCRT_DoStrtoull(nptr, endptr, base); }
+#endif
// ----------------------------------------------------------------------------
// functions which we may need even if !wxUSE_WCHAR_T
// ----------------------------------------------------------------------------
-#ifndef wxStrtok
-
-WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr)
+template<typename T>
+static T *wxCRT_DoStrtok(T *psz, const T *delim, T **save_ptr)
{
if (!psz)
{
psz += wxStrspn(psz, delim);
if (!*psz)
{
- *save_ptr = (wxChar *)NULL;
- return (wxChar *)NULL;
+ *save_ptr = (T *)NULL;
+ return (T *)NULL;
}
- wxChar *ret = psz;
+ T *ret = psz;
psz = wxStrpbrk(psz, delim);
if (!psz)
{
- *save_ptr = (wxChar*)NULL;
+ *save_ptr = (T*)NULL;
}
else
{
return ret;
}
-#endif // wxStrtok
+#ifndef wxCRT_StrtokA
+char *wxCRT_StrtokA(char *psz, const char *delim, char **save_ptr)
+ { return wxCRT_DoStrtok(psz, delim, save_ptr); }
+#endif
+#ifndef wxCRT_StrtokW
+wchar_t *wxCRT_StrtokW(wchar_t *psz, const wchar_t *delim, wchar_t **save_ptr)
+ { return wxCRT_DoStrtok(psz, delim, save_ptr); }
+#endif
// ----------------------------------------------------------------------------
// missing C RTL functions
#endif // __WXWINCE__ <= 211
#ifdef __WXWINCE__
-
-int wxRemove(const wxChar *path)
+int wxCRT_RemoveW(const wchar_t *path)
{
return ::DeleteFile(path) == 0;
}
+#endif
+
+#ifndef wxCRT_TmpnamW
+wchar_t *wxCRT_TmpnamW(wchar_t *s)
+{
+ // tmpnam_r() returns NULL if s=NULL, do the same
+ wxCHECK_MSG( s, NULL, "wxTmpnam must be called with a buffer" );
+#ifndef L_tmpnam
+ #define L_tmpnam 1024
#endif
+ wxCharBuffer buf(L_tmpnam);
+ tmpnam(buf.data());
+
+ wxConvLibc.ToWChar(s, L_tmpnam+1, buf.data());
+ return s;
+}
+#endif // !wxCRT_TmpnamW
-// ----------------------------------------------------------------------------
+// ============================================================================
// wxLocaleIsUtf8
-// ----------------------------------------------------------------------------
+// ============================================================================
#if wxUSE_UNICODE_UTF8
// wx wrappers for CRT functions
// ============================================================================
+#if wxUSE_UNICODE_WCHAR
+ #define CALL_ANSI_OR_UNICODE(callA, callW) return callW
+#elif wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY
+ #define CALL_ANSI_OR_UNICODE(callA, callW) \
+ return wxLocaleIsUtf8 ? callA : callW
+#else // ANSI or UTF8 only
+ #define CALL_ANSI_OR_UNICODE(callA, callW) return callA
+#endif
+
+int wxPuts(const wxString& s)
+{
+ CALL_ANSI_OR_UNICODE(wxCRT_PutsA(s.mb_str()),
+ wxCRT_PutsW(s.wc_str()));
+}
+
+int wxFputs(const wxString& s, FILE *stream)
+{
+ CALL_ANSI_OR_UNICODE(wxCRT_FputsA(s.mb_str(), stream),
+ wxCRT_FputsW(s.wc_str(), stream));
+}
+
+int wxFputc(const wxUniChar& c, FILE *stream)
+{
+#if !wxUSE_UNICODE // FIXME-UTF8: temporary, remove this with ANSI build
+ return wxCRT_FputcA((char)c, stream);
+#else
+ CALL_ANSI_OR_UNICODE(wxCRT_FputsA(c.AsUTF8(), stream),
+ wxCRT_FputcW((wchar_t)c, stream));
+#endif
+}
+
+void wxPerror(const wxString& s)
+{
+#ifdef wxCRT_PerrorW
+ CALL_ANSI_OR_UNICODE(wxCRT_PerrorA(s.mb_str()), wxCRT_PerrorW(s.wc_str()));
+#else
+ wxCRT_PerrorA(s.mb_str());
+#endif
+}
+
+wchar_t *wxFgets(wchar_t *s, int size, FILE *stream)
+{
+ wxCHECK_MSG( s, NULL, "empty buffer passed to wxFgets()" );
+
+ wxCharBuffer buf(size - 1);
+ // FIXME: this reads too little data if wxConvLibc uses UTF-8 ('size' wide
+ // characters may be encoded by up to 'size'*4 bytes), but what
+ // else can we do?
+ if ( wxFgets(buf.data(), size, stream) == NULL )
+ return NULL;
+
+ if ( wxConvLibc.ToWChar(s, size, buf, wxNO_LEN) == wxCONV_FAILED )
+ return NULL;
+
+ return s;
+}
// ----------------------------------------------------------------------------
// wxScanf() and friends
// special test mode: define all functions below even if we don't really need
// them to be able to test them
#ifdef wxTEST_PRINTF
- #undef wxVsnprintf_
+ #undef wxCRT_VsnprintfW_
#endif
// ----------------------------------------------------------------------------
// (very useful for i18n purposes)
// ----------------------------------------------------------------------------
-#if !defined(wxVsnprintf_)
+#if !defined(wxCRT_VsnprintfW_)
-#if !wxUSE_WXVSNPRINTF
- #error wxUSE_WXVSNPRINTF must be 1 if our wxVsnprintf_ is used
+#if !wxUSE_WXVSNPRINTFW
+ #error "wxUSE_WXVSNPRINTFW must be 1 if our wxCRT_VsnprintfW_ is used"
#endif
-// wxUSE_STRUTILS says our wxVsnprintf_ implementation to use or not to
+// wxUSE_STRUTILS says our wxCRT_VsnprintfW_ implementation to use or not to
// use wxStrlen and wxStrncpy functions over one-char processing loops.
//
// Some benchmarking revealed that wxUSE_STRUTILS == 1 has the following
#define SYSTEM_SPRINTF_IS_UNSAFE
#endif
-// the conversion specifiers accepted by wxVsnprintf_
+// the conversion specifiers accepted by wxCRT_VsnprintfW_
enum wxPrintfArgType {
wxPAT_INVALID = -1,
wxPAT_NLONGINT // %ln
};
-// an argument passed to wxVsnprintf_
+// an argument passed to wxCRT_VsnprintfW_
typedef union {
int pad_int; // %d, %i, %o, %u, %x, %X
long int pad_longint; // %ld, etc
// Contains parsed data relative to a conversion specifier given to
-// wxVsnprintf_ and parsed from the format string
+// wxCRT_VsnprintfW_ and parsed from the format string
// NOTE: in C++ there is almost no difference between struct & classes thus
// there is no performance gain by using a struct here...
class wxPrintfConvSpec
// pointer to the '%' of this conversion specifier in the format string
// NOTE: this points somewhere in the string given to the Parse() function -
// it's task of the caller ensure that memory is still valid !
- const wxChar *m_pArgPos;
+ const wchar_t *m_pArgPos;
// pointer to the last character of this conversion specifier in the
// format string
// NOTE: this points somewhere in the string given to the Parse() function -
// it's task of the caller ensure that memory is still valid !
- const wxChar *m_pArgEnd;
+ const wchar_t *m_pArgEnd;
// a little buffer where formatting flags like #+\.hlqLZ are stored by Parse()
// for use in Process()
// NB: even if this buffer is used only for numeric conversion specifiers and
- // thus could be safely declared as a char[] buffer, we want it to be wxChar
+ // thus could be safely declared as a char[] buffer, we want it to be wchar_t
// so that in Unicode builds we can avoid to convert its contents to Unicode
// chars when copying it in user's buffer.
char m_szFlags[wxMAX_SVNPRINTF_FLAGBUFFER_LEN];
public:
// we don't declare this as a constructor otherwise it would be called
- // automatically and we don't want this: to be optimized, wxVsnprintf_
+ // automatically and we don't want this: to be optimized, wxCRT_VsnprintfW_
// calls this function only on really-used instances of this class.
void Init();
// Parses the first conversion specifier in the given string, which must
// begin with a '%'. Returns false if the first '%' does not introduce a
// (valid) conversion specifier and thus should be ignored.
- bool Parse(const wxChar *format);
+ bool Parse(const wchar_t *format);
// Process this conversion specifier and puts the result in the given
// buffer. Returns the number of characters written in 'buf' or -1 if
// there's not enough space.
- int Process(wxChar *buf, size_t lenMax, wxPrintfArg *p, size_t written);
+ int Process(wchar_t *buf, size_t lenMax, wxPrintfArg *p, size_t written);
// Loads the argument of this conversion specifier from given va_list.
bool LoadArg(wxPrintfArg *p, va_list &argptr);
m_szFlags[0] = '%';
}
-bool wxPrintfConvSpec::Parse(const wxChar *format)
+bool wxPrintfConvSpec::Parse(const wchar_t *format)
{
bool done = false;
}
// what follows '%'?
- const wxChar ch = *(++m_pArgEnd);
+ const wchar_t ch = *(++m_pArgEnd);
switch ( ch )
{
case wxT('\0'):
return true; // loading was successful
}
-int wxPrintfConvSpec::Process(wxChar *buf, size_t lenMax, wxPrintfArg *p, size_t written)
+int wxPrintfConvSpec::Process(wchar_t *buf, size_t lenMax, wxPrintfArg *p, size_t written)
{
// buffer to avoid dynamic memory allocation each time for small strings;
// note that this buffer is used only to hold results of number formatting,
case wxPAT_CHAR:
case wxPAT_WCHAR:
{
- wxChar val =
+ wchar_t val =
#if wxUSE_UNICODE
p->pad_wchar;
// conversion, but we can optimise by making use of the fact
// that we are formatting numbers, this should mean only 7-bit
// ascii characters are involved.
- wxChar *bufptr = buf;
- const wxChar *bufend = buf + lenMax;
+ wchar_t *bufptr = buf;
+ const wchar_t *bufend = buf + lenMax;
const char *scratchptr = szScratch;
- // Simply copy each char to a wxChar, stopping on the first
+ // Simply copy each char to a wchar_t, stopping on the first
// null or non-ascii byte. Checking '(signed char)*scratchptr
// > 0' is an extra optimisation over '*scratchptr != 0 &&
// isascii(*scratchptr)', though it assumes signed char is
//
static int wxCopyStrWithPercents(
size_t maxOut,
- wxChar *dest,
+ wchar_t *dest,
size_t maxIn,
- const wxChar *source)
+ const wchar_t *source)
{
size_t written = 0;
return written;
}
-int WXDLLEXPORT wxVsnprintf_(wxChar *buf, size_t lenMax,
- const wxChar *format, va_list argptr)
+int WXDLLEXPORT wxCRT_VsnprintfW_(wchar_t *buf, size_t lenMax,
+ const wchar_t *format, va_list argptr)
{
// useful for debugging, to understand if we are really using this function
// rather than the system implementation
#if 0
- wprintf(L"Using wxVsnprintf_\n");
+ wprintf(L"Using wxCRT_VsnprintfW_\n");
#endif
// required memory:
size_t lenCur = 0;
size_t nargs = 0;
- const wxChar *toparse = format;
+ const wchar_t *toparse = format;
// parse the format string
bool posarg_present = false, nonposarg_present = false;
#undef APPEND_CH
#undef CHECK_PREC
-#else // wxVsnprintf_ is defined
+#else // wxCRT_VsnprintfW_ is defined
-#if wxUSE_WXVSNPRINTF
- #error wxUSE_WXVSNPRINTF must be 0 if our wxVsnprintf_ is not used
+#if wxUSE_WXVSNPRINTFW
+ #error "wxUSE_WXVSNPRINTFW must be 0 if our wxCRT_VsnprintfW_ is not used"
#endif
-#endif // !wxVsnprintf_
+#endif // !wxCRT_VsnprintfW_
argv = new wxChar *[argc + 1];
for ( int i = 0; i < argc; i++ )
{
- argv[i] = wxStrdup(args[i]);
+ argv[i] = wxStrdup(args[i].wx_str());
}
// argv[] must be NULL-terminated
#if wxUSE_BASE
-WXDLLIMPEXP_BASE int wxMSLU__trename(const wxChar *oldname,
- const wxChar *newname)
+WXDLLIMPEXP_BASE int wxMSLU__wrename(const wchar_t *oldname,
+ const wchar_t *newname)
{
if ( wxUsingUnicowsDll() )
return rename(wxConvFile.cWX2MB(oldname), wxConvFile.cWX2MB(newname));
else
- return _trename(oldname, newname);
+ return _wrename(oldname, newname);
}
-WXDLLIMPEXP_BASE int wxMSLU__tremove(const wxChar *name)
+WXDLLIMPEXP_BASE int wxMSLU__wremove(const wchar_t *name)
{
if ( wxUsingUnicowsDll() )
return remove(wxConvFile.cWX2MB(name));
else
- return _tremove(name);
+ return _wremove(name);
}
-WXDLLIMPEXP_BASE FILE* wxMSLU__tfopen(const wxChar *name,const wxChar* mode)
+WXDLLIMPEXP_BASE FILE* wxMSLU__wfopen(const wchar_t *name,const wchar_t* mode)
{
if ( wxUsingUnicowsDll() )
return fopen(wxConvFile.cWX2MB(name),wxConvFile.cWX2MB(mode));
else
- return _tfopen(name,mode);
+ return _wfopen(name,mode);
+}
+
+WXDLLIMPEXP_BASE FILE* wxMSLU__wfreopen(const wchar_t *name,
+ const wchar_t* mode,
+ FILE *stream)
+{
+ if ( wxUsingUnicowsDll() )
+ return freopen(wxConvFile.cWX2MB(name), wxConvFile.cWX2MB(mode), stream);
+ else
+ return _wfreopen(name, mode, stream);
}
#if defined( __VISUALC__ ) \
|| ( defined(__MWERKS__) && defined(__WXMSW__) ) \
|| ( defined(__BORLANDC__) && (__BORLANDC__ > 0x460) )
-WXDLLIMPEXP_BASE int wxMSLU__wopen(const wxChar *name, int flags, int mode)
+WXDLLIMPEXP_BASE int wxMSLU__wopen(const wchar_t *name, int flags, int mode)
{
if ( wxUsingUnicowsDll() )
#ifdef __BORLANDC__
return _wopen(name, flags, mode);
}
-WXDLLIMPEXP_BASE int wxMSLU__waccess(const wxChar *name, int mode)
+WXDLLIMPEXP_BASE int wxMSLU__waccess(const wchar_t *name, int mode)
{
if ( wxUsingUnicowsDll() )
return _access(wxConvFile.cWX2MB(name), mode);
return _waccess(name, mode);
}
-WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wxChar *name)
+WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wchar_t *name)
{
if ( wxUsingUnicowsDll() )
return _mkdir(wxConvFile.cWX2MB(name));
return _wmkdir(name);
}
-WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wxChar *name)
+WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wchar_t *name)
{
if ( wxUsingUnicowsDll() )
return _rmdir(wxConvFile.cWX2MB(name));
return _wrmdir(name);
}
-WXDLLIMPEXP_BASE int wxMSLU__wstat(const wxChar *name, struct _stat *buffer)
+WXDLLIMPEXP_BASE int wxMSLU__wstat(const wchar_t *name, struct _stat *buffer)
{
if ( wxUsingUnicowsDll() )
return _stat((const char*)wxConvFile.cWX2MB(name), buffer);
#ifdef __BORLANDC__
//here _stati64 is defined as stati64, see wx/filefn.h
#undef _stati64
-WXDLLIMPEXP_BASE int wxMSLU__wstati64(const wxChar *name, struct _stati64 *buffer)
+WXDLLIMPEXP_BASE int wxMSLU__wstati64(const wchar_t *name, struct _stati64 *buffer)
{
if ( wxUsingUnicowsDll() )
return _stati64((const char*)wxConvFile.cWX2MB(name), (stati64 *) buffer);
return _wstati64(name, (stati64 *) buffer);
}
#else
-WXDLLIMPEXP_BASE int wxMSLU__wstati64(const wxChar *name, struct _stati64 *buffer)
+WXDLLIMPEXP_BASE int wxMSLU__wstati64(const wchar_t *name, struct _stati64 *buffer)
{
if ( wxUsingUnicowsDll() )
return _stati64((const char*)wxConvFile.cWX2MB(name), buffer);
#ifdef __WXWINCE__
#include "wx/msw/wince/missing.h"
-int wxOpen(const wxChar *filename, int oflag, int WXUNUSED(pmode))
+int wxCRT_Open(const wxChar *filename, int oflag, int WXUNUSED(pmode))
{
DWORD access = 0;
DWORD shareMode = 0;
return fd;
}
-int wxAccess(const wxChar *name, int WXUNUSED(how))
+int wxCRT_Access(const wxChar *name, int WXUNUSED(how))
{
HANDLE fileHandle = ::CreateFile(name, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
// menu creation code
wxMenuItem *item = (wxMenuItem*)mii.dwItemData;
- const wxChar *p = wxStrchr(item->GetText(), _T('&'));
+ const wxChar *p = wxStrchr(item->GetText().wx_str(), _T('&'));
while ( p++ )
{
if ( *p == _T('&') )
*/
#define Tcl_UniChar wxChar
-Tcl_UniChar Tcl_UniCharToUpper(int ch) { return wxToupper(ch); }
-Tcl_UniChar Tcl_UniCharToLower(int ch) { return wxTolower(ch); }
-Tcl_UniChar Tcl_UniCharToTitle(int ch) { return wxToupper(ch); }
+Tcl_UniChar Tcl_UniCharToUpper(int ch) { return wxCRT_ToupperNative(ch); }
+Tcl_UniChar Tcl_UniCharToLower(int ch) { return wxCRT_TolowerNative(ch); }
+Tcl_UniChar Tcl_UniCharToTitle(int ch) { return wxCRT_ToupperNative(ch); }
#endif /* !wxUSE_UNICODE */
/* search table */
for (cn=cnames; cn->name!=NULL; cn++) {
- if (wxStrlen_(cn->name)==len && wxStrncmp(cn->name, startp, len)==0) {
+ if (wxCRT_StrlenNative(cn->name)==len && wxCRT_StrncmpNative(cn->name, startp, len)==0) {
break; /* NOTE BREAK OUT */
}
}
* Remap lower and upper to alpha if the match is case insensitive.
*/
- if (cases && len == 5 && (wxStrncmp(_T("lower"), np, 5) == 0
- || wxStrncmp(_T("upper"), np, 5) == 0)) {
+ if (cases && len == 5 && (wxCRT_StrncmpNative(_T("lower"), np, 5) == 0
+ || wxCRT_StrncmpNative(_T("upper"), np, 5) == 0)) {
np = _T("alpha");
}
index = -1;
for (namePtr=classNames,i=0 ; *namePtr!=NULL ; namePtr++,i++) {
- if ((wxStrlen_(*namePtr) == len) && (wxStrncmp(*namePtr, np, len) == 0)) {
+ if ((wxCRT_StrlenNative(*namePtr) == len) && (wxCRT_StrncmpNative(*namePtr, np, len) == 0)) {
index = i;
break;
}
/* find the name */
len = endp - startp;
np = startp;
- if (cases && len == 5 && (wxStrncmp(_T("lower"), np, 5) == 0 ||
- wxStrncmp(_T("upper"), np, 5) == 0))
+ if (cases && len == 5 && (wxCRT_StrncmpNative(_T("lower"), np, 5) == 0 ||
+ wxCRT_StrncmpNative(_T("upper"), np, 5) == 0))
np = _T("alpha");
for (cc = cclasses; cc->name != NULL; cc++)
- if (wxStrlen_(cc->name) == len && wxStrncmp(cc->name, np, len) == 0)
+ if (wxCRT_StrlenNative(cc->name) == len && wxCRT_StrncmpNative(cc->name, np, len) == 0)
break; /* NOTE BREAK OUT */
if (cc->name == NULL) {
ERR(REG_ECTYPE);
/* must include this after ctype.h inclusion for CodeWarrior/Mac */
#include "wx/defs.h"
#include "wx/chartype.h"
-#include "wx/wxcrt.h"
+#include "wx/wxcrtbase.h"
/*
* Do not insert extras between the "begin" and "end" lines -- this
private:
CPPUNIT_TEST_SUITE( CrtTestCase );
CPPUNIT_TEST( SetGetEnv );
+ CPPUNIT_TEST( Strcmp );
+ CPPUNIT_TEST( Strspn );
+ CPPUNIT_TEST( Strcspn );
CPPUNIT_TEST_SUITE_END();
void SetGetEnv();
+ void Strcmp();
+ void Strspn();
+ void Strcspn();
DECLARE_NO_COPY_CLASS(CrtTestCase)
};
CPPUNIT_ASSERT( wxUnsetEnv(_T("TESTVAR")) );
CPPUNIT_ASSERT( wxGetEnv(_T("TESTVAR"), NULL) == false );
}
+
+void CrtTestCase::Strcmp()
+{
+ // this code tests if all possible ways of calling wxStrcmp() compile:
+ const char * const char1 = "first";
+ const wchar_t * const wchar1 = L"first";
+ wxString str1("first");
+ wxCStrData cstr1(str1.c_str());
+ wxCharBuffer charbuf1(char1);
+ wxWCharBuffer wcharbuf1(wchar1);
+
+ const char * const char2 = "last";
+ const wchar_t * const wchar2 = L"last";
+ wxString str2("last");
+ wxCStrData cstr2(str2.c_str());
+ wxCharBuffer charbuf2(char2);
+ wxWCharBuffer wcharbuf2(wchar2);
+
+ CPPUNIT_ASSERT( wxStrcmp(char1, char2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(char1, wchar2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(char1, str2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(char1, cstr2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(char1, charbuf2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(char1, wcharbuf2) < 0 );
+
+ CPPUNIT_ASSERT( wxStrcmp(wchar1, char2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(wchar1, wchar2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(wchar1, str2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(wchar1, cstr2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(wchar1, charbuf2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(wchar1, wcharbuf2) < 0 );
+
+ CPPUNIT_ASSERT( wxStrcmp(str1, char2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(str1, wchar2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(str1, str2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(str1, cstr2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(str1, charbuf2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(str1, wcharbuf2) < 0 );
+
+ CPPUNIT_ASSERT( wxStrcmp(cstr1, char2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(cstr1, wchar2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(cstr1, str2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(cstr1, cstr2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(cstr1, charbuf2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(cstr1, wcharbuf2) < 0 );
+
+ CPPUNIT_ASSERT( wxStrcmp(charbuf1, char2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(charbuf1, wchar2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(charbuf1, str2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(charbuf1, cstr2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(charbuf1, charbuf2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(charbuf1, wcharbuf2) < 0 );
+
+ CPPUNIT_ASSERT( wxStrcmp(wcharbuf1, char2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(wcharbuf1, wchar2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(wcharbuf1, str2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(wcharbuf1, cstr2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(wcharbuf1, charbuf2) < 0 );
+ CPPUNIT_ASSERT( wxStrcmp(wcharbuf1, wcharbuf2) < 0 );
+}
+
+void CrtTestCase::Strspn()
+{
+ const char *strMB = "hello, world";
+ const char *strWC = "hello, world";
+ const wxString strWX("hello, world");
+
+ CPPUNIT_ASSERT( wxStrspn(strMB, "xyz") == 0 );
+ CPPUNIT_ASSERT( wxStrspn(strWC, "xyz") == 0 );
+ CPPUNIT_ASSERT( wxStrspn(strWX, "xyz") == 0 );
+ CPPUNIT_ASSERT( wxStrspn(strMB, L"xyz") == 0 );
+ CPPUNIT_ASSERT( wxStrspn(strWC, L"xyz") == 0 );
+ CPPUNIT_ASSERT( wxStrspn(strWX, L"xyz") == 0 );
+
+ CPPUNIT_ASSERT( wxStrspn(strMB, "hleo") == 5 );
+ CPPUNIT_ASSERT( wxStrspn(strWC, "hleo") == 5 );
+ CPPUNIT_ASSERT( wxStrspn(strWX, "hleo") == 5 );
+
+ CPPUNIT_ASSERT( wxStrspn(strMB, "ld") == 0 );
+ CPPUNIT_ASSERT( wxStrspn(strWC, "ld") == 0 );
+ CPPUNIT_ASSERT( wxStrspn(strWX, "ld") == 0 );
+
+ CPPUNIT_ASSERT( wxStrspn(strMB, strWC) == strWX.length() );
+ CPPUNIT_ASSERT( wxStrspn(strWC, strWX) == strWX.length() );
+ CPPUNIT_ASSERT( wxStrspn(strWX, strMB) == strWX.length() );
+}
+
+void CrtTestCase::Strcspn()
+{
+ const char *strMB = "hello, world";
+ const char *strWC = "hello, world";
+ const wxString strWX("hello, world");
+
+ CPPUNIT_ASSERT( wxStrcspn(strMB, strWX) == 0 );
+ CPPUNIT_ASSERT( wxStrcspn(strWC, strMB) == 0 );
+ CPPUNIT_ASSERT( wxStrcspn(strWX, strWC) == 0 );
+
+ CPPUNIT_ASSERT( wxStrcspn(strMB, ", ") == 5 );
+ CPPUNIT_ASSERT( wxStrcspn(strWC, ", ") == 5 );
+ CPPUNIT_ASSERT( wxStrcspn(strWX, ", ") == 5 );
+
+ CPPUNIT_ASSERT( wxStrcspn(strMB, "hel") == 0 );
+ CPPUNIT_ASSERT( wxStrcspn(strWC, "hel") == 0 );
+ CPPUNIT_ASSERT( wxStrcspn(strWX, "hel") == 0 );
+
+ CPPUNIT_ASSERT( wxStrcspn(strMB, "xy") == strWX.length() );
+ CPPUNIT_ASSERT( wxStrcspn(strWC, "xy") == strWX.length() );
+ CPPUNIT_ASSERT( wxStrcspn(strWX, "xy") == strWX.length() );
+}
wx/wx.h
wx/wxchar.h
wx/wxcrt.h
+wx/wxcrtbase.h
wx/wxcrtvararg.h
wx/wxprec.h
wx/xti.h
wx/wx.h
wx/wxchar.h
wx/wxcrt.h
+wx/wxcrtbase.h
wx/wxcrtvararg.h
wx/wxprec.h
wx/xti.h
wx/wx.h
wx/wxchar.h
wx/wxcrt.h
+wx/wxcrtbase.h
wx/wxcrtvararg.h
wx/wxprec.h
wx/xti.h