Fix handling of asterisks in wxPrintf() implementation.

Count the number of asterisks before modifying the string we use to do this,
otherwise we were off by one for the format specifications containing two of
them.

This really fixes the handling of asterisks (used for width/precision) in
wxPrintf() format string, it wasn't done correctly by r60120 but now
VsnprintfTestCase::Asterisk() test does pass.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65689 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2010-09-30 14:30:28 +00:00
parent cdd233ef81
commit e2dd624761

View File

@ -831,43 +831,49 @@ struct wxPrintfConvSpecParser
// special handling for specifications including asterisks: we need
// to reserve an extra slot (or two if asterisks were used for both
// width and precision) in specs array in this case
for ( const char *f = strchr(spec->m_szFlags, '*');
f;
f = strchr(f + 1, '*') )
if ( const char *f = strchr(spec->m_szFlags, '*') )
{
if ( nargs++ == wxMAX_SVNPRINTF_ARGUMENTS )
break;
unsigned numAsterisks = 1;
if ( strchr(++f, '*') )
numAsterisks++;
// TODO: we need to support specifiers of the form "%2$*1$s"
// (this is the same as "%*s") as if any positional arguments
// are used all asterisks must be positional as well but this
// requires a lot of changes in this code (basically we'd need
// to rewrite Parse() to return "*" and conversion itself as
// separate entries)
if ( posarg_present )
for ( unsigned n = 0; n < numAsterisks; n++ )
{
wxFAIL_MSG
(
wxString::Format
if ( nargs++ == wxMAX_SVNPRINTF_ARGUMENTS )
break;
// TODO: we need to support specifiers of the form "%2$*1$s"
// (this is the same as "%*s") as if any positional arguments
// are used all asterisks must be positional as well but this
// requires a lot of changes in this code (basically we'd need
// to rewrite Parse() to return "*" and conversion itself as
// separate entries)
if ( posarg_present )
{
wxFAIL_MSG
(
"Format string \"%s\" uses both positional "
"parameters and '*' but this is not currently "
"supported by this implementation, sorry.",
fmt
)
);
wxString::Format
(
"Format string \"%s\" uses both positional "
"parameters and '*' but this is not currently "
"supported by this implementation, sorry.",
fmt
)
);
}
specs[nargs] = *spec;
// make an entry for '*' and point to it from pspec
spec->Init();
spec->m_type = wxPAT_STAR;
pspec[nargs - 1] = spec;
spec = &specs[nargs];
}
specs[nargs] = *spec;
// make an entry for '*' and point to it from pspec
spec->Init();
spec->m_type = wxPAT_STAR;
pspec[nargs - 1] = spec;
spec = &specs[nargs];
}
// check if this is a positional or normal argument
if ( spec->m_pos > 0 )
{