From 359bd4d1a20bdd5c6374f25779a43e92eebe9a1d Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 28 Mar 2007 18:03:26 +0000 Subject: [PATCH] allow passing wx[W]CharBuffer to wx vararg templates git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45099 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/strvararg.h | 17 +++++++++++++++++ src/common/strvararg.cpp | 13 +++++++++++++ tests/strings/vararg.cpp | 11 +++++++++++ 3 files changed, 41 insertions(+) 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;" ); } -- 2.45.2