Add support for 'z' size format specifier.

Assume that non-MSVC compilers support it directly and use 'I' for MSVC.

Closes #16596.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78010 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2014-10-12 20:48:41 +00:00
parent af1191ab99
commit b9e0e606a8
3 changed files with 44 additions and 0 deletions

View File

@ -32,6 +32,7 @@ Changes in behaviour which may result in build errors
All:
- Add "%z" support to printf()-like functions like wxString::Format() (RIVDSL).
- Add wxPowerResourceBlocker (Tobias Taschner).
- Add wxApp::StoreCurrentException() and RethrowStoredException() and implement
their functionality by default when using C++11 compiler.

View File

@ -198,6 +198,17 @@ public:
switch ( *format )
{
#ifdef __VISUALC__
case 'z':
// Used for size_t printing (e.g. %zu) and is in C99,
// but is not portable, MSVC uses 'I' with the same
// meaning.
ChangeFmtChar('I');
format++;
size = Size_Default;
break;
#endif // __VISUALC__
case 'h':
size = Size_Short;
format++;
@ -341,6 +352,18 @@ private:
*(m_fmtLast++) = ch;
}
// change a character
void ChangeFmtChar(CharType ch)
{
if ( m_fmtOrig )
{
// so far we haven't translated anything yet
CopyAllBefore();
}
*m_fmtLast = ch;
}
void CopyAllBefore()
{
wxASSERT_MSG( m_fmtOrig && m_fmt.data() == NULL, "logic error" );

View File

@ -36,6 +36,7 @@ private:
CPPUNIT_TEST_SUITE( VarArgTestCase );
CPPUNIT_TEST( StringPrintf );
CPPUNIT_TEST( CharPrintf );
CPPUNIT_TEST( SizetPrintf );
#if wxUSE_STD_STRING
CPPUNIT_TEST( StdString );
#endif
@ -49,6 +50,7 @@ private:
void StringPrintf();
void CharPrintf();
void SizetPrintf();
#if wxUSE_STD_STRING
void StdString();
#endif
@ -138,6 +140,24 @@ void VarArgTestCase::CharPrintf()
CPPUNIT_ASSERT_EQUAL( "value is 240 (int)", s );
}
void VarArgTestCase::SizetPrintf()
{
size_t i = 1;
ssize_t j = -2;
CPPUNIT_ASSERT_EQUAL
(
"size_t=1 ssize_t=-2",
wxString::Format("size_t=%zu ssize_t=%zd", i, j)
);
CPPUNIT_ASSERT_EQUAL
(
"size_t=0xA0",
wxString::Format("size_t=0x%zX", static_cast<size_t>(160))
);
}
#if wxUSE_STD_STRING
void VarArgTestCase::StdString()
{