diff --git a/include/wx/strvararg.h b/include/wx/strvararg.h index 2aab05e478..6ad650be85 100644 --- a/include/wx/strvararg.h +++ b/include/wx/strvararg.h @@ -161,6 +161,23 @@ struct wxArgNormalizer : public wxArgNormalizer #endif // wxUSE_UNICODE_WCHAR / !wxUSE_UNICODE_WCHAR && wxUSE_WCHAR_T +// versions for passing wx[W]CharBuffer: +template<> +struct WXDLLIMPEXP_BASE wxArgNormalizer + : public wxArgNormalizer +{ + wxArgNormalizer(const wxCharBuffer& buf); +}; + +template<> +struct WXDLLIMPEXP_BASE wxArgNormalizer + : public wxArgNormalizer +{ + wxArgNormalizer(const wxWCharBuffer& buf); +}; + + + // NB: The vararg emulation code is limited to 30 arguments at the moment. // If you need more, you need to // 1) increase the value of _WX_VARARG_MAX_ARGS diff --git a/src/common/strvararg.cpp b/src/common/strvararg.cpp index 00e30cbf84..5e7955dd1e 100644 --- a/src/common/strvararg.cpp +++ b/src/common/strvararg.cpp @@ -77,3 +77,16 @@ const char *wxArgNormalizer::get() const } #endif // wxUSE_UNICODE_WCHAR / !wxUSE_UNICODE_WCHAR && wxUSE_WCHAR_T + +// FIXME-UTF8: move this to the header once it's possible to include buffer.h +// without including wxcrt.h + +wxArgNormalizer::wxArgNormalizer(const wxCharBuffer& buf) + : wxArgNormalizer(buf.data()) +{ +} + +wxArgNormalizer::wxArgNormalizer(const wxWCharBuffer& buf) + : wxArgNormalizer(buf.data()) +{ +} diff --git a/tests/strings/vararg.cpp b/tests/strings/vararg.cpp index 6d902384a5..52fdcfec60 100644 --- a/tests/strings/vararg.cpp +++ b/tests/strings/vararg.cpp @@ -53,15 +53,26 @@ void VarArgTestCase::StringPrintf() { wxString s, s2; + // test passing literals: s.Printf("%s %i", "foo", 42); CPPUNIT_ASSERT( s == "foo 42" ); s.Printf("%s %s %i", _T("bar"), "=", 11); + + // test passing c_str(): CPPUNIT_ASSERT( s == "bar = 11" ); s2.Printf("(%s)", s.c_str()); CPPUNIT_ASSERT( s2 == "(bar = 11)" ); s2.Printf(_T("[%s](%s)"), s.c_str(), "str"); CPPUNIT_ASSERT( s2 == "[bar = 11](str)" ); + // test passing wxString directly: s2.Printf(_T("[%s](%s)"), s, "str"); CPPUNIT_ASSERT( s2 == "[bar = 11](str)" ); + + // test passing wxCharBufferType: + s = "FooBar"; + s2.Printf(_T("(%s)"), s.mb_str()); + CPPUNIT_ASSERT( s2 == "(FooBar)" ); + s2.Printf(_T("value=%s;"), s.wc_str()); + CPPUNIT_ASSERT( s2 == "value=FooBar;" ); }