Fix reading of files with Mac EOLs in wxTextFile.
The last CR-terminated line wasn't handled correctly. Fix this now and add unit tests to ensure that it stays fixed. Closes #15583. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75009 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -275,8 +275,24 @@ bool wxTextFile::OnRead(const wxMBConv& conv)
|
||||
// anything in the last line?
|
||||
if ( lineStart != end )
|
||||
{
|
||||
// add unterminated last line
|
||||
AddLine(wxString(lineStart, end), wxTextFileType_None);
|
||||
// add the last line, notice that it may have been terminated with CR
|
||||
// as we don't end the line immediately when we see a CR, as it could
|
||||
// be followed by a LF.
|
||||
wxString lastLine(lineStart, end);
|
||||
wxTextFileType lastType;
|
||||
if ( chLast == '\r' )
|
||||
{
|
||||
// last line had Mac EOL, exclude it from the string
|
||||
lastLine.RemoveLast();
|
||||
lastType = wxTextFileType_Mac;
|
||||
}
|
||||
else
|
||||
{
|
||||
// last line wasn't terminated at all
|
||||
lastType = wxTextFileType_None;
|
||||
}
|
||||
|
||||
AddLine(lastLine, lastType);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user