Handle strings with embedded NULs in wxDataStream
Read/write the entire string and not just the part until the first NUL in it. Closes #17556.
This commit is contained in:
@@ -72,6 +72,7 @@ All:
|
|||||||
- Add wxFileType::GetExpandedCommand() (troelsk).
|
- Add wxFileType::GetExpandedCommand() (troelsk).
|
||||||
- Make it easier to convert to/from UTF-8-encoded std::string (ARATA Mizuki).
|
- Make it easier to convert to/from UTF-8-encoded std::string (ARATA Mizuki).
|
||||||
- Add support for loading dynamic lexer in wxStyledTextCtrl (New Pagodi).
|
- Add support for loading dynamic lexer in wxStyledTextCtrl (New Pagodi).
|
||||||
|
- Handle strings with embedded NULs in wxDataStream (Nitch).
|
||||||
|
|
||||||
All (GUI):
|
All (GUI):
|
||||||
|
|
||||||
|
@@ -187,7 +187,7 @@ wxString wxDataInputStream::ReadString()
|
|||||||
if ( tmp )
|
if ( tmp )
|
||||||
{
|
{
|
||||||
m_input->Read(tmp.data(), len);
|
m_input->Read(tmp.data(), len);
|
||||||
ret = m_conv->cMB2WX(tmp.data());
|
ret = m_conv->cMB2WC(tmp.data(), len, NULL);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
wxStringBuffer buf(ret, len);
|
wxStringBuffer buf(ret, len);
|
||||||
@@ -590,10 +590,11 @@ void wxDataOutputStream::WriteString(const wxString& string)
|
|||||||
{
|
{
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
const wxWX2MBbuf buf = string.mb_str(*m_conv);
|
const wxWX2MBbuf buf = string.mb_str(*m_conv);
|
||||||
|
size_t len = buf.length();
|
||||||
#else
|
#else
|
||||||
const wxWX2MBbuf buf = string.mb_str();
|
const wxWX2MBbuf buf = string.mb_str();
|
||||||
|
size_t len = string.size();
|
||||||
#endif
|
#endif
|
||||||
size_t len = strlen(buf);
|
|
||||||
Write32(len);
|
Write32(len);
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
m_output->Write(buf, len);
|
m_output->Write(buf, len);
|
||||||
|
@@ -39,6 +39,7 @@ private:
|
|||||||
CPPUNIT_TEST_SUITE( DataStreamTestCase );
|
CPPUNIT_TEST_SUITE( DataStreamTestCase );
|
||||||
CPPUNIT_TEST( FloatRW );
|
CPPUNIT_TEST( FloatRW );
|
||||||
CPPUNIT_TEST( DoubleRW );
|
CPPUNIT_TEST( DoubleRW );
|
||||||
|
CPPUNIT_TEST( StringRW );
|
||||||
#if wxUSE_LONGLONG
|
#if wxUSE_LONGLONG
|
||||||
CPPUNIT_TEST( LongLongRW );
|
CPPUNIT_TEST( LongLongRW );
|
||||||
#endif
|
#endif
|
||||||
@@ -66,6 +67,7 @@ private:
|
|||||||
|
|
||||||
void FloatRW();
|
void FloatRW();
|
||||||
void DoubleRW();
|
void DoubleRW();
|
||||||
|
void StringRW();
|
||||||
#if wxUSE_LONGLONG
|
#if wxUSE_LONGLONG
|
||||||
void LongLongRW();
|
void LongLongRW();
|
||||||
#endif
|
#endif
|
||||||
@@ -236,6 +238,19 @@ void DataStreamTestCase::DoubleRW()
|
|||||||
CPPUNIT_ASSERT( TestFloatRW(21321343431.1232143432) == 21321343431.1232143432 );
|
CPPUNIT_ASSERT( TestFloatRW(21321343431.1232143432) == 21321343431.1232143432 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataStreamTestCase::StringRW()
|
||||||
|
{
|
||||||
|
wxString s(wxT("Test1"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL( TestRW(s), s );
|
||||||
|
|
||||||
|
s.append(2, wxT('\0'));
|
||||||
|
s.append(wxT("Test2"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL( TestRW(s), s );
|
||||||
|
|
||||||
|
s = wxString::FromUTF8("\xc3\xbc"); // U+00FC LATIN SMALL LETTER U WITH DIAERESIS
|
||||||
|
CPPUNIT_ASSERT_EQUAL( TestRW(s), s );
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_LONGLONG
|
#if wxUSE_LONGLONG
|
||||||
void DataStreamTestCase::LongLongRW()
|
void DataStreamTestCase::LongLongRW()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user