+ if ( nRead == 0 )
+ break;
+
+ // this shouldn't happen but don't overwrite the buffer if it does
+ wxCHECK_MSG( bufPos + nRead <= bufSize, false,
+ _T("read more than file length?") );
+
+ // append to the buffer
+ memcpy(buf.data() + bufPos, block, nRead);
+ bufPos += nRead;
+ }
+
+ const wxString str(buf, conv, bufPos);
+
+ // this doesn't risk to happen in ANSI build
+#if wxUSE_UNICODE
+ if ( bufSize > 4 && str.empty() )
+ {
+ wxLogError(_("Failed to convert file contents to Unicode."));
+ return false;
+ }
+#endif // wxUSE_UNICODE
+
+ free(buf.release()); // we don't need this memory any more
+
+
+ // now break the buffer in lines
+
+ // last processed character, we need to know if it was a CR or not
+ wxChar chLast = '\0';
+
+ // the beginning of the current line, changes inside the loop
+ wxString::const_iterator lineStart = str.begin();
+ const wxString::const_iterator end = str.end();
+ for ( wxString::const_iterator p = lineStart; p != end; p++ )
+ {
+ const wxChar ch = *p;
+ switch ( ch )