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
This commit is contained in:
		@@ -161,6 +161,23 @@ struct wxArgNormalizer<wchar_t*> : public wxArgNormalizer<const wchar_t*>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#endif // wxUSE_UNICODE_WCHAR / !wxUSE_UNICODE_WCHAR && wxUSE_WCHAR_T
 | 
					#endif // wxUSE_UNICODE_WCHAR / !wxUSE_UNICODE_WCHAR && wxUSE_WCHAR_T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// versions for passing wx[W]CharBuffer:
 | 
				
			||||||
 | 
					template<>
 | 
				
			||||||
 | 
					struct WXDLLIMPEXP_BASE wxArgNormalizer<wxCharBuffer>
 | 
				
			||||||
 | 
					            : public wxArgNormalizer<const char*>
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    wxArgNormalizer(const wxCharBuffer& buf);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<>
 | 
				
			||||||
 | 
					struct WXDLLIMPEXP_BASE wxArgNormalizer<wxWCharBuffer>
 | 
				
			||||||
 | 
					            : public wxArgNormalizer<const wchar_t*>
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    wxArgNormalizer(const wxWCharBuffer& buf);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NB: The vararg emulation code is limited to 30 arguments at the moment.
 | 
					// NB: The vararg emulation code is limited to 30 arguments at the moment.
 | 
				
			||||||
//     If you need more, you need to
 | 
					//     If you need more, you need to
 | 
				
			||||||
//        1) increase the value of _WX_VARARG_MAX_ARGS
 | 
					//        1) increase the value of _WX_VARARG_MAX_ARGS
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,3 +77,16 @@ const char *wxArgNormalizer<const wchar_t*>::get() const
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // wxUSE_UNICODE_WCHAR / !wxUSE_UNICODE_WCHAR && wxUSE_WCHAR_T
 | 
					#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<wxCharBuffer>::wxArgNormalizer(const wxCharBuffer& buf)
 | 
				
			||||||
 | 
					    : wxArgNormalizer<const char*>(buf.data())
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					wxArgNormalizer<wxWCharBuffer>::wxArgNormalizer(const wxWCharBuffer& buf)
 | 
				
			||||||
 | 
					    : wxArgNormalizer<const wchar_t*>(buf.data())
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,15 +53,26 @@ void VarArgTestCase::StringPrintf()
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    wxString s, s2;
 | 
					    wxString s, s2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // test passing literals:
 | 
				
			||||||
    s.Printf("%s %i", "foo", 42);
 | 
					    s.Printf("%s %i", "foo", 42);
 | 
				
			||||||
    CPPUNIT_ASSERT( s == "foo 42" );
 | 
					    CPPUNIT_ASSERT( s == "foo 42" );
 | 
				
			||||||
    s.Printf("%s %s %i", _T("bar"), "=", 11);
 | 
					    s.Printf("%s %s %i", _T("bar"), "=", 11);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // test passing c_str():
 | 
				
			||||||
    CPPUNIT_ASSERT( s == "bar = 11" );
 | 
					    CPPUNIT_ASSERT( s == "bar = 11" );
 | 
				
			||||||
    s2.Printf("(%s)", s.c_str());
 | 
					    s2.Printf("(%s)", s.c_str());
 | 
				
			||||||
    CPPUNIT_ASSERT( s2 == "(bar = 11)" );
 | 
					    CPPUNIT_ASSERT( s2 == "(bar = 11)" );
 | 
				
			||||||
    s2.Printf(_T("[%s](%s)"), s.c_str(), "str");
 | 
					    s2.Printf(_T("[%s](%s)"), s.c_str(), "str");
 | 
				
			||||||
    CPPUNIT_ASSERT( s2 == "[bar = 11](str)" );
 | 
					    CPPUNIT_ASSERT( s2 == "[bar = 11](str)" );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // test passing wxString directly:
 | 
				
			||||||
    s2.Printf(_T("[%s](%s)"), s, "str");
 | 
					    s2.Printf(_T("[%s](%s)"), s, "str");
 | 
				
			||||||
    CPPUNIT_ASSERT( s2 == "[bar = 11](str)" );
 | 
					    CPPUNIT_ASSERT( s2 == "[bar = 11](str)" );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // test passing wxCharBufferType<T>:
 | 
				
			||||||
 | 
					    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;" );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user