+
+#if !wxUSE_WXVSNPRINTF
+ #error wxUSE_WXVSNPRINTF must be 1 if our wxVsnprintf_ is used
+#endif
+
+// 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 64
+#define wxMAX_SVNPRINTF_FLAGBUFFER_LEN 32
+#define wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN 512
+
+// prefer snprintf over sprintf
+#if defined(__VISUALC__) || \
+ (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
+ #define system_sprintf(buff, max, flags, data) \
+ ::_snprintf(buff, max, flags, data)
+#elif 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)
+
+ #define SYSTEM_SPRINTF_IS_UNSAFE
+#endif
+
+// the conversion specifiers accepted by wxVsnprintf_
+enum wxPrintfArgType {
+ wxPAT_INVALID = -1,
+
+ wxPAT_INT, // %d, %i, %o, %u, %x, %X
+ wxPAT_LONGINT, // %ld, etc
+#ifdef wxLongLong_t
+ 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
+#ifdef wxLongLong_t
+ wxLongLong_t 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