wxchar.h
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C头文件 代码 · 共 1,259 行 · 第 1/3 页
H
1,259 行
inline int wx_fixed_vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
return vsnprintf(str, size, (char*)format, ap);
}
#endif
/*
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(__MWERKS__)
#define HAVE_WCSRTOMBS 1
#define HAVE_VSWPRINTF 1
#endif
#if defined(__WATCOMC__)
#define wxVsnprintf_ _vsnwprintf
#define wxSnprintf_ _snwprintf
#endif
#if defined(HAVE__VSNWPRINTF)
#define wxVsnprintf_ _vsnwprintf
/* MinGW?MSVCRT has the wrong vswprintf */
/* Mac OS X has a somehow buggy vswprintf */
#elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__) && !defined(__DARWIN__)
#define wxVsnprintf_ vswprintf
#endif
#else /* ASCII */
/* all versions of CodeWarrior supported by wxWidgets apparently have */
/* both snprintf() and vsnprintf() */
#if defined(HAVE_SNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__)
#ifndef HAVE_BROKEN_SNPRINTF_DECL
#define wxSnprintf_ snprintf
#endif
#endif
#if defined(HAVE_VSNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__)
#if defined __cplusplus && defined HAVE_BROKEN_VSNPRINTF_DECL
#define wxVsnprintf_ wx_fixed_vsnprintf
#else
#define wxVsnprintf_ vsnprintf
#endif
#endif
#endif
#endif /* wxVsnprintf_ not defined yet */
#ifndef wxSnprintf_
/* no [v]snprintf(), cook our own */
WXDLLIMPEXP_BASE int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
...) ATTRIBUTE_PRINTF_3;
#endif
#ifndef wxVsnprintf_
WXDLLIMPEXP_BASE 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().
*/
#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 */
/*
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.
*/
#if defined(wxNEED_PRINTF_CONVERSION) && defined(wxVsnprintf_)
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 */
/* 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)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);
#endif
#endif
/* stdio.h functions */
#ifdef wxNEED_WX_STDIO_H
#include <stdio.h>
WXDLLIMPEXP_BASE FILE * wxFopen(const wxChar *path, const wxChar *mode);
WXDLLIMPEXP_BASE FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
WXDLLIMPEXP_BASE int wxRemove(const wxChar *path);
WXDLLIMPEXP_BASE int wxRename(const wxChar *oldpath, const wxChar *newpath);
/* *printf() family is handled separately */
#endif /* wxNEED_WX_STDIO_H */
/* stdlib.h functions */
#ifndef wxAtof
WXDLLIMPEXP_BASE double wxAtof(const wxChar *psz);
#endif
#ifdef wxNEED_WX_STDLIB_H
WXDLLIMPEXP_BASE int wxAtoi(const wxChar *psz);
WXDLLIMPEXP_BASE long wxAtol(const wxChar *psz);
WXDLLIMPEXP_BASE wxChar * wxGetenv(const wxChar *name);
WXDLLIMPEXP_BASE int wxSystem(const wxChar *psz);
#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 */
#if wxUSE_WCHAR_T
/* multibyte<->widechar conversion */
WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
#if wxUSE_UNICODE
#define wxMB2WX wxMB2WC
#define wxWX2MB wxWC2MB
#define wxWC2WX wxStrncpy
#define wxWX2WC wxStrncpy
#else
#define wxMB2WX wxStrncpy
#define wxWX2MB wxStrncpy
#define wxWC2WX wxWC2MB
#define wxWX2WC wxMB2WC
#endif
#else /* !wxUSE_UNICODE */
/* Why is this here?
#error ha */
/* No wxUSE_WCHAR_T: we have to do something (JACS) */
#define wxMB2WC wxStrncpy
#define wxWC2MB wxStrncpy
#define wxMB2WX wxStrncpy
#define wxWX2MB wxStrncpy
#define wxWC2WX wxWC2MB
#define wxWX2WC wxMB2WC
#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
#endif /*__cplusplus*/
#endif /* _WX_WXCHAR_H_ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?