Write correct number of bytes in wxFile::Write(wxString).

This function was broken for conversions using more than one byte per
character (e.g. UTF-16 or UTF-32) and also even for UTF-8 for strings
containing NUL bytes as it used strlen() to determine the number of bytes to
write out instead of using the really needed number.

Fix this by using the wxCharBuffer::length() method which always returns the
correct value.

Also add a wxFile unit test verifying that it can correctly read back a string
written using any of UTF-8, UTF-16 or UTF-32.

Closes #11192.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61898 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-09-12 22:40:42 +00:00
parent caa96da739
commit 227989f3e9
12 changed files with 132 additions and 1 deletions

View File

@@ -312,7 +312,7 @@ bool wxFile::Write(const wxString& s, const wxMBConv& conv)
if ( !buf )
return false;
const size_t size = strlen(buf); // FIXME: use buf.length() when available
const size_t size = buf.length();
return Write(buf, size) == size;
}