📄 wxchar.h
字号:
// 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
inline size_t wxWcslen(const wchar_t *s)
{
size_t n = 0;
while ( *s++ )
n++;
return n;
}
#endif
#endif // wxUSE_WCHAR_T
// checks whether the passed in pointer is NULL and if the string is empty
inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
// safe version of strlen() (returns 0 if passed NULL pointer)
inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
WXDLLEXPORT bool wxOKlibc(); // for internal use
// ----------------------------------------------------------------------------
// printf() family saga
// ----------------------------------------------------------------------------
/*
First of all, we always want to define safe snprintf() function to be used
instead of sprintf(). Some compilers already have it (or rather vsnprintf()
which we really need...), otherwise we implement it using our own printf()
code.
We define function with a trailing underscore here because the real one is a
wrapper around it as explained below
*/
#ifndef wxVsnprintf_
#if wxUSE_UNICODE
#if defined(HAVE__VSNWPRINTF)
#define wxVsnprintf_ _vsnwprintf
/* MinGW?MSVCRT has the wrong vswprintf */
#elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
#define wxVsnprintf_ vswprintf
#endif
#else // ASCII
// all versions of CodeWarrior supported by wxWindows apparently have
// vsnprintf()
#if defined(HAVE_VSNPRINTF) || defined(__MWERKS__)
// assume we have snprintf() too if we have vsnprintf()
#define wxVsnprintf_ vsnprintf
#define wxSnprintf_ snprintf
#endif
#endif
#endif // wxVsnprintf_ not defined yet
#ifndef wxSnprintf_
// no [v]snprintf(), cook our own
WXDLLEXPORT int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
...) ATTRIBUTE_PRINTF_3;
#endif
#ifndef wxVsnprintf_
WXDLLEXPORT int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
va_list argptr);
#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
#endif
/*
More Unicode complications: although both ANSI C and C++ define a number of
wide character functions such as wprintf(), not all environments have them.
Worse, those which do have different behaviours: under Windows, %s format
specifier changes its meaning in Unicode build and expects a Unicode string
while under Unix/POSIX it still means an ASCII string even for wprintf() and
%ls has to be used for wide strings.
We choose to always emulate Windows behaviour as more useful for us so even
if we have wprintf() we still must wrap it in a non trivial wxPrintf().
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.
*/
#ifndef wxVsnprintf_
#undef wxNEED_PRINTF_CONVERSION
#endif
#if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
// we need to implement all wide character printf and scanf functions
// either because we don't have them at all or because they don't have the
// semantics we need
#include <stdio.h> // for FILE
int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
int wxVprintf( const wxChar *format, va_list ap );
int wxVsprintf( wxChar *str, const wxChar *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
#ifdef wxNEED_PRINTF_CONVERSION
int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
#else
#define wxSnprintf wxSnprintf_
#define wxVsnprintf wxVsnprintf_
#endif
// ----------------------------------------------------------------------------
// various functions which might not be available in libc and for which we
// provide our own replacements in wxchar.cpp
// ----------------------------------------------------------------------------
// ctype.h functions
//
// VZ: note that this is never defined currently
#ifdef wxNEED_WX_CTYPE_H
WXDLLEXPORT int wxIsalnum(wxChar ch);
WXDLLEXPORT int wxIsalpha(wxChar ch);
WXDLLEXPORT int wxIsctrl(wxChar ch);
WXDLLEXPORT int wxIsdigit(wxChar ch);
WXDLLEXPORT int wxIsgraph(wxChar ch);
WXDLLEXPORT int wxIslower(wxChar ch);
WXDLLEXPORT int wxIsprint(wxChar ch);
WXDLLEXPORT int wxIspunct(wxChar ch);
WXDLLEXPORT int wxIsspace(wxChar ch);
WXDLLEXPORT int wxIsupper(wxChar ch);
WXDLLEXPORT int wxIsxdigit(wxChar ch);
WXDLLEXPORT int wxTolower(wxChar ch);
WXDLLEXPORT 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)c) < 128) && isspace(c))
#endif // VC++
// string.h functions
//
// VZ: this is never defined neither currently
#ifdef wxNEED_WX_STRING_H
WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src);
WXDLLEXPORT const wxChar * wxStrchr(const wxChar *s, wxChar c);
WXDLLEXPORT wxChar * wxStrchr(wxChar *s, wxChar c)
{ return (wxChar *)wxStrchr((const wxChar *)s, c); }
WXDLLEXPORT int wxStrcmp(const wxChar *s1, const wxChar *s2);
WXDLLEXPORT int wxStrcoll(const wxChar *s1, const wxChar *s2);
WXDLLEXPORT wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
WXDLLEXPORT size_t wxStrcspn(const wxChar *s, const wxChar *reject);
WXDLLEXPORT size_t wxStrlen(const wxChar *s);
WXDLLEXPORT wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
WXDLLEXPORT int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
WXDLLEXPORT const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
WXDLLEXPORT wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
{ return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
WXDLLEXPORT const wxChar * wxStrrchr(const wxChar *s, wxChar c);
WXDLLEXPORT wxChar * wxStrrchr(wxChar *s, wxChar c)
{ return (wxChar *)wxStrrchr((const wxChar *)s, c); }
WXDLLEXPORT size_t wxStrspn(const wxChar *s, const wxChar *accept);
WXDLLEXPORT const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
WXDLLEXPORT wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
{ return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
WXDLLEXPORT double wxStrtod(const wxChar *nptr, wxChar **endptr);
WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
WXDLLEXPORT unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
WXDLLEXPORT size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
#endif // wxNEED_WX_STRING_H
#ifndef wxStrdup
WXDLLEXPORT wxChar * wxStrdup(const wxChar *psz);
#endif
#ifndef wxStricmp
WXDLLEXPORT int wxStricmp(const wxChar *psz1, const wxChar *psz2);
#endif
#ifndef wxStrnicmp
WXDLLEXPORT int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
#endif
#ifndef wxStrtok
WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
#endif
#ifndef wxSetlocale
class WXDLLEXPORT wxWCharBuffer;
WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
#endif
// stdio.h functions
#ifdef wxNEED_WX_STDIO_H
#include <stdio.h>
WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode);
WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
WXDLLEXPORT int wxRemove(const wxChar *path);
WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath);
// *printf() family is handled separately
#endif // wxNEED_WX_STDIO_H
// stdlib.h functions
#ifndef wxAtof
WXDLLEXPORT double wxAtof(const wxChar *psz);
#endif
#ifdef wxNEED_WX_STDLIB_H
WXDLLEXPORT int wxAtoi(const wxChar *psz);
WXDLLEXPORT long wxAtol(const wxChar *psz);
WXDLLEXPORT wxChar * wxGetenv(const wxChar *name);
WXDLLEXPORT int wxSystem(const wxChar *psz);
#endif
// time.h functions
#ifdef wxNEED_WX_TIME_H
WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max,
const wxChar *fmt, const struct tm *tm);
#endif // wxNEED_WX_TIME_H
// ----------------------------------------------------------------------------
// multibyte to wide char conversion functions and macros
// ----------------------------------------------------------------------------
#if wxUSE_WCHAR_T
// multibyte<->widechar conversion
WXDLLEXPORT size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
WXDLLEXPORT size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
#if wxUSE_UNICODE
#define wxMB2WX wxMB2WC
#define wxWX2MB wxWC2MB
#define wxWC2WX wxStrncpy
#define wxWX2WC wxStrncpy
#else
#define wxMB2WX wxStrncpy
#define wxWX2MB wxStrncpy
#define wxWC2WX wxWC2MB
#define wxWX2WC wxMB2WC
#endif
#else // !wxUSE_UNICODE
// No wxUSE_WCHAR_T: we have to do something (JACS)
#define wxMB2WC wxStrncpy
#define wxWC2MB wxStrncpy
#define wxMB2WX wxStrncpy
#define wxWX2MB wxStrncpy
#define wxWC2WX wxWC2MB
#define wxWX2WC wxMB2WC
#endif
#endif //_WX_WXCHAR_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -