- case '\n':
- // Dos/Unix line termination
- *strPtr = '\0';
- AddLine(wxString(strBuf, conv),
- chLast == '\r' ? wxTextFileType_Dos
- : wxTextFileType_Unix);
- strPtr = strBuf;
- chLast = '\n';
- break;
-
- case '\r':
- if ( chLast == '\r' )
+ // read error (error message already given in wxFile::Read)
+ return false;
+ }
+
+ if ( nRead == 0 )
+ {
+ // if no bytes have been read, presumably this is a
+ // valid-but-empty file
+ if ( bufSize == 0 )
+ return true;
+
+ // otherwise we've finished reading the file
+ break;
+ }
+
+ // extend the buffer for new data
+ if ( !buf.extend(bufSize + nRead) )
+ return false;
+
+ // and append it to the buffer
+ memcpy(buf.data() + bufSize, block, nRead);
+ bufSize += nRead;
+ }
+ }
+
+ const wxString str(buf, conv, bufSize);
+
+ // there's no risk of this happening in ANSI build
+#if wxUSE_UNICODE
+ if ( bufSize > 4 && str.empty() )
+ {
+ wxLogError(_("Failed to convert file \"%s\" to Unicode."), GetName());
+ return false;
+ }
+#endif // wxUSE_UNICODE
+
+ // we don't need this memory any more
+ buf.reset();
+
+
+ // 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 )
+ {
+ case '\n':
+ // could be a DOS or Unix EOL
+ if ( chLast == '\r' )
+ {
+ if ( p - 1 >= lineStart )