X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1b6dea5de110cd0c5695949d351436048e84e7f8..6342bd1ab36c1957684c00d408d09fba65d33db6:/src/common/textfile.cpp diff --git a/src/common/textfile.cpp b/src/common/textfile.cpp index 89a8e94033..c4863f5bc3 100644 --- a/src/common/textfile.cpp +++ b/src/common/textfile.cpp @@ -67,10 +67,10 @@ const wxChar *wxTextFile::GetEOL(wxTextFileType type) wxFAIL_MSG(wxT("bad file type in wxTextFile::GetEOL.")); // fall through nevertheless - we must return something... - case wxTextFileType_None: return wxT(_T("")); - case wxTextFileType_Unix: return wxT(_T("\n")); - case wxTextFileType_Dos: return wxT(_T("\r\n")); - case wxTextFileType_Mac: return wxT(_T("\r")); + case wxTextFileType_None: return wxT(""); + case wxTextFileType_Unix: return wxT("\n"); + case wxTextFileType_Dos: return wxT("\r\n"); + case wxTextFileType_Mac: return wxT("\r"); } } @@ -118,6 +118,10 @@ wxString wxTextFile::Translate(const wxString& text, wxTextFileType type) if ( chLast == _T('\r') ) { // Mac line termination result += eol; + + // reset chLast to avoid inserting another eol before the + // next character + chLast = 0; } // add to the current line @@ -282,7 +286,7 @@ bool wxTextFile::Read() char ch, chLast = '\0'; char buf[1024]; int n, nRead; - while ( !m_file.Eof() ) { + do { nRead = m_file.Read(buf, WXSIZEOF(buf)); if ( nRead == wxInvalidOffset ) { // read error (error message already given in wxFile::Read) @@ -325,7 +329,7 @@ bool wxTextFile::Read() } } } - } + } while ( nRead == WXSIZEOF(buf) ); // anything in the last line? if ( !str.IsEmpty() ) {