Simplify the code in wxTextFile::OnRead() slightly.

No real changes, just use a self-explanatory "lastWasCR" variable instead of
storing the last character read which wasn't used for anything except
comparing it with '\r'.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75010 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-10-15 13:04:27 +00:00
parent b845aa636a
commit e365d633f0

View File

@@ -208,8 +208,8 @@ bool wxTextFile::OnRead(const wxMBConv& conv)
// now break the buffer in lines // now break the buffer in lines
// last processed character, we need to know if it was a CR or not // was the last processed character a CR?
wxChar chLast = '\0'; bool lastWasCR = false;
// the beginning of the current line, changes inside the loop // the beginning of the current line, changes inside the loop
wxString::const_iterator lineStart = str.begin(); wxString::const_iterator lineStart = str.begin();
@@ -221,7 +221,7 @@ bool wxTextFile::OnRead(const wxMBConv& conv)
{ {
case '\n': case '\n':
// could be a DOS or Unix EOL // could be a DOS or Unix EOL
if ( chLast == '\r' ) if ( lastWasCR )
{ {
if ( p - 1 >= lineStart ) if ( p - 1 >= lineStart )
{ {
@@ -239,10 +239,11 @@ bool wxTextFile::OnRead(const wxMBConv& conv)
} }
lineStart = p + 1; lineStart = p + 1;
lastWasCR = false;
break; break;
case '\r': case '\r':
if ( chLast == '\r' ) if ( lastWasCR )
{ {
// Mac empty line // Mac empty line
AddLine(wxEmptyString, wxTextFileType_Mac); AddLine(wxEmptyString, wxTextFileType_Mac);
@@ -250,10 +251,12 @@ bool wxTextFile::OnRead(const wxMBConv& conv)
} }
//else: we don't know what this is yet -- could be a Mac EOL or //else: we don't know what this is yet -- could be a Mac EOL or
// start of DOS EOL so wait for next char // start of DOS EOL so wait for next char
lastWasCR = true;
break; break;
default: default:
if ( chLast == '\r' ) if ( lastWasCR )
{ {
// Mac line termination // Mac line termination
if ( p - 1 >= lineStart ) if ( p - 1 >= lineStart )
@@ -267,9 +270,8 @@ bool wxTextFile::OnRead(const wxMBConv& conv)
} }
lineStart = p; lineStart = p;
} }
lastWasCR = false;
} }
chLast = ch;
} }
// anything in the last line? // anything in the last line?
@@ -280,7 +282,7 @@ bool wxTextFile::OnRead(const wxMBConv& conv)
// be followed by a LF. // be followed by a LF.
wxString lastLine(lineStart, end); wxString lastLine(lineStart, end);
wxTextFileType lastType; wxTextFileType lastType;
if ( chLast == '\r' ) if ( lastWasCR )
{ {
// last line had Mac EOL, exclude it from the string // last line had Mac EOL, exclude it from the string
lastLine.RemoveLast(); lastLine.RemoveLast();