+#if wxUSE_EXPERIMENTAL_PRINTF
+ // the new implementation
+
+ // buffer to avoid dynamic memory allocation each time for small strings
+ char szScratch[1024];
+
+ Reinit();
+ for (size_t n = 0; pszFormat[n]; n++)
+ if (pszFormat[n] == wxT('%')) {
+ static char s_szFlags[256] = "%";
+ size_t flagofs = 1;
+ bool adj_left = FALSE, in_prec = FALSE,
+ prec_dot = FALSE, done = FALSE;
+ int ilen = 0;
+ size_t min_width = 0, max_width = wxSTRING_MAXLEN;
+ do {
+#define CHECK_PREC if (in_prec && !prec_dot) { s_szFlags[flagofs++] = '.'; prec_dot = TRUE; }
+ switch (pszFormat[++n]) {
+ case wxT('\0'):
+ done = TRUE;
+ break;
+ case wxT('%'):
+ *this += wxT('%');
+ done = TRUE;
+ break;
+ case wxT('#'):
+ case wxT('0'):
+ case wxT(' '):
+ case wxT('+'):
+ case wxT('\''):
+ CHECK_PREC
+ s_szFlags[flagofs++] = pszFormat[n];
+ break;
+ case wxT('-'):
+ CHECK_PREC
+ adj_left = TRUE;
+ s_szFlags[flagofs++] = pszFormat[n];
+ break;
+ case wxT('.'):
+ CHECK_PREC
+ in_prec = TRUE;
+ prec_dot = FALSE;
+ max_width = 0;
+ // dot will be auto-added to s_szFlags if non-negative number follows
+ break;
+ case wxT('h'):
+ ilen = -1;
+ CHECK_PREC
+ s_szFlags[flagofs++] = pszFormat[n];
+ break;
+ case wxT('l'):
+ ilen = 1;
+ CHECK_PREC
+ s_szFlags[flagofs++] = pszFormat[n];
+ break;
+ case wxT('q'):
+ case wxT('L'):
+ ilen = 2;
+ CHECK_PREC
+ s_szFlags[flagofs++] = pszFormat[n];
+ break;
+ case wxT('Z'):
+ ilen = 3;
+ CHECK_PREC
+ s_szFlags[flagofs++] = pszFormat[n];
+ break;
+ case wxT('*'):
+ {
+ int len = va_arg(argptr, int);
+ if (in_prec) {
+ if (len<0) break;
+ CHECK_PREC
+ max_width = len;
+ } else {
+ if (len<0) {
+ adj_left = !adj_left;
+ s_szFlags[flagofs++] = '-';
+ len = -len;
+ }
+ min_width = len;
+ }
+ flagofs += ::sprintf(s_szFlags+flagofs,"%d",len);
+ }
+ break;
+ case wxT('1'): case wxT('2'): case wxT('3'):
+ case wxT('4'): case wxT('5'): case wxT('6'):
+ case wxT('7'): case wxT('8'): case wxT('9'):
+ {
+ int len = 0;
+ CHECK_PREC
+ while ((pszFormat[n]>=wxT('0')) && (pszFormat[n]<=wxT('9'))) {
+ s_szFlags[flagofs++] = pszFormat[n];
+ len = len*10 + (pszFormat[n] - wxT('0'));
+ n++;
+ }
+ if (in_prec) max_width = len;
+ else min_width = len;
+ n--; // the main loop pre-increments n again
+ }
+ break;
+ case wxT('d'):
+ case wxT('i'):
+ case wxT('o'):
+ case wxT('u'):
+ case wxT('x'):
+ case wxT('X'):
+ CHECK_PREC
+ s_szFlags[flagofs++] = pszFormat[n];
+ s_szFlags[flagofs] = '\0';
+ if (ilen == 0 ) {
+ int val = va_arg(argptr, int);
+ ::sprintf(szScratch, s_szFlags, val);
+ }
+ else if (ilen == -1) {
+ short int val = va_arg(argptr, short int);
+ ::sprintf(szScratch, s_szFlags, val);
+ }
+ else if (ilen == 1) {
+ long int val = va_arg(argptr, long int);
+ ::sprintf(szScratch, s_szFlags, val);
+ }
+ else if (ilen == 2) {
+#if SIZEOF_LONG_LONG
+ long long int val = va_arg(argptr, long long int);
+ ::sprintf(szScratch, s_szFlags, val);