1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/wxprintf.cpp
3 // Purpose: wxWidgets wxPrintf() implementation
5 // Modified by: Ron Lee, Francesco Montorsi
8 // Copyright: (c) wxWidgets copyright
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
13 // headers, declarations, constants
14 // ===========================================================================
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/wxchar.h"
28 #include "wx/string.h"
30 #include "wx/utils.h" // for wxMin and wxMax
34 #if defined(__MWERKS__) && __MSL__ >= 0x6000
40 // ============================================================================
41 // printf() implementation
42 // ============================================================================
44 // special test mode: define all functions below even if we don't really need
45 // them to be able to test them
50 // ----------------------------------------------------------------------------
51 // implement [v]snprintf() if the system doesn't provide a safe one
52 // or if the system's one does not support positional parameters
53 // (very useful for i18n purposes)
54 // ----------------------------------------------------------------------------
56 #if !defined(wxVsnprintf_)
58 #if !wxUSE_WXVSNPRINTF
59 #error wxUSE_WXVSNPRINTF must be 1 if our wxVsnprintf_ is used
62 // wxUSE_STRUTILS says our wxVsnprintf_ implementation to use or not to
63 // use wxStrlen and wxStrncpy functions over one-char processing loops.
65 // Some benchmarking revealed that wxUSE_STRUTILS == 1 has the following
68 // when in ANSI mode, this setting does not change almost anything
69 // when in Unicode mode, it gives ~ 50% of slowdown !
71 // both in ANSI and Unicode mode it gives ~ 60% of speedup !
73 #if defined(WIN32) && wxUSE_UNICODE
74 #define wxUSE_STRUTILS 0
76 #define wxUSE_STRUTILS 1
79 // some limits of our implementation
80 #define wxMAX_SVNPRINTF_ARGUMENTS 64
81 #define wxMAX_SVNPRINTF_FLAGBUFFER_LEN 32
82 #define wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN 512
84 // prefer snprintf over sprintf
85 #if defined(__VISUALC__) || \
86 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
87 #define system_sprintf(buff, max, flags, data) \
88 ::_snprintf(buff, max, flags, data)
89 #elif defined(HAVE_SNPRINTF)
90 #define system_sprintf(buff, max, flags, data) \
91 ::snprintf(buff, max, flags, data)
92 #else // NB: at least sprintf() should always be available
93 // since 'max' is not used in this case, wxVsnprintf() should always
94 // ensure that 'buff' is big enough for all common needs
95 // (see wxMAX_SVNPRINTF_FLAGBUFFER_LEN and wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN)
96 #define system_sprintf(buff, max, flags, data) \
97 ::sprintf(buff, flags, data)
99 #define SYSTEM_SPRINTF_IS_UNSAFE
102 // the conversion specifiers accepted by wxVsnprintf_
103 enum wxPrintfArgType
{
106 wxPAT_INT
, // %d, %i, %o, %u, %x, %X
107 wxPAT_LONGINT
, // %ld, etc
109 wxPAT_LONGLONGINT
, // %Ld, etc
111 wxPAT_SIZET
, // %Zd, etc
113 wxPAT_DOUBLE
, // %e, %E, %f, %g, %G
114 wxPAT_LONGDOUBLE
, // %le, etc
118 wxPAT_CHAR
, // %hc (in ANSI mode: %c, too)
119 wxPAT_WCHAR
, // %lc (in Unicode mode: %c, too)
121 wxPAT_PCHAR
, // %s (related to a char *)
122 wxPAT_PWCHAR
, // %s (related to a wchar_t *)
125 wxPAT_NSHORTINT
, // %hn
126 wxPAT_NLONGINT
// %ln
129 // an argument passed to wxVsnprintf_
131 int pad_int
; // %d, %i, %o, %u, %x, %X
132 long int pad_longint
; // %ld, etc
134 wxLongLong_t pad_longlongint
; // %Ld, etc
136 size_t pad_sizet
; // %Zd, etc
138 double pad_double
; // %e, %E, %f, %g, %G
139 long double pad_longdouble
; // %le, etc
141 void *pad_pointer
; // %p
143 char pad_char
; // %hc (in ANSI mode: %c, too)
144 wchar_t pad_wchar
; // %lc (in Unicode mode: %c, too)
146 char *pad_pchar
; // %s (related to a char *)
147 wchar_t *pad_pwchar
; // %s (related to a wchar_t *)
150 short int *pad_nshortint
; // %hn
151 long int *pad_nlongint
; // %ln
155 // Contains parsed data relative to a conversion specifier given to
156 // wxVsnprintf_ and parsed from the format string
157 // NOTE: in C++ there is almost no difference between struct & classes thus
158 // there is no performance gain by using a struct here...
159 class wxPrintfConvSpec
163 // the position of the argument relative to this conversion specifier
166 // the type of this conversion specifier
167 wxPrintfArgType m_type
;
169 // the minimum and maximum width
170 // when one of this var is set to -1 it means: use the following argument
171 // in the stack as minimum/maximum width for this conversion specifier
172 int m_nMinWidth
, m_nMaxWidth
;
174 // does the argument need to the be aligned to left ?
177 // pointer to the '%' of this conversion specifier in the format string
178 // NOTE: this points somewhere in the string given to the Parse() function -
179 // it's task of the caller ensure that memory is still valid !
180 const wxChar
*m_pArgPos
;
182 // pointer to the last character of this conversion specifier in the
184 // NOTE: this points somewhere in the string given to the Parse() function -
185 // it's task of the caller ensure that memory is still valid !
186 const wxChar
*m_pArgEnd
;
188 // a little buffer where formatting flags like #+\.hlqLZ are stored by Parse()
189 // for use in Process()
190 // NB: even if this buffer is used only for numeric conversion specifiers and
191 // thus could be safely declared as a char[] buffer, we want it to be wxChar
192 // so that in Unicode builds we can avoid to convert its contents to Unicode
193 // chars when copying it in user's buffer.
194 char m_szFlags
[wxMAX_SVNPRINTF_FLAGBUFFER_LEN
];
199 // we don't declare this as a constructor otherwise it would be called
200 // automatically and we don't want this: to be optimized, wxVsnprintf_
201 // calls this function only on really-used instances of this class.
204 // Parses the first conversion specifier in the given string, which must
205 // begin with a '%'. Returns false if the first '%' does not introduce a
206 // (valid) conversion specifier and thus should be ignored.
207 bool Parse(const wxChar
*format
);
209 // Process this conversion specifier and puts the result in the given
210 // buffer. Returns the number of characters written in 'buf' or -1 if
211 // there's not enough space.
212 int Process(wxChar
*buf
, size_t lenMax
, wxPrintfArg
*p
, size_t written
);
214 // Loads the argument of this conversion specifier from given va_list.
215 bool LoadArg(wxPrintfArg
*p
, va_list &argptr
);
218 // An helper function of LoadArg() which is used to handle the '*' flag
219 void ReplaceAsteriskWith(int w
);
222 void wxPrintfConvSpec::Init()
225 m_nMaxWidth
= 0xFFFF;
227 m_bAlignLeft
= false;
228 m_pArgPos
= m_pArgEnd
= NULL
;
229 m_type
= wxPAT_INVALID
;
231 // this character will never be removed from m_szFlags array and
232 // is important when calling sprintf() in wxPrintfConvSpec::Process() !
236 bool wxPrintfConvSpec::Parse(const wxChar
*format
)
240 // temporary parse data
242 bool in_prec
, // true if we found the dot in some previous iteration
243 prec_dot
; // true if the dot has been already added to m_szFlags
246 m_bAlignLeft
= in_prec
= prec_dot
= false;
247 m_pArgPos
= m_pArgEnd
= format
;
251 if (in_prec && !prec_dot) \
253 m_szFlags[flagofs++] = '.'; \
258 const wxChar ch
= *(++m_pArgEnd
);
262 return false; // not really an argument
265 return false; // not really an argument
273 m_szFlags
[flagofs
++] = char(ch
);
279 m_szFlags
[flagofs
++] = char(ch
);
287 // dot will be auto-added to m_szFlags if non-negative
294 m_szFlags
[flagofs
++] = char(ch
);
298 // NB: it's safe to use flagofs-1 as flagofs always start from 1
299 if (m_szFlags
[flagofs
-1] == 'l') // 'll' modifier is the same as 'L' or 'q'
304 m_szFlags
[flagofs
++] = char(ch
);
311 m_szFlags
[flagofs
++] = char(ch
);
314 // under Windows we support the special '%I64' notation as longlong
315 // integer conversion specifier for MSVC compatibility
316 // (it behaves exactly as '%lli' or '%Li' or '%qi')
318 if (*(m_pArgEnd
+1) != wxT('6') ||
319 *(m_pArgEnd
+2) != wxT('4'))
320 return false; // bad format
327 m_szFlags
[flagofs
++] = char(ch
);
328 m_szFlags
[flagofs
++] = '6';
329 m_szFlags
[flagofs
++] = '4';
336 m_szFlags
[flagofs
++] = char(ch
);
344 // tell Process() to use the next argument
345 // in the stack as maxwidth...
350 // tell Process() to use the next argument
351 // in the stack as minwidth...
355 // save the * in our formatting buffer...
356 // will be replaced later by Process()
357 m_szFlags
[flagofs
++] = char(ch
);
360 case wxT('1'): case wxT('2'): case wxT('3'):
361 case wxT('4'): case wxT('5'): case wxT('6'):
362 case wxT('7'): case wxT('8'): case wxT('9'):
366 while ( (*m_pArgEnd
>= wxT('0')) &&
367 (*m_pArgEnd
<= wxT('9')) )
369 m_szFlags
[flagofs
++] = char(*m_pArgEnd
);
370 len
= len
*10 + (*m_pArgEnd
- wxT('0'));
379 m_pArgEnd
--; // the main loop pre-increments n again
383 case wxT('$'): // a positional parameter (e.g. %2$s) ?
385 if (m_nMinWidth
<= 0)
386 break; // ignore this formatting flag as no
387 // numbers are preceding it
389 // remove from m_szFlags all digits previously added
392 } while (m_szFlags
[flagofs
] >= '1' &&
393 m_szFlags
[flagofs
] <= '9');
395 // re-adjust the offset making it point to the
396 // next free char of m_szFlags
411 m_szFlags
[flagofs
++] = char(ch
);
412 m_szFlags
[flagofs
] = '\0';
416 // NB: 'short int' value passed through '...'
417 // is promoted to 'int', so we have to get
418 // an int from stack even if we need a short
421 m_type
= wxPAT_LONGINT
;
424 m_type
= wxPAT_LONGLONGINT
;
425 #else // !wxLongLong_t
426 m_type
= wxPAT_LONGINT
;
427 #endif // wxLongLong_t/!wxLongLong_t
429 m_type
= wxPAT_SIZET
;
439 m_szFlags
[flagofs
++] = char(ch
);
440 m_szFlags
[flagofs
] = '\0';
442 m_type
= wxPAT_LONGDOUBLE
;
444 m_type
= wxPAT_DOUBLE
;
449 m_type
= wxPAT_POINTER
;
450 m_szFlags
[flagofs
++] = char(ch
);
451 m_szFlags
[flagofs
] = '\0';
458 // in Unicode mode %hc == ANSI character
459 // and in ANSI mode, %hc == %c == ANSI...
464 // in ANSI mode %lc == Unicode character
465 // and in Unicode mode, %lc == %c == Unicode...
466 m_type
= wxPAT_WCHAR
;
471 // in Unicode mode, %c == Unicode character
472 m_type
= wxPAT_WCHAR
;
474 // in ANSI mode, %c == ANSI character
484 // Unicode mode wx extension: we'll let %hs mean non-Unicode
485 // strings (when in ANSI mode, %s == %hs == ANSI string)
486 m_type
= wxPAT_PCHAR
;
490 // in Unicode mode, %ls == %s == Unicode string
491 // in ANSI mode, %ls == Unicode string
492 m_type
= wxPAT_PWCHAR
;
497 m_type
= wxPAT_PWCHAR
;
499 m_type
= wxPAT_PCHAR
;
509 m_type
= wxPAT_NSHORTINT
;
511 m_type
= wxPAT_NLONGINT
;
516 // bad format, don't consider this an argument;
517 // leave it unchanged
521 if (flagofs
== wxMAX_SVNPRINTF_FLAGBUFFER_LEN
)
523 wxLogDebug(wxT("Too many flags specified for a single conversion specifier!"));
529 return true; // parsing was successful
533 void wxPrintfConvSpec::ReplaceAsteriskWith(int width
)
535 char temp
[wxMAX_SVNPRINTF_FLAGBUFFER_LEN
];
537 // find the first * in our flag buffer
538 char *pwidth
= strchr(m_szFlags
, '*');
539 wxCHECK_RET(pwidth
, _T("field width must be specified"));
541 // save what follows the * (the +1 is to skip the asterisk itself!)
542 strcpy(temp
, pwidth
+1);
545 pwidth
[0] = wxT('-');
549 // replace * with the actual integer given as width
550 #ifndef SYSTEM_SPRINTF_IS_UNSAFE
551 int maxlen
= (m_szFlags
+ wxMAX_SVNPRINTF_FLAGBUFFER_LEN
- pwidth
) /
554 int offset
= system_sprintf(pwidth
, maxlen
, "%d", abs(width
));
556 // restore after the expanded * what was following it
557 strcpy(pwidth
+offset
, temp
);
560 bool wxPrintfConvSpec::LoadArg(wxPrintfArg
*p
, va_list &argptr
)
562 // did the '*' width/precision specifier was used ?
563 if (m_nMaxWidth
== -1)
565 // take the maxwidth specifier from the stack
566 m_nMaxWidth
= va_arg(argptr
, int);
570 ReplaceAsteriskWith(m_nMaxWidth
);
573 if (m_nMinWidth
== -1)
575 // take the minwidth specifier from the stack
576 m_nMinWidth
= va_arg(argptr
, int);
578 ReplaceAsteriskWith(m_nMinWidth
);
581 m_bAlignLeft
= !m_bAlignLeft
;
582 m_nMinWidth
= -m_nMinWidth
;
588 p
->pad_int
= va_arg(argptr
, int);
591 p
->pad_longint
= va_arg(argptr
, long int);
594 case wxPAT_LONGLONGINT
:
595 p
->pad_longlongint
= va_arg(argptr
, wxLongLong_t
);
597 #endif // wxLongLong_t
599 p
->pad_sizet
= va_arg(argptr
, size_t);
602 p
->pad_double
= va_arg(argptr
, double);
604 case wxPAT_LONGDOUBLE
:
605 p
->pad_longdouble
= va_arg(argptr
, long double);
608 p
->pad_pointer
= va_arg(argptr
, void *);
612 p
->pad_char
= (char)va_arg(argptr
, int); // char is promoted to int when passed through '...'
615 p
->pad_wchar
= (wchar_t)va_arg(argptr
, int); // char is promoted to int when passed through '...'
619 p
->pad_pchar
= va_arg(argptr
, char *);
622 p
->pad_pwchar
= va_arg(argptr
, wchar_t *);
626 p
->pad_nint
= va_arg(argptr
, int *);
628 case wxPAT_NSHORTINT
:
629 p
->pad_nshortint
= va_arg(argptr
, short int *);
632 p
->pad_nlongint
= va_arg(argptr
, long int *);
640 return true; // loading was successful
643 int wxPrintfConvSpec::Process(wxChar
*buf
, size_t lenMax
, wxPrintfArg
*p
, size_t written
)
645 // buffer to avoid dynamic memory allocation each time for small strings;
646 // note that this buffer is used only to hold results of number formatting,
647 // %s directly writes user's string in buf, without using szScratch
648 char szScratch
[wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN
];
649 size_t lenScratch
= 0, lenCur
= 0;
651 #define APPEND_CH(ch) \
653 if ( lenCur == lenMax ) \
656 buf[lenCur++] = ch; \
662 lenScratch
= system_sprintf(szScratch
, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN
, m_szFlags
, p
->pad_int
);
666 lenScratch
= system_sprintf(szScratch
, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN
, m_szFlags
, p
->pad_longint
);
670 case wxPAT_LONGLONGINT
:
671 lenScratch
= system_sprintf(szScratch
, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN
, m_szFlags
, p
->pad_longlongint
);
673 #endif // SIZEOF_LONG_LONG
676 lenScratch
= system_sprintf(szScratch
, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN
, m_szFlags
, p
->pad_sizet
);
679 case wxPAT_LONGDOUBLE
:
680 lenScratch
= system_sprintf(szScratch
, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN
, m_szFlags
, p
->pad_longdouble
);
684 lenScratch
= system_sprintf(szScratch
, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN
, m_szFlags
, p
->pad_double
);
688 lenScratch
= system_sprintf(szScratch
, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN
, m_szFlags
, p
->pad_pointer
);
698 if (m_type
== wxPAT_CHAR
)
700 // user passed a character explicitely indicated as ANSI...
701 const char buf
[2] = { p
->pad_char
, 0 };
702 val
= wxString(buf
, wxConvLibc
)[0u];
704 //wprintf(L"converting ANSI=>Unicode"); // for debug
710 if (m_type
== wxPAT_WCHAR
)
712 // user passed a character explicitely indicated as Unicode...
713 const wchar_t buf
[2] = { p
->pad_wchar
, 0 };
714 val
= wxString(buf
, wxConvLibc
)[0u];
716 //printf("converting Unicode=>ANSI"); // for debug
724 for (i
= 1; i
< (size_t)m_nMinWidth
; i
++)
730 for (i
= 1; i
< (size_t)m_nMinWidth
; i
++)
743 if (m_type
== wxPAT_PCHAR
)
745 // user passed a string explicitely indicated as ANSI...
746 val
= s
= wxString(p
->pad_pchar
, wxConvLibc
);
748 //wprintf(L"converting ANSI=>Unicode"); // for debug
754 if (m_type
== wxPAT_PWCHAR
)
756 // user passed a string explicitely indicated as Unicode...
757 val
= s
= wxString(p
->pad_pwchar
, wxConvLibc
);
759 //printf("converting Unicode=>ANSI"); // for debug
768 // at this point we are sure that m_nMaxWidth is positive or null
769 // (see top of wxPrintfConvSpec::LoadArg)
770 len
= wxMin((unsigned int)m_nMaxWidth
, wxStrlen(val
));
772 for ( len
= 0; val
[len
] && (len
< m_nMaxWidth
); len
++ )
776 else if (m_nMaxWidth
>= 6)
791 for (i
= len
; i
< m_nMinWidth
; i
++)
796 len
= wxMin((unsigned int)len
, lenMax
-lenCur
);
797 wxStrncpy(buf
+lenCur
, val
, len
);
800 for (i
= 0; i
< len
; i
++)
806 for (i
= len
; i
< m_nMinWidth
; i
++)
813 *p
->pad_nint
= written
;
816 case wxPAT_NSHORTINT
:
817 *p
->pad_nshortint
= (short int)written
;
821 *p
->pad_nlongint
= written
;
829 // if we used system's sprintf() then we now need to append the s_szScratch
830 // buffer to the given one...
836 case wxPAT_LONGLONGINT
:
839 case wxPAT_LONGDOUBLE
:
842 wxASSERT(lenScratch
< wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN
);
845 if (lenMax
< lenScratch
)
847 // fill output buffer and then return -1
848 wxStrncpy(buf
, szScratch
, lenMax
);
851 wxStrncpy(buf
, szScratch
, lenScratch
);
852 lenCur
+= lenScratch
;
856 // Copy the char scratch to the wide output. This requires
857 // conversion, but we can optimise by making use of the fact
858 // that we are formatting numbers, this should mean only 7-bit
859 // ascii characters are involved.
860 wxChar
*bufptr
= buf
;
861 const wxChar
*bufend
= buf
+ lenMax
;
862 const char *scratchptr
= szScratch
;
864 // Simply copy each char to a wxChar, stopping on the first
865 // null or non-ascii byte. Checking '(signed char)*scratchptr
866 // > 0' is an extra optimisation over '*scratchptr != 0 &&
867 // isascii(*scratchptr)', though it assumes signed char is
868 // 8-bit 2 complement.
869 while ((signed char)*scratchptr
> 0 && bufptr
!= bufend
)
870 *bufptr
++ = *scratchptr
++;
872 if (bufptr
== bufend
)
875 lenCur
+= bufptr
- buf
;
877 // check if the loop stopped on a non-ascii char, if yes then
878 // fall back to wxMB2WX
881 size_t len
= wxMB2WX(bufptr
, scratchptr
, bufend
- bufptr
);
883 if (len
&& len
!= (size_t)(-1))
894 break; // all other cases were completed previously
900 // Copy chars from source to dest converting '%%' to '%'. Takes at most maxIn
901 // chars from source and write at most outMax chars to dest, returns the
902 // number of chars actually written. Does not treat null specially.
904 static int wxCopyStrWithPercents(
908 const wxChar
*source
)
916 for ( i
= 0; i
< maxIn
-1 && written
< maxOut
; source
++, i
++)
918 dest
[written
++] = *source
;
919 if (*(source
+1) == wxT('%'))
921 // skip this additional '%' character
927 if (i
< maxIn
&& written
< maxOut
)
928 // copy last character inconditionally
929 dest
[written
++] = *source
;
934 int WXDLLEXPORT
wxVsnprintf_(wxChar
*buf
, size_t lenMax
,
935 const wxChar
*format
, va_list argptr
)
937 // useful for debugging, to understand if we are really using this function
938 // rather than the system implementation
940 wprintf(L
"Using wxVsnprintf_\n");
944 wxPrintfConvSpec arg
[wxMAX_SVNPRINTF_ARGUMENTS
];
945 wxPrintfArg argdata
[wxMAX_SVNPRINTF_ARGUMENTS
];
946 wxPrintfConvSpec
*pspec
[wxMAX_SVNPRINTF_ARGUMENTS
] = { NULL
};
950 // number of characters in the buffer so far, must be less than lenMax
954 const wxChar
*toparse
= format
;
956 // parse the format string
957 bool posarg_present
= false, nonposarg_present
= false;
958 for (; *toparse
!= wxT('\0'); toparse
++)
960 if (*toparse
== wxT('%') )
964 // let's see if this is a (valid) conversion specifier...
965 if (arg
[nargs
].Parse(toparse
))
968 wxPrintfConvSpec
*current
= &arg
[nargs
];
970 // make toparse point to the end of this specifier
971 toparse
= current
->m_pArgEnd
;
973 if (current
->m_pos
> 0)
975 // the positionals start from number 1... adjust the index
977 posarg_present
= true;
981 // not a positional argument...
982 current
->m_pos
= nargs
;
983 nonposarg_present
= true;
986 // this conversion specifier is tied to the pos-th argument...
987 pspec
[current
->m_pos
] = current
;
990 if (nargs
== wxMAX_SVNPRINTF_ARGUMENTS
)
992 wxLogDebug(wxT("A single call to wxVsnprintf() has more than %d arguments; ")
993 wxT("ignoring all remaining arguments."), wxMAX_SVNPRINTF_ARGUMENTS
);
994 break; // cannot handle any additional conv spec
999 // it's safe to look in the next character of toparse as at worst
1001 if (*(toparse
+1) == wxT('%'))
1002 toparse
++; // the Parse() returned false because we've found a %%
1007 if (posarg_present
&& nonposarg_present
)
1010 return -1; // format strings with both positional and
1011 } // non-positional conversion specifier are unsupported !!
1013 // on platforms where va_list is an array type, it is necessary to make a
1014 // copy to be able to pass it to LoadArg as a reference.
1017 wxVaCopy(ap
, argptr
);
1019 // now load arguments from stack
1020 for (i
=0; i
< nargs
&& ok
; i
++)
1022 // !pspec[i] means that the user forgot a positional parameter (e.g. %$1s %$3s);
1023 // LoadArg == false means that wxPrintfConvSpec::Parse failed to set the
1024 // conversion specifier 'type' to a valid value...
1025 ok
= pspec
[i
] && pspec
[i
]->LoadArg(&argdata
[i
], ap
);
1030 // something failed while loading arguments from the variable list...
1031 // (e.g. the user repeated twice the same positional argument)
1038 // finally, process each conversion specifier with its own argument
1040 for (i
=0; i
< nargs
; i
++)
1042 // copy in the output buffer the portion of the format string between
1043 // last specifier and the current one
1044 size_t tocopy
= ( arg
[i
].m_pArgPos
- toparse
);
1046 lenCur
+= wxCopyStrWithPercents(lenMax
- lenCur
, buf
+ lenCur
,
1048 if (lenCur
== lenMax
)
1050 buf
[lenMax
- 1] = 0;
1051 return lenMax
+1; // not enough space in the output buffer !
1054 // process this specifier directly in the output buffer
1055 int n
= arg
[i
].Process(buf
+lenCur
, lenMax
- lenCur
, &argdata
[arg
[i
].m_pos
], lenCur
);
1058 buf
[lenMax
-1] = wxT('\0'); // be sure to always NUL-terminate the string
1059 return lenMax
+1; // not enough space in the output buffer !
1063 // the +1 is because wxPrintfConvSpec::m_pArgEnd points to the last character
1064 // of the format specifier, but we are not interested to it...
1065 toparse
= arg
[i
].m_pArgEnd
+ 1;
1068 // copy portion of the format string after last specifier
1069 // NOTE: toparse is pointing to the character just after the last processed
1070 // conversion specifier
1071 // NOTE2: the +1 is because we want to copy also the '\0'
1072 size_t tocopy
= wxStrlen(format
) + 1 - ( toparse
- format
) ;
1074 lenCur
+= wxCopyStrWithPercents(lenMax
- lenCur
, buf
+ lenCur
,
1075 tocopy
, toparse
) - 1;
1079 return lenMax
+1; // not enough space in the output buffer !
1083 // wxASSERT(lenCur == wxStrlen(buf));
1084 // in fact if we embedded NULLs in the output buffer (using %c with a '\0')
1085 // such check would fail
1093 #else // wxVsnprintf_ is defined
1095 #if wxUSE_WXVSNPRINTF
1096 #error wxUSE_WXVSNPRINTF must be 0 if our wxVsnprintf_ is not used
1099 #endif // !wxVsnprintf_