+
+// wxUSE_STRUTILS says our wxVsnprintf_ 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
+// effects:
+// -> on Windows:
+// when in ANSI mode, this setting does not change almost anything
+// when in Unicode mode, it gives ~ 50% of slowdown !
+// -> on Linux:
+// both in ANSI and Unicode mode it gives ~ 60% of speedup !
+//
+#if defined(WIN32) && wxUSE_UNICODE
+#define wxUSE_STRUTILS 0
+#else
+#define wxUSE_STRUTILS 1
+#endif
+
+// some limits of our implementation
+#define wxMAX_SVNPRINTF_ARGUMENTS 16
+#define wxMAX_SVNPRINTF_FLAGBUFFER_LEN 32
+#define wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN 512
+
+
+// wxVsnprintf() needs to use a *system* implementation of swnprintf()
+// in order to perform some internal tasks.
+// NB: we cannot just use wxSnprintf() because for some systems it maybe
+// implemented later in this file using wxVsnprintf() and that would
+// result in an endless recursion and thus in a stack overflow
+#if wxUSE_UNICODE
+
+ #if defined(__WXWINCE__) || ( defined(__VISUALC__) && __VISUALC__ <= 1200 )
+ #define HAVE_BROKEN_SWPRINTF_DECL
+ #endif
+
+
+ // problem: on some systems swprintf takes the 'max' argument while on others
+ // it doesn't
+ #if defined(HAVE_BROKEN_SWPRINTF_DECL)
+
+ // like when using sprintf(), since 'max' is not used, wxVsnprintf() should
+ // always ensure that 'buff' is big enough for all common needs
+ #define system_sprintf(buff, max, flags, data) \
+ ::swprintf(buff, flags, data)
+ #else
+
+ #if !defined(HAVE_SWPRINTF)
+ #error wxVsnprintf() needs a system swprintf() implementation!
+ #endif
+
+ #define system_sprintf(buff, max, flags, data) \
+ ::swprintf(buff, max, flags, data)
+ #endif
+
+#else
+
+ #if defined(HAVE_SNPRINTF)
+
+ #define system_sprintf(buff, max, flags, data) \
+ ::snprintf(buff, max, flags, data)
+
+ #else // NB: at least sprintf() should *always* be available
+
+ // since 'max' is not used in this case, wxVsnprintf() should always ensure
+ // that 'buff' is big enough for all common needs
+ // (see wxMAX_SVNPRINTF_FLAGBUFFER_LEN and wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN)
+ #define system_sprintf(buff, max, flags, data) \
+ ::sprintf(buff, flags, data)
+
+ #endif
+#endif
+
+
+
+// the conversion specifiers accepted by wxVsnprintf_
+enum wxPrintfArgType {
+ wxPAT_INVALID = -1,
+
+ wxPAT_INT, // %d, %i, %o, %u, %x, %X
+ wxPAT_LONGINT, // %ld, etc
+#if SIZEOF_LONG_LONG
+ wxPAT_LONGLONGINT, // %Ld, etc
+#endif
+ wxPAT_SIZET, // %Zd, etc
+
+ wxPAT_DOUBLE, // %e, %E, %f, %g, %G
+ wxPAT_LONGDOUBLE, // %le, etc
+
+ wxPAT_POINTER, // %p
+
+ wxPAT_CHAR, // %hc (in ANSI mode: %c, too)
+ wxPAT_WCHAR, // %lc (in Unicode mode: %c, too)
+
+ wxPAT_PCHAR, // %s (related to a char *)
+ wxPAT_PWCHAR, // %s (related to a wchar_t *)
+
+ wxPAT_NINT, // %n
+ wxPAT_NSHORTINT, // %hn
+ wxPAT_NLONGINT // %ln
+};
+
+// an argument passed to wxVsnprintf_
+typedef union {
+ int pad_int; // %d, %i, %o, %u, %x, %X
+ long int pad_longint; // %ld, etc
+#if SIZEOF_LONG_LONG
+ long long int pad_longlongint; // %Ld, etc
+#endif
+ size_t pad_sizet; // %Zd, etc
+
+ double pad_double; // %e, %E, %f, %g, %G
+ long double pad_longdouble; // %le, etc
+
+ void *pad_pointer; // %p
+
+ char pad_char; // %hc (in ANSI mode: %c, too)
+ wchar_t pad_wchar; // %lc (in Unicode mode: %c, too)
+
+ char *pad_pchar; // %s (related to a char *)
+ wchar_t *pad_pwchar; // %s (related to a wchar_t *)
+
+ int *pad_nint; // %n
+ short int *pad_nshortint; // %hn
+ long int *pad_nlongint; // %ln
+} wxPrintfArg;
+
+
+// Contains parsed data relative to a conversion specifier given to
+// wxVsnprintf_ 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