From e365d633f0aaa9e452ab90e0ce3ec242cd3b948e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 15 Oct 2013 13:04:27 +0000 Subject: [PATCH] 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 --- src/common/textfile.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/common/textfile.cpp b/src/common/textfile.cpp index 4607fc207b..ddf88c9e46 100644 --- a/src/common/textfile.cpp +++ b/src/common/textfile.cpp @@ -208,8 +208,8 @@ bool wxTextFile::OnRead(const wxMBConv& conv) // now break the buffer in lines - // last processed character, we need to know if it was a CR or not - wxChar chLast = '\0'; + // was the last processed character a CR? + bool lastWasCR = false; // the beginning of the current line, changes inside the loop wxString::const_iterator lineStart = str.begin(); @@ -221,7 +221,7 @@ bool wxTextFile::OnRead(const wxMBConv& conv) { case '\n': // could be a DOS or Unix EOL - if ( chLast == '\r' ) + if ( lastWasCR ) { if ( p - 1 >= lineStart ) { @@ -239,10 +239,11 @@ bool wxTextFile::OnRead(const wxMBConv& conv) } lineStart = p + 1; + lastWasCR = false; break; case '\r': - if ( chLast == '\r' ) + if ( lastWasCR ) { // Mac empty line 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 // start of DOS EOL so wait for next char + + lastWasCR = true; break; default: - if ( chLast == '\r' ) + if ( lastWasCR ) { // Mac line termination if ( p - 1 >= lineStart ) @@ -267,9 +270,8 @@ bool wxTextFile::OnRead(const wxMBConv& conv) } lineStart = p; } + lastWasCR = false; } - - chLast = ch; } // anything in the last line? @@ -280,7 +282,7 @@ bool wxTextFile::OnRead(const wxMBConv& conv) // be followed by a LF. wxString lastLine(lineStart, end); wxTextFileType lastType; - if ( chLast == '\r' ) + if ( lastWasCR ) { // last line had Mac EOL, exclude it from the string lastLine.RemoveLast();