git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38401
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
wxASSERT( m_file.IsOpened() &&
(m_file.GetKind() != wxFILE_KIND_DISK || m_file.Tell() == 0) );
wxASSERT( m_file.IsOpened() &&
(m_file.GetKind() != wxFILE_KIND_DISK || m_file.Tell() == 0) );
+ static const size_t BUF_SIZE = 1024;
+#if wxUSE_UNICODE
+ static const size_t NUL_SIZE = 4;
+#else
+ static const size_t NUL_SIZE = 1;
+#endif
+
+ char buf[BUF_SIZE + NUL_SIZE];
wxChar chLast = '\0';
wxString str;
for ( ;; )
{
// leave space for trailing NUL
wxChar chLast = '\0';
wxString str;
for ( ;; )
{
// leave space for trailing NUL
- ssize_t nRead = m_file.Read(buf, WXSIZEOF(buf) - 1);
+ ssize_t nRead = m_file.Read(buf, BUF_SIZE);
if ( nRead == wxInvalidOffset )
{
if ( nRead == wxInvalidOffset )
{
+#if wxUSE_UNICODE
+ // we have to properly NUL-terminate the string for any encoding it may
+ // use -- 4 NULs should be enough for everyone (this is why we add 4
+ // extra bytes to the buffer)
+ buf[nRead] =
+ buf[nRead + 1] =
+ buf[nRead + 2] =
+ buf[nRead + 3] = '\0';
// append to the remains of the last block, don't overwrite
// append to the remains of the last block, don't overwrite
- str += wxString(buf, conv);
+ wxString strbuf(buf, conv);
+ if ( strbuf.empty() )
+ {
+ // conversion failed
+ return false;
+ }
+
+ str += strbuf;
+#else // ANSI
+ buf[nRead] = '\0';
+ str += buf;
+#endif // wxUSE_UNICODE/!wxUSE_UNICODE
+
// the beginning of the current line, changes inside the loop
const wxChar *lineStart = str.begin();
// the beginning of the current line, changes inside the loop
const wxChar *lineStart = str.begin();