added wxUTF8StringBuffer for writing UTF8 data into wxString efficiently, similarly to existing wxStringBuffer classes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48222 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2007-08-20 15:19:15 +00:00
parent 4f1cf94b94
commit 628f87da56
3 changed files with 78 additions and 6 deletions

View File

@@ -53,6 +53,7 @@ private:
#endif // wxLongLong_t
CPPUNIT_TEST( ToDouble );
CPPUNIT_TEST( WriteBuf );
CPPUNIT_TEST( UTF8Buf );
CPPUNIT_TEST( CStrDataTernaryOperator );
CPPUNIT_TEST( CStrDataOperators );
CPPUNIT_TEST( CStrDataImplicitConversion );
@@ -80,6 +81,7 @@ private:
#endif // wxLongLong_t
void ToDouble();
void WriteBuf();
void UTF8Buf();
void CStrDataTernaryOperator();
void DoCStrDataTernaryOperator(bool cond);
void CStrDataOperators();
@@ -676,6 +678,26 @@ void StringTestCase::WriteBuf()
CPPUNIT_ASSERT_EQUAL( 0, wxStrcmp(_T("barr"), s) );
}
void StringTestCase::UTF8Buf()
{
#if wxUSE_UNICODE
// "czech" in Czech ("cestina"):
static const char *textUTF8 = "\304\215e\305\241tina";
static const wchar_t textUTF16[] = {0x10D, 0x65, 0x161, 0x74, 0x69, 0x6E, 0x61, 0};
wxString s;
wxStrcpy(wxUTF8StringBuffer(s, 9), textUTF8);
CPPUNIT_ASSERT(s == textUTF16);
{
wxUTF8StringBufferLength buf(s, 20);
wxStrcpy(buf, textUTF8);
buf.SetLength(5);
}
CPPUNIT_ASSERT(s == wxString(textUTF16, 0, 3));
#endif // wxUSE_UNICODE
}
void StringTestCase::CStrDataTernaryOperator()